1 |
1 |
2 local st = require "util.stanza"; |
2 local st = require "util.stanza"; |
3 local send = require "core.sessionmanager".send_to_session; |
|
4 local t_concat = table.concat; |
3 local t_concat = table.concat; |
5 |
4 |
6 add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
5 add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
7 function (session, stanza) |
6 function (session, stanza) |
8 local username = stanza.tags[1]:child_with_name("username"); |
7 local username = stanza.tags[1]:child_with_name("username"); |
9 local password = stanza.tags[1]:child_with_name("password"); |
8 local password = stanza.tags[1]:child_with_name("password"); |
10 local resource = stanza.tags[1]:child_with_name("resource"); |
9 local resource = stanza.tags[1]:child_with_name("resource"); |
11 if not (username and password and resource) then |
10 if not (username and password and resource) then |
12 local reply = st.reply(stanza); |
11 local reply = st.reply(stanza); |
13 send(session, reply:query("jabber:iq:auth") |
12 session.send(reply:query("jabber:iq:auth") |
14 :tag("username"):up() |
13 :tag("username"):up() |
15 :tag("password"):up() |
14 :tag("password"):up() |
16 :tag("resource"):up()); |
15 :tag("resource"):up()); |
17 return true; |
16 return true; |
18 else |
17 else |
28 if not success then |
27 if not success then |
29 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
28 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
30 return true; |
29 return true; |
31 end |
30 end |
32 end |
31 end |
33 send(session, st.reply(stanza)); |
32 session.send(st.reply(stanza)); |
34 return true; |
33 return true; |
35 else |
34 else |
36 local reply = st.reply(stanza); |
35 local reply = st.reply(stanza); |
37 reply.attr.type = "error"; |
36 reply.attr.type = "error"; |
38 reply:tag("error", { code = "401", type = "auth" }) |
37 reply:tag("error", { code = "401", type = "auth" }) |
39 :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); |
38 :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); |
40 send(session, reply); |
39 session.send(reply); |
41 return true; |
40 return true; |
42 end |
41 end |
43 end |
42 end |
44 |
43 |
45 end); |
44 end); |