examples/lm/evil.lua
changeset 68 742878c74b8e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/lm/evil.lua	Tue Mar 31 18:35:34 2009 +0300
@@ -0,0 +1,58 @@
+
+-- 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: --