view mod_ipcheck/mod_ipcheck.lua @ 135:d3c28c5fdbae

mod_ipcheck: Change error from 'item-not-found' to 'service-unavailable' for missing IP.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 06 Mar 2010 06:20:38 +0500
parents 744deabdee81
children 0525c66e7d13
line wrap: on
line source


-- mod_ipcheck.lua
-- Implementation of XEP-xxxx: Server IP Check <http://xmpp.org/extensions/inbox/sic.html>

local st = require "util.stanza";

module:add_feature("urn:xmpp:sic:0");

module:hook("iq/bare/urn:xmpp:sic:0:ip", function(event)
	local origin, stanza = event.origin, event.stanza;
	if stanza.attr.type == "get" then
		if stanza.attr.to then
			origin.send(st.error_reply(stanza, "auth", "forbidden", "You can only ask about your own IP address"));
		elseif origin.ip then
			origin.send(st.reply(stanza):tag("ip", {xmlns='urn:xmpp:sic:0'}):text(origin.ip));
		else
			-- IP addresses should normally be available, but in case they are not
			origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "IP address for this session is not available"));
		end
		return true;
	end
end);