summaryrefslogtreecommitdiff
path: root/src/anyrtpproxy
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-11-25 18:34:39 +0000
committerChristian Pointner <equinox@anytun.org>2008-11-25 18:34:39 +0000
commit025dd79ba96a6d370ac17f37d76f18828f2c2234 (patch)
tree60e886e86306a687d49fa28d0dd2e366fafd54d0 /src/anyrtpproxy
parentanyrtpproxy: small fix (diff)
anyrtpproxy: options parser support ipv6 now
Diffstat (limited to 'src/anyrtpproxy')
-rw-r--r--src/anyrtpproxy/options.cpp53
-rw-r--r--src/anyrtpproxy/options.h10
2 files changed, 58 insertions, 5 deletions
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<Host> HostList;