Mercurial > prosody-modules
changeset 1244:d1bc9a796daf
mod_ipcheck: Add support for XEP version 0.2 (includes port)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 04 Dec 2013 17:37:32 +0100 |
parents | c2bf6b2102aa |
children | a1287d1f8a1f |
files | mod_ipcheck/mod_ipcheck.lua |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_ipcheck/mod_ipcheck.lua Mon Dec 02 03:08:17 2013 +0000 +++ b/mod_ipcheck/mod_ipcheck.lua Wed Dec 04 17:37:32 2013 +0100 @@ -20,3 +20,25 @@ return true; end end); + +module:add_feature("urn:xmpp:sic:1"); + +module:hook("iq/bare/urn:xmpp:sic:1:address", 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 + local reply = st.reply(stanza):tag("address", {xmlns='urn:xmpp:sic:0'}) + :tag("ip"):text(origin.ip):up() + if origin.conn and origin.conn.port then + reply:tag("port"):text(tostring(origin.conn:port())) + end + origin.send(reply); + 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);