[examples] Fix non-table response handling in shortener
Reported by Mikael Berthe
-- MALICIOUS STANZAS (XEP-0076)
-- library
local lm = require 'lm'
local iq = require 'lm.iq'
--
local O = {
handler =
function ( mess )
return false
end,
}
local F = { }
function F.handler ( handler )
O.handler = handler
end
function F.message ( conn, to, mtype, message )
conn:send ( lm.message.create { mtype = 'message-' .. mtype, to = to,
body = { message },
evil = { xmlns = 'http://jabber.org/protocol/evil' },
} )
end
function F.presence ( conn, to, status, message )
local mtype = 'presence-available'
if status == 'unavailable' then
mtype = 'presence-unavailable'
status = ''
end
conn:send ( lm.message.create { mtype = mtype, from = conn:jid (), to = to,
show = { status },
status = { message },
evil = { xmlns = 'http://jabber.org/protocol/evil' },
} )
end
function F.iq ( conn, to, action, contents, success, fail )
contents.evil = { xmlns = 'http://jabber.org/protocol/evil' }
iq.send ( conn, to, action, contents, success, fail )
end
function F.stanza_handler ( conn, mess )
local e = mess:child ( 'evil' )
if e and e:attribute ( 'xmlns' ) == 'http://jabber.org/protocol/evil' then
return O.handler ( mess )
end
end
return F
-- vim: se ts=4: --