📄 sipsentresponsedb.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const SipSentResponseDB_cxx_version = "$Id: SipSentResponseDB.cxx,v 1.31.2.1 2003/02/20 10:14:32 chok Exp $";#include "global.h"#include "SipTransceiver.hxx"#include "SipSentResponseDB.hxx"#include "SipMsg.hxx"#include "SipCommand.hxx"#include "StatusMsg.hxx"#include "SipVia.hxx"using namespace Vocal;SipSentResponseDB::SipSentResponseDB() : SipTransactionDB(){}SipSentResponseDB::SipSentResponseDB(int size) : SipTransactionDB(size){}SipSentResponseDB::~SipSentResponseDB(){ /// the SipTransactionDB::~ will do the clean up}SipMsgContainer*SipSentResponseDB::processSend(const Sptr<SipMsg>& msg){ /// the only send in THIS db can be of the responses StatusMsg * response = dynamic_cast<StatusMsg*>(msg.getPtr()); assert(response); SipMsgContainer * retVal = new SipMsgContainer(); retVal->msg.in = msg; retVal->msg.type = msg->getType(); retVal->msg.transport = msg->getVia(0).getTransport(); /// if its a final response then update the transactionDB if(response->getStatusLine().getStatusCode() >= 200) { SipTransactionId id(*msg); SipTransactionList<SipTransLevel3Node *>::SipTransListNode* level3Node = 0; SipTransLevel1Node * topNode = getTopNode(id,msg); if(topNode) { SipTransactionList<SipTransLevel2Node *>::SipTransListNode* level2Node = 0; level2Node = topNode->find(id); if(level2Node) { level3Node = level2Node->val->find(id); } else { cpLog(DEBUG_NEW_STACK, "ERROR, no Level2[%s] entry for outgoing response...", id.getLevel2().logData()); } } if(level3Node) { /// there's a transaction for this response message /// hence add it to the transaction if(level3Node->val->msgs.response) { cpLog(DEBUG_NEW_STACK,"Collision\nOLD:%s\n\nNEW:%s", level3Node->val->msgs.response->msg.out.logData(), retVal->msg.out.logData()); } else { level3Node->val->msgs.response = retVal; retVal->level3Ptr = level3Node->val; /// make the transport retrans it repeatedly if((level3Node->val->myKey == INVITE_METHOD) && (SipTransceiver::myAppContext != APP_CONTEXT_PROXY)) { cpLog( LOG_DEBUG_STACK, "Set UA INVITE final response retransmission" ); retVal->retransCount = MAX_RETRANS_COUNT; } cpLog( LOG_DEBUG_STACK, "Retransmission count %d", retVal->retransCount ); if(level3Node->val->myKey == INVITE_METHOD) { SipTransactionGC::instance()-> collect(level3Node->val->msgs.request, INVITE_CLEANUP_DELAY); } } } /// release the lock acquired on top level node if(topNode) { topNode->lock.unlock(); } } return retVal;}SipMsgQueue*SipSentResponseDB::processRecv(SipMsgContainer* msgContainer){ /// the only receive in THIS db can be of the requests assert(dynamic_cast<SipCommand*>(msgContainer->msg.in.getPtr())); SipTransactionId id(*(msgContainer->msg.in)); SipMsgQueue * retVal = 0; SipTransLevel1Node * topNode = getTopNode(id,msgContainer->msg.in); if(!topNode) { /// there was no transaction found/created for this message, /// so just proxy it up and hope for the best!!! retVal = new SipMsgQueue; retVal->push_back(msgContainer->msg.in); msgContainer->msg.in = 0; cpLog(LOG_DEBUG,"No trasaction for %s", msgContainer->msg.out.logData()); ///// leak fixed 04/11 @ 1230 SipTransactionGC::instance()-> collect(msgContainer, ORPHAN_CLEANUP_DELAY); } else { SipTransLevel2Node * level2Node = topNode->findOrInsert(id)->val; SipTransactionList<SipTransLevel3Node *>::SipTransListNode *nodePtr = level2Node->findOrInsert(id); if(nodePtr->val->msgs.request) { /// if there is a coresponding response then retrans it if(nodePtr->val->msgs.response) { cpLog(LOG_INFO,"duplicate message: %s", msgContainer->msg.out.logData()); msgContainer->msg.in = nodePtr->val->msgs.response->msg.in; msgContainer->msg.netAddr = nodePtr->val->msgs.response->msg.netAddr; if(nodePtr->val->msgs.response->msg.out.length()) { msgContainer->msg.out = nodePtr->val->msgs.response->msg.out; } else { msgContainer->msg.out = nodePtr->val->msgs.response->msg.in->encode(); } msgContainer->msg.type = nodePtr->val->msgs.response->msg.type; msgContainer->msg.transport = nodePtr->val->msgs.response->msg.transport; msgContainer->msg.netAddr = nodePtr->val->msgs.response->msg.netAddr; msgContainer->retransCount = FILTER_RETRANS_COUNT; } else { /// we didn't find a matching response but since the request /// has been received already so assume that application will /// be sending a response (if it's not an ACK) /// and hence just drop this duplicate msgContainer->msg.in = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -