Software /
code /
prosody
Annotate
plugins/mod_disco.lua @ 12123:7ba686696250
openmetrics/histograms: fix incorrect condition for bucketing
The buckets thresholds are to be taken as "less than or equal to".
The condition as written in the code did only "less than", not
"less than or equal to". That's fixed now.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Sun, 26 Dec 2021 22:32:00 +0100 |
parent | 12017:b3f040e57835 |
child | 12388:50fcd3879482 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1510
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1704
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1704
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5772
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 |
3600
c888328ae6b3
mod_disco: Updated to use hostmanager.get_children instead of componentmanager.get_children.
Waqas Hussain <waqas20@gmail.com>
parents:
3572
diff
changeset
|
9 local get_children = require "core.hostmanager".get_children; |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
10 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
12015
b4db17aeff01
mod_disco: Advertise admin accounts as such via disco identity
Kim Alvefur <zash@zash.se>
parents:
11737
diff
changeset
|
11 local um_is_admin = require "core.usermanager".is_admin; |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
12 local jid_split = require "util.jid".split; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
13 local jid_bare = require "util.jid".bare; |
1704
9b445d2427e2
mod_disco: Rearranged some lines, and added a FIXME comment
Waqas Hussain <waqas20@gmail.com>
parents:
1703
diff
changeset
|
14 local st = require "util.stanza" |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
15 local calculate_hash = require "util.caps".calculate_hash; |
1510
83b2e07e9039
mod_disco: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
16 |
12017
b3f040e57835
mod_disco: Optionally return info on admin accounts to non-contacts
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
17 local expose_admins = module:get_option_boolean("disco_expose_admins", false); |
b3f040e57835
mod_disco: Optionally return info on admin accounts to non-contacts
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
18 |
7977
01d6298de991
plugins/various: Use type-specific config API
Kim Alvefur <zash@zash.se>
parents:
7787
diff
changeset
|
19 local disco_items = module:get_option_array("disco_items", {}) |
2491
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
20 do -- validate disco_items |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
21 for _, item in ipairs(disco_items) do |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
22 local err; |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
23 if type(item) ~= "table" then |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
24 err = "item is not a table"; |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
25 elseif type(item[1]) ~= "string" then |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
26 err = "item jid is not a string"; |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
27 elseif item[2] and type(item[2]) ~= "string" then |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
28 err = "item name is not a string"; |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
29 end |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
30 if err then |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
31 module:log("error", "option disco_items is malformed: %s", err); |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
32 disco_items = {}; -- TODO clean up data instead of removing it? |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
33 break; |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
34 end |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
35 end |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
36 end |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
37 |
5772
9cef4b5c2fe3
mod_disco: Check for host type == 'local' ('normal' never existed)
Matthew Wild <mwild1@gmail.com>
parents:
5689
diff
changeset
|
38 if module:get_host_type() == "local" then |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
39 module:add_identity("server", "im", module:get_option_string("name", "Prosody")); -- FIXME should be in the non-existing mod_router |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
40 end |
1510
83b2e07e9039
mod_disco: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
41 module:add_feature("http://jabber.org/protocol/disco#info"); |
83b2e07e9039
mod_disco: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
42 module:add_feature("http://jabber.org/protocol/disco#items"); |
83b2e07e9039
mod_disco: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
43 |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
44 -- Generate and cache disco result and caps hash |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
45 local _cached_server_disco_info, _cached_server_caps_feature, _cached_server_caps_hash; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
46 local function build_server_disco_info() |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
47 local query = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" }); |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
48 local done = {}; |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
49 for _,identity in ipairs(module:get_host_items("identity")) do |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
50 local identity_s = identity.category.."\0"..identity.type; |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
51 if not done[identity_s] then |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
52 query:tag("identity", identity):up(); |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
53 done[identity_s] = true; |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
54 end |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
55 end |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
56 for _,feature in ipairs(module:get_host_items("feature")) do |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
57 if not done[feature] then |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
58 query:tag("feature", {var=feature}):up(); |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
59 done[feature] = true; |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
60 end |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
61 end |
4337
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
62 for _,extension in ipairs(module:get_host_items("extension")) do |
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
63 if not done[extension] then |
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
64 query:add_child(extension); |
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
65 done[extension] = true; |
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
66 end |
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
67 end |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
68 _cached_server_disco_info = query; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
69 _cached_server_caps_hash = calculate_hash(query); |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
70 _cached_server_caps_feature = st.stanza("c", { |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
71 xmlns = "http://jabber.org/protocol/caps"; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
72 hash = "sha-1"; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
73 node = "http://prosody.im"; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
74 ver = _cached_server_caps_hash; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
75 }); |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
76 end |
11204
ae2a11066001
mod_disco: Add some spacing to improve readability and code navigation
Kim Alvefur <zash@zash.se>
parents:
9223
diff
changeset
|
77 |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
78 local function clear_disco_cache() |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
79 _cached_server_disco_info, _cached_server_caps_feature, _cached_server_caps_hash = nil, nil, nil; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
80 end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
81 local function get_server_disco_info() |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
82 if not _cached_server_disco_info then build_server_disco_info(); end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
83 return _cached_server_disco_info; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
84 end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
85 local function get_server_caps_feature() |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
86 if not _cached_server_caps_feature then build_server_disco_info(); end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
87 return _cached_server_caps_feature; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
88 end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
89 local function get_server_caps_hash() |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
90 if not _cached_server_caps_hash then build_server_disco_info(); end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
91 return _cached_server_caps_hash; |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
92 end |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
93 |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
94 module:hook("item-added/identity", clear_disco_cache); |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
95 module:hook("item-added/feature", clear_disco_cache); |
4337
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
96 module:hook("item-added/extension", clear_disco_cache); |
3665
98b55c3a3deb
mod_disco: Fixed: Service discovery features were not being removed on module unload (issue #205).
Waqas Hussain <waqas20@gmail.com>
parents:
3600
diff
changeset
|
97 module:hook("item-removed/identity", clear_disco_cache); |
98b55c3a3deb
mod_disco: Fixed: Service discovery features were not being removed on module unload (issue #205).
Waqas Hussain <waqas20@gmail.com>
parents:
3600
diff
changeset
|
98 module:hook("item-removed/feature", clear_disco_cache); |
4337
a2ee8ab82dd9
core.modulemanager, mod_disco: Add support for XEP-0128: Service Discovery Extensions
Kim Alvefur <zash@zash.se>
parents:
3695
diff
changeset
|
99 module:hook("item-removed/extension", clear_disco_cache); |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
100 |
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
101 -- Handle disco requests to the server |
9223
80dbb60d81e4
mod_disco: Simplify iq handling by hooking on iq-get/ instead of iq/.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8834
diff
changeset
|
102 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event) |
1699
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
103 local origin, stanza = event.origin, event.stanza; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
104 local node = stanza.tags[1].attr.node; |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
105 if node and node ~= "" and node ~= "http://prosody.im#"..get_server_caps_hash() then |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
106 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
107 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
108 local ret = module:fire_event("host-disco-info-node", node_event); |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
109 if ret ~= nil then return ret; end |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
110 if node_event.exists then |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
111 origin.send(reply); |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
112 else |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
113 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
114 end |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
115 return true; |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
116 end |
3349
a416d714a905
mod_disco: Reflect requested 'node' attribute in the disco#info reply.
Waqas Hussain <waqas20@gmail.com>
parents:
3348
diff
changeset
|
117 local reply_query = get_server_disco_info(); |
8002
57060d0cee4b
mod_disco: Correctly set the 'node' attr (fixes #449)
Kim Alvefur <zash@zash.se>
parents:
5081
diff
changeset
|
118 reply_query.attr.node = node; |
3349
a416d714a905
mod_disco: Reflect requested 'node' attribute in the disco#info reply.
Waqas Hussain <waqas20@gmail.com>
parents:
3348
diff
changeset
|
119 local reply = st.reply(stanza):add_child(reply_query); |
1699
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
120 origin.send(reply); |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
121 return true; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
122 end); |
11204
ae2a11066001
mod_disco: Add some spacing to improve readability and code navigation
Kim Alvefur <zash@zash.se>
parents:
9223
diff
changeset
|
123 |
9223
80dbb60d81e4
mod_disco: Simplify iq handling by hooking on iq-get/ instead of iq/.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8834
diff
changeset
|
124 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event) |
1701
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
125 local origin, stanza = event.origin, event.stanza; |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
126 local node = stanza.tags[1].attr.node; |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
127 if node and node ~= "" then |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
128 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
129 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
130 local ret = module:fire_event("host-disco-items-node", node_event); |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
131 if ret ~= nil then return ret; end |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
132 if node_event.exists then |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
133 origin.send(reply); |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
134 else |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
135 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
136 end |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
137 return true; |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
138 end |
1701
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
139 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
140 local ret = module:fire_event("host-disco-items", { origin = origin, stanza = stanza, reply = reply }); |
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
141 if ret ~= nil then return ret; end |
5081
c0c060e450be
hostmanager, mod_disco: Show optional 'name' option from the config in disco#items queries (fixes use-case in #292) (thanks diSabler, mva)
Matthew Wild <mwild1@gmail.com>
parents:
4985
diff
changeset
|
142 for jid, name in pairs(get_children(module.host)) do |
c0c060e450be
hostmanager, mod_disco: Show optional 'name' option from the config in disco#items queries (fixes use-case in #292) (thanks diSabler, mva)
Matthew Wild <mwild1@gmail.com>
parents:
4985
diff
changeset
|
143 reply:tag("item", {jid = jid, name = name~=true and name or nil}):up(); |
1701
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
144 end |
2491
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
145 for _, item in ipairs(disco_items) do |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
146 reply:tag("item", {jid=item[1], name=item[2]}):up(); |
4be6810914eb
mod_disco: Added option 'disco_items' to allow appending items to a host's disco#items result.
Waqas Hussain <waqas20@gmail.com>
parents:
2383
diff
changeset
|
147 end |
1701
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
148 origin.send(reply); |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
149 return true; |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
150 end); |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
151 |
3347
99f56bed5228
mod_disco: Cache disco#info reply and caps hash for host, return correct caps hash, and respond to disco#info to the caps hash node.
Waqas Hussain <waqas20@gmail.com>
parents:
3343
diff
changeset
|
152 -- Handle caps stream feature |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
153 module:hook("stream-features", function (event) |
8188
8c524b7c9017
mod_disco: Advertise in stream-features after auth (probably what was meant in 200f1f6306a7) (fixes #957)
Kim Alvefur <zash@zash.se>
parents:
8156
diff
changeset
|
154 if event.origin.type == "c2s" or event.origin.type == "c2s_unbound" then |
3695
d2c4856c7ed5
mod_disco: Don't add caps hash to stream features on unauthenticated connections.
Waqas Hussain <waqas20@gmail.com>
parents:
3665
diff
changeset
|
155 event.features:add_child(get_server_caps_feature()); |
d2c4856c7ed5
mod_disco: Don't add caps hash to stream features on unauthenticated connections.
Waqas Hussain <waqas20@gmail.com>
parents:
3665
diff
changeset
|
156 end |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
157 end); |
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
158 |
11737
59cf555b4698
mod_disco: Send XEP-0115 caps in s2s stream features
Kim Alvefur <zash@zash.se>
parents:
11204
diff
changeset
|
159 module:hook("s2s-stream-features", function (event) |
59cf555b4698
mod_disco: Send XEP-0115 caps in s2s stream features
Kim Alvefur <zash@zash.se>
parents:
11204
diff
changeset
|
160 if event.origin.type == "s2sin" then |
59cf555b4698
mod_disco: Send XEP-0115 caps in s2s stream features
Kim Alvefur <zash@zash.se>
parents:
11204
diff
changeset
|
161 event.features:add_child(get_server_caps_feature()); |
59cf555b4698
mod_disco: Send XEP-0115 caps in s2s stream features
Kim Alvefur <zash@zash.se>
parents:
11204
diff
changeset
|
162 end |
59cf555b4698
mod_disco: Send XEP-0115 caps in s2s stream features
Kim Alvefur <zash@zash.se>
parents:
11204
diff
changeset
|
163 end); |
59cf555b4698
mod_disco: Send XEP-0115 caps in s2s stream features
Kim Alvefur <zash@zash.se>
parents:
11204
diff
changeset
|
164 |
3343
c70c6d5bf270
mod_disco: Support for putting the server's caps hash in stream:features to allow the client to cache disco#info for the server instead of requesting it at each login.
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
165 -- Handle disco requests to user accounts |
8834
b0093d3b2d04
mod_disco: Skip code specific to disco on user accounts (avoids invoking usermanager, fixes #1150)
Kim Alvefur <zash@zash.se>
parents:
8188
diff
changeset
|
166 if module:get_host_type() ~= "local" then return end -- skip for components |
9223
80dbb60d81e4
mod_disco: Simplify iq handling by hooking on iq-get/ instead of iq/.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8834
diff
changeset
|
167 module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function(event) |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
168 local origin, stanza = event.origin, event.stanza; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
169 local node = stanza.tags[1].attr.node; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
170 local username = jid_split(stanza.attr.to) or origin.username; |
12017
b3f040e57835
mod_disco: Optionally return info on admin accounts to non-contacts
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
171 local is_admin = um_is_admin(stanza.attr.to or origin.full_jid, module.host) |
b3f040e57835
mod_disco: Optionally return info on admin accounts to non-contacts
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
172 if not stanza.attr.to or (expose_admins and is_admin) or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
173 if node and node ~= "" then |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
174 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
175 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
176 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
177 local ret = module:fire_event("account-disco-info-node", node_event); |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
178 if ret ~= nil then return ret; end |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
179 if node_event.exists then |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
180 origin.send(reply); |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
181 else |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
182 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
183 end |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
184 return true; |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
185 end |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
186 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
187 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
12017
b3f040e57835
mod_disco: Optionally return info on admin accounts to non-contacts
Kim Alvefur <zash@zash.se>
parents:
12016
diff
changeset
|
188 if is_admin then |
12015
b4db17aeff01
mod_disco: Advertise admin accounts as such via disco identity
Kim Alvefur <zash@zash.se>
parents:
11737
diff
changeset
|
189 reply:tag('identity', {category='account', type='admin'}):up(); |
12016
b7e15abde27f
mod_disco: Advertise anonymous users
Kim Alvefur <zash@zash.se>
parents:
12015
diff
changeset
|
190 elseif prosody.hosts[module.host].users.name == "anonymous" then |
b7e15abde27f
mod_disco: Advertise anonymous users
Kim Alvefur <zash@zash.se>
parents:
12015
diff
changeset
|
191 reply:tag('identity', {category='account', type='anonymous'}):up(); |
12015
b4db17aeff01
mod_disco: Advertise admin accounts as such via disco identity
Kim Alvefur <zash@zash.se>
parents:
11737
diff
changeset
|
192 else |
b4db17aeff01
mod_disco: Advertise admin accounts as such via disco identity
Kim Alvefur <zash@zash.se>
parents:
11737
diff
changeset
|
193 reply:tag('identity', {category='account', type='registered'}):up(); |
b4db17aeff01
mod_disco: Advertise admin accounts as such via disco identity
Kim Alvefur <zash@zash.se>
parents:
11737
diff
changeset
|
194 end |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
195 module:fire_event("account-disco-info", { origin = origin, reply = reply }); |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
196 origin.send(reply); |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
197 return true; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
198 end |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
199 end); |
11204
ae2a11066001
mod_disco: Add some spacing to improve readability and code navigation
Kim Alvefur <zash@zash.se>
parents:
9223
diff
changeset
|
200 |
9223
80dbb60d81e4
mod_disco: Simplify iq handling by hooking on iq-get/ instead of iq/.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8834
diff
changeset
|
201 module:hook("iq-get/bare/http://jabber.org/protocol/disco#items:query", function(event) |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
202 local origin, stanza = event.origin, event.stanza; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
203 local node = stanza.tags[1].attr.node; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
204 local username = jid_split(stanza.attr.to) or origin.username; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
205 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
206 if node and node ~= "" then |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
207 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
208 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
209 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
210 local ret = module:fire_event("account-disco-items-node", node_event); |
5689
832ea1e9ac9e
mod_disco: Allow ansering disco requests including nodes, and adding custom items to disco#items requests
Florian Zeitz <florob@babelmonkeys.de>
parents:
5627
diff
changeset
|
211 if ret ~= nil then return ret; end |
8041
3b2cc22e9b5b
mod_disco: Rename variables to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8003
diff
changeset
|
212 if node_event.exists then |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
213 origin.send(reply); |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
214 else |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
215 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
216 end |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
217 return true; |
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
218 end |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
219 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items'}); |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
220 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
5627
0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
Florian Zeitz <florob@babelmonkeys.de>
parents:
5081
diff
changeset
|
221 module:fire_event("account-disco-items", { origin = origin, stanza = stanza, reply = reply }); |
2383
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
222 origin.send(reply); |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
223 return true; |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
224 end |
29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
1704
diff
changeset
|
225 end); |
11204
ae2a11066001
mod_disco: Add some spacing to improve readability and code navigation
Kim Alvefur <zash@zash.se>
parents:
9223
diff
changeset
|
226 |