Comparison

plugins/mod_register.lua @ 4269:cd4011af8b4c

mod_register: Move allow_registration option into an upvalue for efficiency (now it is being checked on every new c2s stream)
author Matthew Wild <mwild1@gmail.com>
date Sat, 28 May 2011 00:21:12 +0100
parent 4268:c249f10eb9bb
child 4270:d2d47fde9811
comparison
equal deleted inserted replaced
4268:c249f10eb9bb 4269:cd4011af8b4c
17 local os_time = os.time; 17 local os_time = os.time;
18 local nodeprep = require "util.encodings".stringprep.nodeprep; 18 local nodeprep = require "util.encodings".stringprep.nodeprep;
19 local jid_bare = require "util.jid".bare; 19 local jid_bare = require "util.jid".bare;
20 20
21 local compat = module:get_option_boolean("registration_compat", true); 21 local compat = module:get_option_boolean("registration_compat", true);
22 local allow_registration = module:get_option_boolean("allow_registration", true);
22 23
23 module:add_feature("jabber:iq:register"); 24 module:add_feature("jabber:iq:register");
24 25
25 local register_stream_feature = st.stanza("register", {xmlns="http://jabber.org/features/iq-register"}):up(); 26 local register_stream_feature = st.stanza("register", {xmlns="http://jabber.org/features/iq-register"}):up();
26 module:hook("stream-features", function(event) 27 module:hook("stream-features", function(event)
27 local session, features = event.origin, event.features; 28 local session, features = event.origin, event.features;
28 29
29 -- Advertise registration to unauthorized clients only. 30 -- Advertise registration to unauthorized clients only.
30 if module:get_option("allow_registration") == false or session.type ~= "c2s_unauthed" then 31 if not(allow_registration) or session.type ~= "c2s_unauthed" then
31 return 32 return
32 end 33 end
33 34
34 features:add_child(register_stream_feature); 35 features:add_child(register_stream_feature);
35 end); 36 end);
124 for _, ip in ipairs(blacklisted_ips) do blacklisted_ips[ip] = true; end 125 for _, ip in ipairs(blacklisted_ips) do blacklisted_ips[ip] = true; end
125 126
126 module:hook("stanza/iq/jabber:iq:register:query", function(event) 127 module:hook("stanza/iq/jabber:iq:register:query", function(event)
127 local session, stanza = event.origin, event.stanza; 128 local session, stanza = event.origin, event.stanza;
128 129
129 if module:get_option("allow_registration") == false or session.type ~= "c2s_unauthed" then 130 if not(allow_registration) or session.type ~= "c2s_unauthed" then
130 session.send(st.error_reply(stanza, "cancel", "service-unavailable")); 131 session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
131 else 132 else
132 local query = stanza.tags[1]; 133 local query = stanza.tags[1];
133 if stanza.attr.type == "get" then 134 if stanza.attr.type == "get" then
134 local reply = st.reply(stanza); 135 local reply = st.reply(stanza);