Annotate

plugins/version.lua @ 96:f0aec10023aa

verse: Return true from connect() on success, add stream:close()
author Matthew Wild <mwild1@gmail.com>
date Sat, 21 Aug 2010 14:36:21 +0100
parent 51:d044a726fef0
child 104:58305b983b1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
27
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end);
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 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
28 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
29 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
30 :tag("query", { xmlns = xmlns_version }),
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 function (reply)
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 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
33 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
34 local name = query:get_child("name");
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local version = query:get_child("version");
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 local os = query:get_child("os");
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 callback({
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 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
39 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
40 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
41 });
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 else
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 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
44 callback({
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 error = true;
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 condition = condition;
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 text = text;
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 type = type;
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 });
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
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
33
4581b2e61429 plugins.version: Return true on module load to indicate load success
Matthew Wild <mwild1@gmail.com>
parents: 29
diff changeset
53 return true;
27
a4a6a33a34c1 Add 'version' plugin to handle and generate version requests
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 end