68
|
1 |
|
|
2 |
-- REMOTE CONTROLLING CLIENTS (XEP-0146) |
|
3 |
|
|
4 |
-- library |
|
5 |
|
|
6 |
local iq = require 'lm.iq' |
|
7 |
local x_data = require 'lm.x_data' |
|
8 |
local disco = require 'lm.disco' |
|
9 |
|
|
10 |
-- |
|
11 |
|
|
12 |
local F = { } |
|
13 |
|
|
14 |
function F.list ( conn, to, success, fail ) |
|
15 |
disco.items ( conn, to, success, fail, 'http://jabber.org/protocol/commands' ) |
|
16 |
end |
|
17 |
|
|
18 |
function F.command ( conn, to, command, success, fail ) |
|
19 |
iq.send ( conn, to, 'set', |
|
20 |
{ |
|
21 |
command = { xmlns = 'http://jabber.org/protocol/commands', action = 'execute', node = command }, |
|
22 |
}, |
|
23 |
function ( mess ) |
|
24 |
local c = mess:child ( 'command' ) |
|
25 |
if c then |
|
26 |
local status = c:attribute ( 'status' ) |
|
27 |
if status == 'completed' then |
|
28 |
success () |
|
29 |
else |
|
30 |
local x = c:child ( 'x' ) |
|
31 |
if x then |
|
32 |
local sid = c:attribute ( 'sessionid' ) |
|
33 |
success ( x_data.parse ( x ), |
|
34 |
function ( form, success, fail ) |
|
35 |
iq.send ( conn, to, 'set', |
|
36 |
{ |
|
37 |
command = form:format ( { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid }, 'submit' ), |
|
38 |
}, |
|
39 |
function ( mess ) |
|
40 |
local c = mess:child ( 'command' ) |
|
41 |
if c and c:attribute ( 'status' ) == 'completed' then |
|
42 |
success () |
|
43 |
else |
|
44 |
fail ( mess:xml () ) -- XXX more forms? results? |
|
45 |
end |
|
46 |
end, fail ) |
|
47 |
end, |
|
48 |
function ( form, success, fail ) |
|
49 |
iq.send ( conn, to, 'set', |
|
50 |
{ |
|
51 |
command = form:format ( { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid }, 'cancel' ), |
|
52 |
}, success, fail ) |
|
53 |
end ) |
|
54 |
else |
|
55 |
fail ( mess:xml () ) -- XXX |
|
56 |
end |
|
57 |
end |
|
58 |
end |
|
59 |
end, fail ) |
|
60 |
end |
|
61 |
|
|
62 |
return F |
|
63 |
|
|
64 |
-- vim: se ts=4: -- |