Software /
code /
prosody-modules
Annotate
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 |
parent | 134:744deabdee81 |
child | 136:0525c66e7d13 |
rev | line source |
---|---|
130
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- mod_ipcheck.lua |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- Implementation of XEP-xxxx: Server IP Check <http://xmpp.org/extensions/inbox/sic.html> |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local st = require "util.stanza"; |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 module:add_feature("urn:xmpp:sic:0"); |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 module:hook("iq/bare/urn:xmpp:sic:0:ip", function(event) |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local origin, stanza = event.origin, event.stanza; |
134
744deabdee81
mod_ipcheck: Fixed: 'service-unavailable' was sent instead of 'forbidden' on unauthorized access.
Waqas Hussain <waqas20@gmail.com>
parents:
131
diff
changeset
|
11 if stanza.attr.type == "get" then |
130
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 if stanza.attr.to then |
131
46741fc09091
mod_ipcheck: Change error from 'not-authorized' to 'forbidden', as specified in the XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
130
diff
changeset
|
13 origin.send(st.error_reply(stanza, "auth", "forbidden", "You can only ask about your own IP address")); |
130
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 elseif origin.ip then |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 origin.send(st.reply(stanza):tag("ip", {xmlns='urn:xmpp:sic:0'}):text(origin.ip)); |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 else |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 -- IP addresses should normally be available, but in case they are not |
135
d3c28c5fdbae
mod_ipcheck: Change error from 'item-not-found' to 'service-unavailable' for missing IP.
Waqas Hussain <waqas20@gmail.com>
parents:
134
diff
changeset
|
18 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "IP address for this session is not available")); |
130
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 end |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 return true; |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 end |
51cd803e86be
mod_ipcheck: Initial commit. An implementation of the Server IP Check proto-XEP.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 end); |