19 stream.disco = { cache = {}, info = {} } |
19 stream.disco = { cache = {}, info = {} } |
20 stream.disco.info.identities = { |
20 stream.disco.info.identities = { |
21 {category = 'client', type='pc', name='Verse'}, |
21 {category = 'client', type='pc', name='Verse'}, |
22 } |
22 } |
23 stream.disco.info.features = { |
23 stream.disco.info.features = { |
24 {var = 'http://jabber.org/protocol/caps'}, |
24 {var = xmlns_caps}, |
25 {var = 'http://jabber.org/protocol/disco#info'}, |
25 {var = xmlns_disco_info}, |
26 {var = 'http://jabber.org/protocol/disco#items'}, |
26 {var = xmlns_disco_items}, |
27 } |
27 } |
28 stream.disco.items = {} |
28 stream.disco.items = {} |
29 stream.disco.nodes = {} |
29 stream.disco.nodes = {} |
30 |
30 |
31 stream.caps = {} |
31 stream.caps = {} |
79 __call = function (...) -- vararg: allow calling as function or member |
79 __call = function (...) -- vararg: allow calling as function or member |
80 -- retrieve the c stanza to insert into the |
80 -- retrieve the c stanza to insert into the |
81 -- presence stanza |
81 -- presence stanza |
82 local hash = calculate_hash() |
82 local hash = calculate_hash() |
83 return st.stanza('c', { |
83 return st.stanza('c', { |
84 xmlns = 'http://jabber.org/protocol/caps', |
84 xmlns = xmlns_caps, |
85 hash = 'sha-1', |
85 hash = 'sha-1', |
86 node = stream.caps.node, |
86 node = stream.caps.node, |
87 ver = hash |
87 ver = hash |
88 }) |
88 }) |
89 end |
89 end |
253 end |
253 end |
254 return callback(disco_items); |
254 return callback(disco_items); |
255 end); |
255 end); |
256 end |
256 end |
257 |
257 |
258 stream:hook("iq/http://jabber.org/protocol/disco#info", function (stanza) |
258 stream:hook("iq/"..xmlns_disco_info, function (stanza) |
259 if stanza.attr.type == 'get' then |
259 if stanza.attr.type == 'get' then |
260 local query = stanza:child_with_name('query') |
260 local query = stanza:child_with_name('query') |
261 if not query then return; end |
261 if not query then return; end |
262 -- figure out what identities/features to send |
262 -- figure out what identities/features to send |
263 local identities |
263 local identities |
278 to = stanza.attr.from, |
278 to = stanza.attr.from, |
279 from = stanza.attr.to, |
279 from = stanza.attr.to, |
280 id = stanza.attr.id, |
280 id = stanza.attr.id, |
281 type = 'error' |
281 type = 'error' |
282 }) |
282 }) |
283 response:tag('query',{xmlns = 'http://jabber.org/protocol/disco#info'}):reset() |
283 response:tag('query',{xmlns = xmlns_disco_info}):reset() |
284 response:tag('error',{type = 'cancel'}):tag( |
284 response:tag('error',{type = 'cancel'}):tag( |
285 'item-not-found',{xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas'} |
285 'item-not-found',{xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas'} |
286 ) |
286 ) |
287 stream:send(response) |
287 stream:send(response) |
288 return true |
288 return true |
291 identities = stream.disco.info.identities |
291 identities = stream.disco.info.identities |
292 features = stream.disco.info.features |
292 features = stream.disco.info.features |
293 end |
293 end |
294 -- construct the response |
294 -- construct the response |
295 local result = st.stanza('query',{ |
295 local result = st.stanza('query',{ |
296 xmlns = 'http://jabber.org/protocol/disco#info', |
296 xmlns = xmlns_disco_info, |
297 node = query.attr.node |
297 node = query.attr.node |
298 }) |
298 }) |
299 for key,identity in pairs(identities) do |
299 for key,identity in pairs(identities) do |
300 result:tag('identity', identity):reset() |
300 result:tag('identity', identity):reset() |
301 end |
301 end |
310 }):add_child(result)) |
310 }):add_child(result)) |
311 return true |
311 return true |
312 end |
312 end |
313 end); |
313 end); |
314 |
314 |
315 stream:hook("iq/http://jabber.org/protocol/disco#items", function (stanza) |
315 stream:hook("iq/"..xmlns_disco_items, function (stanza) |
316 if stanza.attr.type == 'get' then |
316 if stanza.attr.type == 'get' then |
317 local query = stanza:child_with_name('query') |
317 local query = stanza:child_with_name('query') |
318 if not query then return; end |
318 if not query then return; end |
319 -- figure out what items to send |
319 -- figure out what items to send |
320 local items |
320 local items |
328 to = stanza.attr.from, |
328 to = stanza.attr.from, |
329 from = stanza.attr.to, |
329 from = stanza.attr.to, |
330 id = stanza.attr.id, |
330 id = stanza.attr.id, |
331 type = 'error' |
331 type = 'error' |
332 }) |
332 }) |
333 response:tag('query',{xmlns = 'http://jabber.org/protocol/disco#items'}):reset() |
333 response:tag('query',{xmlns = xmlns_disco_items}):reset() |
334 response:tag('error',{type = 'cancel'}):tag( |
334 response:tag('error',{type = 'cancel'}):tag( |
335 'item-not-found',{xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas'} |
335 'item-not-found',{xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas'} |
336 ) |
336 ) |
337 stream:send(response) |
337 stream:send(response) |
338 return true |
338 return true |
340 else |
340 else |
341 items = stream.disco.items |
341 items = stream.disco.items |
342 end |
342 end |
343 -- construct the response |
343 -- construct the response |
344 local result = st.stanza('query',{ |
344 local result = st.stanza('query',{ |
345 xmlns = 'http://jabber.org/protocol/disco#items', |
345 xmlns = xmlns_disco_items, |
346 node = query.attr.node |
346 node = query.attr.node |
347 }) |
347 }) |
348 for key,item in pairs(items) do |
348 for key,item in pairs(items) do |
349 result:tag('item', item):reset() |
349 result:tag('item', item):reset() |
350 end |
350 end |