Software /
code /
verse
Annotate
plugins/version.lua @ 119:989cb40f8e62
plugins.disco: Fixes for storing/retrieving items from the disco cache.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 19:11:27 +0100 |
parent | 104:58305b983b1a |
child | 218:39af184385cd |
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) |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local query = reply:get_child("query", xmlns_version); |
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
|
34 if reply.attr.type == "result" then |
27
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local name = query:get_child("name"); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local version = query:get_child("version"); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local os = query:get_child("os"); |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 callback({ |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 name = name and name:get_text() or nil; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 version = version and version:get_text() or nil; |
a4a6a33a34c1
Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 platform = os and os:get_text() or nil; |
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 |