examples/lm/disco.lua
changeset 68 742878c74b8e
child 70 e43e386c8a33
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/lm/disco.lua	Tue Mar 31 18:35:34 2009 +0300
@@ -0,0 +1,58 @@
+
+-- 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: --