scripts/xep0030.lua
changeset 5 cba039bd6f13
parent 4 bca17e4a9851
child 6 90dceae3ed1f
--- a/scripts/xep0030.lua	Mon Feb 23 23:16:46 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-
-function disco_items ( callback, what, node )
-	local request =
-		lm.message.create { to = what, mtype = 'iq-get',
-			query = { xmlns = 'http://jabber.org/protocol/disco#items' }
-		}
-	if node then
-		request:child( 'query' ):attribute ( 'node', node )
-	end
-	return lm.connection.bless( main.connection () ):send ( request,
-		function ( conn, message )
-			if message:child ( 'error' ) then
-				callback ( message:child( 'error' ):children():name () )
-			else
-				local item = message:child( 'query' ):children ()
-				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
-				callback ( items )
-			end
-			return true
-		end )
-end
-
-function disco_info ( callback, what )
-	return lm.connection.bless( main.connection () ):send (
-		lm.message.create { to = what, mtype = 'iq-get',
-			query = { xmlns='http://jabber.org/protocol/disco#info' }
-		},
-		function ( conn, message )
-			local items_supported = false
-			if message:child ( 'error' ) then
-				callback ( message:child( 'error' ):children():name () )
-			else
-				local item = message:child( 'query' ):children ()
-				local identities = { }
-				local features   = { }
-				while item do
-					if item:name () == 'identity' then
-						table.insert ( identities, { category = item:attribute ( 'category' ), type = item:attribute ( 'type' ), name = item:attribute ( 'name' ) } )
-					elseif item:name () == 'feature' then
-						table.insert ( features, item:attribute ( 'var' ) )
-					end
-					item = item:next ()
-				end
-				callback ( identities, features )
-			end
-			return true
-		end )
-end
-
-main.add_command ( 'disco',
-	function ( args )
-		args = parse_args ( args )
-		local who
-		if args.t then
-			who = args.t
-			args.t = nil
-		else
-			who = full_current_jid ()
-		end
-		if args[1] == 'items' then
-			local node = nil
-			if args[2] then
-				args[1] = nil
-				node = rebuild_args_string ( args )
-			end
-			disco_items (
-				function ( items )
-					if type ( items ) == 'string' then
-						main.print_info ( who, string.format ( "Service items discovery for %s (%s) failed: %s", who, node or '', items ) )
-					else
-						main.print_info ( who, string.format ( "Service items discovery result for %s (%s):", who, node or '' ) )
-						for index, item in ipairs ( items ) do
-							main.print_info ( who, string.format ( "    [%s (%s)] %s", item.jid or '', item.node or '', item.name or '' ) )
-						end
-					end
-				end, who, node )
-		else
-			disco_info (
-				function ( identities, features )
-					if type ( identities ) == 'string' then
-						main.print_info ( who, string.format ( "Service info discovery for %s failed: %s", who, identities ) )
-					else
-						main.print_info ( who, string.format ( "Service info discovery result for %s:", who ) )
-						main.print_info ( who, "  Identities:" )
-						for index, identity in ipairs ( identities ) do
-							main.print_info ( who, string.format ( "    [%s (%s)] %s", identity.category or '', identity.type or '', identity.name or '' ) )
-						end
-						main.print_info ( who, "  Features:" )
-						for index, feature in ipairs ( features ) do
-							main.print_info ( who, string.format ( "    [%s]", feature or '' ) )
-						end
-					end
-				end, who )
-		end
-	end )
-
-commands_help['disco'] = "[-t target_jid] [info | items] [node]\n\nService discovery request.\nInfo is sent if omitted.\nIf info reveals, that buddy can do items, items request also will be sent."
-
--- vim: se ts=4: --