38 local new_sasl = require "util.sasl".new; |
38 local new_sasl = require "util.sasl".new; |
39 |
39 |
40 local function build_reply(status, ret, err_msg) |
40 local function build_reply(status, ret, err_msg) |
41 local reply = st.stanza(status, {xmlns = xmlns_sasl}); |
41 local reply = st.stanza(status, {xmlns = xmlns_sasl}); |
42 if status == "challenge" then |
42 if status == "challenge" then |
43 log("challenge", ret or ""); |
43 log("debug", ret or ""); |
44 reply:text(base64.encode(ret or "")); |
44 reply:text(base64.encode(ret or "")); |
45 elseif status == "failure" then |
45 elseif status == "failure" then |
46 reply:tag(ret):up(); |
46 reply:tag(ret):up(); |
47 if err_msg then reply:tag("text"):text(err_msg); end |
47 if err_msg then reply:tag("text"):text(err_msg); end |
48 elseif status == "success" then |
48 elseif status == "success" then |
49 log("success", ret or ""); |
49 log("debug", ret or ""); |
50 reply:text(base64.encode(ret or "")); |
50 reply:text(base64.encode(ret or "")); |
51 else |
51 else |
52 error("Unknown sasl status: "..status); |
52 error("Unknown sasl status: "..status); |
53 end |
53 end |
54 return reply; |
54 return reply; |
87 return; -- FIXME ignoring out of order stanzas because ejabberd does |
87 return; -- FIXME ignoring out of order stanzas because ejabberd does |
88 end |
88 end |
89 local text = stanza[1]; |
89 local text = stanza[1]; |
90 if text then |
90 if text then |
91 text = base64.decode(text); |
91 text = base64.decode(text); |
92 log("recieved", text); |
92 log("debug", text); |
93 if not text then |
93 if not text then |
94 session.sasl_handler = nil; |
94 session.sasl_handler = nil; |
95 session.send(build_reply("failure", "incorrect-encoding")); |
95 session.send(build_reply("failure", "incorrect-encoding")); |
96 return; |
96 return; |
97 end |
97 end |