X-Git-Url: https://git.syn-net.org/debian/?a=blobdiff_plain;f=src%2Fanyrtpproxy%2Foptions.cpp;h=218fd56da53f8674245a88b0cc087a93ce7421a7;hb=bd02a5f6be4815d46524d613f727199ca756c971;hp=6a48483f6f3380d455ba14c31f364bf0e56d50a0;hpb=058ae090a970436caec3b3059e9e18b310dd6b0d;p=anytun.git diff --git a/src/anyrtpproxy/options.cpp b/src/anyrtpproxy/options.cpp index 6a48483..218fd56 100644 --- a/src/anyrtpproxy/options.cpp +++ b/src/anyrtpproxy/options.cpp @@ -11,14 +11,15 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * 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 @@ -44,9 +45,10 @@ Options& Options::instance() { Lock lock(instMutex); static instanceCleaner c; - if(!inst) + if(!inst) { inst = new Options(); - + } + return *inst; } @@ -55,34 +57,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 +96,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 +118,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 +209,13 @@ bool Options::parse(int argc, char* argv[]) progname_ = argv[0]; std::queue 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 +226,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 +384,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;