From 2e66b95ef050df22e0e8db753a0893f80637ae86 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 16 Oct 2010 05:03:00 +0500 Subject: mod_saslauth: Updated to use the new events API. --- plugins/mod_saslauth.lua | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'plugins/mod_saslauth.lua') diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 732d5d91..7fb22b3e 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -141,29 +141,28 @@ module:hook("stream-features", function(event) end end); -module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", function(session, stanza) +module:hook("iq/self/urn:ietf:params:xml:ns:xmpp-bind:bind", function(event) log("debug", "Client requesting a resource bind"); + local origin, stanza = event.origin, event.stanza; local resource; if stanza.attr.type == "set" then local bind = stanza.tags[1]; - if bind and bind.attr.xmlns == xmlns_bind then - resource = bind:child_with_name("resource"); - if resource then - resource = resource[1]; - end - end + resource = bind:child_with_name("resource"); + resource = resource and #resource.tags == 0 and resource[1] or nil; end - local success, err_type, err, err_msg = sm_bind_resource(session, resource); - if not success then - session.send(st.error_reply(stanza, err_type, err, err_msg)); + local success, err_type, err, err_msg = sm_bind_resource(origin, resource); + if success then + origin.send(st.reply(stanza) + :tag("bind", { xmlns = xmlns_bind }) + :tag("jid"):text(origin.full_jid)); else - session.send(st.reply(stanza) - :tag("bind", { xmlns = xmlns_bind}) - :tag("jid"):text(session.full_jid)); + origin.send(st.error_reply(stanza, err_type, err, err_msg)); end + return true; end); -module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", function(session, stanza) +module:hook("iq/self/urn:ietf:params:xml:ns:xmpp-session:session", function(event) log("debug", "Client requesting a session"); - session.send(st.reply(stanza)); + event.origin.send(st.reply(event.stanza)); + return true; end); -- cgit v1.2.3