From ddfc1b38d7bb5cc607afc7fadc6374911f5a9e60 Mon Sep 17 00:00:00 2001 From: Markus Grüneis Date: Wed, 17 Feb 2010 21:40:54 +0000 Subject: whitespace only change: unified formatting with "astyle --style=k/r --indent=spaces=2 --unpad-paren --add-brackets --align-pointer=type --keep-one-line-blocks --indent-col1-comments --lineend=linux --suffix=none --recursive" --- src/anyrtpproxy/anyrtpproxy.cpp | 238 +++++++++++++++++------------------- src/anyrtpproxy/callIdQueue.cpp | 10 +- src/anyrtpproxy/callIdQueue.h | 19 +-- src/anyrtpproxy/commandHandler.cpp | 84 ++++++------- src/anyrtpproxy/commandHandler.h | 36 +++--- src/anyrtpproxy/connectionList.cpp | 24 ++-- src/anyrtpproxy/connectionList.h | 28 ++--- src/anyrtpproxy/options.cpp | 65 +++++----- src/anyrtpproxy/options.h | 45 +++---- src/anyrtpproxy/portWindow.cpp | 26 ++-- src/anyrtpproxy/portWindow.h | 12 +- src/anyrtpproxy/rtpSession.cpp | 8 +- src/anyrtpproxy/rtpSession.h | 82 ++++++------- src/anyrtpproxy/rtpSessionTable.cpp | 28 +++-- src/anyrtpproxy/rtpSessionTable.h | 47 +++---- src/anyrtpproxy/syncRtpCommand.cpp | 14 +-- src/anyrtpproxy/syncRtpCommand.h | 23 ++-- 17 files changed, 390 insertions(+), 399 deletions(-) (limited to 'src/anyrtpproxy') diff --git a/src/anyrtpproxy/anyrtpproxy.cpp b/src/anyrtpproxy/anyrtpproxy.cpp index 7c5514c..22d7494 100644 --- a/src/anyrtpproxy/anyrtpproxy.cpp +++ b/src/anyrtpproxy/anyrtpproxy.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -66,64 +66,62 @@ void listener(RtpSession::proto::socket* sock1, RtpSession::proto::socket* sock2 { cLog.msg(Log::PRIO_NOTICE) << "listener(" << call_id << "/" << dir << ") started"; - try - { + try { Buffer buf(u_int32_t(MAX_PACKET_SIZE)); RtpSession::proto::endpoint remote_end; while(1) { buf.setLength(MAX_PACKET_SIZE); u_int32_t len=0; - if(dir == 1) - len = 0;//sock1->recvFromNonBlocking(buf.getBuf(), buf.getLength(), remote_end, 1000); - else if(dir == 2) - len = 0; //sock2->recvFromNonBlocking(buf.getBuf(), buf.getLength(), remote_end, 1000); - else break; + if(dir == 1) { + len = 0; //sock1->recvFromNonBlocking(buf.getBuf(), buf.getLength(), remote_end, 1000); + } else if(dir == 2) { + len = 0; //sock2->recvFromNonBlocking(buf.getBuf(), buf.getLength(), remote_end, 1000); + } else { break; } RtpSession& session = gRtpSessionTable.getSession(call_id); if(session.isDead()) { - cLog.msg(Log::PRIO_NOTICE) << "listener(" << call_id << "/" << dir << ") session is dead, exiting"; + cLog.msg(Log::PRIO_NOTICE) << "listener(" << call_id << "/" << dir << ") session is dead, exiting"; break; } - if(!len) + if(!len) { continue; + } buf.setLength(len); - - if((dir == 1 && remote_end != session.getRemoteEnd1()) || - (dir == 2 && remote_end != session.getRemoteEnd2())) - { + + if((dir == 1 && remote_end != session.getRemoteEnd1()) || + (dir == 2 && remote_end != session.getRemoteEnd2())) { if(gOpt.getNat() || - (!gOpt.getNoNatOnce() && ((dir == 1 && !session.getSeen1()) || - (dir == 2 && !session.getSeen2())))) - { + (!gOpt.getNoNatOnce() && ((dir == 1 && !session.getSeen1()) || + (dir == 2 && !session.getSeen2())))) { cLog.msg(Log::PRIO_NOTICE) << "listener(" << call_id << "/" << dir << ") setting remote host to " << remote_end; - if(dir == 1) + if(dir == 1) { session.setRemoteEnd1(remote_end); - if(dir == 2) + } + if(dir == 2) { session.setRemoteEnd2(remote_end); - + } + if(!gOpt.getNat()) { // with nat enabled sync is not needed SyncRtpCommand sc(call_id); queue->push(sc); } - } - else + } else { continue; - } + } + } session.setSeen1(); session.setSeen2(); - if(dir == 1) + if(dir == 1) { sock2->send_to(boost::asio::buffer(buf.getBuf(), buf.getLength()), session.getRemoteEnd2()); - else if(dir == 2) + } else if(dir == 2) { sock1->send_to(boost::asio::buffer(buf.getBuf(), buf.getLength()), session.getRemoteEnd1()); - else break; - } - } - catch(std::exception &e) - { + } else { break; } + } + } catch(std::exception& e) { cLog.msg(Log::PRIO_ERR) << "listener(" << call_id << "/" << dir << ") exiting because: " << e.what(); } *running = false; @@ -150,21 +148,19 @@ void listenerManager(void* p) SyncQueue* queue_ = reinterpret_cast(p); std::map listenerMap; - while(1) - { - try - { + while(1) { + try { std::string call_id = gCallIdQueue.front(); // waits for semaphor and returns next call_id gCallIdQueue.pop(); RtpSession& session = gRtpSessionTable.getSession(call_id); - if(!session.isComplete()) + if(!session.isComplete()) { continue; + } std::map::iterator it; it = listenerMap.find(call_id); - if(it == listenerMap.end()) // listener Threads not existing yet - { + if(it == listenerMap.end()) { // listener Threads not existing yet ListenerData* ld = new ListenerData(); ld->sock1_.open(session.getLocalEnd1().protocol()); @@ -181,8 +177,7 @@ void listenerManager(void* p) continue; } - if(!it->second->running1_ && !it->second->running2_) - { + if(!it->second->running1_ && !it->second->running2_) { cLog.msg(Log::PRIO_NOTICE) << "listenerManager both threads for '" << call_id << "' exited, cleaning up"; if(it->second->thread1_) { it->second->thread1_->join(); @@ -197,10 +192,8 @@ void listenerManager(void* p) gRtpSessionTable.delSession(call_id); continue; } - // TODO: reinit if session changed - } - catch(std::exception &e) - { + // TODO: reinit if session changed + } catch(std::exception& e) { cLog.msg(Log::PRIO_ERR) << "listenerManager restarting after exception: " << e.what(); usleep(500); // in case of an hard error don't block cpu (this is ugly) } @@ -210,33 +203,28 @@ void listenerManager(void* p) void chrootAndDrop(string const& chrootdir, string const& username) { - if (getuid() != 0) - { - std::cerr << "this program has to be run as root in order to run in a chroot" << std::endl; - exit(-1); - } - - struct passwd *pw = getpwnam(username.c_str()); - if(pw) { - if(chroot(chrootdir.c_str())) - { + if(getuid() != 0) { + std::cerr << "this program has to be run as root in order to run in a chroot" << std::endl; + exit(-1); + } + + struct passwd* pw = getpwnam(username.c_str()); + if(pw) { + if(chroot(chrootdir.c_str())) { std::cerr << "can't chroot to " << chrootdir << std::endl; exit(-1); - } + } std::cout << "we are in chroot jail (" << chrootdir << ") now" << std::endl; chdir("/"); - if (initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)) - { - std::cerr << "can't drop to user " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - exit(-1); - } + if(initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)) { + std::cerr << "can't drop to user " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; + exit(-1); + } std::cout << "dropped user to " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - } - else - { + } else { std::cerr << "unknown user " << username << std::endl; exit(-1); - } + } } void daemonize() @@ -244,65 +232,62 @@ void daemonize() pid_t pid; pid = fork(); - if(pid) exit(0); + if(pid) { exit(0); } setsid(); pid = fork(); - if(pid) exit(0); - -// std::cout << "running in background now..." << std::endl; + if(pid) { exit(0); } + + // std::cout << "running in background now..." << std::endl; int fd; -// for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors - for (fd=0;fd<=2;fd++) // close all file descriptors + // for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors + for(fd=0; fd<=2; fd++) { // close all file descriptors close(fd); + } fd=open("/dev/null",O_RDWR); // stdin dup(fd); // stdout dup(fd); // stderr - umask(027); + umask(027); } class ThreadParam { public: - ThreadParam(SyncQueue & queue_,OptionConnectTo & connto_) + ThreadParam(SyncQueue& queue_,OptionConnectTo& connto_) : queue(queue_),connto(connto_) - {}; - SyncQueue & queue; - OptionConnectTo & connto; + {}; + SyncQueue& queue; + OptionConnectTo& connto; }; void syncConnector(void* p) { - ThreadParam* param = reinterpret_cast(p); + ThreadParam* param = reinterpret_cast(p); - SyncClient sc ( param->connto.host, param->connto.port); - sc.run(); + SyncClient sc(param->connto.host, param->connto.port); + sc.run(); } -void syncListener(SyncQueue * queue) +void syncListener(SyncQueue* queue) { - try - { + try { boost::asio::io_service io_service; - SyncTcpConnection::proto::resolver resolver(io_service); - SyncTcpConnection::proto::endpoint e; - if(gOpt.getLocalSyncAddr()!="") - { - SyncTcpConnection::proto::resolver::query query(gOpt.getLocalSyncAddr(), gOpt.getLocalSyncPort()); - e = *resolver.resolve(query); - } else { - SyncTcpConnection::proto::resolver::query query(gOpt.getLocalSyncPort()); - e = *resolver.resolve(query); - } + SyncTcpConnection::proto::resolver resolver(io_service); + SyncTcpConnection::proto::endpoint e; + if(gOpt.getLocalSyncAddr()!="") { + SyncTcpConnection::proto::resolver::query query(gOpt.getLocalSyncAddr(), gOpt.getLocalSyncPort()); + e = *resolver.resolve(query); + } else { + SyncTcpConnection::proto::resolver::query query(gOpt.getLocalSyncPort()); + e = *resolver.resolve(query); + } SyncServer server(io_service,e); - server.onConnect=boost::bind(syncOnConnect,_1); - queue->setSyncServerPtr(&server); + server.onConnect=boost::bind(syncOnConnect,_1); + queue->setSyncServerPtr(&server); io_service.run(); - } - catch (std::exception& e) - { + } catch(std::exception& e) { std::string addr = gOpt.getLocalSyncAddr() == "" ? "*" : gOpt.getLocalSyncAddr(); cLog.msg(Log::PRIO_ERR) << "sync: cannot bind to " << addr << ":" << gOpt.getLocalSyncPort() << " (" << e.what() << ")" << std::endl; @@ -312,9 +297,8 @@ void syncListener(SyncQueue * queue) int main(int argc, char* argv[]) { -// std::cout << "anyrtpproxy" << std::endl; - if(!gOpt.parse(argc, argv)) - { + // std::cout << "anyrtpproxy" << std::endl; + if(!gOpt.parse(argc, argv)) { gOpt.printUsage(); exit(-1); } @@ -330,17 +314,19 @@ int main(int argc, char* argv[]) } } - if(gOpt.getChroot()) + if(gOpt.getChroot()) { chrootAndDrop(gOpt.getChrootDir(), gOpt.getUsername()); - if(gOpt.getDaemonize()) + } + if(gOpt.getDaemonize()) { daemonize(); + } if(pidFile.is_open()) { pid_t pid = getpid(); pidFile << pid; pidFile.close(); } - + SignalController sig; sig.init(); @@ -350,38 +336,38 @@ int main(int argc, char* argv[]) boost::thread listenerManagerThread(boost::bind(listenerManager,&queue)); -// #ifndef ANYTUN_NOSYNC -// boost::thread * syncListenerThread; -// if(gOpt.getLocalSyncPort() != "") -// syncListenerThread = new boost::thread(boost::bind(syncListener,&queue)); - -// std::list connectThreads; -// for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { -// ThreadParam * point = new ThreadParam(dev, *src, cl, queue,*it); -// connectThreads.push_back(new boost::thread(boost::bind(syncConnector,point))); -// } -// #endif + // #ifndef ANYTUN_NOSYNC + // boost::thread * syncListenerThread; + // if(gOpt.getLocalSyncPort() != "") + // syncListenerThread = new boost::thread(boost::bind(syncListener,&queue)); + + // std::list connectThreads; + // for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { + // ThreadParam * point = new ThreadParam(dev, *src, cl, queue,*it); + // connectThreads.push_back(new boost::thread(boost::bind(syncConnector,point))); + // } + // #endif -// pthread_t syncListenerThread; + // pthread_t syncListenerThread; -// ConnectToList connect_to = gOpt.getConnectTo(); -// ThreadParam p( queue,*(new OptionConnectTo())); -// if ( gOpt.getLocalSyncPort()) -// pthread_create(&syncListenerThread, NULL, syncListener, &p); + // ConnectToList connect_to = gOpt.getConnectTo(); + // ThreadParam p( queue,*(new OptionConnectTo())); + // if ( gOpt.getLocalSyncPort()) + // pthread_create(&syncListenerThread, NULL, syncListener, &p); -// std::list connectThreads; -// for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) -// { -// connectThreads.push_back(pthread_t()); -// ThreadParam * point = new ThreadParam(queue,*it); -// pthread_create(& connectThreads.back(), NULL, syncConnector, point); -// } + // std::list connectThreads; + // for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) + // { + // connectThreads.push_back(pthread_t()); + // ThreadParam * point = new ThreadParam(queue,*it); + // pthread_create(& connectThreads.back(), NULL, syncConnector, point); + // } - PortWindow port_window(gOpt.getRtpStartPort(),gOpt.getRtpEndPort()); + PortWindow port_window(gOpt.getRtpStartPort(),gOpt.getRtpEndPort()); CommandHandler cmd(queue, gOpt.getControlInterface().addr_, gOpt.getControlInterface().port_,port_window); - + int ret = sig.run(); return ret; } diff --git a/src/anyrtpproxy/callIdQueue.cpp b/src/anyrtpproxy/callIdQueue.cpp index de48bab..514abf6 100644 --- a/src/anyrtpproxy/callIdQueue.cpp +++ b/src/anyrtpproxy/callIdQueue.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -40,9 +40,10 @@ CallIdQueue& CallIdQueue::instance() { Lock lock(instMutex); static instanceCleaner c; - if(!inst) + if(!inst) { inst = new CallIdQueue(); - + } + return *inst; } @@ -52,8 +53,9 @@ CallIdQueue::CallIdQueue() CallIdQueue::~CallIdQueue() { - while(!callids_.empty()) + while(!callids_.empty()) { pop(); + } } std::string& CallIdQueue::front() diff --git a/src/anyrtpproxy/callIdQueue.h b/src/anyrtpproxy/callIdQueue.h index 2cea155..4d6f7fc 100644 --- a/src/anyrtpproxy/callIdQueue.h +++ b/src/anyrtpproxy/callIdQueue.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -41,8 +41,8 @@ class CallIdQueue { public: - static CallIdQueue& instance(); - + static CallIdQueue& instance(); + std::string& front(); void push(std::string c); void pop(); @@ -51,15 +51,18 @@ private: CallIdQueue(); ~CallIdQueue(); - void operator=(const CallIdQueue &src); - CallIdQueue(const CallIdQueue &src); + void operator=(const CallIdQueue& src); + CallIdQueue(const CallIdQueue& src); static CallIdQueue* inst; static ::Mutex instMutex; - class instanceCleaner { - public: ~instanceCleaner() { - if(CallIdQueue::inst != 0) + class instanceCleaner + { + public: + ~instanceCleaner() { + if(CallIdQueue::inst != 0) { delete CallIdQueue::inst; + } } }; friend class instanceCleaner; diff --git a/src/anyrtpproxy/commandHandler.cpp b/src/anyrtpproxy/commandHandler.cpp index db0ca4d..72c3061 100644 --- a/src/anyrtpproxy/commandHandler.cpp +++ b/src/anyrtpproxy/commandHandler.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -50,23 +50,23 @@ #define MAX_COMMAND_LENGTH 1000 -CommandHandler::CommandHandler(SyncQueue& q, std::string lp,PortWindow & pw) : thread_(boost::bind(run,this)), - queue_(q), running_(true), control_sock_(io_service_), - local_address_(""), local_port_(lp),port_window_(pw) +CommandHandler::CommandHandler(SyncQueue& q, std::string lp,PortWindow& pw) : thread_(boost::bind(run,this)), + queue_(q), running_(true), control_sock_(io_service_), + local_address_(""), local_port_(lp),port_window_(pw) { proto::resolver resolver(io_service_); - proto::resolver::query query(local_port_); + proto::resolver::query query(local_port_); proto::endpoint e = *resolver.resolve(query); control_sock_.open(e.protocol()); control_sock_.bind(e); } -CommandHandler::CommandHandler(SyncQueue& q, string la, std::string lp, PortWindow & pw) : thread_(boost::bind(run,this)), - queue_(q), running_(true), control_sock_(io_service_), - local_address_(la), local_port_(lp),port_window_(pw) +CommandHandler::CommandHandler(SyncQueue& q, string la, std::string lp, PortWindow& pw) : thread_(boost::bind(run,this)), + queue_(q), running_(true), control_sock_(io_service_), + local_address_(la), local_port_(lp),port_window_(pw) { proto::resolver resolver(io_service_); - proto::resolver::query query(local_address_, local_port_); + proto::resolver::query query(local_address_, local_port_); proto::endpoint e = *resolver.resolve(query); control_sock_.open(e.protocol()); control_sock_.bind(e); @@ -77,13 +77,11 @@ void CommandHandler::run(void* s) CommandHandler* self = reinterpret_cast(s); Buffer buf(u_int32_t(MAX_COMMAND_LENGTH)); - try - { + try { proto::endpoint remote_end; int len; - while(1) - { + while(1) { buf.setLength(MAX_COMMAND_LENGTH); len = self->control_sock_.receive_from(boost::asio::buffer(buf.getBuf(), buf.getLength()), remote_end); @@ -95,9 +93,7 @@ void CommandHandler::run(void* s) self->control_sock_.send_to(boost::asio::buffer(ret.c_str(), ret.length()), remote_end); } - } - catch(std::exception& e) - { + } catch(std::exception& e) { self->running_ = false; } self->running_ = false; @@ -133,8 +129,7 @@ std::string CommandHandler::handle(std::string command) params.push_back(tmp); } - switch(std::toupper(cmd[0])) - { + switch(std::toupper(cmd[0])) { case CMD_REQUEST: if(params.size() < 4) { oss << RET_ERR_SYNTAX; break; } oss << handleRequest(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]); @@ -168,24 +163,21 @@ std::string CommandHandler::handle(std::string command) string CommandHandler::handleRequest(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag) { - std::cout << "received request[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port + std::cout << "received request[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port << "','" << from_tag << "','" << to_tag << "')" << std::endl; - try - { + try { RtpSession::proto::resolver resolver(io_service_); bool is_new; RtpSession& session = gRtpSessionTable.getOrNewSession(call_id, is_new); - if(is_new) - { + if(is_new) { u_int16_t port1 = port_window_.newPort(); // TODO: get next available port u_int16_t port2 = port_window_.newPort(); // TODO: get next available port - if( !port1 || !port2) - { - if( port1) port_window_.freePort(port1); - if( port2) port_window_.freePort(port2); - throw std::runtime_error("no free port found"); - } + if(!port1 || !port2) { + if(port1) { port_window_.freePort(port1); } + if(port2) { port_window_.freePort(port2); } + throw std::runtime_error("no free port found"); + } std::stringstream ps1, ps2; ps1 << port1; ps2 << port2; @@ -196,8 +188,7 @@ string CommandHandler::handleRequest(string modifiers, string call_id, string ad e1 = *resolver.resolve(query1); RtpSession::proto::resolver::query query2(ps2.str()); e2 = *resolver.resolve(query2); - } - else { + } else { RtpSession::proto::resolver::query query1(gOpt.getLocalAddr(),ps1.str()); e1 = *resolver.resolve(query1); RtpSession::proto::resolver::query query2(gOpt.getLocalAddr(),ps2.str()); @@ -213,20 +204,17 @@ string CommandHandler::handleRequest(string modifiers, string call_id, string ad ostringstream oss; oss << session.getLocalEnd2().port(); return oss.str(); - } - catch(std::exception& e) - { + } catch(std::exception& e) { return RET_ERR_UNKNOWN; // TODO: change to corret error value } } string CommandHandler::handleResponse(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag) { - std::cout << "received response[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port + std::cout << "received response[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port << "','" << from_tag << "','" << to_tag << "')" << std::endl; - try - { + try { RtpSession& session = gRtpSessionTable.getSession(call_id); RtpSession::proto::resolver resolver(io_service_); RtpSession::proto::resolver::query query(addr,port); @@ -238,9 +226,7 @@ string CommandHandler::handleResponse(string modifiers, string call_id, string a ostringstream oss; oss << session.getLocalEnd1().port(); return oss.str(); - } - catch(std::exception& e) - { + } catch(std::exception& e) { return RET_ERR_UNKNOWN; // TODO: change to corret error value } } @@ -249,39 +235,37 @@ string CommandHandler::handleDelete(string call_id, string from_tag, string to_t { std::cout << "received delete command ('" << call_id << "','" << from_tag << "','" << to_tag << "')" << std::endl; - try - { + try { RtpSession& session = gRtpSessionTable.getSession(call_id); session.isDead(true); SyncRtpCommand sc(call_id); queue_.push(sc); return RET_OK; - } - catch(std::exception& e) - { + } catch(std::exception& e) { return RET_ERR_UNKNOWN; // TODO: change to corret error value } } string CommandHandler::handleVersion() { - std::cout << "received version command" << std::endl; + std::cout << "received version command" << std::endl; return BASE_VERSION; } string CommandHandler::handleVersionF(string date_code) { - std::cout << "received version[F] command ('" << date_code << "')" << std::endl; - if(!date_code.compare(SUP_VERSION)) + std::cout << "received version[F] command ('" << date_code << "')" << std::endl; + if(!date_code.compare(SUP_VERSION)) { return "1"; - + } + return "0"; } string CommandHandler::handleInfo() { - std::cout << "received info command, ignoring" << std::endl; + std::cout << "received info command, ignoring" << std::endl; return RET_OK; } diff --git a/src/anyrtpproxy/commandHandler.h b/src/anyrtpproxy/commandHandler.h index 6634f14..954efc7 100644 --- a/src/anyrtpproxy/commandHandler.h +++ b/src/anyrtpproxy/commandHandler.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -46,31 +46,31 @@ class CommandHandler public: typedef boost::asio::ip::udp proto; - CommandHandler(SyncQueue& q, std::string lp, PortWindow &); - CommandHandler(SyncQueue& q, std::string la, std::string lp, PortWindow &); - + CommandHandler(SyncQueue& q, std::string lp, PortWindow&); + CommandHandler(SyncQueue& q, std::string la, std::string lp, PortWindow&); + bool isRunning(); - #define CMD_REQUEST 'U' - #define CMD_RESPONSE 'L' - #define CMD_DELETE 'D' - #define CMD_VERSION 'V' - #define CMD_INFO 'I' +#define CMD_REQUEST 'U' +#define CMD_RESPONSE 'L' +#define CMD_DELETE 'D' +#define CMD_VERSION 'V' +#define CMD_INFO 'I' - #define RET_OK "0" - #define RET_ERR_SYNTAX "E1" - #define RET_ERR_UNKNOWN "E2" +#define RET_OK "0" +#define RET_ERR_SYNTAX "E1" +#define RET_ERR_UNKNOWN "E2" - #define BASE_VERSION "20040107" - #define SUP_VERSION "20050322" +#define BASE_VERSION "20040107" +#define SUP_VERSION "20050322" private: - CommandHandler(const CommandHandler &c); - void operator=(const CommandHandler &c); + CommandHandler(const CommandHandler& c); + void operator=(const CommandHandler& c); static void run(void* s); std::string handle(std::string command); - + std::string handleRequest(std::string modifiers, std::string call_id, std::string addr, std::string port, std::string from_tag, std::string to_tag); std::string handleResponse(std::string modifiers, std::string call_id, std::string addr, std::string port, std::string from_tag, std::string to_tag); std::string handleDelete(std::string call_id, std::string from_tag, std::string to_tag); @@ -86,7 +86,7 @@ private: proto::socket control_sock_; std::string local_address_; std::string local_port_; - PortWindow& port_window_; + PortWindow& port_window_; }; diff --git a/src/anyrtpproxy/connectionList.cpp b/src/anyrtpproxy/connectionList.cpp index 4c274e8..e83a6ba 100644 --- a/src/anyrtpproxy/connectionList.cpp +++ b/src/anyrtpproxy/connectionList.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -38,15 +38,15 @@ ConnectionList::ConnectionList() ConnectionList::~ConnectionList() { -} +} -void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux ) +void ConnectionList::addConnection(ConnectionParam& conn, u_int16_t mux) { } const ConnectionMap::iterator ConnectionList::getEnd() { - return connections_.end(); + return connections_.end(); } ConnectionMap::iterator ConnectionList::getBeginUnlocked() @@ -61,28 +61,28 @@ ConnectionMap::iterator ConnectionList::getEndUnlocked() const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux) { - Lock lock(mutex_); - ConnectionMap::iterator it = connections_.find(mux); - return it; + Lock lock(mutex_); + ConnectionMap::iterator it = connections_.find(mux); + return it; } -ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux) +ConnectionParam& ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux) { - ConnectionMap::iterator it = connections_.find(mux); - return it->second; + ConnectionMap::iterator it = connections_.find(mux); + return it->second; } void ConnectionList::clear() { Lock lock(mutex_); - connections_.clear(); + connections_.clear(); } bool ConnectionList::empty() { Lock lock(mutex_); - return connections_.empty(); + return connections_.empty(); } Mutex& ConnectionList::getMutex() diff --git a/src/anyrtpproxy/connectionList.h b/src/anyrtpproxy/connectionList.h index a30f6d5..62da471 100644 --- a/src/anyrtpproxy/connectionList.h +++ b/src/anyrtpproxy/connectionList.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -44,22 +44,22 @@ typedef std::map ConnectionMap; class ConnectionList { public: - ConnectionList(); - ~ConnectionList(); - void addConnection(ConnectionParam &conn, u_int16_t mux); - const ConnectionMap::iterator getConnection(u_int16_t mux); - const ConnectionMap::iterator getEnd(); - ConnectionMap::iterator getEndUnlocked(); - ConnectionMap::iterator getBeginUnlocked(); - ConnectionParam & getOrNewConnectionUnlocked(u_int16_t mux); - bool empty(); - void clear(); + ConnectionList(); + ~ConnectionList(); + void addConnection(ConnectionParam& conn, u_int16_t mux); + const ConnectionMap::iterator getConnection(u_int16_t mux); + const ConnectionMap::iterator getEnd(); + ConnectionMap::iterator getEndUnlocked(); + ConnectionMap::iterator getBeginUnlocked(); + ConnectionParam& getOrNewConnectionUnlocked(u_int16_t mux); + bool empty(); + void clear(); Mutex& getMutex(); private: - ConnectionList(const ConnectionList &s); - void operator=(const ConnectionList &s); - ConnectionMap connections_; + ConnectionList(const ConnectionList& s); + void operator=(const ConnectionList& s); + ConnectionMap connections_; Mutex mutex_; }; diff --git a/src/anyrtpproxy/options.cpp b/src/anyrtpproxy/options.cpp index e651770..3fd9975 100644 --- a/src/anyrtpproxy/options.cpp +++ b/src/anyrtpproxy/options.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -45,9 +45,10 @@ Options& Options::instance() { Lock lock(instMutex); static instanceCleaner c; - if(!inst) + if(!inst) { inst = new Options(); - + } + return *inst; } @@ -56,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); } @@ -92,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 } @@ -114,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() @@ -205,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_) @@ -222,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; } diff --git a/src/anyrtpproxy/options.h b/src/anyrtpproxy/options.h index 679dace..8188831 100644 --- a/src/anyrtpproxy/options.h +++ b/src/anyrtpproxy/options.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -37,8 +37,7 @@ #include #include -typedef struct OptionConnectTo -{ +typedef struct OptionConnectTo { std::string host; std::string port; }; @@ -51,16 +50,15 @@ public: Host(std::string addr, std::string port) : addr_(addr), port_(port) {} Host(std::string addr_port) { splitAndSetAddrPort(addr_port); - } - std::string toString() const - { + } + std::string toString() const { std::ostringstream oss; oss << addr_ << ":" << port_; return oss.str(); } - + std::string addr_; - std::string port_; + std::string port_; protected: void splitAndSetAddrPort(std::string addr_port); @@ -89,28 +87,31 @@ public: std::string getLocalAddr(); Options& setLocalAddr(std::string l); std::string getLocalSyncAddr(); - Options& setLocalSyncAddr(std::string l); + Options& setLocalSyncAddr(std::string l); std::string getLocalSyncPort(); - Options& setLocalSyncPort(std::string l); + Options& setLocalSyncPort(std::string l); u_int16_t getRtpStartPort(); - Options& setRtpStartPort(u_int16_t l); + Options& setRtpStartPort(u_int16_t l); u_int16_t getRtpEndPort(); - Options& setRtpEndPort(u_int16_t l); + Options& setRtpEndPort(u_int16_t l); ConnectToList getConnectTo(); private: Options(); ~Options(); - Options(const Options &l); - void operator=(const Options &l); + Options(const Options& l); + void operator=(const Options& l); bool sanityCheck(); static Options* inst; static ::Mutex instMutex; - class instanceCleaner { - public: ~instanceCleaner() { - if(Options::inst != 0) + class instanceCleaner + { + public: + ~instanceCleaner() { + if(Options::inst != 0) { delete Options::inst; + } } }; friend class instanceCleaner; @@ -125,12 +126,12 @@ private: std::string chroot_dir_; std::string pid_file_; bool daemonize_; - std::string local_sync_addr_; - std::string local_sync_port_; + std::string local_sync_addr_; + std::string local_sync_port_; std::string local_addr_; - u_int16_t rtp_start_port_; - u_int16_t rtp_end_port_; - ConnectToList connect_to_; + u_int16_t rtp_start_port_; + u_int16_t rtp_end_port_; + ConnectToList connect_to_; Host control_interface_; }; diff --git a/src/anyrtpproxy/portWindow.cpp b/src/anyrtpproxy/portWindow.cpp index 3e07662..ed23686 100644 --- a/src/anyrtpproxy/portWindow.cpp +++ b/src/anyrtpproxy/portWindow.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -51,8 +51,9 @@ bool PortWindow::hasPort(u_int16_t port) Lock lock(mutex_); PortSet::const_iterator it=ports_.find(port); - if(it == ports_.end()) + if(it == ports_.end()) { return false; + } return true; } @@ -61,22 +62,25 @@ bool PortWindow::freePort(u_int16_t port) Lock lock(mutex_); PortSet::iterator it=ports_.find(port); - if(it == ports_.end()) + if(it == ports_.end()) { return false; - ports_.erase(it); + } + ports_.erase(it); return true; } u_int16_t PortWindow::newPort() { Lock lock(mutex_); - u_int16_t port= start_port_; - while (port=end_port_) - return 0; - ports_.insert(port); - return port; + u_int16_t port= start_port_; + while(port=end_port_) { + return 0; + } + ports_.insert(port); + return port; } void PortWindow::clear() diff --git a/src/anyrtpproxy/portWindow.h b/src/anyrtpproxy/portWindow.h index b5a667f..74cd4ed 100644 --- a/src/anyrtpproxy/portWindow.h +++ b/src/anyrtpproxy/portWindow.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -53,13 +53,13 @@ public: private: - u_int16_t start_port_; - u_int16_t end_port_; + u_int16_t start_port_; + u_int16_t end_port_; ::Mutex mutex_; - PortSet ports_; + PortSet ports_; - PortWindow(const PortWindow &s); - void operator=(const PortWindow &s); + PortWindow(const PortWindow& s); + void operator=(const PortWindow& s); }; #endif diff --git a/src/anyrtpproxy/rtpSession.cpp b/src/anyrtpproxy/rtpSession.cpp index 93333ac..3afba33 100644 --- a/src/anyrtpproxy/rtpSession.cpp +++ b/src/anyrtpproxy/rtpSession.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -34,9 +34,9 @@ #include "callIdQueue.h" -RtpSession::RtpSession(const std::string& call_id) : in_sync_(false), call_id_(call_id) , dead_(false), complete_(false), - seen1_(false), seen2_(false) -{ +RtpSession::RtpSession(const std::string& call_id) : in_sync_(false), call_id_(call_id) , dead_(false), complete_(false), + seen1_(false), seen2_(false) +{ } void RtpSession::reinit() diff --git a/src/anyrtpproxy/rtpSession.h b/src/anyrtpproxy/rtpSession.h index cac5115..3247dcc 100644 --- a/src/anyrtpproxy/rtpSession.h +++ b/src/anyrtpproxy/rtpSession.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -45,7 +45,7 @@ class RtpSession public: typedef boost::asio::ip::udp proto; - RtpSession(const std::string& call_id); + RtpSession(const std::string& call_id); bool isDead(); bool isDead(bool d); @@ -63,71 +63,71 @@ public: proto::endpoint getRemoteEnd2(); RtpSession& setRemoteEnd2(proto::endpoint e); - RtpSession& setSeen1(); + RtpSession& setSeen1(); bool getSeen1(); - RtpSession& setSeen2(); + RtpSession& setSeen2(); bool getSeen2(); private: - RtpSession(const RtpSession & src); - + RtpSession(const RtpSession& src); + void reinit(); //TODO: check if this is ok friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version) - { + void serialize(Archive& ar, const unsigned int version) { Lock lock(mutex_); - // address of local_end1 and local_end2 are always equal - std::string local_addr(local_end1_.address().to_string()); - u_int16_t local_port1 = local_end1_.port(); - u_int16_t local_port2 = local_end2_.port(); - - std::string remote_addr1(remote_end1_.address().to_string()); - u_int16_t remote_port1 = remote_end1_.port(); - std::string remote_addr2(remote_end2_.address().to_string()); - u_int16_t remote_port2 = remote_end2_.port(); - - ar & dead_; - ar & complete_; - ar & local_addr; - ar & local_port1; - ar & local_port2; - ar & remote_addr1; - ar & remote_port1; - ar & remote_addr2; - ar & remote_port2; - ar & seen1_; - ar & seen2_; - - proto::endpoint local_end1(boost::asio::ip::address::from_string(local_addr), local_port1); + // address of local_end1 and local_end2 are always equal + std::string local_addr(local_end1_.address().to_string()); + u_int16_t local_port1 = local_end1_.port(); + u_int16_t local_port2 = local_end2_.port(); + + std::string remote_addr1(remote_end1_.address().to_string()); + u_int16_t remote_port1 = remote_end1_.port(); + std::string remote_addr2(remote_end2_.address().to_string()); + u_int16_t remote_port2 = remote_end2_.port(); + + ar& dead_; + ar& complete_; + ar& local_addr; + ar& local_port1; + ar& local_port2; + ar& remote_addr1; + ar& remote_port1; + ar& remote_addr2; + ar& remote_port2; + ar& seen1_; + ar& seen2_; + + proto::endpoint local_end1(boost::asio::ip::address::from_string(local_addr), local_port1); local_end1_ = local_end1; - proto::endpoint local_end2(boost::asio::ip::address::from_string(local_addr), local_port2); - local_end2_ = local_end2; + proto::endpoint local_end2(boost::asio::ip::address::from_string(local_addr), local_port2); + local_end2_ = local_end2; - proto::endpoint remote_end1(boost::asio::ip::address::from_string(remote_addr1), remote_port1); - remote_end1_ = remote_end1; - proto::endpoint remote_end2(boost::asio::ip::address::from_string(remote_addr2), remote_port2); - remote_end2_ = remote_end2; + proto::endpoint remote_end1(boost::asio::ip::address::from_string(remote_addr1), remote_port1); + remote_end1_ = remote_end1; + proto::endpoint remote_end2(boost::asio::ip::address::from_string(remote_addr2), remote_port2); + remote_end2_ = remote_end2; - if(complete_ && !dead_) + if(complete_ && !dead_) { reinit(); + } in_sync_ = true; - } + } bool in_sync_; - ::Mutex mutex_; + ::Mutex mutex_; const std::string& call_id_; bool dead_; bool complete_; proto::endpoint local_end1_, local_end2_; proto::endpoint remote_end1_, remote_end2_; - bool seen1_,seen2_; //has at least 1 packet been recieved? + bool seen1_,seen2_; //has at least 1 packet been recieved? }; diff --git a/src/anyrtpproxy/rtpSessionTable.cpp b/src/anyrtpproxy/rtpSessionTable.cpp index 934cf8c..de7b031 100644 --- a/src/anyrtpproxy/rtpSessionTable.cpp +++ b/src/anyrtpproxy/rtpSessionTable.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -43,8 +43,9 @@ RtpSessionTable& RtpSessionTable::instance() { Lock lock(instMutex); static instanceCleaner c; - if(!inst) + if(!inst) { inst = new RtpSessionTable(); + } return *inst; } @@ -55,31 +56,33 @@ RtpSessionTable::RtpSessionTable() RtpSessionTable::~RtpSessionTable() { -} +} -void RtpSessionTable::delSession(const std::string & call_id) +void RtpSessionTable::delSession(const std::string& call_id) { Lock lock(mutex_); RtpSessionMap::iterator it = map_.find(call_id); - if(it!=map_.end()) + if(it!=map_.end()) { delete it->second; + } map_.erase(it); } -RtpSession& RtpSessionTable::getOrNewSession(const std::string & call_id, bool& is_new) +RtpSession& RtpSessionTable::getOrNewSession(const std::string& call_id, bool& is_new) { Lock lock(mutex_); return getOrNewSessionUnlocked(call_id, is_new); } -RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string & call_id, bool& is_new) +RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string& call_id, bool& is_new) { is_new = false; RtpSessionMap::iterator it = map_.find(call_id); - if(it!=map_.end()) + if(it!=map_.end()) { return *(it->second); + } is_new = true; std::pair ret = map_.insert(RtpSessionMap::value_type(call_id, NULL)); @@ -87,11 +90,12 @@ RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string & call_id return *(ret.first->second); } -RtpSession& RtpSessionTable::getSession(const std::string & call_id) +RtpSession& RtpSessionTable::getSession(const std::string& call_id) { RtpSessionMap::iterator it = map_.find(call_id); - if(it!=map_.end()) + if(it!=map_.end()) { return *(it->second); + } throw std::runtime_error("session not found"); } @@ -109,13 +113,13 @@ RtpSessionMap::iterator RtpSessionTable::getEndUnlocked() void RtpSessionTable::clear() { Lock lock(mutex_); - map_.clear(); + map_.clear(); } bool RtpSessionTable::empty() { Lock lock(mutex_); - return map_.empty(); + return map_.empty(); } Mutex& RtpSessionTable::getMutex() diff --git a/src/anyrtpproxy/rtpSessionTable.h b/src/anyrtpproxy/rtpSessionTable.h index 49a062f..79be6cc 100644 --- a/src/anyrtpproxy/rtpSessionTable.h +++ b/src/anyrtpproxy/rtpSessionTable.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -43,31 +43,34 @@ typedef std::map RtpSessionMap; class RtpSessionTable { public: - static RtpSessionTable& instance(); - RtpSessionTable(); - ~RtpSessionTable(); - void delSession(const std::string & call_id); - bool empty(); - void clear(); + static RtpSessionTable& instance(); + RtpSessionTable(); + ~RtpSessionTable(); + void delSession(const std::string& call_id); + bool empty(); + void clear(); ::Mutex& getMutex(); - RtpSessionMap::iterator getBeginUnlocked(); - RtpSessionMap::iterator getEndUnlocked(); - RtpSession& getOrNewSession(const std::string & call_id, bool& isnew); - RtpSession& getOrNewSessionUnlocked(const std::string & call_id, bool& isnew); - RtpSession& getSession(const std::string & call_id); + RtpSessionMap::iterator getBeginUnlocked(); + RtpSessionMap::iterator getEndUnlocked(); + RtpSession& getOrNewSession(const std::string& call_id, bool& isnew); + RtpSession& getOrNewSessionUnlocked(const std::string& call_id, bool& isnew); + RtpSession& getSession(const std::string& call_id); private: static ::Mutex instMutex; - static RtpSessionTable* inst; - class instanceCleaner { - public: ~instanceCleaner() { - if(RtpSessionTable::inst != 0) - delete RtpSessionTable::inst; - } - }; - RtpSessionTable(const RtpSessionTable &s); - void operator=(const RtpSessionTable &s); - RtpSessionMap map_; + static RtpSessionTable* inst; + class instanceCleaner + { + public: + ~instanceCleaner() { + if(RtpSessionTable::inst != 0) { + delete RtpSessionTable::inst; + } + } + }; + RtpSessionTable(const RtpSessionTable& s); + void operator=(const RtpSessionTable& s); + RtpSessionMap map_; ::Mutex mutex_; }; diff --git a/src/anyrtpproxy/syncRtpCommand.cpp b/src/anyrtpproxy/syncRtpCommand.cpp index 10dfbf4..e1d5147 100644 --- a/src/anyrtpproxy/syncRtpCommand.cpp +++ b/src/anyrtpproxy/syncRtpCommand.cpp @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -32,16 +32,16 @@ #include "syncRtpCommand.h" SyncRtpCommand::SyncRtpCommand() -{ +{ } -SyncRtpCommand::SyncRtpCommand( const std::string & addr ) -:callid_(addr) -{ +SyncRtpCommand::SyncRtpCommand(const std::string& addr) + :callid_(addr) +{ } -std::string SyncRtpCommand::getCallId() const +std::string SyncRtpCommand::getCallId() const { - return callid_; + return callid_; } diff --git a/src/anyrtpproxy/syncRtpCommand.h b/src/anyrtpproxy/syncRtpCommand.h index 7b4c186..31b333c 100644 --- a/src/anyrtpproxy/syncRtpCommand.h +++ b/src/anyrtpproxy/syncRtpCommand.h @@ -11,7 +11,7 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, * Christian Pointner * * This file is part of Anytun. @@ -40,22 +40,21 @@ class SyncRtpCommand { public: - SyncRtpCommand(const std::string & ); - SyncRtpCommand(); - std::string getCallId() const; + SyncRtpCommand(const std::string&); + SyncRtpCommand(); + std::string getCallId() const; private: - SyncRtpCommand(const SyncRtpCommand &); - std::string callid_; + SyncRtpCommand(const SyncRtpCommand&); + std::string callid_; friend class boost::serialization::access; template - void serialize(Archive & ar, const unsigned int version) - { - Lock lock(gRtpSessionTable.getMutex()); - ar & callid_; + void serialize(Archive& ar, const unsigned int version) { + Lock lock(gRtpSessionTable.getMutex()); + ar& callid_; bool is_new; - ar & gRtpSessionTable.getOrNewSessionUnlocked(callid_, is_new); - }; + ar& gRtpSessionTable.getOrNewSessionUnlocked(callid_, is_new); + }; }; -- cgit v1.2.3