Software /
code /
prosody
Comparison
plugins/mod_disco.lua @ 9223:80dbb60d81e4
mod_disco: Simplify iq handling by hooking on iq-get/ instead of iq/.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 24 Aug 2018 20:34:18 +0200 |
parent | 8834:b0093d3b2d04 |
child | 11204:ae2a11066001 |
comparison
equal
deleted
inserted
replaced
9222:fe8abac62682 | 9223:80dbb60d81e4 |
---|---|
93 module:hook("item-removed/identity", clear_disco_cache); | 93 module:hook("item-removed/identity", clear_disco_cache); |
94 module:hook("item-removed/feature", clear_disco_cache); | 94 module:hook("item-removed/feature", clear_disco_cache); |
95 module:hook("item-removed/extension", clear_disco_cache); | 95 module:hook("item-removed/extension", clear_disco_cache); |
96 | 96 |
97 -- Handle disco requests to the server | 97 -- Handle disco requests to the server |
98 module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) | 98 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event) |
99 local origin, stanza = event.origin, event.stanza; | 99 local origin, stanza = event.origin, event.stanza; |
100 if stanza.attr.type ~= "get" then return; end | |
101 local node = stanza.tags[1].attr.node; | 100 local node = stanza.tags[1].attr.node; |
102 if node and node ~= "" and node ~= "http://prosody.im#"..get_server_caps_hash() then | 101 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}); | 102 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); |
104 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; | 103 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
105 local ret = module:fire_event("host-disco-info-node", node_event); | 104 local ret = module:fire_event("host-disco-info-node", node_event); |
115 reply_query.attr.node = node; | 114 reply_query.attr.node = node; |
116 local reply = st.reply(stanza):add_child(reply_query); | 115 local reply = st.reply(stanza):add_child(reply_query); |
117 origin.send(reply); | 116 origin.send(reply); |
118 return true; | 117 return true; |
119 end); | 118 end); |
120 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event) | 119 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event) |
121 local origin, stanza = event.origin, event.stanza; | 120 local origin, stanza = event.origin, event.stanza; |
122 if stanza.attr.type ~= "get" then return; end | |
123 local node = stanza.tags[1].attr.node; | 121 local node = stanza.tags[1].attr.node; |
124 if node and node ~= "" then | 122 if node and node ~= "" then |
125 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); | 123 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); |
126 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; | 124 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
127 local ret = module:fire_event("host-disco-items-node", node_event); | 125 local ret = module:fire_event("host-disco-items-node", node_event); |
153 end | 151 end |
154 end); | 152 end); |
155 | 153 |
156 -- Handle disco requests to user accounts | 154 -- Handle disco requests to user accounts |
157 if module:get_host_type() ~= "local" then return end -- skip for components | 155 if module:get_host_type() ~= "local" then return end -- skip for components |
158 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) | 156 module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function(event) |
159 local origin, stanza = event.origin, event.stanza; | 157 local origin, stanza = event.origin, event.stanza; |
160 if stanza.attr.type ~= "get" then return; end | |
161 local node = stanza.tags[1].attr.node; | 158 local node = stanza.tags[1].attr.node; |
162 local username = jid_split(stanza.attr.to) or origin.username; | 159 local username = jid_split(stanza.attr.to) or origin.username; |
163 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | 160 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
164 if node and node ~= "" then | 161 if node and node ~= "" then |
165 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); | 162 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); |
180 module:fire_event("account-disco-info", { origin = origin, reply = reply }); | 177 module:fire_event("account-disco-info", { origin = origin, reply = reply }); |
181 origin.send(reply); | 178 origin.send(reply); |
182 return true; | 179 return true; |
183 end | 180 end |
184 end); | 181 end); |
185 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) | 182 module:hook("iq-get/bare/http://jabber.org/protocol/disco#items:query", function(event) |
186 local origin, stanza = event.origin, event.stanza; | 183 local origin, stanza = event.origin, event.stanza; |
187 if stanza.attr.type ~= "get" then return; end | |
188 local node = stanza.tags[1].attr.node; | 184 local node = stanza.tags[1].attr.node; |
189 local username = jid_split(stanza.attr.to) or origin.username; | 185 local username = jid_split(stanza.attr.to) or origin.username; |
190 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | 186 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
191 if node and node ~= "" then | 187 if node and node ~= "" then |
192 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); | 188 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items', node=node}); |