Software /
code /
prosody
Comparison
plugins/mod_disco.lua @ 5627:0439d1349dc1
mod_disco: Emit events for disco requests, which contain a node, on user accounts
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 17 May 2013 18:35:50 +0200 |
parent | 5081:c0c060e450be |
child | 5689:832ea1e9ac9e |
comparison
equal
deleted
inserted
replaced
5626:8416d4619d80 | 5627:0439d1349dc1 |
---|---|
131 -- Handle disco requests to user accounts | 131 -- Handle disco requests to user accounts |
132 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) | 132 module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(event) |
133 local origin, stanza = event.origin, event.stanza; | 133 local origin, stanza = event.origin, event.stanza; |
134 if stanza.attr.type ~= "get" then return; end | 134 if stanza.attr.type ~= "get" then return; end |
135 local node = stanza.tags[1].attr.node; | 135 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; | 136 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 | 137 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
138 if node and node ~= "" then | |
139 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); | |
140 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account | |
141 local event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false} | |
142 module:fire_event("account-disco-info-node", event); | |
143 if event.exists then | |
144 origin.send(reply); | |
145 else | |
146 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); | |
147 end | |
148 return true; | |
149 end | |
139 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); | 150 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 | 151 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 }); | 152 module:fire_event("account-disco-info", { origin = origin, reply = reply }); |
142 origin.send(reply); | 153 origin.send(reply); |
143 return true; | 154 return true; |
144 end | 155 end |
145 end); | 156 end); |
146 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) | 157 module:hook("iq/bare/http://jabber.org/protocol/disco#items:query", function(event) |
147 local origin, stanza = event.origin, event.stanza; | 158 local origin, stanza = event.origin, event.stanza; |
148 if stanza.attr.type ~= "get" then return; end | 159 if stanza.attr.type ~= "get" then return; end |
149 local node = stanza.tags[1].attr.node; | 160 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; | 161 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 | 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#items', 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 module:fire_event("account-disco-items-node", event); | |
168 if event.exists then | |
169 origin.send(reply); | |
170 else | |
171 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Node does not exist")); | |
172 end | |
173 return true; | |
174 end | |
153 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#items'}); | 175 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 | 176 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 }); | 177 module:fire_event("account-disco-items", { origin = origin, stanza = stanza, reply = reply }); |
156 origin.send(reply); | 178 origin.send(reply); |
157 return true; | 179 return true; |
158 end | 180 end |
159 end); | 181 end); |