Software /
code /
verse
Annotate
plugins/legacy.lua @ 223:30e66eabffa9
squishy: add vcard, vcard_update, jingle_ibb
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 02 Nov 2011 01:11:35 +0100 |
parent | 181:c61ba3d1b39a |
child | 250:a5ac643a7fd6 |
rev | line source |
---|---|
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local uuid = require "util.uuid".generate; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local xmlns_auth = "jabber:iq:auth"; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 function verse.plugins.legacy(stream) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 function handle_auth_form(result) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local query = result:get_child("query", xmlns_auth); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 if result.attr.type ~= "result" or not query then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local type, cond, text = result:get_error(); |
169
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
10 stream:debug("warn", "%s %s: %s", type, cond, text); |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
11 --stream:event("authentication-failure", { condition = cond }); |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
12 -- COMPAT continue anyways |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local auth_data = { |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 username = stream.username; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 password = stream.password; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 resource = stream.resource or uuid(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 digest = false, sequence = false, token = false; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 }; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local request = verse.iq({ to = stream.host, type = "set" }) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 :tag("query", { xmlns = xmlns_auth }); |
169
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
22 if #query > 0 then |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 for tag in query:childtags() do |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local field = tag.name; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local value = auth_data[field]; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 if value then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 request:tag(field):text(auth_data[field]):up(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 elseif value == nil then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local cond = "feature-not-implemented"; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 return false; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
169
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
34 else -- COMPAT for servers not following XEP 78 |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
35 for field, value in pairs(auth_data) do |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
36 if value then |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
37 request:tag(field):text(value):up(); |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
38 end |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
39 end |
4bb1e9c91fbe
plugins.legacy: Try to login anyways, compat for servers not supporting XEP 78 properly.
Kim Alvefur <zash@zash.se>
parents:
152
diff
changeset
|
40 end |
152
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 stream:send_iq(request, function (response) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 if response.attr.type == "result" then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 stream.resource = auth_data.resource; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 stream.jid = auth_data.username.."@"..stream.host.."/"..auth_data.resource; |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 stream:event("authentication-success"); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 stream:event("bind-success", stream.jid); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 else |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 local type, cond, text = response:get_error(); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 stream:event("authentication-failure", { condition = cond }); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 function handle_opened(attr) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 if not attr.version then |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 stream:send_iq(verse.iq({type="get"}) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 :tag("query", { xmlns = "jabber:iq:auth" }) |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 :tag("username"):text(stream.username), |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 handle_auth_form); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 stream:hook("opened", handle_opened); |
55ea7ffafd7f
plugins.legacy: Support for legacy non-SASL authentication :(
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |