diff --git a/core/plug-in/sipctrl/SipCtrlInterface.cpp b/core/plug-in/sipctrl/SipCtrlInterface.cpp index 17fd39ca..e216ee9b 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.cpp +++ b/core/plug-in/sipctrl/SipCtrlInterface.cpp @@ -34,6 +34,9 @@ using std::stack; EXPORT_CONTROL_INTERFACE_FACTORY(SipCtrlInterfaceFactory,MOD_NAME); +string SipCtrlInterfaceFactory::outbound_host = ""; +unsigned int SipCtrlInterfaceFactory::outbound_port = 0; + AmCtrlInterface* SipCtrlInterfaceFactory::instance() { SipCtrlInterface* ctrl = new SipCtrlInterface(bind_addr,bind_port); @@ -51,6 +54,19 @@ int SipCtrlInterfaceFactory::onLoad() INFO("SIP bind_addr: `%s'.\n", bind_addr.c_str()); INFO("SIP bind_port: `%i'.\n", bind_port); + if (!AmConfig::OutboundProxy.empty()) { + sip_uri parsed_uri; + if (parse_uri(&parsed_uri, (char *)AmConfig::OutboundProxy.c_str(), + AmConfig::OutboundProxy.length()) < 0) { + ERROR("invalid outbound_proxy specified\n"); + return -1; + } + SipCtrlInterfaceFactory::outbound_host = c2stlstr(parsed_uri.host); + if (parsed_uri.port) { + SipCtrlInterfaceFactory::outbound_port = parsed_uri.port; + } + } + return 0; } diff --git a/core/plug-in/sipctrl/SipCtrlInterface.h b/core/plug-in/sipctrl/SipCtrlInterface.h index 772ecf6b..30696b9c 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.h +++ b/core/plug-in/sipctrl/SipCtrlInterface.h @@ -27,6 +27,10 @@ class SipCtrlInterfaceFactory: public AmCtrlInterfaceFactory unsigned short bind_port; public: + + static string outbound_host; + static unsigned int outbound_port; + SipCtrlInterfaceFactory(const string& name): AmCtrlInterfaceFactory(name) {} ~SipCtrlInterfaceFactory() {} diff --git a/core/plug-in/sipctrl/trans_layer.cpp b/core/plug-in/sipctrl/trans_layer.cpp index d6af41fb..fba12bca 100644 --- a/core/plug-in/sipctrl/trans_layer.cpp +++ b/core/plug-in/sipctrl/trans_layer.cpp @@ -17,6 +17,7 @@ #include "SipCtrlInterface.h" #include "AmUtils.h" #include "AmSipMsg.h" +#include "AmConfig.h" #include #include @@ -287,9 +288,14 @@ int trans_layer::set_next_hop(list& route_hdrs, } } - - next_hop = c2stlstr(na.uri.host); - next_port = na.uri.port; + + if (SipCtrlInterfaceFactory::outbound_host.empty()) { + next_hop = c2stlstr(na.uri.host); + next_port = na.uri.port; + } else { + next_hop = SipCtrlInterfaceFactory::outbound_host; + next_port = SipCtrlInterfaceFactory::outbound_port; + } if(!is_lr){ @@ -379,17 +385,23 @@ int trans_layer::set_next_hop(list& route_hdrs, } else { - sip_uri parsed_r_uri; - err = parse_uri(&parsed_r_uri,r_uri.s,r_uri.len); - if(err < 0){ - ERROR("Invalid Request URI\n"); - return -1; + if (SipCtrlInterfaceFactory::outbound_host.empty()) { + sip_uri parsed_r_uri; + err = parse_uri(&parsed_r_uri,r_uri.s,r_uri.len); + if(err < 0){ + ERROR("Invalid Request URI\n"); + return -1; + } + next_hop = c2stlstr(parsed_r_uri.host); + next_port = parsed_r_uri.port; + } else { + next_hop = SipCtrlInterfaceFactory::outbound_host; + next_port = SipCtrlInterfaceFactory::outbound_port; } - - next_hop = c2stlstr(parsed_r_uri.host); - next_port = parsed_r_uri.port; } + DBG("next_hop:next_port is <%s:%u>\n", next_hop.c_str(), next_port); + err = resolver::instance()->resolve_name(next_hop.c_str(), remote_ip,IPv4,UDP); if(err < 0){