From 025dd79ba96a6d370ac17f37d76f18828f2c2234 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 25 Nov 2008 18:34:39 +0000 Subject: anyrtpproxy: options parser support ipv6 now --- src/anyrtpproxy/options.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ src/anyrtpproxy/options.h | 10 ++++----- 2 files changed, 58 insertions(+), 5 deletions(-) (limited to 'src/anyrtpproxy') diff --git a/src/anyrtpproxy/options.cpp b/src/anyrtpproxy/options.cpp index fa0879e..6a48483 100644 --- a/src/anyrtpproxy/options.cpp +++ b/src/anyrtpproxy/options.cpp @@ -50,6 +50,59 @@ Options& Options::instance() return *inst; } +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); + 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 + + 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 < addr_port.length()-2) { + + 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 + + addr_port.erase(pos, 1); + } + + if(hasPort) { + std::stringstream tmp_stream(addr_port); + + getline(tmp_stream, addr_, '/'); + if(!tmp_stream.good()) + return; + + tmp_stream >> port_; + } + else { + addr_ = addr_port; + port_ = "2323"; // default sync port + } +} + + Options::Options() : control_interface_("0.0.0.0", "22222") { diff --git a/src/anyrtpproxy/options.h b/src/anyrtpproxy/options.h index 50e16f9..af09d4f 100644 --- a/src/anyrtpproxy/options.h +++ b/src/anyrtpproxy/options.h @@ -48,11 +48,8 @@ class Host { public: Host(std::string addr, std::string port) : addr_(addr), port_(port) {} - Host(std::string addr_port) - { - std::istringstream iss(addr_port); - getline(iss, addr_, ':'); - if(!(iss >> port_)) port_ = ""; + Host(std::string addr_port) { + splitAndSetAddrPort(addr_port); } std::string toString() const { @@ -63,6 +60,9 @@ public: std::string addr_; std::string port_; + +protected: + void splitAndSetAddrPort(std::string addr_port); }; typedef std::list HostList; -- cgit v1.2.3