Mercurial > prosody-modules
comparison mod_inject_ecaps2/mod_insert_ecaps2.lua @ 2908:5665d14dcc6e
mod_inject_ecaps2: Add Lua 5.1 compatibility by replacing \xHEX with \DECIMAL in strings
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 07 Mar 2018 19:39:52 +0100 |
parents | 776017c92076 |
children |
comparison
equal
deleted
inserted
replaced
2907:776017c92076 | 2908:5665d14dcc6e |
---|---|
16 -- TODO: move that to util.caps maybe. | 16 -- TODO: move that to util.caps maybe. |
17 local function calculate_hash(disco_info) | 17 local function calculate_hash(disco_info) |
18 local identities, features, extensions = {}, {}, {}; | 18 local identities, features, extensions = {}, {}, {}; |
19 for _, tag in ipairs(disco_info) do | 19 for _, tag in ipairs(disco_info) do |
20 if tag.name == "identity" then | 20 if tag.name == "identity" then |
21 t_insert(identities, ((tag.attr.category or "").."\x1f".. | 21 t_insert(identities, ((tag.attr.category or "").."\31".. |
22 (tag.attr.type or "").."\x1f".. | 22 (tag.attr.type or "").."\31".. |
23 (tag.attr["xml:lang"] or "").."\x1f".. | 23 (tag.attr["xml:lang"] or "").."\31".. |
24 (tag.attr.name or "").."\x1f\x1e")); | 24 (tag.attr.name or "").."\31\30")); |
25 elseif tag.name == "feature" then | 25 elseif tag.name == "feature" then |
26 t_insert(features, (tag.attr.var or "").."\x1f"); | 26 t_insert(features, (tag.attr.var or "").."\31"); |
27 elseif tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then | 27 elseif tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then |
28 local form = {}; | 28 local form = {}; |
29 for _, field in ipairs(tag.tags) do | 29 for _, field in ipairs(tag.tags) do |
30 if field.name == "field" and field.attr.xmlns == "jabber:x:data" and field.attr.var then | 30 if field.name == "field" and field.attr.xmlns == "jabber:x:data" and field.attr.var then |
31 local values = {}; | 31 local values = {}; |
32 for _, value in ipairs(field.tags) do | 32 for _, value in ipairs(field.tags) do |
33 if value.name == "value" and value.attr.xmlns == "jabber:x:data" then | 33 if value.name == "value" and value.attr.xmlns == "jabber:x:data" then |
34 value = #value.tags == 0 and value:get_text(); | 34 value = #value.tags == 0 and value:get_text(); |
35 if value then t_insert(values, value.."\x1f"); end | 35 if value then t_insert(values, value.."\31"); end |
36 end | 36 end |
37 end | 37 end |
38 t_sort(values); | 38 t_sort(values); |
39 if #values > 0 then | 39 if #values > 0 then |
40 t_insert(form, field.attr.var.."\x1f"..t_concat(values, "\x1f").."\x1f\x1e"); | 40 t_insert(form, field.attr.var.."\31"..t_concat(values, "\31").."\31\30"); |
41 else | 41 else |
42 t_insert(form, field.attr.var.."\x1f\x1e"); | 42 t_insert(form, field.attr.var.."\31\30"); |
43 end | 43 end |
44 end | 44 end |
45 end | 45 end |
46 t_sort(form); | 46 t_sort(form); |
47 form = t_concat(form, "\x1d").."\x1d"; | 47 form = t_concat(form, "\29").."\29"; |
48 t_insert(extensions, form); | 48 t_insert(extensions, form); |
49 else | 49 else |
50 return nil, "Unknown element in disco#info"; | 50 return nil, "Unknown element in disco#info"; |
51 end | 51 end |
52 end | 52 end |
53 t_sort(identities); | 53 t_sort(identities); |
54 t_sort(features); | 54 t_sort(features); |
55 t_sort(extensions); | 55 t_sort(extensions); |
56 if #identities > 0 then identities = t_concat(identities, "\x1c").."\x1c"; else identities = "\x1c"; end | 56 if #identities > 0 then identities = t_concat(identities, "\28").."\28"; else identities = "\28"; end |
57 if #features > 0 then features = t_concat(features).."\x1c"; else features = "\x1c"; end | 57 if #features > 0 then features = t_concat(features).."\28"; else features = "\28"; end |
58 if #extensions > 0 then extensions = t_concat(extensions, "\x1c").."\x1c"; else extensions = "\x1c"; end | 58 if #extensions > 0 then extensions = t_concat(extensions, "\28").."\28"; else extensions = "\28"; end |
59 return features..identities..extensions; | 59 return features..identities..extensions; |
60 end | 60 end |
61 | 61 |
62 local function caps_handler(event) | 62 local function caps_handler(event) |
63 local origin = event.origin; | 63 local origin = event.origin; |