author | Myhailo Danylenko <isbear@ukrpost.net> |
Sat, 28 Mar 2009 19:43:12 +0200 | |
changeset 67 | d33ca5572e91 |
parent 66 | 542f61e113cb |
child 68 | 742878c74b8e |
permissions | -rw-r--r-- |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
1 |
|
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
2 |
-- REMOTE CONTROLLING CLIENTS (XEP-0146) |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
3 |
|
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
4 |
-- library |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
5 |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
6 |
local iq = require 'iq' |
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
7 |
local x_data = require 'x_data' |
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
8 |
local disco = require 'disco' |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
9 |
|
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
10 |
-- public |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
11 |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
12 |
local F = { } |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
13 |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
14 |
function F.list ( conn, to, success, fail ) |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
15 |
disco.items ( conn, to, success, fail, 'http://jabber.org/protocol/commands' ) |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
16 |
end |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
17 |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
18 |
function F.command ( conn, to, command, success, fail ) |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
19 |
iq.send ( conn, to, 'set', |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
20 |
{ |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
21 |
command = { xmlns = 'http://jabber.org/protocol/commands', action = 'execute', node = command }, |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
22 |
}, |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
23 |
function ( mess ) |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
24 |
local c = mess:child ( 'command' ) |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
25 |
if c then |
49 | 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 |
{ |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
37 |
command = form:format ( { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid }, 'submit' ), |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
38 |
}, |
49 | 39 |
function ( mess ) |
40 |
local c = mess:child ( 'command' ) |
|
41 |
if c and c:attribute ( 'status' ) == 'completed' then |
|
42 |
success () |
|
43 |
else |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
44 |
fail ( mess:xml () ) -- XXX more forms? results? |
49 | 45 |
end |
46 |
end, fail ) |
|
47 |
end, |
|
48 |
function ( form, success, fail ) |
|
51
a95a3a73482c
Pubsub uses new forms
Myhailo Danylenko <isbear@ukrpost.net>
parents:
49
diff
changeset
|
49 |
iq.send ( conn, to, 'set', |
a95a3a73482c
Pubsub uses new forms
Myhailo Danylenko <isbear@ukrpost.net>
parents:
49
diff
changeset
|
50 |
{ |
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
51 |
command = form:format ( { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid }, 'cancel' ), |
51
a95a3a73482c
Pubsub uses new forms
Myhailo Danylenko <isbear@ukrpost.net>
parents:
49
diff
changeset
|
52 |
}, success, fail ) |
49 | 53 |
end ) |
54 |
else |
|
55 |
fail ( mess:xml () ) -- XXX |
|
56 |
end |
|
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
57 |
end |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
58 |
end |
49 | 59 |
end, fail ) |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
60 |
end |
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
61 |
|
67
d33ca5572e91
Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
62 |
return F |
44
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
63 |
|
bd66956cd397
Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff
changeset
|
64 |
-- vim: se ts=4: -- |