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

Author: Raphael Coeffic <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Sun Feb 13 15:32:40 2011 +0100

adds outbound interface computation to AmSipDialog.

---

 core/AmSipDialog.cpp |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++
 core/AmSipDialog.h   |   12 ++++++
 2 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp
index f9314fd..8db4161 100644
--- a/core/AmSipDialog.cpp
+++ b/core/AmSipDialog.cpp
@@ -33,6 +33,9 @@
 #include "SipCtrlInterface.h"
 #include "sems.h"
 
+#include "sip/parse_route.h"
+#include "sip/parse_uri.h"
+
 const char* AmSipDialog::status2str[4]  = {    
   "Disconnected",
   "Pending",
@@ -517,6 +520,96 @@ string AmSipDialog::getContactHdr()
   return contact_uri;
 }
 
+/** 
+ * Computes, set and return the outbound interface
+ * based on remote_uri, next_hop_ip, outbound_proxy, route.
+ */
+int AmSipDialog::getOutboundIf()
+{
+  if (outbound_interface >= 0)
+    return outbound_interface;
+
+  if(AmConfig::Ifs.size() == 1){
+    return (outbound_interface = 0);
+  }
+
+  // Destination priority:
+  // 1. next_hop_ip
+  // 2. outbound_proxy (if 1st req or force_outbound_proxy)
+  // 3. first route
+  // 4. remote URI
+  
+  string dest_uri;
+  string dest_ip;
+  string local_ip;
+  multimap<string,unsigned short>::iterator if_it;
+
+  if(!next_hop_ip.empty()) {
+    dest_ip = next_hop_ip;
+  }
+  else if(!outbound_proxy.empty() &&
+         (remote_tag.empty() || force_outbound_proxy)) {
+    dest_uri = outbound_proxy;
+  }
+  else if(!route.empty()){
+    // parse first route
+    sip_header fr;
+    fr.value = stl2cstr(route);
+    sip_uri* route_uri = get_first_route_uri(&fr);
+    if(!route_uri){
+      ERROR("Could not parse route (local_tag='%s';route='%s')",
+           local_tag.c_str(),route.c_str());
+      goto error;
+    }
+
+    dest_ip = c2stlstr(route_uri->host);
+  }
+  else {
+    dest_uri = remote_uri;
+  }
+
+  if(dest_uri.empty() && dest_ip.empty()) {
+    ERROR("No destination found (local_tag='%s')",local_tag.c_str());
+    goto error;
+  }
+  
+  if(!dest_uri.empty()){
+    sip_uri d_uri;
+    if(parse_uri(&d_uri,dest_uri.c_str(),dest_uri.length()) < 0){
+      ERROR("Could not parse destination URI (local_tag='%s';dest_uri='%s')",
+           local_tag.c_str(),dest_uri.c_str());
+      goto error;
+    }
+
+    dest_ip = c2stlstr(d_uri.host);
+  }
+
+  if(get_local_addr_for_dest(dest_ip,local_ip) < 0){
+    ERROR("No local address for dest '%s' 
(local_tag='%s')",dest_ip.c_str(),local_tag.c_str());
+    goto error;
+  }
+
+  if_it = AmConfig::LocalSIPIP2If.find(local_ip);
+  if(if_it == AmConfig::LocalSIPIP2If.end()){
+    ERROR("Could not find a local interface for resolved local IP 
(local_tag='%s';local_ip='%s')",
+         local_tag.c_str(), local_ip.c_str());
+    goto error;
+  }
+
+  outbound_interface = if_it->second;
+  return outbound_interface;
+
+ error:
+  WARN("Error while computing outbound interface: default interface will be 
used instead.");
+  outbound_interface = 0;
+  return outbound_interface;
+}
+
+void AmSipDialog::resetOutboundIf()
+{
+  outbound_interface = -1;
+}
+
 string AmSipDialog::getRoute() {
   string res;
 
diff --git a/core/AmSipDialog.h b/core/AmSipDialog.h
index 11c2d83..52f2a36 100644
--- a/core/AmSipDialog.h
+++ b/core/AmSipDialog.h
@@ -223,6 +223,18 @@ class AmSipDialog
 
   string getContactHdr();
 
+  /** 
+   * Computes, set and return the outbound interface
+   * based on remote_uri, next_hop_ip, outbound_proxy, route.
+   */
+  int getOutboundIf();
+
+  /**
+   * Resets outbound_interface to it default value (-1).
+   */
+  void resetOutboundIf();
+
+
   /** update Status from locally originated request (e.g. INVITE) */
   void updateStatusFromLocalRequest(const AmSipRequest& req);
 

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

Reply via email to