examples/disco.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Fri, 27 Mar 2009 12:06:19 +0200
changeset 66 542f61e113cb
parent 64 bf7521ed96eb
child 68 742878c74b8e
permissions -rw-r--r--
Modularization, I * activity * attention * avatar * disco * evil * geoloc * ibb * iq * mood * oob * ping * pubsub * tune * mpd * pep


-- SERVICE DISCOVERY (XEP-0030)

-- TODO add handler (unused by mcabber)

-- library

local iq = require '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: --