From 0e9bc0366a7253ca4ad98142bd06433010f53ea8 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Thu, 4 Oct 2007 18:26:13 +0000 Subject: [PATCH] adds optional outbound_proxy, the next_hop for dialogs initiated by SEMS git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@503 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/registrar_client/SIPRegistrarClient.cpp | 22 +++++++++++--------- core/AmConfig.cpp | 4 ++++ core/AmConfig.h | 2 ++ core/AmUAC.cpp | 4 ++++ core/sems.conf.sample | 21 +++++++++++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/apps/registrar_client/SIPRegistrarClient.cpp b/apps/registrar_client/SIPRegistrarClient.cpp index 5328fe76..fe9a7540 100644 --- a/apps/registrar_client/SIPRegistrarClient.cpp +++ b/apps/registrar_client/SIPRegistrarClient.cpp @@ -94,12 +94,12 @@ void SIPRegistration::doRegistration() { req.r_uri = "sip:"+info.domain; dlg.remote_uri = req.r_uri; // set outbound proxy as next hop -// if (!AmConfig::OutboundProxy.empty()) -// dlg.next_hop = AmConfig::OutboundProxy; -// else -// dlg.next_hop = ""; - - dlg.sendRequest(req.method, "", "", "Expires: 240\n"); + if (!AmConfig::OutboundProxy.empty()) + dlg.next_hop = AmConfig::OutboundProxy; + else + dlg.next_hop = ""; + + dlg.sendRequest(req.method, "", "", "Expires: 1000\n"); // save TS struct timeval now; @@ -113,11 +113,13 @@ void SIPRegistration::doUnregister() { dlg.remote_tag = ""; req.r_uri = "sip:"+info.domain; dlg.remote_uri = req.r_uri; + // set outbound proxy as next hop -// if (!AmConfig::OutboundProxy.empty()) -// dlg.next_hop = AmConfig::OutboundProxy; -// else -// dlg.next_hop = ""; + if (!AmConfig::OutboundProxy.empty()) + dlg.next_hop = AmConfig::OutboundProxy; + else + dlg.next_hop = ""; + dlg.sendRequest(req.method, "", "", "Expires: 0\n"); // save TS diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index f2864559..d0ea7ac4 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -55,6 +55,7 @@ int AmConfig::RtpHighPort = RTP_HIGHPORT; int AmConfig::MediaProcessorThreads = NUM_MEDIA_PROCESSORS; int AmConfig::LocalSIPPort = 5060; string AmConfig::LocalSIPIP = ""; +string AmConfig::OutboundProxy = ""; string AmConfig::Signature = ""; bool AmConfig::SingleCodecInOK = false; unsigned int AmConfig::DeadRtpTime = DEAD_RTP_TIME; @@ -182,6 +183,9 @@ int AmConfig::readConfiguration() } } + // outbound_proxy + OutboundProxy = cfg.getParameter("outbound_proxy"); + // socket_name SocketName = cfg.getParameter("socket_name"); diff --git a/core/AmConfig.h b/core/AmConfig.h index f6e656f0..6c8c9889 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -83,6 +83,8 @@ struct AmConfig static string LocalSIPIP; /** the port SIP requests are sent from - optional (default 5060) */ static int LocalSIPPort; + /** Outbound Proxy (optional, outgoing calls only) */ + static string OutboundProxy; /** Server/User-Agent header (optional) */ static string Signature; /** If 200 OK reply should be limited to preferred codec only */ diff --git a/core/AmUAC.cpp b/core/AmUAC.cpp index 131b6ca7..afd5fdfb 100644 --- a/core/AmUAC.cpp +++ b/core/AmUAC.cpp @@ -57,6 +57,10 @@ AmSession* AmUAC::dialout(const string& user, req.to_tag = ""; req.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP; + // set outbound proxy as next hop + if (!AmConfig::OutboundProxy.empty()) + req.next_hop = AmConfig::OutboundProxy; + return AmSessionContainer::instance()->startSessionUAC(req, session_params); } diff --git a/core/sems.conf.sample b/core/sems.conf.sample index 216a0f2c..59ebd1be 100644 --- a/core/sems.conf.sample +++ b/core/sems.conf.sample @@ -131,6 +131,27 @@ media_processor_threads=1 # #sip_port=5060 +# optional parameter: outbound_proxy=uri +# +# - this sets a next hop for calls and registrations outgoing +# from SEMS. This does not apply to requests in a dialog that +# is initiated by someone else and incoming to SEMS, as in +# this case the next_hop is taken by SEMS from the incoming +# request that established the dialog. +# If this is not set (default setting), then for dialogs +# initiated by SEMS the r-uri is resolved and the request +# is sent there directly. +# This is resolved by the SIP stack with DNS if a name is given. +# Warning: If the value set here can not be resolved, no +# requests will be sent out at all! +# +# default: empty +# +# example: +# outbound_proxy=sip:proxy.mydomain.net +# +#outbound_proxy=sip:192.168.0.1 + # optional parameter: dead_rtp_time= # # - if != 0, after this time (in seconds) of no RTP