# HG changeset patch # User Waqas Hussain # Date 1258994323 -18000 # Node ID c1f4edf3bea76fa2aff029dd6ebc91bc48f78f89 # Parent e704834c5613895eb4a0529ff4048333faf1baf4 mod_srvinjection: Initial commit. diff -r e704834c5613 -r c1f4edf3bea7 mod_srvinjection/mod_srvinjection.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_srvinjection/mod_srvinjection.lua Mon Nov 23 21:38:43 2009 +0500 @@ -0,0 +1,40 @@ + +module.host = "*"; + +local adns = require "net.adns"; + +local map = module:get_option("srvinjection") or {}; + +for host, mapping in pairs(map) do + if type(mapping) == "table" and type(mapping[1]) == "string" and (type(mapping[2]) == "number") then + local connecthost, connectport = mapping[1], mapping[2] or 5269; + map[host] = {{ + srv = { + target = connecthost.."."; + port = connectport; + priority = 1; + weight = 0; + }; + }}; + else + module:log("warn", "Ignoring invalid SRV injection for host '%s'", host); + map[host] = nil; + end +end + +local original_lookup = adns.lookup; +function adns.lookup(handler, qname, qtype, qclass) + if qtype == "SRV" then + local host = qname:match("^_xmpp%-server%._tcp%.(.*)%.$"); + local mapping = map[host]; + if mapping then + handler(mapping); + return; + end + end + return original_lookup(handler, qname, qtype, qclass); +end + +function module.unload() + adns.lookup = original_lookup; +end