Software / code / verse
Comparison
plugins/version.lua @ 29:0d275519eff4
verse.plugins.version: Fix for handling of version requests
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 09 Dec 2009 20:57:18 +0000 |
| parent | 27:a4a6a33a34c1 |
| child | 33:4581b2e61429 |
comparison
equal
deleted
inserted
replaced
| 28:afe9e6d6c87a | 29:0d275519eff4 |
|---|---|
| 1 local xmlns_version = "jabber:iq:version"; | 1 local xmlns_version = "jabber:iq:version"; |
| 2 | 2 |
| 3 local function set_version(version_info) | 3 local function set_version(self, version_info) |
| 4 self.name = version_info.name; | 4 self.name = version_info.name; |
| 5 self.version = version_info.version; | 5 self.version = version_info.version; |
| 6 self.platform = version_info.platform; | 6 self.platform = version_info.platform; |
| 7 end | 7 end |
| 8 | 8 |
| 9 function verse.plugins.version(stream) | 9 function verse.plugins.version(stream) |
| 10 stream.version = { set = set_version }; | 10 stream.version = { set = set_version }; |
| 11 stream:hook("iq/"..xmlns_version, function (event) | 11 stream:hook("iq/"..xmlns_version, function (stanza) |
| 12 if event.stanza.attr.type ~= "get" then return; end | 12 if stanza.attr.type ~= "get" then return; end |
| 13 local reply = verse.reply(event.stanza) | 13 local reply = verse.reply(stanza) |
| 14 :tag("query", { xmlns = xmlns_version }); | 14 :tag("query", { xmlns = xmlns_version }); |
| 15 if stream.version.name then | 15 if stream.version.name then |
| 16 reply:tag("name"):text(tostring(stream.version.name)):up(); | 16 reply:tag("name"):text(tostring(stream.version.name)):up(); |
| 17 end | 17 end |
| 18 if stream.version.version then | 18 if stream.version.version then |
| 19 reply:tag("version"):text(tostring(stream.version.version)):up() | 19 reply:tag("version"):text(tostring(stream.version.version)):up() |
| 20 end | 20 end |
| 21 if stream.version.platform then | 21 if stream.version.platform then |
| 22 reply:tag("os"):text(stream.version.platform); | 22 reply:tag("os"):text(stream.version.platform); |
| 23 end | 23 end |
| 24 stream:send(reply); | |
| 24 end); | 25 end); |
| 25 | 26 |
| 26 function stream:query_version(target_jid, callback) | 27 function stream:query_version(target_jid, callback) |
| 27 callback = callback or function (version) return stream:event("version/response", version); end | 28 callback = callback or function (version) return stream:event("version/response", version); end |
| 28 stream:send_iq(verse.iq({ type = "get", to = target_jid }) | 29 stream:send_iq(verse.iq({ type = "get", to = target_jid }) |