summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-03-14 13:38:51 +0000
committerChristian Pointner <equinox@anytun.org>2008-03-14 13:38:51 +0000
commit4d95b9eb68c438ad166d75b1cb9053c03bf2356e (patch)
treede59c9404be32ae4db5a9dd9a201492f5c86a065
parentanyrtpproxy can handled most commands (diff)
bugfixes @ anyrtpproxy
-rw-r--r--anyrtpproxy/commandHandler.cpp58
-rw-r--r--rtpSession.cpp57
-rw-r--r--rtpSession.h28
-rw-r--r--rtpSessionTable.cpp13
-rw-r--r--rtpSessionTable.h3
-rw-r--r--syncRtpCommand.h3
6 files changed, 89 insertions, 73 deletions
diff --git a/anyrtpproxy/commandHandler.cpp b/anyrtpproxy/commandHandler.cpp
index efb3c82..f2d1a23 100644
--- a/anyrtpproxy/commandHandler.cpp
+++ b/anyrtpproxy/commandHandler.cpp
@@ -125,37 +125,36 @@ std::string CommandHandler::handle(std::string command)
params.push_back(tmp);
}
- std::string ret;
switch(std::toupper(cmd[0]))
{
case CMD_REQUEST:
- if(params.size() < 4) { ret = RET_ERR_SYNTAX; break; }
- ret = handleRequest(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]);
+ 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]);
break;
case CMD_RESPONSE:
- if(params.size() < 4) { ret = RET_ERR_SYNTAX; break; }
- ret = handleResponse(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]);
+ if(params.size() < 4) { oss << RET_ERR_SYNTAX; break; }
+ oss << handleResponse(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]);
break;
case CMD_DELETE:
- if(params.size() < 2) { ret = RET_ERR_SYNTAX; break; }
- return handleDelete(params[0], params[1], (params.size() < 3) ? "" : params[2]);
+ if(params.size() < 2) { oss << RET_ERR_SYNTAX; break; }
+ oss << handleDelete(params[0], params[1], (params.size() < 3) ? "" : params[2]);
+ break;
case CMD_VERSION:
if(cmd.length() > 1 && cmd[1] == 'F') {
- if(params.size() < 1) { ret = RET_ERR_SYNTAX; break; }
- ret = handleVersionF(params[0]);
+ if(params.size() < 1) { oss << RET_ERR_SYNTAX; break; }
+ oss << handleVersionF(params[0]);
break;
}
- ret = handleVersion();
+ oss << handleVersion();
break;
case CMD_INFO:
- ret = handleInfo();
+ oss << handleInfo();
break;
default:
- ret = RET_ERR_SYNTAX;
+ oss << RET_ERR_SYNTAX;
break;
}
- oss << ret;
return oss.str();
}
@@ -166,18 +165,27 @@ string CommandHandler::handleRequest(string modifiers, string call_id, string ad
try
{
- gRtpSessionTable.addSession(call_id, new RtpSession());
- u_int16_t port = 35000; // TODO: get next available port
- RtpSession& session = gRtpSessionTable.getSession(call_id);
- session.setLocalPort(port);
- session.setLocalAddr("0.0.0.0"); // TODO: read this from config;
- session.setRemotePort1(port);
+ bool is_new;
+ RtpSession& session = gRtpSessionTable.getOrNewSession(call_id, is_new);
+ if(is_new)
+ {
+ u_int16_t port1 = 35000; // TODO: get next available port
+ u_int16_t port2 = 35001; // TODO: get next available port
+
+ session.setLocalAddr("0.0.0.0"); // TODO: read this from config
+ session.setLocalPort1(port1);
+ session.setLocalPort2(port2);
+ }
+ istringstream iss(port);
+ u_int16_t rport;
+ iss >> rport;
+ session.setRemotePort1(rport);
session.setRemoteAddr1(addr);
SyncCommand sc(call_id);
queue_.push(sc);
ostringstream oss;
- oss << port;
+ oss << session.getLocalPort1();
return oss.str();
}
catch(std::exception& e)
@@ -194,14 +202,18 @@ string CommandHandler::handleResponse(string modifiers, string call_id, string a
try
{
RtpSession& session = gRtpSessionTable.getSession(call_id);
- u_int16_t port = session.getLocalPort();
- session.setRemotePort2(port);
+ istringstream iss(port);
+ u_int16_t rport;
+ iss >> rport;
+ session.setRemotePort2(rport);
session.setRemoteAddr2(addr);
SyncCommand sc(call_id);
queue_.push(sc);
+ session.init();
+
ostringstream oss;
- oss << port;
+ oss << session.getLocalPort2();
return oss.str();
}
catch(std::exception& e)
diff --git a/rtpSession.cpp b/rtpSession.cpp
index ef48538..403f9b2 100644
--- a/rtpSession.cpp
+++ b/rtpSession.cpp
@@ -28,48 +28,31 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "PracticalSocket.h"
-
#include "rtpSession.h"
-RtpSession::RtpSession() : in_sync_(false), sock_(NULL), dead_(false), local_port_(0), local_addr_(""),
+RtpSession::RtpSession() : in_sync_(false), dead_(false), local_addr_(""), local_port1_(0), local_port2_(0),
remote_addr1_(""), remote_addr2_(""), remote_port1_(0), remote_port2_(0)
{
}
-RtpSession::~RtpSession()
-{
- if(sock_)
- delete reinterpret_cast<UDPSocket*>(sock_);
-}
-
void RtpSession::init()
{
Lock lock(mutex_);
- if(sock_ || !local_port_)
- return;
-
- sock_ = new UDPSocket(local_addr_, local_port_);
// TODO: start threads
}
-void RtpSession::reinitSock()
+void RtpSession::reinit()
{
- if(sock_)
- delete reinterpret_cast<UDPSocket*>(sock_);
- sock_ = NULL;
-
- if(!local_port_)
- return;
+ Lock lock(mutex_);
- sock_ = new UDPSocket(local_addr_, local_port_);
+// TODO: inform threads of reinit
}
bool RtpSession::isDead()
{
Lock lock(mutex_);
- return dead_;
+ return (dead_ && in_sync_);
}
bool RtpSession::isDead(bool d)
@@ -78,31 +61,45 @@ bool RtpSession::isDead(bool d)
return dead_ = d;
}
-u_int16_t RtpSession::getLocalPort()
+std::string RtpSession::getLocalAddr()
{
Lock lock(mutex_);
- return local_port_;
+ return local_addr_;
}
-RtpSession& RtpSession::setLocalPort(u_int16_t p)
+RtpSession& RtpSession::setLocalAddr(std::string a)
{
Lock lock(mutex_);
in_sync_ = false;
- local_port_ = p;
+ local_addr_ = a;
return *this;
}
-std::string RtpSession::getLocalAddr()
+u_int16_t RtpSession::getLocalPort1()
{
Lock lock(mutex_);
- return local_addr_;
+ return local_port1_;
}
-RtpSession& RtpSession::setLocalAddr(std::string a)
+RtpSession& RtpSession::setLocalPort1(u_int16_t p)
{
Lock lock(mutex_);
in_sync_ = false;
- local_addr_ = a;
+ local_port1_ = p;
+ return *this;
+}
+
+u_int16_t RtpSession::getLocalPort2()
+{
+ Lock lock(mutex_);
+ return local_port2_;
+}
+
+RtpSession& RtpSession::setLocalPort2(u_int16_t p)
+{
+ Lock lock(mutex_);
+ in_sync_ = false;
+ local_port2_ = p;
return *this;
}
diff --git a/rtpSession.h b/rtpSession.h
index 4a43d3f..0a21e5e 100644
--- a/rtpSession.h
+++ b/rtpSession.h
@@ -33,8 +33,6 @@
#include "threadUtils.hpp"
-#include <iostream>
-
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
@@ -42,17 +40,19 @@ class RtpSession
{
public:
RtpSession();
- ~RtpSession();
void init();
bool isDead();
bool isDead(bool d);
- u_int16_t getLocalPort();
- RtpSession& setLocalPort(u_int16_t p);
std::string getLocalAddr();
RtpSession& setLocalAddr(std::string a);
+ u_int16_t getLocalPort1();
+ RtpSession& setLocalPort1(u_int16_t p);
+ u_int16_t getLocalPort2();
+ RtpSession& setLocalPort2(u_int16_t p);
+
u_int16_t getRemotePort1();
RtpSession& setRemotePort1(u_int16_t p);
@@ -67,7 +67,7 @@ public:
private:
RtpSession(const RtpSession & src);
- void reinitSock();
+ void reinit();
//TODO: check if this is ok
friend class boost::serialization::access;
@@ -76,33 +76,31 @@ private:
{
Lock lock(mutex_);
- std::cout << "seralize called: " << local_port_ << "," << local_addr_ << std::endl;
-
-
- u_int16_t old_local_port = local_port_;
std::string old_local_addr = local_addr_;
+ u_int16_t old_local_port1 = local_port1_;
+ u_int16_t old_local_port2 = local_port2_;
ar & dead_;
ar & local_addr_;
- ar & local_port_;
+ ar & local_port1_;
+ ar & local_port2_;
ar & remote_addr1_;
ar & remote_port1_;
ar & remote_addr2_;
ar & remote_port2_;
- if(old_local_port != local_port_ || old_local_addr != local_addr_)
- reinitSock();
+ if(old_local_port1 != local_port1_ || old_local_port2 != local_port2_ || old_local_addr != local_addr_)
+ reinit();
in_sync_ = true;
}
bool in_sync_;
::Mutex mutex_;
- void* sock_;
bool dead_;
- u_int16_t local_port_;
std::string local_addr_;
+ u_int16_t local_port1_, local_port2_;
std::string remote_addr1_, remote_addr2_;
u_int16_t remote_port1_, remote_port2_;
};
diff --git a/rtpSessionTable.cpp b/rtpSessionTable.cpp
index a577613..1556752 100644
--- a/rtpSessionTable.cpp
+++ b/rtpSessionTable.cpp
@@ -18,8 +18,7 @@
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
@@ -80,12 +79,20 @@ void RtpSessionTable::delSession(const std::string & call_id )
map_.erase(it);
}
-RtpSession& RtpSessionTable::getOrNewSessionUnlocked(const std::string & call_id)
+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)
+{
+ is_new = false;
RtpSessionMap::iterator it = map_.find(call_id);
if(it!=map_.end())
return *(it->second);
+ is_new = true;
map_.insert(RtpSessionMap::value_type(call_id, new RtpSession()));
it = map_.find(call_id);
return *(it->second);
diff --git a/rtpSessionTable.h b/rtpSessionTable.h
index d4140ac..19aec6f 100644
--- a/rtpSessionTable.h
+++ b/rtpSessionTable.h
@@ -49,7 +49,8 @@ public:
bool empty();
void clear();
::Mutex& getMutex();
- RtpSession& getOrNewSessionUnlocked(const std::string & call_id);
+ 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:
diff --git a/syncRtpCommand.h b/syncRtpCommand.h
index 7ac9859..cc1309e 100644
--- a/syncRtpCommand.h
+++ b/syncRtpCommand.h
@@ -22,7 +22,8 @@ private:
{
Lock lock(gRtpSessionTable.getMutex());
ar & callid_;
- ar & gRtpSessionTable.getOrNewSessionUnlocked(callid_);
+ bool is_new;
+ ar & gRtpSessionTable.getOrNewSessionUnlocked(callid_, is_new);
};
};