Software /
code /
verse
Comparison
plugins/legacy.lua @ 152:55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Nov 2010 03:12:53 +0000 |
child | 169:4bb1e9c91fbe |
child | 174:1c8d48120e21 |
comparison
equal
deleted
inserted
replaced
151:75016d851648 | 152:55ea7ffafd7f |
---|---|
1 local uuid = require "util.uuid".generate; | |
2 | |
3 local xmlns_auth = "jabber:iq:auth"; | |
4 | |
5 function verse.plugins.legacy(stream) | |
6 function handle_auth_form(result) | |
7 local query = result:get_child("query", xmlns_auth); | |
8 if result.attr.type ~= "result" or not query then | |
9 local type, cond, text = result:get_error(); | |
10 stream:event("authentication-failure", { condition = cond }); | |
11 end | |
12 local auth_data = { | |
13 username = stream.username; | |
14 password = stream.password; | |
15 resource = stream.resource or uuid(); | |
16 digest = false, sequence = false, token = false; | |
17 }; | |
18 local request = verse.iq({ to = stream.host, type = "set" }) | |
19 :tag("query", { xmlns = xmlns_auth }); | |
20 for tag in query:childtags() do | |
21 local field = tag.name; | |
22 local value = auth_data[field]; | |
23 if value then | |
24 request:tag(field):text(auth_data[field]):up(); | |
25 elseif value == nil then | |
26 local cond = "feature-not-implemented"; | |
27 stream:event("authentication-failure", { condition = cond }); | |
28 return false; | |
29 end | |
30 end | |
31 stream:send_iq(request, function (response) | |
32 if response.attr.type == "result" then | |
33 stream.resource = auth_data.resource; | |
34 stream.jid = auth_data.username.."@"..stream.host.."/"..auth_data.resource; | |
35 stream:event("authentication-success"); | |
36 stream:event("bind-success", stream.jid); | |
37 else | |
38 local type, cond, text = response:get_error(); | |
39 stream:event("authentication-failure", { condition = cond }); | |
40 end | |
41 end); | |
42 end | |
43 | |
44 function handle_opened(attr) | |
45 if not attr.version then | |
46 stream:send_iq(verse.iq({type="get"}) | |
47 :tag("query", { xmlns = "jabber:iq:auth" }) | |
48 :tag("username"):text(stream.username), | |
49 handle_auth_form); | |
50 | |
51 end | |
52 end | |
53 stream:hook("opened", handle_opened); | |
54 end |