examples/ping.lua
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--
Modularization, I * activity * attention * avatar * disco * evil * geoloc * ibb * iq * mood * oob * ping * pubsub * tune * mpd * pep


-- XMPP PING (XEP-0199)

-- library

local lm = require 'lm'
local iq = require 'iq'

--

local F = { }

function F.send ( conn, to, success, fail )
	iq.send ( conn, to, 'get',
		{
			ping = { xmlns = 'urn:xmpp:ping' },
		}, success, fail )
end

function F.iq_handler ( conn, mess )
	local mtype, smtype = mess:type ()
	if smtype == 'get' then
		local p = mess:child ( 'ping' )
		if p and p:attribute ( 'xmlns' ) == 'urn:xmpp:ping' then
			conn:send ( lm.message.create { mtype = 'iq-result', to = mess:attribute ( 'from' ), id = mess:attribute ( 'id' ) } )
			return true
		end
	end
	return false
end

return F

-- vim: se ts=4: --