comparison mod_ipcheck/mod_ipcheck.lua @ 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 0525c66e7d13
children a1287d1f8a1f
comparison
equal deleted inserted replaced
1243:c2bf6b2102aa 1244:d1bc9a796daf
18 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "IP address for this session is not available")); 18 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "IP address for this session is not available"));
19 end 19 end
20 return true; 20 return true;
21 end 21 end
22 end); 22 end);
23
24 module:add_feature("urn:xmpp:sic:1");
25
26 module:hook("iq/bare/urn:xmpp:sic:1:address", function(event)
27 local origin, stanza = event.origin, event.stanza;
28 if stanza.attr.type == "get" then
29 if stanza.attr.to then
30 origin.send(st.error_reply(stanza, "auth", "forbidden", "You can only ask about your own IP address"));
31 elseif origin.ip then
32 local reply = st.reply(stanza):tag("address", {xmlns='urn:xmpp:sic:0'})
33 :tag("ip"):text(origin.ip):up()
34 if origin.conn and origin.conn.port then
35 reply:tag("port"):text(tostring(origin.conn:port()))
36 end
37 origin.send(reply);
38 else
39 -- IP addresses should normally be available, but in case they are not
40 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "IP address for this session is not available"));
41 end
42 return true;
43 end
44 end);