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 st = require "util.stanza" |
|
10 local b64 = require("mime").b64 |
9 local b64 = require("mime").b64 |
11 local sha1 = require("util.sha1").sha1 |
10 local sha1 = require("util.sha1").sha1 |
12 |
11 |
13 local xmlns_caps = "http://jabber.org/protocol/caps"; |
12 local xmlns_caps = "http://jabber.org/protocol/caps"; |
14 local xmlns_disco = "http://jabber.org/protocol/disco"; |
13 local xmlns_disco = "http://jabber.org/protocol/disco"; |
77 setmetatable(stream.caps, { |
76 setmetatable(stream.caps, { |
78 __call = function (...) -- vararg: allow calling as function or member |
77 __call = function (...) -- vararg: allow calling as function or member |
79 -- retrieve the c stanza to insert into the |
78 -- retrieve the c stanza to insert into the |
80 -- presence stanza |
79 -- presence stanza |
81 local hash = calculate_hash() |
80 local hash = calculate_hash() |
82 return st.stanza('c', { |
81 return verse.stanza('c', { |
83 xmlns = xmlns_caps, |
82 xmlns = xmlns_caps, |
84 hash = 'sha-1', |
83 hash = 'sha-1', |
85 node = stream.caps.node, |
84 node = stream.caps.node, |
86 ver = hash |
85 ver = hash |
87 }) |
86 }) |
271 -- matches caps hash, so use the main info |
270 -- matches caps hash, so use the main info |
272 identities = stream.disco.info.identities |
271 identities = stream.disco.info.identities |
273 features = stream.disco.info.features |
272 features = stream.disco.info.features |
274 else |
273 else |
275 -- unknown node: give an error |
274 -- unknown node: give an error |
276 local response = st.stanza('iq',{ |
275 local response = verse.stanza('iq',{ |
277 to = stanza.attr.from, |
276 to = stanza.attr.from, |
278 from = stanza.attr.to, |
277 from = stanza.attr.to, |
279 id = stanza.attr.id, |
278 id = stanza.attr.id, |
280 type = 'error' |
279 type = 'error' |
281 }) |
280 }) |
289 else |
288 else |
290 identities = stream.disco.info.identities |
289 identities = stream.disco.info.identities |
291 features = stream.disco.info.features |
290 features = stream.disco.info.features |
292 end |
291 end |
293 -- construct the response |
292 -- construct the response |
294 local result = st.stanza('query',{ |
293 local result = verse.stanza('query',{ |
295 xmlns = xmlns_disco_info, |
294 xmlns = xmlns_disco_info, |
296 node = query.attr.node |
295 node = query.attr.node |
297 }) |
296 }) |
298 for key,identity in pairs(identities) do |
297 for key,identity in pairs(identities) do |
299 result:tag('identity', identity):reset() |
298 result:tag('identity', identity):reset() |
300 end |
299 end |
301 for key,feature in pairs(features) do |
300 for key,feature in pairs(features) do |
302 result:tag('feature', feature):reset() |
301 result:tag('feature', feature):reset() |
303 end |
302 end |
304 stream:send(st.stanza('iq',{ |
303 stream:send(verse.stanza('iq',{ |
305 to = stanza.attr.from, |
304 to = stanza.attr.from, |
306 from = stanza.attr.to, |
305 from = stanza.attr.to, |
307 id = stanza.attr.id, |
306 id = stanza.attr.id, |
308 type = 'result' |
307 type = 'result' |
309 }):add_child(result)) |
308 }):add_child(result)) |
321 local node = stream.disco.nodes[query.attr.node] |
320 local node = stream.disco.nodes[query.attr.node] |
322 if node then |
321 if node then |
323 items = node.items or {} |
322 items = node.items or {} |
324 else |
323 else |
325 -- unknown node: give an error |
324 -- unknown node: give an error |
326 local response = st.stanza('iq',{ |
325 local response = verse.stanza('iq',{ |
327 to = stanza.attr.from, |
326 to = stanza.attr.from, |
328 from = stanza.attr.to, |
327 from = stanza.attr.to, |
329 id = stanza.attr.id, |
328 id = stanza.attr.id, |
330 type = 'error' |
329 type = 'error' |
331 }) |
330 }) |
338 end |
337 end |
339 else |
338 else |
340 items = stream.disco.items |
339 items = stream.disco.items |
341 end |
340 end |
342 -- construct the response |
341 -- construct the response |
343 local result = st.stanza('query',{ |
342 local result = verse.stanza('query',{ |
344 xmlns = xmlns_disco_items, |
343 xmlns = xmlns_disco_items, |
345 node = query.attr.node |
344 node = query.attr.node |
346 }) |
345 }) |
347 for key,item in pairs(items) do |
346 for key,item in pairs(items) do |
348 result:tag('item', item):reset() |
347 result:tag('item', item):reset() |
349 end |
348 end |
350 stream:send(st.stanza('iq',{ |
349 stream:send(verse.stanza('iq',{ |
351 to = stanza.attr.from, |
350 to = stanza.attr.from, |
352 from = stanza.attr.to, |
351 from = stanza.attr.to, |
353 id = stanza.attr.id, |
352 id = stanza.attr.id, |
354 type = 'result' |
353 type = 'result' |
355 }):add_child(result)) |
354 }):add_child(result)) |