Mercurial > prosody-hg
comparison plugins/mod_disco.lua @ 6054:7a5ddbaf758d
Merge 0.9->0.10
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 02 Apr 2014 17:41:38 +0100 |
| parents | bd0ff8ae98a8 |
| children | 200f1f6306a7 |
comparison
equal
deleted
inserted
replaced
| 6053:2f93a04564b2 | 6054:7a5ddbaf758d |
|---|---|
| 1 -- Prosody IM | 1 -- Prosody IM |
| 2 -- Copyright (C) 2008-2010 Matthew Wild | 2 -- Copyright (C) 2008-2010 Matthew Wild |
| 3 -- Copyright (C) 2008-2010 Waqas Hussain | 3 -- Copyright (C) 2008-2010 Waqas Hussain |
| 4 -- | 4 -- |
| 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 get_children = require "core.hostmanager".get_children; | 9 local get_children = require "core.hostmanager".get_children; |
| 30 break; | 30 break; |
| 31 end | 31 end |
| 32 end | 32 end |
| 33 end | 33 end |
| 34 | 34 |
| 35 module:add_identity("server", "im", module:get_option_string("name", "Prosody")); -- FIXME should be in the non-existing mod_router | 35 if module:get_host_type() == "local" then |
| 36 module:add_identity("server", "im", module:get_option_string("name", "Prosody")); -- FIXME should be in the non-existing mod_router | |
| 37 end | |
| 36 module:add_feature("http://jabber.org/protocol/disco#info"); | 38 module:add_feature("http://jabber.org/protocol/disco#info"); |
| 37 module:add_feature("http://jabber.org/protocol/disco#items"); | 39 module:add_feature("http://jabber.org/protocol/disco#items"); |
| 38 | 40 |
| 39 -- Generate and cache disco result and caps hash | 41 -- Generate and cache disco result and caps hash |
| 40 local _cached_server_disco_info, _cached_server_caps_feature, _cached_server_caps_hash; | 42 local _cached_server_disco_info, _cached_server_caps_feature, _cached_server_caps_hash; |
| 95 -- Handle disco requests to the server | 97 -- Handle disco requests to the server |
| 96 module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) | 98 module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) |
| 97 local origin, stanza = event.origin, event.stanza; | 99 local origin, stanza = event.origin, event.stanza; |
| 98 if stanza.attr.type ~= "get" then return; end | 100 if stanza.attr.type ~= "get" then return; end |
| 99 local node = stanza.tags[1].attr.node; | 101 local node = stanza.tags[1].attr.node; |
| 100 if node and node ~= "" and node ~= "http://prosody.im#"..get_server_caps_hash() then return; end -- TODO fire event? | 102 if node and node ~= "" and node ~= "http://prosody.im#"..get_server_caps_hash() then |
| 103 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); | |
| 104 local event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; | |
| 105 local ret = module:fire_event("host-disco-info-node", event); | |
| 106 if ret ~= nil then return ret; end | |
| 107 if event.exists then | |
| 108 origin.send(reply); | |
| 109 else | |
| 110 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); | |
| 111 end | |
| 112 return true; | |
| 113 end | |
| 101 local reply_query = get_server_disco_info(); | 114 local reply_query = get_server_disco_info(); |
| 102 reply_query.node = node; | 115 reply_query.node = node; |
| 103 local reply = st.reply(stanza):add_child(reply_query); | 116 local reply = st.reply(stanza):add_child(reply_query); |
| 104 origin.send(reply); | 117 origin.send(reply); |
| 105 return true; | 118 return true; |
| 106 end); | 119 end); |
| 107 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event) | 120 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event) |
| 108 local origin, stanza = event.origin, event.stanza; | 121 local origin, stanza = event.origin, event.stanza; |
| 109 if stanza.attr.type ~= "get" then return; end | 122 if stanza.attr.type ~= "get" then return; end |
| 110 local node = stanza.tags[1].attr.node; | 123 local node = stanza.tags[1].attr.node; |
| 111 if node and node ~= "" then return; end -- TODO fire event? | 124 if node and node ~= "" then |
| 112 | 125 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); |
| 126 local event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; | |
| 127 local ret = module:fire_event("host-disco-items-node", event); | |
| 128 if ret ~= nil then return ret; end | |
| 129 if event.exists then | |
| 130 origin.send(reply); | |
| 131 else | |
| 132 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); | |
| 133 end | |
| 134 return true; | |
| 135 end | |
| 113 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); | 136 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
| 137 local ret = module:fire_event("host-disco-items", { origin = origin, stanza = stanza, reply = reply }); | |
| 138 if ret ~= nil then return ret; end | |
| 114 for jid, name in pairs(get_children(module.host)) do | 139 for jid, name in pairs(get_children(module.host)) do |
| 115 reply:tag("item", {jid = jid, name = name~=true and name or nil}):up(); | 140 reply:tag("item", {jid = jid, name = name~=true and name or nil}):up(); |
| 116 end | 141 end |
| 117 for _, item in ipairs(disco_items) do | 142 for _, item in ipairs(disco_items) do |
| 118 reply:tag("item", {jid=item[1], name=item[2]}):up(); | 143 reply:tag("item", {jid=item[1], name=item[2]}):up(); |
| 131 -- Handle disco requests to user accounts | 156 -- Handle disco requests to user accounts |
| 132 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) | 157 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) |
| 133 local origin, stanza = event.origin, event.stanza; | 158 local origin, stanza = event.origin, event.stanza; |
| 134 if stanza.attr.type ~= "get" then return; end | 159 if stanza.attr.type ~= "get" then return; end |
| 135 local node = stanza.tags[1].attr.node; | 160 local node = stanza.tags[1].attr.node; |
| 136 if node and node ~= "" then return; end -- TODO fire event? | |
| 137 local username = jid_split(stanza.attr.to) or origin.username; | 161 local username = jid_split(stanza.attr.to) or origin.username; |
| 138 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | 162 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
| 163 if node and node ~= "" then | |
| 164 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); | |
| 165 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | |
| 166 local event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; | |
| 167 local ret = module:fire_event("account-disco-info-node", event); | |
| 168 if ret ~= nil then return ret; end | |
| 169 if event.exists then | |
| 170 origin.send(reply); | |
| 171 else | |
| 172 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); | |
| 173 end | |
| 174 return true; | |
| 175 end | |
| 139 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); | 176 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); |
| 140 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | 177 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
| 141 module:fire_event("account-disco-info", { origin = origin, stanza = reply }); | 178 module:fire_event("account-disco-info", { origin = origin, reply = reply }); |
| 142 origin.send(reply); | 179 origin.send(reply); |
| 143 return true; | 180 return true; |
| 144 end | 181 end |
| 145 end); | 182 end); |
| 146 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) | 183 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) |
| 147 local origin, stanza = event.origin, event.stanza; | 184 local origin, stanza = event.origin, event.stanza; |
| 148 if stanza.attr.type ~= "get" then return; end | 185 if stanza.attr.type ~= "get" then return; end |
| 149 local node = stanza.tags[1].attr.node; | 186 local node = stanza.tags[1].attr.node; |
| 150 if node and node ~= "" then return; end -- TODO fire event? | |
| 151 local username = jid_split(stanza.attr.to) or origin.username; | 187 local username = jid_split(stanza.attr.to) or origin.username; |
| 152 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | 188 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
| 189 if node and node ~= "" then | |
| 190 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); | |
| 191 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | |
| 192 local event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; | |
| 193 local ret = module:fire_event("account-disco-items-node", event); | |
| 194 if ret ~= nil then return ret; end | |
| 195 if event.exists then | |
| 196 origin.send(reply); | |
| 197 else | |
| 198 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); | |
| 199 end | |
| 200 return true; | |
| 201 end | |
| 153 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items'}); | 202 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items'}); |
| 154 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | 203 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
| 155 module:fire_event("account-disco-items", { origin = origin, stanza = reply }); | 204 module:fire_event("account-disco-items", { origin = origin, stanza = stanza, reply = reply }); |
| 156 origin.send(reply); | 205 origin.send(reply); |
| 157 return true; | 206 return true; |
| 158 end | 207 end |
| 159 end); | 208 end); |
