Imported Upstream version 0.3.5
[anytun.git] / src / anyrtpproxy / options.cpp
index 6a48483..55f5dcd 100644 (file)
@@ -6,19 +6,20 @@
  *  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
  *  mode and allows tunneling of every ETHER TYPE protocol (e.g.
  *  ethernet, ip, arp ...). satp directly includes cryptography and
- *  message authentication based on the methodes used by SRTP.  It is
+ *  message authentication based on the methods used by SRTP.  It is
  *  intended to deliver a generic, scaleable and secure solution for
  *  tunneling and relaying of packets of any protocol.
  *
  *
- *  Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl, 
+ *  Copyright (C) 2007-2014 Markus Grüneis, Othmar Gsenger, Erwin Nindl,
  *                          Christian Pointner <satp@wirdorange.org>
  *
  *  This file is part of Anytun.
  *
  *  Anytun is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 3 as
- *  published by the Free Software Foundation.
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  any later version.
  *
  *  Anytun is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
+ *  along with Anytun.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  In addition, as a special exception, the copyright holders give
+ *  permission to link the code of portions of this program with the
+ *  OpenSSL library under certain conditions as described in each
+ *  individual source file, and distribute linked combinations
+ *  including the two.
+ *  You must obey the GNU General Public License in all respects
+ *  for all of the code used other than OpenSSL.  If you modify
+ *  file(s) with this exception, you may extend this exception to your
+ *  version of the file(s), but you are not obligated to do so.  If you
+ *  do not wish to do so, delete this exception statement from your
+ *  version.  If you delete this exception statement from all source
+ *  files in the program, then also delete it here.
  */
 
 #include <iostream>
@@ -44,9 +58,10 @@ Options& Options::instance()
 {
   Lock lock(instMutex);
   static instanceCleaner c;
-  if(!inst)
+  if(!inst) {
     inst = new Options();
-  
+  }
+
   return *inst;
 }
 
@@ -55,34 +70,37 @@ void Host::splitAndSetAddrPort(std::string addr_port)
   if(addr_port.length() >= 2 && addr_port[0] == ':' && addr_port[1] != ':') {
     addr_ = "";
     addr_port.erase(0,1);
-    std::stringstream tmp_stream(addr_port);    
+    std::stringstream tmp_stream(addr_port);
     tmp_stream >> port_;
     return;
   }
 
   size_t pos = addr_port.find_first_of("[");
 
-  if(pos != std::string::npos && pos != 0)
-    return; // an [ was found but not at the beginning
+  if(pos != std::string::npos && pos != 0) {
+    return;  // an [ was found but not at the beginning
+  }
 
   bool hasPort = false;
   if(pos != std::string::npos) {
     addr_port.erase(pos, 1);
     pos = addr_port.find_first_of("]");
 
-    if(pos == std::string::npos)
-      return; // no trailing ] although an leading [ was found
+    if(pos == std::string::npos) {
+      return;  // no trailing ] although an leading [ was found
+    }
 
     if(pos < addr_port.length()-2) {
 
-      if(addr_port[pos+1] != ':')
-        return; // wrong port delimieter
+      if(addr_port[pos+1] != ':') {
+        return;  // wrong port delimieter
+      }
 
       addr_port[pos+1] = '/';
       hasPort = true;
+    } else if(pos != addr_port.length()-1) {
+      return;  // to few characters left
     }
-    else if(pos != addr_port.length()-1)
-      return; // to few characters left
 
     addr_port.erase(pos, 1);
   }
@@ -91,12 +109,12 @@ void Host::splitAndSetAddrPort(std::string addr_port)
     std::stringstream tmp_stream(addr_port);
 
     getline(tmp_stream, addr_, '/');
-    if(!tmp_stream.good())
+    if(!tmp_stream.good()) {
       return;
+    }
 
     tmp_stream >> port_;
-  }
-  else {
+  } else {
     addr_ = addr_port;
     port_ = "2323"; // default sync port
   }
@@ -113,11 +131,11 @@ Options::Options() : control_interface_("0.0.0.0", "22222")
   daemonize_ = true;
   pid_file_ = "";
   local_addr_ = "";
-       local_sync_port_ = "";
-       rtp_start_port_ = 34000;
-       rtp_end_port_ = 35000;
-       no_nat_once_ = false;
-       nat_ = false;
+  local_sync_port_ = "";
+  rtp_start_port_ = 34000;
+  rtp_end_port_ = 35000;
+  no_nat_once_ = false;
+  nat_ = false;
 }
 
 Options::~Options()
@@ -204,13 +222,13 @@ bool Options::parse(int argc, char* argv[])
   progname_ = argv[0];
   std::queue<std::string> host_port_queue;
   argc--;
-  for(int i=1; argc > 0; ++i)
-  {
+  for(int i=1; argc > 0; ++i) {
     std::string str(argv[i]);
     argc--;
 
-    if(str == "-h" || str == "--help")
+    if(str == "-h" || str == "--help") {
       return false;
+    }
     PARSE_BOOL_PARAM("-t","--chroot", chroot_)
     PARSE_BOOL_PARAM("-n","--nat", nat_)
     PARSE_BOOL_PARAM("-o","--no-nat-once", no_nat_once_)
@@ -221,30 +239,31 @@ bool Options::parse(int argc, char* argv[])
     PARSE_SCALAR_PARAM("-i","--interface", local_addr_)
     PARSE_STRING_PARAM("-s","--control", control_interface_)
     PARSE_SCALAR_PARAM2("-p","--port-range", rtp_start_port_, rtp_end_port_)
-               PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue)
+    PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue)
     PARSE_SCALAR_PARAM("-S","--sync-port", local_sync_port_)
     PARSE_SCALAR_PARAM("-I","--sync-interface", local_sync_addr_)
-    else 
+    else {
       return false;
+    }
   }
-  while(!host_port_queue.empty())
-  {
+  while(!host_port_queue.empty()) {
     std::stringstream tmp_stream(host_port_queue.front());
     OptionConnectTo oct;
     getline(tmp_stream,oct.host,':');
-    if(!tmp_stream.good())
+    if(!tmp_stream.good()) {
       return false;
+    }
     tmp_stream >> oct.port;
     host_port_queue.pop();
     connect_to_.push_back(oct);
   }
-  
+
   return sanityCheck();
 }
 
 bool Options::sanityCheck()
 {
-  if(control_interface_.port_ == "") control_interface_.port_ = "22222";
+  if(control_interface_.port_ == "") { control_interface_.port_ = "22222"; }
   return true;
 }
 
@@ -378,23 +397,23 @@ Options& Options::setLocalSyncPort(std::string l)
   return *this;
 }
 
-u_int16_t Options::getRtpStartPort()
+uint16_t Options::getRtpStartPort()
 {
   return rtp_start_port_;
 }
 
-Options& Options::setRtpStartPort(u_int16_t l)
+Options& Options::setRtpStartPort(uint16_t l)
 {
   rtp_start_port_ = l;
   return *this;
 }
 
-u_int16_t Options::getRtpEndPort()
+uint16_t Options::getRtpEndPort()
 {
   return rtp_end_port_;
 }
 
-Options& Options::setRtpEndPort(u_int16_t l)
+Options& Options::setRtpEndPort(uint16_t l)
 {
   rtp_end_port_ = l;
   return *this;