68
|
1 |
|
|
2 |
-- MALICIOUS STANZAS (XEP-0076) |
|
3 |
|
|
4 |
-- library |
|
5 |
|
|
6 |
local lm = require 'lm' |
|
7 |
local iq = require 'lm.iq' |
|
8 |
|
|
9 |
-- |
|
10 |
|
|
11 |
local O = { |
|
12 |
handler = |
|
13 |
function ( mess ) |
|
14 |
return false |
|
15 |
end, |
|
16 |
} |
|
17 |
|
|
18 |
local F = { } |
|
19 |
|
|
20 |
function F.handler ( handler ) |
|
21 |
O.handler = handler |
|
22 |
end |
|
23 |
|
|
24 |
function F.message ( conn, to, mtype, message ) |
|
25 |
conn:send ( lm.message.create { mtype = 'message-' .. mtype, to = to, |
|
26 |
body = { message }, |
|
27 |
evil = { xmlns = 'http://jabber.org/protocol/evil' }, |
|
28 |
} ) |
|
29 |
end |
|
30 |
|
|
31 |
function F.presence ( conn, to, status, message ) |
|
32 |
local mtype = 'presence-available' |
|
33 |
if status == 'unavailable' then |
|
34 |
mtype = 'presence-unavailable' |
|
35 |
status = '' |
|
36 |
end |
|
37 |
conn:send ( lm.message.create { mtype = mtype, from = conn:jid (), to = to, |
|
38 |
show = { status }, |
|
39 |
status = { message }, |
|
40 |
evil = { xmlns = 'http://jabber.org/protocol/evil' }, |
|
41 |
} ) |
|
42 |
end |
|
43 |
|
|
44 |
function F.iq ( conn, to, action, contents, success, fail ) |
|
45 |
contents.evil = { xmlns = 'http://jabber.org/protocol/evil' } |
|
46 |
iq.send ( conn, to, action, contents, success, fail ) |
|
47 |
end |
|
48 |
|
|
49 |
function F.stanza_handler ( conn, mess ) |
|
50 |
local e = mess:child ( 'evil' ) |
|
51 |
if e and e:attribute ( 'xmlns' ) == 'http://jabber.org/protocol/evil' then |
|
52 |
return O.handler ( mess ) |
|
53 |
end |
|
54 |
end |
|
55 |
|
|
56 |
return F |
|
57 |
|
|
58 |
-- vim: se ts=4: -- |