Added record routing support.

git-svn-id: http://voip.null.ro/svn/yate@402 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2005-06-13 15:01:15 +00:00
parent d6d6d54baf
commit de2e013fe2
3 changed files with 53 additions and 5 deletions

View File

@ -76,8 +76,9 @@ SIPHeaderLine::SIPHeaderLine(const char* name, const String& value, char sep)
}
}
SIPHeaderLine::SIPHeaderLine(const SIPHeaderLine& original)
: NamedString(original.name(),original), m_separator(original.separator())
SIPHeaderLine::SIPHeaderLine(const SIPHeaderLine& original, const char* name)
: NamedString(name ? name : original.name().c_str(),original),
m_separator(original.separator())
{
XDebug(DebugAll,"SIPHeaderLine::SIPHeaderLine(%p '%s') [%p]",&original,name().c_str(),this);
const ObjList* l = &original.params();
@ -307,6 +308,7 @@ SIPMessage::SIPMessage(const SIPMessage* message, int _code, const char* _reason
uri = message->uri;
method = message->method;
copyAllHeaders(message,"Via");
copyAllHeaders(message,"Record-Route");
copyHeader(message,"From");
copyHeader(message,"To");
copyHeader(message,"Call-ID");
@ -775,6 +777,30 @@ SIPAuthLine* SIPMessage::buildAuth(const String& username, const String& passwor
return 0;
}
ObjList* SIPMessage::getRoutes() const
{
ObjList* list = 0;
const ObjList* l = &header;
for (; l; l = l->next()) {
const SIPHeaderLine* h = YOBJECT(SIPHeaderLine,l->get());
if (h && (h->name() &= "Record-Route")) {
if (!list)
list = new ObjList;
list->append(new SIPHeaderLine(*h,"Route"));
}
}
return list;
}
void SIPMessage::addRoutes(const ObjList* routes)
{
for (; routes; routes = routes->next()) {
const SIPHeaderLine* h = YOBJECT(SIPHeaderLine,routes->get());
if (h)
addHeader(h->clone());
}
}
SIPDialog::SIPDialog()
{
}

View File

@ -180,7 +180,7 @@ class YSIP_API SIPHeaderLine : public NamedString
{
public:
SIPHeaderLine(const char* name, const String& value, char sep = 0);
SIPHeaderLine(const SIPHeaderLine& original);
SIPHeaderLine(const SIPHeaderLine& original, const char* name = 0);
virtual ~SIPHeaderLine();
virtual void* getObject(const String& name) const;
virtual SIPHeaderLine* clone() const;
@ -407,6 +407,18 @@ public:
SIPAuthLine* buildAuth(const String& username, const String& password,
const String& meth, const String& uri, bool proxy = false) const;
/**
* Extract routes from Record-Route: headers
* @return A list of SIPHeaderLine representing SIP routes
*/
ObjList* getRoutes() const;
/**
* Add Route: headers to an outgoing message
* @param routes List of SIPHeaderLine representing SIP routes
*/
void addRoutes(const ObjList* routes);
/**
* Creates a binary buffer from a SIPMessage.
*/

View File

@ -238,6 +238,7 @@ private:
String m_line;
int m_port;
Message* m_route;
ObjList* m_routes;
};
class UserHandler : public MessageHandler
@ -702,7 +703,7 @@ YateSIPConnection::YateSIPConnection(SIPEvent* ev, SIPTransaction* tr)
: Channel(plugin,0,false),
m_tr(tr), m_hungup(false), m_byebye(true), m_retry(false),
m_state(Incoming),
m_rtpSession(0), m_rtpVersion(0), m_port(0), m_route(0)
m_rtpSession(0), m_rtpVersion(0), m_port(0), m_route(0), m_routes(0)
{
Debug(this,DebugAll,"YateSIPConnection::YateSIPConnection(%p,%p) [%p]",ev,tr,this);
setReason();
@ -776,7 +777,7 @@ YateSIPConnection::YateSIPConnection(Message& msg, const String& uri, const char
: Channel(plugin,0,true),
m_tr(0), m_hungup(false), m_byebye(true), m_retry(true),
m_state(Outgoing),
m_rtpSession(0), m_rtpVersion(0), m_port(0), m_route(0)
m_rtpSession(0), m_rtpVersion(0), m_port(0), m_route(0), m_routes(0)
{
Debug(this,DebugAll,"YateSIPConnection::YateSIPConnection(%p,'%s') [%p]",
&msg,uri.c_str(),this);
@ -828,6 +829,10 @@ YateSIPConnection::~YateSIPConnection()
delete m_route;
m_route = 0;
}
if (m_routes) {
delete m_routes;
m_routes = 0;
}
}
void YateSIPConnection::startRouter()
@ -879,6 +884,7 @@ void YateSIPConnection::hangup()
case Ringing:
if (m_tr) {
SIPMessage* m = new SIPMessage("CANCEL",m_uri);
m->addRoutes(m_routes);
plugin.ep()->buildParty(m,m_host,m_port);
const SIPMessage* i = m_tr->initialMessage();
m->copyHeader(i,"Via");
@ -899,6 +905,7 @@ void YateSIPConnection::hangup()
if (m_byebye) {
m_byebye = false;
SIPMessage* m = new SIPMessage("BYE",m_uri);
m->addRoutes(m_routes);
plugin.ep()->buildParty(m,m_host,m_port);
m->addHeader("Call-ID",m_callid);
String tmp;
@ -1069,6 +1076,9 @@ bool YateSIPConnection::process(SIPEvent* ev)
m_dialog = *ev->getTransaction()->recentMessage();
const SIPMessage* msg = ev->getMessage();
if (msg && !msg->isOutgoing() && msg->isAnswer() && (msg->code >= 300)) {
// HERE
if (!m_routes)
m_routes = msg->getRoutes();
if (m_retry && m_line
&& ((msg->code == 401) || (msg->code == 407))
&& plugin.validLine(m_line)) {