summaryrefslogtreecommitdiff
path: root/anyrtpproxy/options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'anyrtpproxy/options.cpp')
-rw-r--r--anyrtpproxy/options.cpp105
1 files changed, 32 insertions, 73 deletions
diff --git a/anyrtpproxy/options.cpp b/anyrtpproxy/options.cpp
index 6e7f291..2acc597 100644
--- a/anyrtpproxy/options.cpp
+++ b/anyrtpproxy/options.cpp
@@ -49,16 +49,16 @@ Options& Options::instance()
return *inst;
}
-Options::Options()
+Options::Options() : control_interface_("0.0.0.0", 22220)
+
{
progname_ = "anyrtpproxy";
chroot_ = false;
username_ = "nobody";
chroot_dir_ = "/var/run";
daemonize_ = true;
- send_port_ = 22220;
- local_interfaces_.push_back(IfListElement("0.0.0.0", 22221));
- remote_hosts_.push_back(IfListElement("127.0.0.1", 22222));
+ send_port_ = 22221;
+ remote_hosts_.push_back(Host("127.0.0.1", 22222));
}
Options::~Options()
@@ -99,6 +99,16 @@ Options::~Options()
i+=2; \
}
+#define PARSE_STRING_PARAM(SHORT, LONG, VALUE) \
+ else if(str == SHORT || str == LONG) \
+ { \
+ if(argc < 1 || argv[i+1][0] == '-') \
+ return false; \
+ VALUE = std::string(argv[i+1]); \
+ argc--; \
+ i++; \
+ }
+
#define PARSE_HEXSTRING_PARAM(SHORT, LONG, VALUE) \
else if(str == SHORT || str == LONG) \
{ \
@@ -109,6 +119,7 @@ Options::~Options()
i++; \
}
+
#define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
else if(str == SHORT || str == LONG) \
{ \
@@ -143,9 +154,9 @@ bool Options::parse(int argc, char* argv[])
PARSE_SCALAR_PARAM("-u","--user", username_)
PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_)
PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_)
+ PARSE_STRING_PARAM("-s","--control", control_interface_)
PARSE_SCALAR_PARAM("-p","--port", send_port_)
- PARSE_CSLIST_PARAM("-l","--listen", local_interfaces_)
- PARSE_CSLIST_PARAM("-r","--hosts", remote_hosts_)
+ PARSE_CSLIST_PARAM("-r","--remote-hosts", remote_hosts_)
else
return false;
}
@@ -155,11 +166,9 @@ bool Options::parse(int argc, char* argv[])
bool Options::sanityCheck()
{
- IfList::iterator it=local_interfaces_.begin();
- for(u_int32_t i=0; it != local_interfaces_.end(); ++it, ++i)
- if(!it->port_) it->port_ = 22221;
+ if(control_interface_.port_) control_interface_.port_ = 22220;
- it=remote_hosts_.begin();
+ HostList::iterator it=remote_hosts_.begin();
for(u_int32_t i=0; it != remote_hosts_.end(); ++it, ++i)
if(!it->port_) it->port_ = 22222;
@@ -169,14 +178,14 @@ bool Options::sanityCheck()
void Options::printUsage()
{
std::cout << "USAGE:" << std::endl;
- std::cout << "anyrtpproxy [-h|--help] prints this..." << std::endl;
- std::cout << " [-t|--chroot] chroot and drop priviledges" << std::endl;
- std::cout << " [-u|--username] <username> in case of chroot run as this user" << std::endl;
- std::cout << " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl;
- std::cout << " [-d|--nodaemonize] don't run in background" << std::endl;
- std::cout << " [-p|--port] <port> use this port to send out packets" << std::endl;
- std::cout << " [-l|--listen] <host[:port]>[,<host>[:<port> ..] a list of local interfaces to listen on" << std::endl;
- std::cout << " [-r|--hosts] <host[:port]>[,<host>[:<port> ..] a list of remote hosts to send duplicates to" << std::endl;
+ std::cout << "anyrtpproxy [-h|--help] prints this..." << std::endl;
+ std::cout << " [-t|--chroot] chroot and drop priviledges" << std::endl;
+ std::cout << " [-u|--username] <username> in case of chroot run as this user" << std::endl;
+ std::cout << " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl;
+ std::cout << " [-d|--nodaemonize] don't run in background" << std::endl;
+ std::cout << " [-s|--control] <addr[:port]> the address/port to listen on for control commands" << std::endl;
+ std::cout << " [-p|--port] <port> use this port to send out packets to remote hosts" << std::endl;
+ std::cout << " [-r|--remote-hosts] <addr[:port]>[,<addr[:<port]> .. ] a list of remote hosts to send duplicates to" << std::endl;
}
void Options::printOptions()
@@ -187,17 +196,10 @@ void Options::printOptions()
std::cout << "username='" << username_ << "'" << std::endl;
std::cout << "chroot-dir='" << chroot_dir_ << "'" << std::endl;
std::cout << "daemonize='" << daemonize_ << "'" << std::endl;
+ std::cout << "control-interface='" << control_interface_.toString() << "'" << std::endl;
std::cout << "send-port='" << send_port_ << "'" << std::endl;
- std::cout << "local interfaces='";
- IfList::const_iterator it=local_interfaces_.begin();
- for(u_int32_t i=0; it != local_interfaces_.end(); ++it, ++i)
- {
- if(i) std::cout << "','";
- std::cout << it->toString();
- }
- std::cout << "'" << std::endl;
std::cout << "remote hosts='";
- it=remote_hosts_.begin();
+ HostList::const_iterator it=remote_hosts_.begin();
for(u_int32_t i=0; it != remote_hosts_.end(); ++it, ++i)
{
if(i) std::cout << "','";
@@ -212,86 +214,43 @@ std::string Options::getProgname()
return progname_;
}
-
-Options& Options::setProgname(std::string p)
-{
- Lock lock(mutex);
- progname_ = p;
- return *this;
-}
-
bool Options::getChroot()
{
Lock lock(mutex);
return chroot_;
}
-Options& Options::setChroot(bool c)
-{
- Lock lock(mutex);
- chroot_ = c;
- return *this;
-}
-
std::string Options::getUsername()
{
Lock lock(mutex);
return username_;
}
-Options& Options::setUsername(std::string u)
-{
- Lock lock(mutex);
- username_ = u;
- return *this;
-}
-
std::string Options::getChrootDir()
{
Lock lock(mutex);
return chroot_dir_;
}
-Options& Options::setChrootDir(std::string c)
-{
- Lock lock(mutex);
- chroot_dir_ = c;
- return *this;
-}
-
bool Options::getDaemonize()
{
Lock lock(mutex);
return daemonize_;
}
-Options& Options::setDaemonize(bool d)
-{
- Lock lock(mutex);
- daemonize_ = d;
- return *this;
-}
-
u_int16_t Options::getSendPort()
{
Lock lock(mutex);
return send_port_;
}
-Options& Options::setSendPort(u_int16_t p)
-{
- Lock lock(mutex);
- send_port_ = p;
- return *this;
-}
-
-IfList Options::getLocalInterfaces()
+Host Options::getControlInterface()
{
Lock lock(mutex);
- return local_interfaces_;
+ return control_interface_;
}
-IfList Options::getRemoteHosts()
+HostList Options::getRemoteHosts()
{
Lock lock(mutex);
return remote_hosts_;