Annotate

plugins/disco.lua @ 448:6d97b42bb1b4

plugins.smacks: Handle failed resumption by trying to bind instead
author Kim Alvefur <zash@zash.se>
date Sat, 19 Feb 2022 15:43:47 +0100
parent 429:46897d7769c3
child 473:b2198cd64c5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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>
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
4 --
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
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;
392
cdea6a28369e plugins: Use util.hashes instead of util.sha1
Kim Alvefur <zash@zash.se>
parents: 380
diff changeset
11 local sha1 = require("util.hashes").sha1;
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
12 local calculate_hash = require "util.caps".calculate_hash;
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
13
175
4d2a5d02fdfa plugins.disco: Fix missing xmlns variable.
Kim Alvefur <zash@zash.se>
parents: 172
diff changeset
14 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
15 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
16 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
17 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
18
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
19 function verse.plugins.disco(stream)
180
58537eb98506 plugins.disco: Load the presence plugin
Kim Alvefur <zash@zash.se>
parents: 179
diff changeset
20 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
21 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
22 __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
23 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
24 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
25 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
26 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
27 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
28 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
29 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
30 };
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 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
32 __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
33 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
34 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
35 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
36 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
37 };
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 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
39 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
40 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
41 [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
42 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
43 {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
44 },
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 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
46 [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
47 [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
48 [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
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 },
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 }, 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
52 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
53 };
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
54
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 = {}
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 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
57
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
58 local function build_self_disco_info_stanza(query_node)
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
59 local node = stream.disco.info[query_node or false];
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
60 if query_node and query_node == stream.caps.node .. "#" .. stream.caps.hash then
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
61 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
62 end
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
63 local identities, features = node.identities, node.features
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
64
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
65 -- construct the response
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
66 local result = verse.stanza("query", {
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
67 xmlns = xmlns_disco_info,
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
68 node = query_node,
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
69 });
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
70 for _,identity in pairs(identities) do
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
71 result:tag('identity', identity):up()
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
72 end
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
73 for feature in pairs(features) do
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
74 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
75 end
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
76 return 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
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
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
79 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
80 __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
81 -- 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
82 -- presence stanza
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
83 local hash = calculate_hash(build_self_disco_info_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
84 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
85 -- 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
86 return verse.stanza('c', {
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
87 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
88 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
89 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
90 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
91 })
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
92 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
93 })
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
94
267
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
95 function stream:set_identity(identity, node)
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
96 self.disco.info[node or false].identities = { identity };
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
97 stream:resend_presence();
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
98 end
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
99
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
100 function stream:add_identity(identity, node)
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
101 local identities = self.disco.info[node or false].identities;
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
102 identities[#identities + 1] = identity;
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
103 stream:resend_presence();
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
104 end
d30897e4f5c2 plugins.disco: Add set_ and add_identity()
Kim Alvefur <zash@zash.se>
parents: 266
diff changeset
105
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
106 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
107 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
108 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
109 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
110 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
111
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
112 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
113 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
114 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
115 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
116 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
117
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
118 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
119 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
120 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
121 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
122
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 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
124 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
125 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
126 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
127 table.remove(items, i);
113
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
128 end
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
129 end
769366a8b238 verse.plugins.disco: Add stream:remove_disco_feature()
Matthew Wild <mwild1@gmail.com>
parents: 112
diff changeset
130 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
131
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
132 -- 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 -- 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
143 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
144 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
145 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
146 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
147 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
148 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
149
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 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
151 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
152 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
153 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
154 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
155 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
156 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
157
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
158 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
159 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
160 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
161 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
162 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
163
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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
172
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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
185
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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
197
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
198 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
199 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
200 :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
201 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
202 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
203 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
204 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
205
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
206 local identities, features = {}, {};
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
207
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
208 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
209 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
210 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
211 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
212 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
213 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
214 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
215
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
216
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 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
218 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
219 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
220
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 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
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 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
232 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
233 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
234
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
235 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
236 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
237 :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
238 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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 jid = tag.attr.jid;
120
47449a29d8ed plugins.disco: Store node of disco items
Matthew Wild <mwild1@gmail.com>
parents: 119
diff changeset
248 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
249 });
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 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
251 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
252
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
253 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
254 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
255 end
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
256
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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265 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
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
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
268
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
269 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
270 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
271 if stanza.attr.type == 'get' and query.name == "query" then
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
272 local query_tag = build_self_disco_info_stanza(query.attr.node);
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
273 local result = verse.reply(stanza):add_child(query_tag);
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
274 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
275 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
276 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
277 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
278
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
279 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
280 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
281 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
282 -- 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
283 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
284
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
285 -- 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
286 local result = verse.reply(stanza):tag('query',{
176
6004486e8b6c plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents: 175
diff changeset
287 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
288 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
289 })
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
290 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
291 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
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 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
294 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
295 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
296 end);
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
297
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
298 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
299 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
300 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
301 initial_disco_started = true;
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
302
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
303 -- Using the disco cache, fires events for each identity of a given JID
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
304 local function scan_identities_for_service(service_jid)
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
305 local service_disco_info = stream.disco.cache[service_jid];
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
306 if service_disco_info then
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
307 for identity in pairs(service_disco_info.identities) do
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
308 local category, type = identity:match("^(.*)/(.*)$");
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
309 print(service_jid, category, type)
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
310 stream:event("disco/service-discovered/"..category, {
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
311 type = type, jid = service_jid;
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
312 });
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
313 end
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
314 end
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
315 end
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
316
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
317 stream:disco_info(stream.host, nil, function ()
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
318 scan_identities_for_service(stream.host);
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
319 end);
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
320
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
321 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
322 for _, service in ipairs(services) do
423
e98cef597393 plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents: 392
diff changeset
323 scan_identities_for_service(service.jid);
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
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
325 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
326 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
327 return true;
212
cd2e5eef7a7a plugins.disco: Increase hook priority. Fixes duplicated disco features.
Kim Alvefur <zash@zash.se>
parents: 197
diff changeset
328 end, 50);
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 267
diff changeset
329
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
330 stream:hook("presence-out", function (presence)
429
46897d7769c3 disco: Force calculated caps in outgoing presence
Matthew Wild <mwild1@gmail.com>
parents: 423
diff changeset
331 presence:remove_children("c", xmlns_caps);
46897d7769c3 disco: Force calculated caps in outgoing presence
Matthew Wild <mwild1@gmail.com>
parents: 423
diff changeset
332 presence:reset():add_child(stream:caps()):reset();
179
5e2ff25c1dd9 plugins.disco: Use the new presence plugin for caching and resending
Kim Alvefur <zash@zash.se>
parents: 176
diff changeset
333 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
334 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
335
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
336 -- end of disco.lua