-- SERVICE DISCOVERY (XEP-0030)
-- TODO handler
-- library
local iq = require 'lm.iq'
--
local F = { }
function F.items ( conn, to, success, fail, node )
iq.send ( conn, to, 'get',
{
query = { xmlns = 'http://jabber.org/protocol/disco#items', node = node }
},
function ( mess )
local item = mess:child( 'query' ):child ()
local items = { }
while item do
if item:name () == 'item' then
table.insert ( items, { jid = item:attribute ( 'jid' ), node = item:attribute ( 'node' ), name = item:attribute ( 'name' ) } )
end
item = item:next ()
end
success ( items )
end,
fail )
end
function F.info ( conn, to, success, fail )
iq.send ( conn, to, 'get',
{
query = { xmlns='http://jabber.org/protocol/disco#info' }
},
function ( mess )
local identities = { }
local features = { }
local item = mess:child( 'query' ):child ()
while item do
local name = item:name ()
if name == 'identity' then
table.insert ( identities, { category = item:attribute ( 'category' ), type = item:attribute ( 'type' ), name = item:attribute ( 'name' ) } )
elseif name == 'feature' then
table.insert ( features, item:attribute ( 'var' ) )
end
item = item:next ()
end
success ( identities, features )
end, fail )
end
return F
-- vim: se ts=4: --