function remote_command ( who, command )
lm.connection.bless( main.connection () ):send (
lm.message.create { mtype = 'iq-set', to = who,
command = { xmlns = 'http://jabber.org/protocol/commands', action = 'execute', node = command }
},
function ( conn, mess )
if mess:child ( 'command' ) and mess:child( 'command' ):child ( 'x' ) then
local id = parse_form ( mess:child( 'command' ):child ( 'x' ) )
local sid = mess:child( 'command' ):attribute ( 'sessionid' )
forms[id].send =
function ( form )
conn:send (
lm.message.create { mtype = 'iq-set', to = who,
command = { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid,
x = { xmlns = 'jabber:x:data', type = 'form',
field = form.val,
},
},
},
function ( conn, mess )
if mess:child ( 'command' ) and mess:child( 'command' ):attribute ( 'status' ) == 'completed' then
main.print_info ( who, 'Now you can run /form del ' .. id .. ' to delete form from list' )
forms.status = 'acquired'
else
main.print_info ( who, 'Got non-successful response to form:\n' .. mess:xml () )
forms.status = 'rejected'
end
return true
end )
form.status = 'sent'
end
forms[id].status = 'filling'
main.print_info ( who, 'You have new form. To fill it, use /form ' .. id .. ' fieldname value' )
else
main.print_info ( who, 'Got response to command request:\n' .. mess:xml () )
end
return true
end )
end
main.command ( 'remote',
function ( args )
local who
if args.t then
who = args.t
else
who = main.full_jid ()
end
local action = args[1]
if not action then
disco_items ( lm.connection.bless ( main.connection (),
function ( items )
if type ( items ) == 'string' then
main.print_info ( who, string.format ( "Service items discovery for %s (http://jabber.org/protocol/commands) failed: %s", who, items ) )
else
local text = ''
for index, item in ipairs ( items ) do
text = text .. '\n - ' .. item.node
end
if text ~= '' then
main.print_info ( who, 'Available commands:' .. text )
else
main.print_info ( who, 'No commands available.' )
end
end
end, who, 'http://jabber.org/protocol/commands' )
elseif action then
remote_command ( who, action )
end
end, true, 'jid' )
commands_help['remote'] = "[-t target_jid] [remote_command]\n\nPrints list of available remote command or requests execution of specified command."
-- vim: se ts=4: --