Module: sems
Branch: master
Commit: 4febe1c75f5cd41ebc3be4071ee531ef6db64c99
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=4febe1c75f5cd41ebc3be4071ee531ef6db64c99

Author: Raphael Coeffic <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Sat Feb  4 15:23:50 2012 +0100

core: remove next_hop parameters for replies.

---

 core/AmSipDialog.cpp      |    7 ++---
 core/SipCtrlInterface.cpp |    2 -
 core/SipCtrlInterface.h   |    7 ++---
 core/sip/trans_layer.cpp  |   63 +++++++++++++++++---------------------------
 core/sip/trans_layer.h    |    1 -
 5 files changed, 30 insertions(+), 50 deletions(-)

diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp
index ace53b3..4cea444 100644
--- a/core/AmSipDialog.cpp
+++ b/core/AmSipDialog.cpp
@@ -724,9 +724,8 @@ int AmSipDialog::reply(const AmSipTransaction& t,
     return -1;
   }
 
-  int ret = SipCtrlInterface::send(reply, next_hop_for_replies ? next_hop_ip : 
"",
-                                  next_hop_for_replies ? next_hop_port : 0,
-                                  out_intf_for_replies ? outbound_interface : 
-1 );
+  int ret = SipCtrlInterface::send(reply, out_intf_for_replies ? 
+                                  outbound_interface : -1 );
 
   if(ret){
     ERROR("Could not send reply: code=%i; reason='%s'; method=%s; call-id=%s; 
cseq=%i\n",
@@ -767,7 +766,7 @@ int AmSipDialog::reply_error(const AmSipRequest& req, 
unsigned int code,
   if (AmConfig::Signature.length())
     reply.hdrs += SIP_HDR_COLSP(SIP_HDR_SERVER) + AmConfig::Signature + CRLF;
 
-  int ret = SipCtrlInterface::send(reply, next_hop_ip, next_hop_port, 
outbound_interface);
+  int ret = SipCtrlInterface::send(reply, outbound_interface);
   if(ret){
     ERROR("Could not send reply: code=%i; reason='%s'; method=%s; call-id=%s; 
cseq=%i\n",
          
reply.code,reply.reason.c_str(),req.method.c_str(),req.callid.c_str(),req.cseq);
diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp
index 4e7af84..94ee463 100644
--- a/core/SipCtrlInterface.cpp
+++ b/core/SipCtrlInterface.cpp
@@ -308,7 +308,6 @@ void SipCtrlInterface::cleanup()
 }
 
 int SipCtrlInterface::send(const AmSipReply &rep,
-                          const string& next_hop_ip, unsigned short 
next_hop_port,
                           int out_interface)
 {
     sip_msg msg;
@@ -365,7 +364,6 @@ int SipCtrlInterface::send(const AmSipReply &rep,
                                            rep.code,stl2cstr(rep.reason),
                                            stl2cstr(rep.to_tag),
                                            cstring(hdrs_buf,hdrs_len), 
stl2cstr(rep.body),
-                                           stl2cstr(next_hop_ip),next_hop_port,
                                            out_interface);
 
     delete [] hdrs_buf;
diff --git a/core/SipCtrlInterface.h b/core/SipCtrlInterface.h
index 1b96070..7f6194a 100644
--- a/core/SipCtrlInterface.h
+++ b/core/SipCtrlInterface.h
@@ -90,7 +90,8 @@ public:
      *            its ticket is written into req.tt.
      */
     static int send(AmSipRequest &req,
-                   const string& next_hop_ip = "", unsigned short 
next_hop_port = 5060,
+                   const string& next_hop_ip = "", 
+                   unsigned short next_hop_port = 5060,
                    int outbound_interface = -1);
 
     /**
@@ -99,9 +100,7 @@ public:
      * @param rep The reply to be sent. 'rep.tt' should be set to transaction 
      *            ticket included in the SIP request.
      */
-    static int send(const AmSipReply &rep,
-                   const string& next_hop_ip = "", unsigned short 
next_hop_port = 5060,
-                   int outbound_interface = -1);
+    static int send(const AmSipReply &rep, int outbound_interface = -1);
 
     /**
      * CANCELs an INVITE transaction.
diff --git a/core/sip/trans_layer.cpp b/core/sip/trans_layer.cpp
index 1dc6e73..d314cec 100644
--- a/core/sip/trans_layer.cpp
+++ b/core/sip/trans_layer.cpp
@@ -91,7 +91,6 @@ int _trans_layer::send_reply(trans_ticket* tt,
                             int reply_code, const cstring& reason,
                             const cstring& to_tag, const cstring& hdrs,
                             const cstring& body,
-                            const cstring& _next_hop, unsigned short 
_next_port,
                             int out_interface)
 {
     // Ref.: RFC 3261 8.2.6, 12.1.1
@@ -151,7 +150,7 @@ int _trans_layer::send_reply(trans_ticket* tt,
     unsigned int new_via1_len = copy_hdr_len(req->via1);
     string remote_ip_str = get_addr_str(&req->remote_ip);
 
-    bool append_received = !(remote_ip_str == req->via_p1->host);
+    bool append_received = !(req->via_p1->host == remote_ip_str);
     if(append_received) {
        new_via1_len += 10/*;received=*/ + remote_ip_str.length();
     }
@@ -398,52 +397,38 @@ int _trans_layer::send_reply(trans_ticket* tt,
        local_socket = req->local_socket;
     }
 
-    if (!_next_hop.len) {
-       memcpy(&remote_ip,&req->remote_ip,sizeof(sockaddr_storage));
-
-       if(req->via_p1->has_rport){
+    memcpy(&remote_ip,&req->remote_ip,sizeof(sockaddr_storage));
 
-           if(req->via_p1->rport_i){
-               // use 'rport'
-               ((sockaddr_in*)&remote_ip)->sin_port = 
htons(req->via_p1->rport_i);
-           }
-           // else: use the source port from the replied request (from IP hdr)
-           //       (already set).
+    if(req->via_p1->has_rport){
+       
+       if(req->via_p1->rport_i){
+           // use 'rport'
+           ((sockaddr_in*)&remote_ip)->sin_port = htons(req->via_p1->rport_i);
        }
-       else {
+       // else: use the source port from the replied request (from IP hdr)
+       //       (already set).
+    }
+    else {
        
-           if(req->via_p1->port_i){
-               // use port from 'sent-by' via address
-               ((sockaddr_in*)&remote_ip)->sin_port = 
htons(req->via_p1->port_i);
-           }
-           else {
-               // use 5060
-               ((sockaddr_in*)&remote_ip)->sin_port = htons(5060);
-           }
+       if(req->via_p1->port_i){
+           // use port from 'sent-by' via address
+           ((sockaddr_in*)&remote_ip)->sin_port = htons(req->via_p1->port_i);
        }
-
-       if(local_socket->is_opt_set(trsp_socket::force_via_address)) {
-           DBG("force_via_address\n");
-           string via_host = c2stlstr(req->via_p1->host);
-           if (resolver::instance()->str2ip(via_host.c_str(), &remote_ip,
-                                            (address_type)(IPv4 | IPv6)) != 1) 
{
-               ERROR("Invalid via_host '%s'\n", via_host.c_str());
-               delete [] reply_buf;
-               goto end;
-           }
+       else {
+           // use 5060
+           ((sockaddr_in*)&remote_ip)->sin_port = htons(5060);
        }
-    } else {
-       DBG("setting next hop '%.*s:%u'\n",
-           _next_hop.len, _next_hop.s, _next_port ? _next_port : 5060);
-       // use _next_hop:_next_port
-       if (resolver::instance()->str2ip(_next_hop.s, &remote_ip,
+    }
+    
+    if(local_socket->is_opt_set(trsp_socket::force_via_address)) {
+       DBG("force_via_address\n");
+       string via_host = c2stlstr(req->via_p1->host);
+       if (resolver::instance()->str2ip(via_host.c_str(), &remote_ip,
                                         (address_type)(IPv4 | IPv6)) != 1) {
-           ERROR("Invalid next_hop_ip '%.*s'\n", _next_hop.len, _next_hop.s);
+           ERROR("Invalid via_host '%s'\n", via_host.c_str());
            delete [] reply_buf;
            goto end;
        }
-       // default port to 5060
-       ((sockaddr_in*)&remote_ip)->sin_port = htons(_next_port ? _next_port : 
5060);
     }
 
     DBG("Sending to %s:%i <%.*s...>\n",
diff --git a/core/sip/trans_layer.h b/core/sip/trans_layer.h
index 12d0e80..0fbdce6 100644
--- a/core/sip/trans_layer.h
+++ b/core/sip/trans_layer.h
@@ -92,7 +92,6 @@ public:
                   int reply_code, const cstring& reason,
                   const cstring& to_tag, const cstring& hdrs, 
                   const cstring& body,
-                  const cstring& _next_hop, unsigned short _next_port,
                   int out_interface = -1);
 
     /**

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to