Created
August 30, 2013 21:19
-
-
Save anonymous/6394383 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sip = require('sip'); | |
var digest = require('sip/digest'); | |
var util = require('util'); | |
var dns = require('dns'); | |
var registry = {}; | |
sip.start({}, function(rq) { | |
try { | |
if(rq.method === 'INVITE') { | |
var username = sip.parseUri(rq.uri).user; | |
var domain = sip.parseUri(rq.uri).host; | |
dns.resolveTxt('sip-'+username+'.'+domain, function (err, addresses) { | |
if (err) throw err; | |
addresses.every(function (a) { | |
var rs = sip.makeResponse(rq, 302, 'Moved Temporarily'); | |
rs.headers = rq.headers; | |
rs.headers.contact = 'sip:'+a; | |
rs.content = rq.content; | |
sip.send(rs); | |
if (err) { | |
throw err; | |
} | |
return false; | |
}); | |
}); | |
} | |
else { | |
sip.send(sip.makeResponse(rq, 405, 'Method Not Allowed')); | |
} | |
} catch(e) { | |
util.debug(e); | |
util.debug(e.stack); | |
sip.send(sip.makeResponse(rq, 500, "Server Internal Error")); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment