diff options
author | Waqas Hussain <waqas20@gmail.com> | 2010-11-02 21:19:50 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2010-11-02 21:19:50 +0500 |
commit | 3b185b580e413ebb763c616b347428ec7e999716 (patch) | |
tree | 8eb7c9a16f1c5bb0078e912418c83e566aee72ed | |
parent | 372813b78e29479f655712c651a1a57828423987 (diff) | |
download | prosody-3b185b580e413ebb763c616b347428ec7e999716.tar.gz prosody-3b185b580e413ebb763c616b347428ec7e999716.zip |
mod_saslauth: Moved SASL mechanism selection and CDATA handling into separate functions.
-rw-r--r-- | plugins/mod_saslauth.lua | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 85f7fcbf..28ec1416 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -72,6 +72,25 @@ local function handle_status(session, status, ret, err_msg) return status, ret, err_msg; end +local function sasl_process_cdata(session, stanza) + local text = stanza[1]; + if text then + text = base64.decode(text); + --log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " ")); + if not text then + session.sasl_handler = nil; + session.send(build_reply("failure", "incorrect-encoding")); + return true; + end + end + local status, ret, err_msg = session.sasl_handler:process(text); + status, ret, err_msg = handle_status(session, status, ret, err_msg); + local s = build_reply(status, ret, err_msg); + log("debug", "sasl reply: %s", tostring(s)); + session.send(s); + return true; +end + local function sasl_handler(event) local session, stanza = event.origin, event.stanza; if session.type ~= "c2s_unauthed" then return; end @@ -100,22 +119,7 @@ local function sasl_handler(event) elseif not session.sasl_handler then return true; -- FIXME ignoring out of order stanzas because ejabberd does end - local text = stanza[1]; - if text then - text = base64.decode(text); - --log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " ")); - if not text then - session.sasl_handler = nil; - session.send(build_reply("failure", "incorrect-encoding")); - return true; - end - end - local status, ret, err_msg = session.sasl_handler:process(text); - status, ret, err_msg = handle_status(session, status, ret, err_msg); - local s = build_reply(status, ret, err_msg); - log("debug", "sasl reply: %s", tostring(s)); - session.send(s); - return true; + return sasl_process_cdata(session, stanza); end module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:auth", sasl_handler); |