5 function verse.plugins.legacy(stream) |
5 function verse.plugins.legacy(stream) |
6 function handle_auth_form(result) |
6 function handle_auth_form(result) |
7 local query = result:get_child("query", xmlns_auth); |
7 local query = result:get_child("query", xmlns_auth); |
8 if result.attr.type ~= "result" or not query then |
8 if result.attr.type ~= "result" or not query then |
9 local type, cond, text = result:get_error(); |
9 local type, cond, text = result:get_error(); |
10 stream:event("authentication-failure", { condition = cond }); |
10 stream:debug("warn", "%s %s: %s", type, cond, text); |
|
11 --stream:event("authentication-failure", { condition = cond }); |
|
12 -- COMPAT continue anyways |
11 end |
13 end |
12 local auth_data = { |
14 local auth_data = { |
13 username = stream.username; |
15 username = stream.username; |
14 password = stream.password; |
16 password = stream.password; |
15 resource = stream.resource or uuid(); |
17 resource = stream.resource or uuid(); |
16 digest = false, sequence = false, token = false; |
18 digest = false, sequence = false, token = false; |
17 }; |
19 }; |
18 local request = verse.iq({ to = stream.host, type = "set" }) |
20 local request = verse.iq({ to = stream.host, type = "set" }) |
19 :tag("query", { xmlns = xmlns_auth }); |
21 :tag("query", { xmlns = xmlns_auth }); |
|
22 if #query > 0 then |
20 for tag in query:childtags() do |
23 for tag in query:childtags() do |
21 local field = tag.name; |
24 local field = tag.name; |
22 local value = auth_data[field]; |
25 local value = auth_data[field]; |
23 if value then |
26 if value then |
24 request:tag(field):text(auth_data[field]):up(); |
27 request:tag(field):text(auth_data[field]):up(); |
25 elseif value == nil then |
28 elseif value == nil then |
26 local cond = "feature-not-implemented"; |
29 local cond = "feature-not-implemented"; |
27 stream:event("authentication-failure", { condition = cond }); |
30 stream:event("authentication-failure", { condition = cond }); |
28 return false; |
31 return false; |
|
32 end |
|
33 end |
|
34 else -- COMPAT for servers not following XEP 78 |
|
35 for field, value in pairs(auth_data) do |
|
36 if value then |
|
37 request:tag(field):text(value):up(); |
|
38 end |
29 end |
39 end |
30 end |
40 end |
31 stream:send_iq(request, function (response) |
41 stream:send_iq(request, function (response) |
32 if response.attr.type == "result" then |
42 if response.attr.type == "result" then |
33 stream.resource = auth_data.resource; |
43 stream.resource = auth_data.resource; |