Comparison

mod_muc_gc10/mod_muc_gc10.lua @ 2940:0167a102ed35

mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
author Kim Alvefur <zash@zash.se>
date Thu, 22 Mar 2018 14:28:27 +0100
child 2944:37ec4c2f319a
comparison
equal deleted inserted replaced
2939:280305c043b0 2940:0167a102ed35
1 local jid_bare = require "util.jid".bare;
2 local st = require "util.stanza";
3
4 local rooms = module:depends"muc".rooms;
5
6 module:hook("presence/bare", function (event)
7 local stanza, origin = event.stanza, event.origin;
8 if stanza.attr.type ~= nil then return end
9
10 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc");
11
12 local room_jid = jid_bare(stanza.attr.to);
13 local room = rooms[room_jid];
14 if not room then
15 if muc_x then
16 -- Normal MUC creation
17 else
18 module:log("info", "GC 1.0 room creation from %s", stanza.attr.from);
19 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version"));
20 end
21 return;
22 end
23 local current_nick = room._jid_nick[stanza.attr.from];
24
25 if current_nick then
26 -- present
27 if muc_x then
28 module:log("info", "MUC desync with %s", stanza.attr.from);
29 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version"));
30 else
31 -- normal presence update
32 end
33 else
34 -- joining
35 if muc_x then
36 -- normal join
37 else
38 module:log("info", "GC 1.0 join from %s", stanza.attr.from);
39 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version"));
40 end
41 end
42 end);
43
44 module:hook("iq-result/host/"..module.name, function (event)
45 local stanza, origin = event.stanza, event.origin;
46 local version = stanza:get_child("query", "jabber:iq:version");
47 if not version then
48 module:log("info", "%s replied with an invalid version reply: %s", stanza.attr.from, tostring(stanza));
49 return true;
50 end
51 module:log("info", "%s is running: %s %s", stanza.attr.from, version:get_child_text("name"), version:get_child_text("version"));
52 end);
53
54 module:hook("iq-error/host/"..module.name, function (event)
55 local stanza, origin = event.stanza, event.origin;
56 module:log("info", "%s replied with an error: %s %s", stanza.attr.from, stanza:get_error());
57 return true;
58 end);