Software /
code /
verse
Annotate
plugins/version.lua @ 242:ab4773b0ef5e
verse: Add default log handler for errors
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 27 Nov 2011 23:00:15 +0000 |
parent | 218:39af184385cd |
child | 250:a5ac643a7fd6 |
rev | line source |
---|---|
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local xmlns_version = "jabber:iq:version"; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
29
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
3 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
|
4 self.name = version_info.name; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 self.version = version_info.version; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 self.platform = version_info.platform; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 function verse.plugins.version(stream) |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 local reply = verse.reply(stanza) |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 :tag("query", { xmlns = xmlns_version }); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 if stream.version.name then |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 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
|
17 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if stream.version.version then |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 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
|
20 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if stream.version.platform then |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 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
|
23 end |
29
0d275519eff4
verse.plugins.version: Fix for handling of version requests
Matthew Wild <mwild1@gmail.com>
parents:
27
diff
changeset
|
24 stream:send(reply); |
104
58305b983b1a
verse.plugins.version: Return true when handling a version request
Matthew Wild <mwild1@gmail.com>
parents:
51
diff
changeset
|
25 return true; |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 function stream:query_version(target_jid, callback) |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 callback = callback or function (version) return stream:event("version/response", version); end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 stream:send_iq(verse.iq({ type = "get", to = target_jid }) |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 :tag("query", { xmlns = xmlns_version }), |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 platform = os; |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 }); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 else |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 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
|
45 callback({ |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 error = true; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 condition = condition; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 text = text; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 type = type; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 }); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
33
4581b2e61429
plugins.version: Return true on module load to indicate load success
Matthew Wild <mwild1@gmail.com>
parents:
29
diff
changeset
|
54 return true; |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |