author | Myhailo Danylenko <isbear@ukrpost.net> |
Fri, 27 Mar 2009 12:06:19 +0200 | |
changeset 66 | 542f61e113cb |
parent 64 | bf7521ed96eb |
child 68 | 742878c74b8e |
permissions | -rw-r--r-- |
62 | 1 |
|
2 |
-- MALICIOUS STANZAS (XEP-0076) |
|
3 |
||
4 |
-- library |
|
5 |
||
66 | 6 |
local lm = require 'lm' |
64
bf7521ed96eb
Rewrite of ibb in object style
Myhailo Danylenko <isbear@ukrpost.net>
parents:
63
diff
changeset
|
7 |
local iq = require 'iq' |
62 | 8 |
|
9 |
-- public |
|
10 |
||
66 | 11 |
local O = { |
62 | 12 |
handler = |
13 |
function ( mess ) |
|
14 |
return false |
|
15 |
end, |
|
16 |
} |
|
17 |
||
66 | 18 |
local F = { } |
19 |
||
20 |
function F.handler ( handler ) |
|
21 |
O.handler = handler |
|
22 |
end |
|
23 |
||
24 |
function F.message ( conn, to, mtype, message ) |
|
62 | 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 |
||
66 | 31 |
function F.presence ( conn, to, status, message ) |
62 | 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 |
||
66 | 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 |
|
62 | 48 |
|
66 | 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 |
|
62 | 55 |
|
66 | 56 |
return F |
62 | 57 |
|
58 |
-- vim: se ts=4: -- |