plugins/disco.lua

Fri, 16 Dec 2011 22:00:41 +0100

author
Kim Alvefur <zash@zash.se>
date
Fri, 16 Dec 2011 22:00:41 +0100
changeset 266
ad8a918fa6e6
parent 250
a5ac643a7fd6
child 267
d30897e4f5c2
permissions
-rw-r--r--

plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.

99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Verse XMPP Library
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2010 Hubert Chathi <hubert@uhoreg.ca>
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2010 Matthew Wild <mwild1@gmail.com>
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 212
diff changeset
9 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 212
diff changeset
10 local b64 = require("mime").b64;
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 212
diff changeset
11 local sha1 = require("util.sha1").sha1;
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
175
4d2a5d02fdfa plugins.disco: Fix missing xmlns variable.
Kim Alvefur <zash@zash.se>
parents: 172
diff changeset
13 local xmlns_caps = "http://jabber.org/protocol/caps";
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local xmlns_disco = "http://jabber.org/protocol/disco";
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local xmlns_disco_info = xmlns_disco.."#info";
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local xmlns_disco_items = xmlns_disco.."#items";
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 function verse.plugins.disco(stream)
180
58537eb98506 plugins.disco: Load the presence plugin
Kim Alvefur <zash@zash.se>
parents: 179
diff changeset
19 stream:add_plugin("presence");
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
20 local disco_info_mt = {
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
21 __index = function(t, k)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
22 local node = { identities = {}, features = {} };
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
23 if k == "identities" or k == "features" then
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
24 return t[false][k]
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
25 end
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
26 t[k] = node;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
27 return node;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
28 end,
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
29 };
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
30 local disco_items_mt = {
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
31 __index = function(t, k)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
32 local node = { };
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
33 t[k] = node;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
34 return node;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
35 end,
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
36 };
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
37 stream.disco = {
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
38 cache = {},
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
39 info = setmetatable({
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
40 [false] = {
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
41 identities = {
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
42 {category = 'client', type='pc', name='Verse'},
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
43 },
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
44 features = {
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
45 [xmlns_caps] = true,
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
46 [xmlns_disco_info] = true,
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
47 [xmlns_disco_items] = true,
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
48 },
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
49 },
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
50 }, disco_info_mt);
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
51 items = setmetatable({[false]={}}, disco_items_mt);
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
52 };
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 stream.caps = {}
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 stream.caps.node = 'http://code.matthewwild.co.uk/verse/'
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 local function cmp_identity(item1, item2)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 if item1.category < item2.category then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 return true;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 elseif item2.category < item1.category then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 return false;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 if item1.type < item2.type then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 return true;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 elseif item2.type < item1.type then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 return false;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 if (not item1['xml:lang'] and item2['xml:lang']) or
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 (item2['xml:lang'] and item1['xml:lang'] < item2['xml:lang']) then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 return true
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 return false
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 local function cmp_feature(item1, item2)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 return item1.var < item2.var
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
79 local function calculate_hash(node)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
80 local identities = stream.disco.info[node or false].identities;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
81 table.sort(identities, cmp_identity)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
82 local features = {};
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
83 for var in pairs(stream.disco.info[node or false].features) do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
84 features[#features+1] = { var = var };
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
85 end
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
86 table.sort(features, cmp_feature)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
87 local S = {};
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
88 for key,identity in pairs(identities) do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
89 S[#S+1] = table.concat({
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
90 identity.category, identity.type or '',
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 identity['xml:lang'] or '', identity.name or ''
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
92 }, '/');
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 end
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
94 for key,feature in pairs(features) do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
95 S[#S+1] = feature.var
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
97 S[#S+1] = '';
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
98 S = table.concat(S,'<');
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 -- FIXME: make sure S is utf8-encoded
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 --stream:debug("Computed hash string: "..S);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 --stream:debug("Computed hash string (sha1): "..sha1(S, true));
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 --stream:debug("Computed hash string (sha1+b64): "..b64(sha1(S)));
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 return (b64(sha1(S)))
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 setmetatable(stream.caps, {
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 __call = function (...) -- vararg: allow calling as function or member
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 -- retrieve the c stanza to insert into the
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 -- presence stanza
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 local hash = calculate_hash()
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
111 stream.caps.hash = hash;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
112 -- TODO proper caching.... some day
197
7e98cf2c1d8d plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents: 180
diff changeset
113 return verse.stanza('c', {
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
114 xmlns = xmlns_caps,
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 hash = 'sha-1',
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 node = stream.caps.node,
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 ver = hash
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 })
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 })
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
122 function stream:add_disco_feature(feature, node)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
123 local feature = feature.var or feature;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
124 self.disco.info[node or false].features[feature] = true;
179
5e2ff25c1dd9 plugins.disco: Use the new presence plugin for caching and resending
Kim Alvefur <zash@zash.se>
parents: 176
diff changeset
125 stream:resend_presence();
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 end
113
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
127
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
128 function stream:remove_disco_feature(feature, node)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
129 local feature = feature.var or feature;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
130 self.disco.info[node or false].features[feature] = nil;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
131 stream:resend_presence();
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
132 end
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
133
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
134 function stream:add_disco_item(item, node)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
135 local items = self.disco.items[node or false];
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
136 items[#items +1] = item;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
137 end
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
138
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
139 function stream:remove_disco_item(item, node)
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
140 local items = self.disco.items[node or false];
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
141 for i=#items,1,-1 do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
142 if items[i] == item then
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
143 table.remove(items, i);
113
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
144 end
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
145 end
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
146 end
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
148 -- TODO Node?
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 function stream:jid_has_identity(jid, category, type)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 local cached_disco = self.disco.cache[jid];
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 if not cached_disco then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 return nil, "no-cache";
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 local identities = self.disco.cache[jid].identities;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 if type then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 return identities[category.."/"..type] or false;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 -- Check whether we have any identities with this category instead
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 for identity in pairs(identities) do
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 if identity:match("^(.*)/") == category then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 return true;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 function stream:jid_supports(jid, feature)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 local cached_disco = self.disco.cache[jid];
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 if not cached_disco or not cached_disco.features then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 return nil, "no-cache";
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 return cached_disco.features[feature] or false;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 function stream:get_local_services(category, type)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 local host_disco = self.disco.cache[self.host];
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 if not(host_disco) or not(host_disco.items) then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 return nil, "no-cache";
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 local results = {};
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 for _, service in ipairs(host_disco.items) do
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 if self:jid_has_identity(service.jid, category, type) then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 table.insert(results, service.jid);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 return results;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 function stream:disco_local_services(callback)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 self:disco_items(self.host, nil, function (items)
172
1a32e9ae79d0 plugins.disco: Fix disco_local_services() to call callback with empty array in case of disco error
Matthew Wild <mwild1@gmail.com>
parents: 167
diff changeset
191 if not items then
1a32e9ae79d0 plugins.disco: Fix disco_local_services() to call callback with empty array in case of disco error
Matthew Wild <mwild1@gmail.com>
parents: 167
diff changeset
192 return callback({});
1a32e9ae79d0 plugins.disco: Fix disco_local_services() to call callback with empty array in case of disco error
Matthew Wild <mwild1@gmail.com>
parents: 167
diff changeset
193 end
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 local n_items = 0;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 local function item_callback()
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 n_items = n_items - 1;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 if n_items == 0 then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 return callback(items);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202 for _, item in ipairs(items) do
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 if item.jid then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 n_items = n_items + 1;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205 self:disco_info(item.jid, nil, item_callback);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 if n_items == 0 then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 return callback(items);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 end);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 function stream:disco_info(jid, node, callback)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 local disco_request = verse.iq({ to = jid, type = "get" })
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 :tag("query", { xmlns = xmlns_disco_info, node = node });
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 self:send_iq(disco_request, function (result)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 if result.attr.type == "error" then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 return callback(nil, result:get_error());
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222 local identities, features = {}, {};
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 for tag in result:get_child("query", xmlns_disco_info):childtags() do
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 if tag.name == "identity" then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 identities[tag.attr.category.."/"..tag.attr.type] = tag.attr.name or true;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227 elseif tag.name == "feature" then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228 features[tag.attr.var] = true;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233 if not self.disco.cache[jid] then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
234 self.disco.cache[jid] = { nodes = {} };
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 if node then
119
989cb40f8e62 plugins.disco: Fixes for storing/retrieving items from the disco cache.
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
238 if not self.disco.cache[jid].nodes[node] then
989cb40f8e62 plugins.disco: Fixes for storing/retrieving items from the disco cache.
Matthew Wild <mwild1@gmail.com>
parents: 115
diff changeset
239 self.disco.cache[jid].nodes[node] = { nodes = {} };
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 self.disco.cache[jid].nodes[node].identities = identities;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 self.disco.cache[jid].nodes[node].features = features;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
243 else
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244 self.disco.cache[jid].identities = identities;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 self.disco.cache[jid].features = features;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 return callback(self.disco.cache[jid]);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 end);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 function stream:disco_items(jid, node, callback)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 local disco_request = verse.iq({ to = jid, type = "get" })
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 :tag("query", { xmlns = xmlns_disco_items, node = node });
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254 self:send_iq(disco_request, function (result)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 if result.attr.type == "error" then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
256 return callback(nil, result:get_error());
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 local disco_items = { };
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 for tag in result:get_child("query", xmlns_disco_items):childtags() do
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260 if tag.name == "item" then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 table.insert(disco_items, {
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 name = tag.attr.name;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263 jid = tag.attr.jid;
120
47449a29d8ed plugins.disco: Store node of disco items
Matthew Wild <mwild1@gmail.com>
parents: 119
diff changeset
264 node = tag.attr.node;
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 });
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269 if not self.disco.cache[jid] then
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270 self.disco.cache[jid] = { nodes = {} };
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 if node then
121
9b31ac5a37ea plugins.disco: Further fixes to storing and retrieving to/from the disco cache
Matthew Wild <mwild1@gmail.com>
parents: 120
diff changeset
274 if not self.disco.cache[jid].nodes[node] then
9b31ac5a37ea plugins.disco: Further fixes to storing and retrieving to/from the disco cache
Matthew Wild <mwild1@gmail.com>
parents: 120
diff changeset
275 self.disco.cache[jid].nodes[node] = { nodes = {} };
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
276 end
121
9b31ac5a37ea plugins.disco: Further fixes to storing and retrieving to/from the disco cache
Matthew Wild <mwild1@gmail.com>
parents: 120
diff changeset
277 self.disco.cache[jid].nodes[node].items = disco_items;
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
278 else
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279 self.disco.cache[jid].items = disco_items;
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 return callback(disco_items);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282 end);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
285 stream:hook("iq/"..xmlns_disco_info, function (stanza)
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
286 local query = stanza.tags[1];
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
287 if stanza.attr.type == 'get' and query.name == "query" then
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
288 local query_node = query.attr.node;
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
289 local node = stream.disco.info[query_node or false];
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
290 if query_node and query_node == stream.caps.node .. "#" .. stream.caps.hash then
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
291 node = stream.disco.info[false];
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 end
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
293 local identities, features = node.identities, node.features
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
294
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 -- construct the response
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
296 local result = verse.reply(stanza):tag("query", {
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
297 xmlns = xmlns_disco_info,
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
298 node = query_node,
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
299 });
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
300 for _,identity in pairs(identities) do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
301 result:tag('identity', identity):up()
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 end
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
303 for feature in pairs(features) do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
304 result:tag('feature', { var = feature }):up()
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
305 end
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
306 stream:send(result);
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307 return true
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
308 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 end);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
310
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
311 stream:hook("iq/"..xmlns_disco_items, function (stanza)
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
312 local query = stanza.tags[1];
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
313 if stanza.attr.type == 'get' and query.name == "query" then
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314 -- figure out what items to send
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
315 local items = stream.disco.items[query.attr.node or false];
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
316
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317 -- construct the response
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
318 local result = verse.reply(stanza):tag('query',{
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
319 xmlns = xmlns_disco_items,
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
320 node = query.attr.node
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 })
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
322 for i=1,#items do
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
323 result:tag('item', items[i]):up()
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 end
266
ad8a918fa6e6 plugins.disco: A little cleanup and a bit of rewrite with a touch of premature optimization.
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
325 stream:send(result);
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 return true
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 end);
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329
109
60a03b2cabec verse.plugins.disco: Auto-disco local services on connect, and delay 'ready' event until done
Matthew Wild <mwild1@gmail.com>
parents: 99
diff changeset
330 local initial_disco_started;
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331 stream:hook("ready", function ()
109
60a03b2cabec verse.plugins.disco: Auto-disco local services on connect, and delay 'ready' event until done
Matthew Wild <mwild1@gmail.com>
parents: 99
diff changeset
332 if initial_disco_started then return; end
60a03b2cabec verse.plugins.disco: Auto-disco local services on connect, and delay 'ready' event until done
Matthew Wild <mwild1@gmail.com>
parents: 99
diff changeset
333 initial_disco_started = true;
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 stream:disco_local_services(function (services)
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 for _, service in ipairs(services) do
146
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
336 local service_disco_info = stream.disco.cache[service.jid];
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
337 if service_disco_info then
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
338 for identity in pairs(service_disco_info.identities) do
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
339 local category, type = identity:match("^(.*)/(.*)$");
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
340 stream:event("disco/service-discovered/"..category, {
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
341 type = type, jid = service.jid;
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
342 });
2678048e93e6 plugins.disco: Fix traceback when disco#info isn't returned for a service in disco#items
Matthew Wild <mwild1@gmail.com>
parents: 121
diff changeset
343 end
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 end
109
60a03b2cabec verse.plugins.disco: Auto-disco local services on connect, and delay 'ready' event until done
Matthew Wild <mwild1@gmail.com>
parents: 99
diff changeset
346 stream:event("ready");
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347 end);
109
60a03b2cabec verse.plugins.disco: Auto-disco local services on connect, and delay 'ready' event until done
Matthew Wild <mwild1@gmail.com>
parents: 99
diff changeset
348 return true;
212
cd2e5eef7a7a plugins.disco: Increase hook priority. Fixes duplicated disco features.
Kim Alvefur <zash@zash.se>
parents: 197
diff changeset
349 end, 50);
167
a2ae7a9d360f plugins.disco: Automatically insert caps into outgoing presence, and re-send last global presence with new caps when features change
Matthew Wild <mwild1@gmail.com>
parents: 146
diff changeset
350
a2ae7a9d360f plugins.disco: Automatically insert caps into outgoing presence, and re-send last global presence with new caps when features change
Matthew Wild <mwild1@gmail.com>
parents: 146
diff changeset
351 stream:hook("presence-out", function (presence)
a2ae7a9d360f plugins.disco: Automatically insert caps into outgoing presence, and re-send last global presence with new caps when features change
Matthew Wild <mwild1@gmail.com>
parents: 146
diff changeset
352 if not presence:get_child("c", xmlns_caps) then
a2ae7a9d360f plugins.disco: Automatically insert caps into outgoing presence, and re-send last global presence with new caps when features change
Matthew Wild <mwild1@gmail.com>
parents: 146
diff changeset
353 presence:reset():add_child(stream:caps()):reset();
a2ae7a9d360f plugins.disco: Automatically insert caps into outgoing presence, and re-send last global presence with new caps when features change
Matthew Wild <mwild1@gmail.com>
parents: 146
diff changeset
354 end
179
5e2ff25c1dd9 plugins.disco: Use the new presence plugin for caching and resending
Kim Alvefur <zash@zash.se>
parents: 176
diff changeset
355 end, 10);
99
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
356 end
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357
0f5a8d530fcd verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted for Verse with new APIs added to allow disco'ing the local server and remote entities
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 -- end of disco.lua

mercurial