# HG changeset patch # User Waqas Hussain # Date 1287187380 -18000 # Node ID 32a0c3816d739ddcefd79ae557d11595ee3b3f19 # Parent 4646b5b039ca821576aa1306cb23a9131929555d mod_saslauth: Updated to use the new events API. diff -r 4646b5b039ca -r 32a0c3816d73 plugins/mod_saslauth.lua --- a/plugins/mod_saslauth.lua Sat Oct 16 04:11:48 2010 +0500 +++ b/plugins/mod_saslauth.lua Sat Oct 16 05:03:00 2010 +0500 @@ -141,29 +141,28 @@ 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);