Mercurial > prosody-modules
comparison mod_cache_c2s_caps/mod_cache_c2s_caps.lua @ 3080:b003d72d9ce6
mod_cache_c2s_caps: Switch to origin.log to provide better debug to admins.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 01 Jun 2018 18:33:53 +0200 |
parents | 0fb44258d2cf |
children | 7a3ac037e57f |
comparison
equal
deleted
inserted
replaced
3079:2a918a8c47db | 3080:b003d72d9ce6 |
---|---|
23 end | 23 end |
24 iq_node_map[from..id] = nil; | 24 iq_node_map[from..id] = nil; |
25 in_flight_iqs[from..node_string] = nil; | 25 in_flight_iqs[from..node_string] = nil; |
26 | 26 |
27 if node_string ~= node_query then | 27 if node_string ~= node_query then |
28 module:log("debug", "Wrong node for our disco#info query, expected %s, received %s", node_string, node_query); | 28 origin.log("debug", "Wrong node for our disco#info query, expected %s, received %s", node_string, node_query); |
29 return; | 29 return; |
30 end | 30 end |
31 | 31 |
32 local node, ver = node_query:match("([^#]+)#([^#]+)"); | 32 local node, ver = node_query:match("([^#]+)#([^#]+)"); |
33 local hash = calculate_hash(query) | 33 local hash = calculate_hash(query) |
34 if ver ~= hash then | 34 if ver ~= hash then |
35 module:log("debug", "Wrong hash for disco#info: %s ~= %s", ver, hash); | 35 origin.log("debug", "Wrong hash for disco#info: %s ~= %s", ver, hash); |
36 end | 36 end |
37 | 37 |
38 origin.caps_cache = query; | 38 origin.caps_cache = query; |
39 module:log("info", "Stored caps %s", ver); | 39 origin.log("info", "Stored caps %s", ver); |
40 module:fire_event("c2s-capabilities-changed", { origin = origin }); | 40 module:fire_event("c2s-capabilities-changed", { origin = origin }); |
41 return true; | 41 return true; |
42 end | 42 end |
43 | 43 |
44 local function iq_error_handler(event) | 44 local function iq_error_handler(event) |
55 return; | 55 return; |
56 end | 56 end |
57 | 57 |
58 local caps = stanza:get_child("c", "http://jabber.org/protocol/caps"); | 58 local caps = stanza:get_child("c", "http://jabber.org/protocol/caps"); |
59 if caps == nil then | 59 if caps == nil then |
60 module:log("debug", "Presence without caps received, skipping"); | 60 origin.log("debug", "Presence without caps received, skipping"); |
61 return; | 61 return; |
62 end | 62 end |
63 | 63 |
64 local hash = caps.attr.hash; | 64 local hash = caps.attr.hash; |
65 local node = caps.attr.node; | 65 local node = caps.attr.node; |
66 local ver = caps.attr.ver; | 66 local ver = caps.attr.ver; |
67 if not hash or not node or not ver then | 67 if not hash or not node or not ver then |
68 return; | 68 return; |
69 end | 69 end |
70 if hash ~= "sha-1" then | 70 if hash ~= "sha-1" then |
71 module:log("warn", "Non-SHA-1 caps received: %s", hash); | 71 origin.log("warn", "Non-SHA-1 caps received: %s", hash); |
72 return; | 72 return; |
73 end | 73 end |
74 | 74 |
75 local node_query = node.."#"..ver; | 75 local node_query = node.."#"..ver; |
76 if (origin.caps_cache and origin.caps_cache.attr.node == node_query) or in_flight_iqs[from..node_query] ~= nil then | 76 if (origin.caps_cache and origin.caps_cache.attr.node == node_query) or in_flight_iqs[from..node_query] ~= nil then |
77 module:log("debug", "Already requested these caps, skipping"); | 77 origin.log("debug", "Already requested these caps, skipping"); |
78 return; | 78 return; |
79 end | 79 end |
80 | 80 |
81 module:log("debug", "Received presence with SHA-1 caps %s, querying disco#info", node_query); | 81 origin.log("debug", "Received presence with SHA-1 caps %s, querying disco#info", node_query); |
82 | 82 |
83 local id = uuid_gen(); | 83 local id = uuid_gen(); |
84 iq_node_map[from..id] = node_query | 84 iq_node_map[from..id] = node_query |
85 local iq = st_iq({ type = "get", from = module.host, to = from, id = id }) | 85 local iq = st_iq({ type = "get", from = module.host, to = from, id = id }) |
86 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info", node = node_query }); | 86 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info", node = node_query }); |