Mercurial > prosody-modules
annotate mod_query_client_ver/mod_query_client_ver.lua @ 2058:4b3037c7af62
mod_invite: Allows existing users to generate URLs that can be used to invite new users. Mutual presence subscriptions are automatically created when the creation succeeds.
author | Thijs Alkemade <me@thijsalkema.de> |
---|---|
date | Wed, 02 Mar 2016 18:12:34 +0100 |
parents | b5f9f1111a8b |
children | 20ebfa4ad7f4 |
rev | line source |
---|---|
1588
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Query and log client software |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local st = require"util.stanza"; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local uuid = require"util.uuid".generate; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local xmlns_iq_version = "jabber:iq:version"; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local version_id = uuid(); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local xmlns_disco_info = "http://jabber.org/protocol/disco#info"; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local disco_id = uuid(); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 module:hook("presence/bare", function(event) |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local origin, stanza = event.origin, event.stanza; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 if origin.type == "c2s" and not origin.presence and not stanza.attr.to then |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 module:add_timer(1, function() |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 if origin.type ~= "c2s" then return end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 origin.log("debug", "Sending version query"); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 origin.send(st.iq({ id = version_id, type = "get", from = module.host, to = origin.full_jid }):query(xmlns_iq_version)); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end, 1); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 module:hook("iq-result/host/"..version_id, function(event) |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local origin, stanza = event.origin, event.stanza; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local query = stanza:get_child("query", xmlns_iq_version); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 if query then |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local client = query:get_child_text("name"); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if client then |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 local version = query:get_child_text("version"); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 if version then |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 client = client .. " version " .. version; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 origin.log("info", "Running %s", client); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 return true; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 origin.send(st.iq({ id = disco_id, type = "get", from = module.host, to = origin.full_jid }):query(xmlns_disco_info)); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 module:hook("iq-result/host/"..disco_id, function(event) |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 local origin, stanza = event.origin, event.stanza; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 local query = stanza:get_child("query", xmlns_disco_info); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 if query then |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 local ident = query:get_child("identity"); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 if ident and ident.attr.name then |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 origin.log("info", "Running %s", ident.attr.name); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 return true; |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 end |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 -- Unknown software |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 end); |
b5f9f1111a8b
mod_query_client_ver: Query and log client software
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 |