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