⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipmsg.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 CXX
📖 第 1 页 / 共 4 页
字号:
/* ==================================================================== * 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 SipMsg_cxx_Version =     "$Id: SipMsg.cxx,v 1.183.2.2 2003/02/25 01:18:17 bko Exp $";#include "global.h"#include <strstream>#include "AckMsg.hxx"#include "ByeMsg.hxx"#include "CancelMsg.hxx"#include "InfoMsg.hxx"#include "InviteMsg.hxx"#include "MessageMsg.hxx"#include "NotifyMsg.hxx"#include "OptionsMsg.hxx"#include "ReferMsg.hxx"#include "RegisterMsg.hxx"#include "SipAccept.hxx"#include "SipAcceptEncoding.hxx"#include "SipAcceptLanguage.hxx"#include "SipAllow.hxx"#include "SipAlso.hxx"#include "SipContact.hxx"#include "SipContentDisposition.hxx"#include "SipContentData.hxx"#include "SipContentLength.hxx"#include "SipContentType.hxx"#include "SipDiversion.hxx"#include "SipEncryption.hxx"#include "SipExpires.hxx"#include "SipMethod.hxx"#include "SipMimeVersion.hxx"#include "SipMsg.hxx"#include "SipRecordRoute.hxx"#include "SipReplaces.hxx"#include "SipReferTo.hxx"#include "SipReferredBy.hxx"#include "SipRetryAfter.hxx"#include "SipRoute.hxx"#include "SipSubsNotifyEvent.hxx"#include "SipTimestamp.hxx"#include "SipTransferTo.hxx"#include "SipUserAgent.hxx"#include "SipVia.hxx"#include "StatusMsg.hxx"#include "SubscribeMsg.hxx"#include "TransferMsg.hxx"#include "UnknownExtensionMsg.hxx"#include "symbols.hxx"         using namespace Vocal;    SipParserException::SipParserException(                               const string& msg,                              const string& file,                              const int line,                              const int error /*Default Arguments*/ ) : VException( msg, file, line, error ){}stringSipParserException::getName( void ) const{    return "SipParserException";}SipMsg::SipMsg()    :    myVersion(),    myReceivedAddress(),    mySendAddress(),    myHeaderList(),    myMimeList(),    myNextHopIsAProxy(false){}SipMsg::~SipMsg(){}        SipMsg& SipMsg::operator=(const SipMsg& newSipMsg){    if ( &newSipMsg != this)     {	myVersion = newSipMsg.myVersion;	myReceivedAddress = newSipMsg.myReceivedAddress;        mySendAddress = newSipMsg.mySendAddress;	myHeaderList = newSipMsg.myHeaderList;        myMimeList = newSipMsg.myMimeList;        myNextHopIsAProxy = newSipMsg.myNextHopIsAProxy;    }    return *(this);}boolSipMsg::operator<(const SipMsg& src) const{    cpLog(LOG_INFO,  "not verified!");    assert(0);    return false;}   boolSipMsg::operator==(const SipMsg& src) const{    bool equal = ((myVersion == src.myVersion) &&                  (myReceivedAddress == src.myReceivedAddress) &&                  (myHeaderList == src.myHeaderList));    cpLog(LOG_DEBUG_STACK, "SipMsg::operator== returns %s", 	  equal ? "true" : "false");    return equal;}    SipMsg::SipMsg(const SipMsg& src)    :    myVersion(src.myVersion),    myReceivedAddress(src.myReceivedAddress),    mySendAddress(src.mySendAddress),    myHeaderList(src.myHeaderList),    myMimeList(src.myMimeList),    myNextHopIsAProxy(src.myNextHopIsAProxy){ }void SipMsg::copyHeader(const SipMsg& src, SipHeaderType type){    Sptr <SipRawHeader> hdr = src.myHeaderList.getHeader(type);    Sptr <SipRawHeader> copy;    if(hdr != 0)    {        copy = hdr->duplicate();    }    myHeaderList.replaceHeader(type, copy);    myNextHopIsAProxy = src.myNextHopIsAProxy;}    bool SipMsg::containsHeader(SipHeaderType type){    return (myHeaderList.getNumHeaders(type) != 0);}    int SipMsg::getNumAccept() const{    return myHeaderList.getNumHeaders(SIP_ACCEPT_HDR);}    const SipAccept&SipMsg::getAccept( int i /*default argument*/) const{    Sptr<SipAccept> x;    myHeaderList.getParsedHeader(x, SIP_ACCEPT_HDR, i);    return *x;}/** set or add another Accept item, if the index is -1, it is appended         to the current list */void SipMsg::setAccept(const SipAccept& item, int index /*default argument*/ ){    Sptr<SipHeader> x = new SipAccept(item);    myHeaderList.appendHeader(SIP_ACCEPT_HDR, x, index);}        /** set or add another Accept item, if the index is -1, it is appended         to the current list */void SipMsg::setAccept(const Data&item, int index /*default argument*/ ){    Sptr<SipHeader> x = new SipAcceptLanguage(item);    myHeaderList.appendHeader(SIP_ACCEPT_LANGUAGE_HDR, x, index);}    /** Set number of Accept items.	If i is less than current number then the extras are deleted. */void SipMsg::setNumAccept(int index){    myHeaderList.setNumHeaders(SIP_ACCEPT_HDR, index);}    int SipMsg::getNumAcceptEncoding() const{     return myHeaderList.getNumHeaders(SIP_ACCEPT_ENCODING_HDR);}const SipAcceptEncoding&SipMsg::getAcceptEncoding( int i /*default argument*/ ) const{    Sptr<SipAcceptEncoding> x;    myHeaderList.getParsedHeader(x, SIP_ACCEPT_ENCODING_HDR, i);    return *x;}/** set or add another AcceptEncoding itme, if the index is -1, it is appended         to the current list */void SipMsg::setAcceptEncoding(const Data& item, int index /*default argument*/){    Sptr<SipHeader> x = new SipAcceptEncoding(item);    myHeaderList.appendHeader(SIP_ACCEPT_ENCODING_HDR, x, index); }    /** set or add another AcceptEncoding itme, if the index is -1, it is appended         to the current list */void SipMsg::setAcceptEncoding(const SipAcceptEncoding& item,                           int index /*default argument*/){    Sptr<SipHeader> x = new SipAcceptEncoding(item);    myHeaderList.appendHeader(SIP_ACCEPT_ENCODING_HDR, x, index);}    /** Set number of AcceptEncoding items.	If i is less than current number then the extras are deleted. */void SipMsg::setNumAcceptEncoding(int index){    myHeaderList.setNumHeaders(SIP_ACCEPT_ENCODING_HDR, index);}void SipMsg::flushAcceptEncodingList(){    myHeaderList.setNumHeaders(SIP_ACCEPT_ENCODING_HDR, 0);}    /// get the number of AcceptLanguage items int SipMsg::getNumAcceptLanguage() const{    return myHeaderList.getNumHeaders(SIP_ACCEPT_LANGUAGE_HDR);}/// Get the i'th AcceptLanguage item. If i is -1, it gets the last one const SipAcceptLanguage&SipMsg::getAcceptLanguage( int i /*default argument*/ ) const{        Sptr<SipAcceptLanguage> x;    myHeaderList.getParsedHeader(x, SIP_ACCEPT_LANGUAGE_HDR, i);    return *x;}/** set or add another AcceptLanguage itme, if the index is -1, it is appended  to the current list */void SipMsg::setAcceptLanguage(const SipAcceptLanguage& item,                           int index /*default argument*/){    Sptr<SipHeader> x = new SipAcceptLanguage(item);    myHeaderList.appendHeader(SIP_ACCEPT_LANGUAGE_HDR, x, index);}        void SipMsg::setAcceptLanguage(const Data& item, int index /*default argument*/){    Sptr<SipHeader> x = new SipAcceptLanguage(item);    myHeaderList.appendHeader(SIP_ACCEPT_LANGUAGE_HDR, x, index);    }    /** Set number of AcceptLanguage items.	If i is less than current number then the extras are deleted. */void SipMsg::setNumAcceptLanguage(int index){    myHeaderList.setNumHeaders(SIP_ACCEPT_LANGUAGE_HDR, index);}void SipMsg::flushAcceptLanguageList(){   myHeaderList.setNumHeaders(SIP_ACCEPT_LANGUAGE_HDR, 0);}/*--------------------------- SipSubsNotifyEvent ---------------------------*/int SipMsg::getNumSubsNotifyEvent() const {    return myHeaderList.getNumHeaders(SIP_EVENT_HDR);}const SipSubsNotifyEvent&SipMsg::getSubsNotifyEvent(int i) const{    Sptr<SipSubsNotifyEvent> x;    myHeaderList.getParsedHeader(x, SIP_EVENT_HDR, i);    return *x;}void SipMsg::setSubsNotifyEvent(const SipSubsNotifyEvent& item, int index){    Sptr<SipHeader> x = new SipSubsNotifyEvent(item);    myHeaderList.appendHeader(SIP_EVENT_HDR, x, index);}void SipMsg::setSubsNotifyEvent(const Data& item, int index){    Sptr<SipHeader> x = new SipSubsNotifyEvent(item);    myHeaderList.appendHeader(SIP_EVENT_HDR, x, index);}void SipMsg::removeSubsNotifyEvent(int index){    myHeaderList.removeHeader(SIP_EVENT_HDR, index);}void SipMsg::setNumSubsNotifyEvent(int i){    myHeaderList.setNumHeaders(SIP_EVENT_HDR, i);}void SipMsg::flushSubsNotifyEvent(){    myHeaderList.setNumHeaders(SIP_EVENT_HDR, 0);}void SipMsg::copySubsNotifyEvent(const SipMsg& srcObject){    Sptr <SipRawHeader> hdr         = srcObject.myHeaderList.getHeader(SIP_EVENT_HDR);    Sptr <SipRawHeader> copy;    if(hdr != 0)    {        copy = hdr->duplicate();    }    myHeaderList.replaceHeader(SIP_EVENT_HDR, copy);}// ----------------- CSeq Header Methods ------------------/// Get the current CSeq header const SipCSeq&SipMsg::getCSeq() const{    Sptr<SipCSeq> cseq;    myHeaderList.getParsedHeader(cseq, SIP_CSEQ_HDR);    return *cseq;}    /// Set the CSeq header void SipMsg::setCSeq( const SipCSeq& newcseq){    Sptr<SipCSeq> cseq;    myHeaderList.getParsedHeader(cseq, SIP_CSEQ_HDR);    *cseq = newcseq;}    void SipMsg::setCSeq( const Data& newcseq){    Sptr<SipCSeq> cseq;    myHeaderList.getParsedHeader(cseq, SIP_CSEQ_HDR);    cseq->decode(newcseq);}    voidSipMsg::incrementCSeq(){    Sptr<SipCSeq> cseq;    myHeaderList.getParsedHeader(cseq, SIP_CSEQ_HDR);    cseq->incrCSeq();}// ----------------- CallId Header Methods ------------------/// Get the current CallId header const SipCallId& SipMsg::getCallId() const{    Sptr<SipCallId> callId;    myHeaderList.getParsedHeader(callId, SIP_CALLID_HDR);    return *callId;}/// Set the CallId header void SipMsg::setCallId( const SipCallId& newcallId){    Sptr<SipCallId> callId;    myHeaderList.getParsedHeader(callId, SIP_CALLID_HDR);    *callId = newcallId;}    void SipMsg::setCallId( const Data& data){    Sptr<SipCallId> callId;    myHeaderList.getParsedHeader(callId, SIP_CALLID_HDR);    callId->decode(data);}    // ----------------- Also Header Methods ------------------/// Get the current Also header const SipAlso& SipMsg::getAlso() const{    Sptr<SipAlso> also;    myHeaderList.getParsedHeader(also, SIP_ALSO_HDR);    return *also;}/// Set the Also header void SipMsg::setAlso( const SipAlso& newalso){    Sptr<SipAlso> also;    myHeaderList.getParsedHeader(also, SIP_ALSO_HDR);    *also = newalso;}    /// Set the Also header void SipMsg::setAlso( const Data& newalso){    Sptr<SipAlso> also;    myHeaderList.getParsedHeader(also, SIP_ALSO_HDR);    also->decode(newalso);}    // ----------------- CallLeg Header Methods ------------------/// Get the current CallLeg header SipCallLegSipMsg::computeCallLeg() const{    SipCallLeg callLeg(getFrom(), getTo(), getCallId());    return callLeg;//form callleg from from, to , callid and return.}int SipMsg::getNumContact() const{    return myHeaderList.getNumHeaders(SIP_CONTACT_HDR);}const SipContact&SipMsg::getContact( int i /*default argument*/) const{    Sptr<SipContact> x;    myHeaderList.getParsedHeader(x, SIP_CONTACT_HDR, i);    return *x;}void SipMsg::setContact(const SipContact& item, int index /*default argument*/ ){    Sptr<SipHeader> x = new SipContact(item);    myHeaderList.appendHeader(SIP_CONTACT_HDR, x, index);}void SipMsg::setContact(const Data& item, int index /*default argument*/ ){    Sptr<SipHeader> x = new SipContact(item);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -