Comparison

plugins/sasl.lua @ 399:82ad158714e5

Merge with Zash
author Matthew Wild <mwild1@gmail.com>
date Tue, 12 Jan 2016 13:14:36 +0000
parent 395:e86144a4eaa1
child 456:6a65142052c8
comparison
equal deleted inserted replaced
378:6042c938e369 399:82ad158714e5
1 -- local verse = require"verse"; 1 local verse = require"verse";
2 local base64, unbase64 = require "mime".b64, require"mime".unb64; 2 local base64, unbase64 = require "mime".b64, require"mime".unb64;
3 local xmlns_sasl = "urn:ietf:params:xml:ns:xmpp-sasl"; 3 local xmlns_sasl = "urn:ietf:params:xml:ns:xmpp-sasl";
4 4
5 function verse.plugins.sasl(stream) 5 function verse.plugins.sasl(stream)
6 local function handle_features(features_stanza) 6 local function handle_features(features_stanza)
46 auth_stanza:text(base64(initial_data)); 46 auth_stanza:text(base64(initial_data));
47 end 47 end
48 stream:send(auth_stanza); 48 stream:send(auth_stanza);
49 return true; 49 return true;
50 end 50 end
51 51
52 local function handle_sasl(sasl_stanza) 52 local function handle_sasl(sasl_stanza)
53 if sasl_stanza.name == "failure" then 53 if sasl_stanza.name == "failure" then
54 local err = sasl_stanza.tags[1]; 54 local err = sasl_stanza.tags[1];
55 local text = sasl_stanza:get_child_text("text"); 55 local text = sasl_stanza:get_child_text("text");
56 stream:event("authentication-failure", { condition = err.name, text = text }); 56 stream:event("authentication-failure", { condition = err.name, text = text });
69 else 69 else
70 stream:send(verse.stanza("response", { xmlns = xmlns_sasl }):text(base64(ok))); 70 stream:send(verse.stanza("response", { xmlns = xmlns_sasl }):text(base64(ok)));
71 end 71 end
72 return true; 72 return true;
73 end 73 end
74 74
75 stream:hook("stream-features", handle_features, 300); 75 stream:hook("stream-features", handle_features, 300);
76 stream:hook("stream/"..xmlns_sasl, handle_sasl); 76 stream:hook("stream/"..xmlns_sasl, handle_sasl);
77 77
78 return true; 78 return true;
79 end 79 end
80 80