68
|
1 |
|
|
2 |
-- XMPP PING (XEP-0199) |
|
3 |
|
|
4 |
-- library |
|
5 |
|
|
6 |
local lm = require 'lm' |
|
7 |
local iq = require 'lm.iq' |
|
8 |
|
|
9 |
-- |
|
10 |
|
|
11 |
local F = { } |
|
12 |
|
|
13 |
function F.send ( conn, to, success, fail ) |
|
14 |
iq.send ( conn, to, 'get', |
|
15 |
{ |
|
16 |
ping = { xmlns = 'urn:xmpp:ping' }, |
|
17 |
}, success, fail ) |
|
18 |
end |
|
19 |
|
|
20 |
function F.iq_handler ( conn, mess ) |
|
21 |
local mtype, smtype = mess:type () |
|
22 |
if smtype == 'get' then |
|
23 |
local p = mess:child ( 'ping' ) |
|
24 |
if p and p:attribute ( 'xmlns' ) == 'urn:xmpp:ping' then |
|
25 |
conn:send ( lm.message.create { mtype = 'iq-result', to = mess:attribute ( 'from' ), id = mess:attribute ( 'id' ) } ) |
|
26 |
return true |
|
27 |
end |
|
28 |
end |
|
29 |
return false |
|
30 |
end |
|
31 |
|
|
32 |
return F |
|
33 |
|
|
34 |
-- vim: se ts=4: -- |