examples/lm/evil.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Tue, 07 Aug 2012 20:58:31 +0300
changeset 127 9157566033e8
parent 68 742878c74b8e
permissions -rw-r--r--
Support for goo.gl api key * option lua_shorten_googl_key * better error parsing


-- 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: --