68
|
1 |
|
|
2 |
-- SERVICE DISCOVERY (XEP-0030) |
|
3 |
|
|
4 |
-- TODO handler |
|
5 |
|
|
6 |
-- library |
|
7 |
|
|
8 |
local iq = require 'lm.iq' |
|
9 |
|
|
10 |
-- |
|
11 |
|
|
12 |
local F = { } |
|
13 |
|
|
14 |
function F.items ( conn, to, success, fail, node ) |
|
15 |
iq.send ( conn, to, 'get', |
|
16 |
{ |
|
17 |
query = { xmlns = 'http://jabber.org/protocol/disco#items', node = node } |
|
18 |
}, |
|
19 |
function ( mess ) |
|
20 |
local item = mess:child( 'query' ):child () |
|
21 |
local items = { } |
|
22 |
while item do |
|
23 |
if item:name () == 'item' then |
|
24 |
table.insert ( items, { jid = item:attribute ( 'jid' ), node = item:attribute ( 'node' ), name = item:attribute ( 'name' ) } ) |
|
25 |
end |
|
26 |
item = item:next () |
|
27 |
end |
|
28 |
success ( items ) |
|
29 |
end, |
|
30 |
fail ) |
|
31 |
end |
|
32 |
|
|
33 |
function F.info ( conn, to, success, fail ) |
|
34 |
iq.send ( conn, to, 'get', |
|
35 |
{ |
|
36 |
query = { xmlns='http://jabber.org/protocol/disco#info' } |
|
37 |
}, |
|
38 |
function ( mess ) |
|
39 |
local identities = { } |
|
40 |
local features = { } |
|
41 |
local item = mess:child( 'query' ):child () |
|
42 |
while item do |
|
43 |
local name = item:name () |
|
44 |
if name == 'identity' then |
|
45 |
table.insert ( identities, { category = item:attribute ( 'category' ), type = item:attribute ( 'type' ), name = item:attribute ( 'name' ) } ) |
|
46 |
elseif name == 'feature' then |
|
47 |
table.insert ( features, item:attribute ( 'var' ) ) |
|
48 |
end |
|
49 |
item = item:next () |
|
50 |
end |
|
51 |
success ( identities, features ) |
|
52 |
end, |
|
53 |
fail ) |
|
54 |
end |
|
55 |
|
|
56 |
return F |
|
57 |
|
|
58 |
-- vim: se ts=4: -- |