Mercurial > prosody-modules
comparison mod_query_client_ver/mod_query_client_ver.lua @ 1588:b5f9f1111a8b
mod_query_client_ver: Query and log client software
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 20 Dec 2014 16:07:50 +0100 |
| parents | |
| children | 20ebfa4ad7f4 |
comparison
equal
deleted
inserted
replaced
| 1587:3ac2b835c7b3 | 1588:b5f9f1111a8b |
|---|---|
| 1 -- Query and log client software | |
| 2 | |
| 3 local st = require"util.stanza"; | |
| 4 local uuid = require"util.uuid".generate; | |
| 5 | |
| 6 local xmlns_iq_version = "jabber:iq:version"; | |
| 7 local version_id = uuid(); | |
| 8 local xmlns_disco_info = "http://jabber.org/protocol/disco#info"; | |
| 9 local disco_id = uuid(); | |
| 10 | |
| 11 module:hook("presence/bare", function(event) | |
| 12 local origin, stanza = event.origin, event.stanza; | |
| 13 if origin.type == "c2s" and not origin.presence and not stanza.attr.to then | |
| 14 module:add_timer(1, function() | |
| 15 if origin.type ~= "c2s" then return end | |
| 16 origin.log("debug", "Sending version query"); | |
| 17 origin.send(st.iq({ id = version_id, type = "get", from = module.host, to = origin.full_jid }):query(xmlns_iq_version)); | |
| 18 end); | |
| 19 end | |
| 20 end, 1); | |
| 21 | |
| 22 module:hook("iq-result/host/"..version_id, function(event) | |
| 23 local origin, stanza = event.origin, event.stanza; | |
| 24 local query = stanza:get_child("query", xmlns_iq_version); | |
| 25 if query then | |
| 26 local client = query:get_child_text("name"); | |
| 27 if client then | |
| 28 local version = query:get_child_text("version"); | |
| 29 if version then | |
| 30 client = client .. " version " .. version; | |
| 31 end | |
| 32 origin.log("info", "Running %s", client); | |
| 33 return true; | |
| 34 end | |
| 35 end | |
| 36 origin.send(st.iq({ id = disco_id, type = "get", from = module.host, to = origin.full_jid }):query(xmlns_disco_info)); | |
| 37 end); | |
| 38 | |
| 39 module:hook("iq-result/host/"..disco_id, function(event) | |
| 40 local origin, stanza = event.origin, event.stanza; | |
| 41 local query = stanza:get_child("query", xmlns_disco_info); | |
| 42 if query then | |
| 43 local ident = query:get_child("identity"); | |
| 44 if ident and ident.attr.name then | |
| 45 origin.log("info", "Running %s", ident.attr.name); | |
| 46 return true; | |
| 47 end | |
| 48 end | |
| 49 -- Unknown software | |
| 50 end); | |
| 51 |
