Fri, 17 Mar 2023 11:12:12 +0000
disco: Remove stray print()
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 | 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 | 9 | local verse = require "verse"; |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 205 | |
473
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
206 | local identities, features, extended = {}, {}, {}; |
380 | 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 | 215 | |
473
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
216 | for tag in result:get_child("query", xmlns_disco_info):childtags("x", "jabber:x:data") do |
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
217 | local form_type_field = tag:get_child_with_attr("field", nil, "var", "FORM_TYPE"); |
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
218 | local form_type = form_type_field and form_type_field:get_child_text("value"); |
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
219 | if form_type then |
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
220 | extended[form_type] = tag; |
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
221 | end |
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
222 | 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
|
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 | 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
|
225 | 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
|
226 | 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
|
227 | |
0f5a8d530fcd
verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted 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 | 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
|
229 | 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
|
230 | 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
|
231 | 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
|
232 | 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
|
233 | self.disco.cache[jid].nodes[node].features = features; |
473
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
234 | self.disco.cache[jid].nodes[node].extended = extended; |
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 | 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
|
236 | 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
|
237 | self.disco.cache[jid].features = features; |
473
b2198cd64c5a
disco: Add support for extended disco forms
Matthew Wild <mwild1@gmail.com>
parents:
429
diff
changeset
|
238 | self.disco.cache[jid].extended = extended; |
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
|
239 | 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
|
240 | 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
|
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 | end |
380 | 243 | |
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
|
244 | 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
|
245 | 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
|
246 | :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
|
247 | 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
|
248 | 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
|
249 | 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
|
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 | 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
|
252 | 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
|
253 | 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
|
254 | 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
|
255 | 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
|
256 | jid = tag.attr.jid; |
120
47449a29d8ed
plugins.disco: Store node of disco items
Matthew Wild <mwild1@gmail.com>
parents:
119
diff
changeset
|
257 | 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
|
258 | }); |
0f5a8d530fcd
verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted 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 | 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
|
260 | end |
380 | 261 | |
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 | 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
|
263 | 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
|
264 | end |
380 | 265 | |
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
|
266 | 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
|
267 | 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
|
268 | 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
|
269 | 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
|
270 | 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
|
271 | 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
|
272 | 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
|
273 | 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
|
274 | 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
|
275 | 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
|
276 | end |
380 | 277 | |
176
6004486e8b6c
plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents:
175
diff
changeset
|
278 | 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
|
279 | 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
|
280 | 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
|
281 | 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
|
282 | 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
|
283 | 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
|
284 | 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
|
285 | 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
|
286 | 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
|
287 | |
176
6004486e8b6c
plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents:
175
diff
changeset
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | -- 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
|
292 | 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
|
293 | |
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 | -- 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
|
295 | local result = verse.reply(stanza):tag('query',{ |
176
6004486e8b6c
plugins.disco,compression: Use xmlns_* variables
Kim Alvefur <zash@zash.se>
parents:
175
diff
changeset
|
296 | 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
|
297 | 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
|
298 | }) |
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
|
299 | 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
|
300 | 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
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | 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
|
305 | end); |
380 | 306 | |
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
|
307 | 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
|
308 | 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
|
309 | 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
|
310 | 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
|
311 | |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
312 | -- 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
|
313 | 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
|
314 | 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
|
315 | 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
|
316 | 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
|
317 | 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
|
318 | 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
|
319 | 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
|
320 | }); |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
321 | end |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
322 | end |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
323 | end |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
324 | |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
325 | 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
|
326 | 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
|
327 | end); |
e98cef597393
plugins.disco: Fix to use util.caps instead of broken hacky implementation
Matthew Wild <mwild1@gmail.com>
parents:
392
diff
changeset
|
328 | |
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
|
329 | 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
|
330 | 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
|
331 | 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
|
332 | 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
|
333 | 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
|
334 | 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
|
335 | return true; |
212
cd2e5eef7a7a
plugins.disco: Increase hook priority. Fixes duplicated disco features.
Kim Alvefur <zash@zash.se>
parents:
197
diff
changeset
|
336 | end, 50); |
380 | 337 | |
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
|
338 | stream:hook("presence-out", function (presence) |
429
46897d7769c3
disco: Force calculated caps in outgoing presence
Matthew Wild <mwild1@gmail.com>
parents:
423
diff
changeset
|
339 | presence:remove_children("c", xmlns_caps); |
46897d7769c3
disco: Force calculated caps in outgoing presence
Matthew Wild <mwild1@gmail.com>
parents:
423
diff
changeset
|
340 | 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
|
341 | 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
|
342 | 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
|
343 | |
0f5a8d530fcd
verse.plugins.disco: Add disco plugin originally developed by Hubert Chathi for Riddim, but here adapted 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 of disco.lua |