Software /
code /
prosody
Comparison
plugins/mod_disco.lua @ 2383:29a30884aadd
mod_disco: Handle and fire events for service discovery queries for bare account JIDs (thanks darkrain).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 21 Dec 2009 06:25:12 +0500 |
parent | 1704:9b445d2427e2 |
child | 2491:4be6810914eb |
comparison
equal
deleted
inserted
replaced
2382:5e37e28a429f | 2383:29a30884aadd |
---|---|
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local componentmanager_get_children = require "core.componentmanager".get_children; | 9 local componentmanager_get_children = require "core.componentmanager".get_children; |
10 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | |
11 local jid_split = require "util.jid".split; | |
12 local jid_bare = require "util.jid".bare; | |
10 local st = require "util.stanza" | 13 local st = require "util.stanza" |
11 | 14 |
12 module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router | 15 module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router |
13 module:add_feature("http://jabber.org/protocol/disco#info"); | 16 module:add_feature("http://jabber.org/protocol/disco#info"); |
14 module:add_feature("http://jabber.org/protocol/disco#items"); | 17 module:add_feature("http://jabber.org/protocol/disco#items"); |
48 reply:tag("item", {jid = jid}):up(); | 51 reply:tag("item", {jid = jid}):up(); |
49 end | 52 end |
50 origin.send(reply); | 53 origin.send(reply); |
51 return true; | 54 return true; |
52 end); | 55 end); |
56 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) | |
57 local origin, stanza = event.origin, event.stanza; | |
58 if stanza.attr.type ~= "get" then return; end | |
59 local node = stanza.tags[1].attr.node; | |
60 if node and node ~= "" then return; end -- TODO fire event? | |
61 local username = jid_split(stanza.attr.to) or origin.username; | |
62 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | |
63 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); | |
64 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | |
65 module:fire_event("account-disco-info", { session = origin, stanza = reply }); | |
66 origin.send(reply); | |
67 return true; | |
68 end | |
69 end); | |
70 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) | |
71 local origin, stanza = event.origin, event.stanza; | |
72 if stanza.attr.type ~= "get" then return; end | |
73 local node = stanza.tags[1].attr.node; | |
74 if node and node ~= "" then return; end -- TODO fire event? | |
75 local username = jid_split(stanza.attr.to) or origin.username; | |
76 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | |
77 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items'}); | |
78 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | |
79 module:fire_event("account-disco-items", { session = origin, stanza = reply }); | |
80 origin.send(reply); | |
81 return true; | |
82 end | |
83 end); |