Software /
code /
prosody
Annotate
plugins/mod_disco.lua @ 2472:cde876604bb7
s2smanager: Log error and fail gracefully if we can't open a socket for an outgoing s2s connection (thanks foucault)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 19 Jan 2010 19:58:02 +0000 |
parent | 2383:29a30884aadd |
child | 2491:4be6810914eb |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1510
diff
changeset
|
1 -- Prosody IM |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
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 |
1701
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
9 local componentmanager_get_children = require "core.componentmanager".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; |
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
|
11 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
|
12 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
|
13 local st = require "util.stanza" |
1510
83b2e07e9039
mod_disco: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
14 |
1704
9b445d2427e2
mod_disco: Rearranged some lines, and added a FIXME comment
Waqas Hussain <waqas20@gmail.com>
parents:
1703
diff
changeset
|
15 module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router |
1510
83b2e07e9039
mod_disco: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
16 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
|
17 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
|
18 |
1699
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
19 module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
20 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
|
21 if stanza.attr.type ~= "get" then return; end |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
22 local node = stanza.tags[1].attr.node; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
23 if node and node ~= "" then return; end -- TODO fire event? |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
24 |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
25 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
26 local done = {}; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
27 for _,identity in ipairs(module:get_host_items("identity")) do |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
28 local identity_s = identity.category.."\0"..identity.type; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
29 if not done[identity_s] then |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
30 reply:tag("identity", identity):up(); |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
31 done[identity_s] = true; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
32 end |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
33 end |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
34 for _,feature in ipairs(module:get_host_items("feature")) do |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
35 if not done[feature] then |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
36 reply:tag("feature", {var=feature}):up(); |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
37 done[feature] = true; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
38 end |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
39 end |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
40 origin.send(reply); |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
41 return true; |
53d16a28ee00
mod_disco: Handle disco#info queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
42 end); |
1701
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
43 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event) |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
44 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
|
45 if stanza.attr.type ~= "get" then return; end |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
46 local node = stanza.tags[1].attr.node; |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
47 if node and node ~= "" then return; end -- TODO fire event? |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
48 |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
49 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
50 for jid in pairs(componentmanager_get_children(module.host)) do |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
51 reply:tag("item", {jid = jid}):up(); |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
52 end |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
53 origin.send(reply); |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
54 return true; |
ceab61010f87
mod_disco: Handle disco#items queries using new APIs
Waqas Hussain <waqas20@gmail.com>
parents:
1700
diff
changeset
|
55 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
|
56 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) |
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
|
57 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
|
58 if stanza.attr.type ~= "get" then return; 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
|
59 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
|
60 if node and node ~= "" then return; end -- TODO fire event? |
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
|
61 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
|
62 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
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
|
63 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
|
64 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
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
|
65 module:fire_event("account-disco-info", { session = origin, stanza = 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) |
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
|
71 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
|
72 if stanza.attr.type ~= "get" then return; 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
|
73 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
|
74 if node and node ~= "" then return; end -- TODO fire event? |
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
|
75 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
|
76 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
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
|
77 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
|
78 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
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
|
79 module:fire_event("account-disco-items", { session = origin, stanza = 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
|
80 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
|
81 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
|
82 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
|
83 end); |