Software /
code /
verse
Annotate
plugins/version.lua @ 490:6b2f31da9610
Update for new Prosody module namespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 May 2023 20:48:03 +0200 |
parent | 395:e86144a4eaa1 |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
2 | |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local xmlns_version = "jabber:iq:version"; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
29
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
5 local function set_version(self, version_info) |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 self.name = version_info.name; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 self.version = version_info.version; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 self.platform = version_info.platform; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 function verse.plugins.version(stream) |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 stream.version = { set = set_version }; |
29
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
13 stream:hook("iq/"..xmlns_version, function (stanza) |
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
14 if stanza.attr.type ~= "get" then return; end |
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
15 local reply = verse.reply(stanza) |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 :tag("query", { xmlns = xmlns_version }); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 if stream.version.name then |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 reply:tag("name"):text(tostring(stream.version.name)):up(); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 if stream.version.version then |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 reply:tag("version"):text(tostring(stream.version.version)):up() |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 if stream.version.platform then |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 reply:tag("os"):text(stream.version.platform); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
29
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
26 stream:send(reply); |
104
58305b983b1a
verse.plugins.version: Return true when handling a version request
Matthew Wild <mwild1@gmail.com>
parents:
51
diff
changeset
|
27 return true; |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end); |
380 | 29 |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 function stream:query_version(target_jid, callback) |
395 | 31 callback = callback or function (version) return self:event("version/response", version); end |
32 self:send_iq(verse.iq({ type = "get", to = target_jid }) | |
380 | 33 :tag("query", { xmlns = xmlns_version }), |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 function (reply) |
51
d044a726fef0
plugins.version: Detect errors based on type attribute, rather than presence of query element
Matthew Wild <mwild1@gmail.com>
parents:
33
diff
changeset
|
35 if reply.attr.type == "result" then |
218
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
36 local query = reply:get_child("query", xmlns_version); |
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
37 local name = query and query:get_child_text("name"); |
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
38 local version = query and query:get_child_text("version"); |
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
39 local os = query and query:get_child_text("os"); |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 callback({ |
218
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
41 name = name; |
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
42 version = version; |
39af184385cd
plugins.version: Use get_child_text() and fix traceback on empty iq-result reply.
Kim Alvefur <zash@zash.se>
parents:
104
diff
changeset
|
43 platform = os; |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 }); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 else |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local type, condition, text = reply:get_error(); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 callback({ |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 error = true; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 condition = condition; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 text = text; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 type = type; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 }); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |
33
4581b2e61429
plugins.version: Return true on module load to indicate load success
Matthew Wild <mwild1@gmail.com>
parents:
29
diff
changeset
|
56 return true; |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |