node.js - SIP Redirect via Proxy (SIP.js) -
i'm trying create minimal sip proxy serves 1 purpose: redirects requests domain. catch domain i'm redirecting requires authorization assume need rewrite sip attributes since sip authorization based partly on domain name of destination.
i've tried issuing 302 redirect proxying , changing values of each sip request none seem quit trick. i'm using node.js library (sip.js) , have tried redirect , proxy modules (https://github.com/kirm/sip.js/blob/master/doc/api.markdown).
any ideas how need modify sip data redirect requests domain , enable authentication take place against other domain?
below basic node script got working own sip server. you'll need replace credentials , ip address fro own testing.
the proxy script not send redirect response client instead initiates new transaction server on client's behalf. sip server operating in mode more correctly called back-to-back user agent (b2bua). haven't added functionality needed, such matching , passing responses original client; there fair bit of work involved in that.
var sip = require('sip'); var digest = require('sip/digest'); var util = require('util'); var os = require('os'); var proxy = require('sip/proxy'); var registry = { 'user': { user: "user", password: "password", realm: "sipserver.com"}, }; function rstring() { return math.floor(math.random()*1e6).tostring(); } sip.start({ address: "192.168.33.116", // if ip not specified here proxy uses hostname in via header causes issue if it's not qualified. logger: { send: function(message, address) { debugger; util.debug("send\n" + util.inspect(message, false, null)); }, recv: function(message, address) { debugger; util.debug("recv\n" + util.inspect(message, false, null)); } } }, function(rq) { try { if(rq.method === 'invite') { proxy.send(sip.makeresponse(rq, 100, 'trying')); //looking user info var username = sip.parseuri(rq.headers.to.uri).user; var creds = registry[username]; if(!creds) { proxy.send(sip.makeresponse(rq, 404, 'user not found')); } else { proxy.send(rq, function(rs) { if(rs.status === 401) { // update original request it's not treated duplicate. rq.headers['cseq'].seq++; rq.headers.via.shift (); rq.headers['call-id'] = rstring(); digest.signrequest(creds, rq, rs, creds); proxy.send(rq); } }); } } else { proxy.send(sip.makeresponse(rq, 405, 'method not allowed')); } } catch(e) { util.debug(e); util.debug(e.stack); proxy.send(sip.makeresponse(rq, 500, "server internal error")); } });
Comments
Post a Comment