Author: rnewman
Date: 2008-04-30 02:29:08 +0200 (Wed, 30 Apr 2008)
New Revision: 917

Modified:
   trunk/core/AmConfig.cpp
   trunk/core/AmConfig.h
   trunk/core/AmSession.cpp
   trunk/core/AmSession.h
   trunk/core/etc/sems.conf.sample
   trunk/core/sems.cpp
Log:
Add configuration parameter 'public_ip' and mechanisms to use it in SDP body 
generation.

Modified: trunk/core/AmConfig.cpp
===================================================================
--- trunk/core/AmConfig.cpp     2008-04-24 09:07:02 UTC (rev 916)
+++ trunk/core/AmConfig.cpp     2008-04-30 00:29:08 UTC (rev 917)
@@ -47,6 +47,7 @@
 string       AmConfig::ExcludePayloads         = "";
 int          AmConfig::DaemonMode              = DEFAULT_DAEMON_MODE;
 string       AmConfig::LocalIP                 = "";
+string       AmConfig::PublicIP                = "";
 string       AmConfig::PrefixSep               = PREFIX_SEPARATOR;
 int          AmConfig::RtpLowPort              = RTP_LOWPORT;
 int          AmConfig::RtpHighPort             = RTP_HIGHPORT;
@@ -146,6 +147,8 @@
 
 int AmConfig::readConfiguration()
 {
+  DBG("Reading configuration...");
+  
   AmConfigReader cfg;
 
   if(cfg.loadFile(ConfigurationFile.c_str())){
@@ -180,6 +183,15 @@
   if(cfg.hasParameter("sip_ip"))
     LocalSIPIP = cfg.getParameter("sip_ip");
   
+  if(cfg.hasParameter("public_ip")){
+    string p_ip = cfg.getParameter("public_ip");
+    DBG("Setting public_ip parameter to %s.\n", p_ip.c_str());
+    PublicIP = p_ip;
+  }
+  else {
+    DBG("Config file has no public_ip parameter.");
+  }
+  
   // outbound_proxy
   OutboundProxy = cfg.getParameter("outbound_proxy");
   

Modified: trunk/core/AmConfig.h
===================================================================
--- trunk/core/AmConfig.h       2008-04-24 09:07:02 UTC (rev 916)
+++ trunk/core/AmConfig.h       2008-04-30 00:29:08 UTC (rev 917)
@@ -62,8 +62,14 @@
   //static unsigned int MaxRecordTime;
   /** run the programm in daemon mode? */
   static int DaemonMode;
+  
   /** local IP for SDP media advertising */
   static string LocalIP;
+  
+  /** public IP for SDP media advertising; we actually
+   *  bind to local IP, but advertise public IP. */ 
+  static string PublicIP;
+  
   /** Separator character for uri application prefix (ex: [EMAIL PROTECTED]) */
   static string PrefixSep;
   /** Lowest local RTP port */

Modified: trunk/core/AmSession.cpp
===================================================================
--- trunk/core/AmSession.cpp    2008-04-24 09:07:02 UTC (rev 916)
+++ trunk/core/AmSession.cpp    2008-04-30 00:29:08 UTC (rev 917)
@@ -322,7 +322,7 @@
   if( sdp.remote_active || force_symmetric_rtp) {
     DBG("The other UA is NATed: switched to passive mode.\n");
     DBG("remote_active = %i; force_symmetric_rtp = %i\n",
-       sdp.remote_active,force_symmetric_rtp);
+       sdp.remote_active, force_symmetric_rtp);
 
     passive_mode = true;
   }
@@ -339,7 +339,7 @@
   unlockAudio();
 
   if(sdp_reply)
-    sdp.genResponse(AmConfig::LocalIP,rtp_str.getLocalPort(),*sdp_reply, 
AmConfig::SingleCodecInOK);
+    sdp.genResponse(advertisedIP(), rtp_str.getLocalPort(), *sdp_reply, 
AmConfig::SingleCodecInOK);
 }
 
 void AmSession::run()
@@ -784,7 +784,7 @@
   if (updateSDP) {
     rtp_str.setLocalIP(AmConfig::LocalIP);
     string sdp_body;
-    sdp.genResponse(AmConfig::LocalIP,rtp_str.getLocalPort(),sdp_body);
+    sdp.genResponse(advertisedIP(), rtp_str.getLocalPort(), sdp_body);
     dlg.reinvite(headers, "application/sdp", sdp_body);
   } else {
     dlg.reinvite(headers, "", "");
@@ -793,12 +793,13 @@
 
 int AmSession::sendInvite(const string& headers) 
 {
-  // set local IP first, so that IP is set when 
-  // getLocalPort/setLocalPort may bind 
+  // Set local IP first, so that IP is set when 
+  // getLocalPort/setLocalPort may bind.
   rtp_str.setLocalIP(AmConfig::LocalIP);
-  // generate SDP
+  
+  // Generate SDP.
   string sdp_body;
-  sdp.genRequest(AmConfig::LocalIP,rtp_str.getLocalPort(),sdp_body);
+  sdp.genRequest(advertisedIP(), rtp_str.getLocalPort(), sdp_body);
   return dlg.invite(headers, "application/sdp", sdp_body);
 }
 
@@ -811,3 +812,15 @@
     sendReinvite();
   unlockAudio();
 }
+
+// Utility for basic NAT handling: allow the config file to specify the IP
+// address to use in SDP bodies and Contact header.
+// TODO: Contact header! :)
+string AmSession::advertisedIP()
+{
+  string set_ip = AmConfig::PublicIP; // "public_ip" parameter. (NEW)
+  DBG("AmConfig::PublicIP is %s.", set_ip.c_str());
+  if (set_ip.empty())
+    return AmConfig::LocalIP;           // "listen" parameter.
+  return set_ip;
+}  

Modified: trunk/core/AmSession.h
===================================================================
--- trunk/core/AmSession.h      2008-04-24 09:07:02 UTC (rev 916)
+++ trunk/core/AmSession.h      2008-04-30 00:29:08 UTC (rev 917)
@@ -457,6 +457,9 @@
                           const string& body,
                           string& hdrs,
                           int flags);
+  
+  // The IP address to put as c= in SDP bodies and to use for Contact:.
+  string advertisedIP();
 };
 
 #endif

Modified: trunk/core/etc/sems.conf.sample
===================================================================
--- trunk/core/etc/sems.conf.sample     2008-04-24 09:07:02 UTC (rev 916)
+++ trunk/core/etc/sems.conf.sample     2008-04-30 00:29:08 UTC (rev 917)
@@ -162,13 +162,27 @@
 #   registrations. 
 #   It defaults to the value of 'listen' (see above).
 #
-# Example :
+# Example:
 #  sip_ip=10.0.0.34
 #
 # default: <listen ip address>
 #
 #sip_ip=10.0.0.34
 
+# optional parameter: public_ip=<ip_address>
+# 
+# - when running SEMS behind certain simple NAT configurations,
+#   you can use this parameter to inform SEMS of its public IP
+#   address. If this parameter is set, SEMS will write this value
+#   into SDP bodies.
+#   If this parameter is not set, the local IP address is used.
+#   N.B., there is no support for port translation; the local 
+#   RTP port is used in either case.
+#   
+# Example:
+#  public_sip=75.101.219.48
+#  
+  
 # optional parameter: sip_port=<port_number>
 #
 # - this informs SEMS about the port where its SIP stack is 

Modified: trunk/core/sems.cpp
===================================================================
--- trunk/core/sems.cpp 2008-04-24 09:07:02 UTC (rev 916)
+++ trunk/core/sems.cpp 2008-04-30 00:29:08 UTC (rev 917)
@@ -253,6 +253,7 @@
          "       plug-in path:        %s\n"
          "       daemon mode:         %i\n"
          "       local SIP IP:        %s\n"
+          "       public media IP:     %s\n"
          "       local SIP port:      %i\n"
          "       local media IP:      %s\n"
          "       application:         %s\n"
@@ -261,6 +262,7 @@
          AmConfig::PlugInPath.c_str(),
          AmConfig::DaemonMode,
          AmConfig::LocalSIPIP.c_str(),
+         AmConfig::PublicIP.c_str(),
          AmConfig::LocalSIPPort,
          AmConfig::LocalIP.c_str(),
          AmConfig::Application.empty()?

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

Reply via email to