plugins/mod_saslauth.lua

changeset 3523
32a0c3816d73
parent 3468
d50e2c937717
child 3524
d206b4e0a9f3
equal deleted inserted replaced
3522:4646b5b039ca 3523:32a0c3816d73
139 features:tag("bind", bind_attr):tag("required"):up():up(); 139 features:tag("bind", bind_attr):tag("required"):up():up();
140 features:tag("session", xmpp_session_attr):tag("optional"):up():up(); 140 features:tag("session", xmpp_session_attr):tag("optional"):up():up();
141 end 141 end
142 end); 142 end);
143 143
144 module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", function(session, stanza) 144 module:hook("iq/self/urn:ietf:params:xml:ns:xmpp-bind:bind", function(event)
145 log("debug", "Client requesting a resource bind"); 145 log("debug", "Client requesting a resource bind");
146 local origin, stanza = event.origin, event.stanza;
146 local resource; 147 local resource;
147 if stanza.attr.type == "set" then 148 if stanza.attr.type == "set" then
148 local bind = stanza.tags[1]; 149 local bind = stanza.tags[1];
149 if bind and bind.attr.xmlns == xmlns_bind then 150 resource = bind:child_with_name("resource");
150 resource = bind:child_with_name("resource"); 151 resource = resource and #resource.tags == 0 and resource[1] or nil;
151 if resource then
152 resource = resource[1];
153 end
154 end
155 end 152 end
156 local success, err_type, err, err_msg = sm_bind_resource(session, resource); 153 local success, err_type, err, err_msg = sm_bind_resource(origin, resource);
157 if not success then 154 if success then
158 session.send(st.error_reply(stanza, err_type, err, err_msg)); 155 origin.send(st.reply(stanza)
156 :tag("bind", { xmlns = xmlns_bind })
157 :tag("jid"):text(origin.full_jid));
159 else 158 else
160 session.send(st.reply(stanza) 159 origin.send(st.error_reply(stanza, err_type, err, err_msg));
161 :tag("bind", { xmlns = xmlns_bind})
162 :tag("jid"):text(session.full_jid));
163 end 160 end
161 return true;
164 end); 162 end);
165 163
166 module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", function(session, stanza) 164 module:hook("iq/self/urn:ietf:params:xml:ns:xmpp-session:session", function(event)
167 log("debug", "Client requesting a session"); 165 log("debug", "Client requesting a session");
168 session.send(st.reply(stanza)); 166 event.origin.send(st.reply(event.stanza));
167 return true;
169 end); 168 end);

mercurial