comparison mod_srvinjection/mod_srvinjection.lua @ 96:c1f4edf3bea7

mod_srvinjection: Initial commit.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 23 Nov 2009 21:38:43 +0500
parents
children 2d03350613c4
comparison
equal deleted inserted replaced
95:e704834c5613 96:c1f4edf3bea7
1
2 module.host = "*";
3
4 local adns = require "net.adns";
5
6 local map = module:get_option("srvinjection") or {};
7
8 for host, mapping in pairs(map) do
9 if type(mapping) == "table" and type(mapping[1]) == "string" and (type(mapping[2]) == "number") then
10 local connecthost, connectport = mapping[1], mapping[2] or 5269;
11 map[host] = {{
12 srv = {
13 target = connecthost..".";
14 port = connectport;
15 priority = 1;
16 weight = 0;
17 };
18 }};
19 else
20 module:log("warn", "Ignoring invalid SRV injection for host '%s'", host);
21 map[host] = nil;
22 end
23 end
24
25 local original_lookup = adns.lookup;
26 function adns.lookup(handler, qname, qtype, qclass)
27 if qtype == "SRV" then
28 local host = qname:match("^_xmpp%-server%._tcp%.(.*)%.$");
29 local mapping = map[host];
30 if mapping then
31 handler(mapping);
32 return;
33 end
34 end
35 return original_lookup(handler, qname, qtype, qclass);
36 end
37
38 function module.unload()
39 adns.lookup = original_lookup;
40 end