mod_register: Move allow_registration option into an upvalue for efficiency (now it is being checked on every new c2s stream)
authorMatthew Wild <mwild1@gmail.com>
Sat, 28 May 2011 00:21:12 +0100
changeset 4269 cd4011af8b4c
parent 4268 c249f10eb9bb
child 4270 d2d47fde9811
mod_register: Move allow_registration option into an upvalue for efficiency (now it is being checked on every new c2s stream)
plugins/mod_register.lua
--- a/plugins/mod_register.lua	Fri May 27 17:04:43 2011 +0100
+++ b/plugins/mod_register.lua	Sat May 28 00:21:12 2011 +0100
@@ -19,6 +19,7 @@
 local jid_bare = require "util.jid".bare;
 
 local compat = module:get_option_boolean("registration_compat", true);
+local allow_registration = module:get_option_boolean("allow_registration", true);
 
 module:add_feature("jabber:iq:register");
 
@@ -27,7 +28,7 @@
         local session, features = event.origin, event.features;
 
 	-- Advertise registration to unauthorized clients only.
-	if module:get_option("allow_registration") == false or session.type ~= "c2s_unauthed" then
+	if not(allow_registration) or session.type ~= "c2s_unauthed" then
 		return
 	end
 
@@ -126,7 +127,7 @@
 module:hook("stanza/iq/jabber:iq:register:query", function(event)
 	local session, stanza = event.origin, event.stanza;
 
-	if module:get_option("allow_registration") == false or session.type ~= "c2s_unauthed" then
+	if not(allow_registration) or session.type ~= "c2s_unauthed" then
 		session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
 	else
 		local query = stanza.tags[1];