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

📄 sipdiversion.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * 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 SipRedirect_cxx_Version =    "$Id: SipDiversion.cxx,v 1.15.24.1 2003/02/27 04:08:26 sprajpat Exp $";#include "global.h"#include "cpLog.h"#include "symbols.hxx"#include "SipDiversion.hxx"#include "SipParserMode.hxx"#include "SipUrl.hxx"using namespace Vocal;stringSipDiversionParserException::getName( void ) const{    return "SipDiversionParserException";}SipDiversion::SipDiversion(UrlType uType)        : rurl(),        tokenMap(){      urlType =  uType;}        SipDiversion::SipDiversion( Sptr <BaseUrl> rurl):        rurl(duplicateUrl(rurl)),        tokenMap(){}SipDiversion::~SipDiversion(){}SipDiversion::SipDiversion(const Data& data )        : rurl(),        tokenMap(){    try    {        Data kdata = data;        decode(kdata);	if (rurl != 0)	{	    urlType = rurl->getType();    	    if (rurl->getType() == SIP_URL)	    {		Sptr <SipUrl> sipUrl;		sipUrl.dynamicCast(rurl);		sipUrl->initializeFrom();		sipUrl->initializeTo();	    }	}    }    catch (SipDiversionParserException&)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Constructor :o( ");            throw SipDiversionParserException("failed in Decode", __FILE__, __LINE__, DECODE_DIVERSION_FAILED);        }    }}SipDiversion::SipDiversion(const SipDiversion& src)    :    rurl(duplicateUrl(src.rurl)){    if (rurl != 0)    {	urlType = rurl->getType();    	if (rurl->getType() == SIP_URL)	{	    Sptr <SipUrl> sipUrl;	    sipUrl.dynamicCast(rurl);    	    sipUrl->initializeTo();	    sipUrl->initializeFrom();	}    }    rcounter = src.rcounter;    rlimit = src.rlimit;    rreason = src.rreason;    displayName = src.displayName;    tag = src.tag;    tokenMap = src.tokenMap;}Data SipDiversion::encode() const{    Data sipDiversion;    sipDiversion = SIPDIVERSION;    sipDiversion += SP;    if (displayName.length() )    {        sipDiversion += displayName;    }    if (rurl != 0)    {	if (rurl->getType() == SIP_URL)	{	    rurl->encode();	    	    sipDiversion += "<";                Sptr <SipUrl> sipUrl;	    sipUrl.dynamicCast(rurl);    	    //get before the url param.	    Data nameaddr;	    nameaddr = sipUrl->getNameAddr();	    sipDiversion += nameaddr;	    	    Data userparam;	    userparam = sipUrl->getUrlParam();	     if (userparam.length())	     {		 sipDiversion += userparam;	     }	     sipDiversion += ">";	}    }       Data tagparam = getTag();    if (tagparam.length() > 0)    {        sipDiversion += Data(";") + "tag=";        sipDiversion += tagparam;    }    if (tokenMap.size() != 0 )    {        sipDiversion += ";";    }    TokenMapDiversion::const_iterator i = tokenMap.begin();    while (i != tokenMap.end())    {        Data token1 = i->first;        Data tokenValue1 = i->second;        sipDiversion += token1;        if (tokenValue1.length() > 0)        {            sipDiversion += "=";            sipDiversion += tokenValue1;        }        ++i;        if ( i != tokenMap.end())        {            sipDiversion += ";";        }    }    Data reasonparam = getReason();    LocalScopeAllocator lo;    string reasons = reasonparam.getData(lo);    if (reasonparam.length() > 0)    {        sipDiversion += Data(";") + DIVERSION_REASON;        sipDiversion += reasonparam;    }    Data countparam = getCounter();    string counts = countparam.getData(lo);    if (countparam.length() > 0)    {        sipDiversion += Data(";") + COUNTER;        sipDiversion += countparam;    }    Data limitparam = getLimit();    string limits = limitparam.getData(lo);    if (limitparam.length() > 0)    {        sipDiversion += Data(";") + LIMIT;        sipDiversion += limitparam;    }    sipDiversion += CRLF;    return sipDiversion;}void SipDiversion::decode(const Data& diversiondata){    Data rdata = diversiondata;    try    {        parse(rdata);    }    catch (SipDiversionParserException exception)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in decode() :o( ");            throw SipDiversionParserException("failed in Decode", __FILE__, __LINE__, DECODE_DIVERSION_FAILED);        }    }}SipDiversion& SipDiversion::operator = (const SipDiversion& src){    if (&src != this)    {        rurl = duplicateUrl(src.rurl);	urlType = src.urlType;        rcounter = src.rcounter;        rlimit = src.rlimit;        rreason = src.rreason;        displayName = src.displayName;        tag = src.tag;        tokenMap = src.tokenMap;    }    return *this;}void SipDiversion::setReason(const Data& res){    rreason = res;}Data SipDiversion::getReason() const{    return rreason;}void SipDiversion::setCounter(const Data& count){    rcounter = count;}Data SipDiversion::getCounter() const{    return rcounter;}void SipDiversion::setLimit(const Data& lim){    rlimit = lim;}Data SipDiversion::getLimit() const{    return rlimit;}Sptr<BaseUrl> SipDiversion::getUrl() const{    return duplicateUrl(rurl, true);}void SipDiversion::setUrl(Sptr<BaseUrl> diversionurl){    rurl = duplicateUrl(diversionurl);}bool SipDiversion::operator ==(const SipDiversion& sdiversion) const{    bool equal = false;        cpLog(LOG_DEBUG_STACK, "SipDiversion ::operator ==");    if ( (rurl != 0) && (sdiversion.rurl != 0) )    {	equal = (rurl->areEqual(sdiversion.rurl));    }    else if ( (rurl == 0) && (sdiversion.rurl == 0) )     {	equal = true;    }    else    {	equal = false;    }    cpLog(LOG_DEBUG_STACK, " url equal is : %d", equal);        equal = equal && (( rcounter == sdiversion.rcounter) &&                  ( rlimit == sdiversion.rlimit) &&                  ( rreason == sdiversion.rreason));       return equal;}voidSipDiversion::parse( const Data& diversiondata){    Data data = diversiondata;    try    {        scanSipDiversion(data);    }    catch (SipDiversionParserException exception)    {        if (SipParserMode::sipParserMode())        {            cpLog(LOG_ERR, "Failed to Decode in Parse :o( ");            throw SipDiversionParserException("failed in Decode", __FILE__, __LINE__, DECODE_DIVERSION_FAILED);        }    }    //everything allright.}voidSipDiversion::scanSipDiversion( const Data & tmpdata){    Data sipdata;    Data data = tmpdata;    int ret = data.match("<", &sipdata, true);    if (ret == NOT_FOUND)    {        Data value;        Data tmpval;        int retn = data.match(";", &value, true) ;        if (retn == NOT_FOUND)        {  // it's Ok becos it Can be URl only since Addrs. Params are Optional            tmpval = value;            rurl = BaseUrl::decode(data);        }        if (retn == FIRST)        {            if (SipParserMode::sipParserMode())            {                cpLog(LOG_ERR, "Failed to Decode in Constructor :o( ");                throw SipDiversionParserException("failed in Decode", __FILE__, __LINE__, DECODE_DIVERSION_FAILED);            }        }        if (retn == FOUND)        { // if found then it has the Addrs-params            tmpval = value;            rurl = BaseUrl::decode(tmpval);            value = data;        }    }    if (ret == FIRST)    {        parseUrl(data);    }    if (ret == FOUND)    {        if (sipdata.length())        {            parseNameInfo(sipdata);        }        Data urlvalue;        Data tempData = data;        parseUrl(data);    }}void SipDiversion::setHost(const Data& newhost){    if (urlType == TEL_URL)    {	return;    }    if (rurl == 0)    {	rurl = new SipUrl();    }    if (rurl != 0)    {	if (rurl->getType() == SIP_URL)	{	    Sptr <SipUrl> sipUrl;	    sipUrl.dynamicCast(rurl);    	    sipUrl->setHost(newhost);	}    }}Data SipDiversion::getHost() const{    Data myHost;    if (rurl != 0)    {	if (rurl->getType() == SIP_URL)	{	    Sptr<SipUrl> sipUrl;	    sipUrl.dynamicCast(rurl);    	    myHost = sipUrl->getHost();	}    }    return myHost;}voidSipDiversion::parseNameInfo(const Data& data){    Data newnameinfo;    Data nameinfo = data;    int ret = nameinfo.match(":", &newnameinfo, true);    Data newnameinf;    ret = nameinfo.match(" ", &newnameinf, true);    setDisplayName(nameinfo);}void SipDiversion::setDisplayName(const Data& name){    displayName = name;}voidSipDiversion::parseUrl(const Data& data){    Data urlvalue = data;    Data avalue;

⌨️ 快捷键说明

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