From da59d9196541670dad5c5ffc8b6947c82f13b002 Mon Sep 17 00:00:00 2001 From: paulc Date: Sun, 2 Jan 2005 04:52:02 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: http://yate.null.ro/svn/yate/trunk@153 acf43c95-373e-0410-b603-e72c3f656dc1 --- contrib/ysip/engine.cpp | 9 ++++++++- contrib/ysip/message.cpp | 9 +++++---- contrib/ysip/transaction.cpp | 20 +++++++++++++++----- modules/ysipchan.cpp | 24 +++++++++++++++--------- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/contrib/ysip/engine.cpp b/contrib/ysip/engine.cpp index 6273ff86..52601842 100644 --- a/contrib/ysip/engine.cpp +++ b/contrib/ysip/engine.cpp @@ -197,7 +197,7 @@ SIPTransaction* SIPEngine::addMessage(SIPMessage* message) return 0; } message->complete(this); - return new SIPTransaction(message,this,false); + return new SIPTransaction(message,this,message->isOutgoing()); } bool SIPEngine::process() @@ -232,6 +232,13 @@ void SIPEngine::processEvent(SIPEvent *event) { Lock lock(m_mutex); if (event) { + const char* type = "unknown"; + if (event->isOutgoing()) + type = "outgoing"; + if (event->isIncoming()) + type = "incoming"; + Debug("SIPEngine",DebugAll,"Processing %s event %p message %p [%p]", + type,event,event->getMessage(),this); if (event->isOutgoing() && event->getParty()) event->getParty()->transmit(event); if (event->isIncoming() && (event->getState() == SIPTransaction::Trying) && diff --git a/contrib/ysip/message.cpp b/contrib/ysip/message.cpp index 7157ab6a..7bfcddbf 100644 --- a/contrib/ysip/message.cpp +++ b/contrib/ysip/message.cpp @@ -128,7 +128,8 @@ SIPMessage::SIPMessage(const char* _method, const char* _uri, const char* _versi body(0), m_ep(0), m_valid(true), m_answer(false), m_outgoing(true), m_ack(false), m_cseq(-1) { - Debug(DebugAll,"SIPMessage::SIPMessage() [%p]",this); + Debug(DebugAll,"SIPMessage::SIPMessage('%s','%s','%s') [%p]", + _method,_uri,_version,this); } SIPMessage::SIPMessage(SIPParty* ep, const char *buf, int len) @@ -222,7 +223,7 @@ void SIPMessage::complete(SIPEngine* engine, const char* user, const char* domai if (!user) user = "anonymous"; if (!domain) - domain = "localhost"; + domain = getParty()->getLocalAddr(); HeaderLine* hl = const_cast(getLastHeader("Via")); if (!hl) { @@ -232,7 +233,7 @@ void SIPMessage::complete(SIPEngine* engine, const char* user, const char* domai hl = new HeaderLine("Via",tmp); header.append(hl); } - if (!hl->getParam("branch")) { + if (!(isAnswer() || hl->getParam("branch"))) { String tmp("z9hG4bK"); tmp << (int)::random(); hl->setParam("branch",tmp); @@ -249,7 +250,7 @@ void SIPMessage::complete(SIPEngine* engine, const char* user, const char* domai hl = new HeaderLine("From",tmp); header.append(hl); } - if (!hl->getParam("tag")) + if (!(isAnswer() || hl->getParam("tag"))) hl->setParam("tag",String((int)::random())); hl = const_cast(getHeader("To")); diff --git a/contrib/ysip/transaction.cpp b/contrib/ysip/transaction.cpp index 88114988..18ba3597 100644 --- a/contrib/ysip/transaction.cpp +++ b/contrib/ysip/transaction.cpp @@ -34,7 +34,8 @@ SIPTransaction::SIPTransaction(SIPMessage* message, SIPEngine* engine, bool outg : m_outgoing(outgoing), m_invite(false), m_transmit(false), m_state(Invalid), m_timeout(0), m_firstMessage(message), m_lastMessage(0), m_pending(0), m_engine(engine), m_private(0) { - Debug(DebugAll,"SIPTransaction::SIPTransaction(%p,%p) [%p]",message,engine,this); + Debug(DebugAll,"SIPTransaction::SIPTransaction(%p,%p,%d) [%p]", + message,engine,outgoing,this); if (m_firstMessage) { m_firstMessage->ref(); const NamedString* ns = message->getParam("Via","branch"); @@ -48,7 +49,7 @@ SIPTransaction::SIPTransaction(SIPMessage* message, SIPEngine* engine, bool outg const HeaderLine* hl = message->getHeader("Call-ID"); if (hl) m_callid = *hl; - if (m_firstMessage->getParty()) { + if (!m_outgoing && m_firstMessage->getParty()) { hl = message->getHeader("Contact"); if (hl) { URI uri(*hl); @@ -241,6 +242,10 @@ void SIPTransaction::setResponse(int code, const char* reason) bool SIPTransaction::processMessage(SIPMessage* message, const String& branch) { + if (!message) + return false; + if (isOutgoing() != message->isAnswer()) + return false; DDebug("SIPTransaction",DebugAll,"processMessage(%p,'%s') [%p]", message,branch.c_str(),this); if (branch) { @@ -297,9 +302,8 @@ void SIPTransaction::processClientMessage(SIPMessage* message, int state) setTimeout(); changeState(isInvite() ? Finish : Cleared); } - else { + else changeState(Process); - } break; case Process: if (message->code > 100) @@ -379,8 +383,14 @@ SIPEvent* SIPTransaction::getServerEvent(int state, int timeout) setResponse(100, "Trying"); changeState(Trying); } - else + else { setResponse(405, "Method Not Allowed"); + e = new SIPEvent(m_lastMessage,this); + m_transmit = false; + changeState(Invalid); + // remove from list and dereference + m_engine->TransList.remove(this); + } break; case Trying: e = new SIPEvent(m_firstMessage,this); diff --git a/modules/ysipchan.cpp b/modules/ysipchan.cpp index fcc8f57b..2c2d01a0 100644 --- a/modules/ysipchan.cpp +++ b/modules/ysipchan.cpp @@ -538,8 +538,9 @@ void YateSIPEndPoint::invite(SIPEvent* e, SIPTransaction* t) if (e->getMessage()->body && e->getMessage()->body->isSDP()) { String addr,port,formats; parseSDP(static_cast(e->getMessage()->body),addr,port,formats); - m->addParam("rtp.addr",addr); - m->addParam("rtp.port",port); + m->addParam("rtp_forward","possible"); + m->addParam("rtp_addr",addr); + m->addParam("rtp_port",port); m->addParam("formats",formats); } SipMsgThread *thr = new SipMsgThread(t,m); @@ -571,8 +572,8 @@ YateSIPConnection::YateSIPConnection(Message& msg, SIPTransaction* tr) m_tr->setUserData(this); s_calls.append(this); s_mutex.unlock(); - m_rtpAddr = msg.getValue("rtp.addr"); - m_rtpPort = msg.getValue("rtp.port"); + m_rtpAddr = msg.getValue("rtp_addr"); + m_rtpPort = msg.getValue("rtp_port"); m_formats = msg.getValue("formats"); int q = m_formats.find(','); m_rtpFormat = m_formats.substr(0,q); @@ -632,14 +633,19 @@ void YateSIPConnection::hangup() // Creates a SDP from RTP address data present in message SDPBody* YateSIPConnection::createPasstroughSDP(Message &msg) { - String tmp = msg.getValue("rtp.forward"); + String tmp = msg.getValue("rtp_forward"); + msg.clearParam("rtp_forward"); if (!tmp.toBoolean()) return 0; - tmp = msg.getValue("rtp.port"); + tmp = msg.getValue("rtp_port"); int port = tmp.toInteger(); - String addr(msg.getValue("rtp.addr")); - if (port && addr) - return createSDP(addr,tmp,msg.getValue("formats")); + String addr(msg.getValue("rtp_addr")); + if (port && addr) { + SDPBody* sdp = createSDP(addr,tmp,msg.getValue("formats")); + if (sdp) + msg.setParam("rtp_forward","accepted"); + return sdp; + } return 0; }