Software /
code /
prosody-modules
Annotate
mod_srvinjection/mod_srvinjection.lua @ 401:c85397063eca
mod_pubsub_feed: Try harder to figure out ones callback URL.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 24 Aug 2011 15:03:38 +0200 |
parent | 337:beb5073b866a |
child | 662:b3d130e4b3ae |
rev | line source |
---|---|
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 module.host = "*"; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local adns = require "net.adns"; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 local map = module:get_option("srvinjection") or {}; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 for host, mapping in pairs(map) do |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 if type(mapping) == "table" and type(mapping[1]) == "string" and (type(mapping[2]) == "number") then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local connecthost, connectport = mapping[1], mapping[2] or 5269; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 map[host] = {{ |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 srv = { |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 target = connecthost.."."; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 port = connectport; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 priority = 1; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 weight = 0; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 }; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 }}; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 else |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 module:log("warn", "Ignoring invalid SRV injection for host '%s'", host); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 map[host] = nil; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local original_lookup = adns.lookup; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 function adns.lookup(handler, qname, qtype, qclass) |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 if qtype == "SRV" then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local host = qname:match("^_xmpp%-server%._tcp%.(.*)%.$"); |
337
beb5073b866a
mod_srvinjection: Fix type in variable name.
Waqas Hussain <waqas20@gmail.com>
parents:
336
diff
changeset
|
29 local mapping = map[host] or map["*"]; |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 if mapping then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 handler(mapping); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 return; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 end |
99
2d03350613c4
mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
Waqas Hussain <waqas20@gmail.com>
parents:
96
diff
changeset
|
34 elseif qtype == "A" and (qname == "localhost." or qname == "127.0.0.1.") then |
2d03350613c4
mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
Waqas Hussain <waqas20@gmail.com>
parents:
96
diff
changeset
|
35 handler({{ a = "127.0.0.1" }}); |
2d03350613c4
mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
Waqas Hussain <waqas20@gmail.com>
parents:
96
diff
changeset
|
36 return; |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 return original_lookup(handler, qname, qtype, qclass); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 function module.unload() |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 adns.lookup = original_lookup; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 end |