📄 sipredirect.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 SipRedirect_cxx_Version = "$Id: SipRedirect.cxx,v 1.22 2002/02/25 05:53:20 sprajpat Exp $";#include "SipRedirect.hxx"#include "symbols.hxx"stringSipRedirectParserException::getName( void ) const{ return "SipRedirectParserException";}SipRedirect::SipRedirect() : rurl(), tokenMap(){ rurl.initializeFromTo();}///SipRedirect::SipRedirect( const SipUrl& rurl): rurl(rurl), tokenMap(){}///SipRedirect::~SipRedirect(){}///SipRedirect::SipRedirect(const Data& data ) : rurl(), tokenMap(){ rurl.initializeFromTo(); try { Data kdata = data; decode(kdata); } catch (SipRedirectParserException& expection) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in Constructor :o( "); throw SipRedirectParserException("failed in Decode", __FILE__, __LINE__, DECODE_REDIRECT_FAILED); } }}///SipRedirect::SipRedirect(const SipRedirect& sredirect){ rurl = sredirect.rurl; rcounter = sredirect.rcounter; rlimit = sredirect.rlimit; rreason = sredirect.rreason; displayName = sredirect.displayName; tag = sredirect.tag; tokenMap = sredirect.tokenMap;}///Data SipRedirect::encode(){ Data sipRedirect; sipRedirect = SIPREDIRECT; sipRedirect += SP; if (displayName.length() ) { sipRedirect += displayName; } sipRedirect += "<"; rurl.encode(); //get before the url param. Data nameaddr; nameaddr = rurl.getNameAddr(); sipRedirect += nameaddr; rurl.setTransport(""); rurl.setMaddr(""); Data userparam; userparam = rurl.getUrlParam(); if (userparam.length()) { sipRedirect += userparam; } sipRedirect += ">"; Data tagparam = getTag(); if (tagparam.length() > 0) { sipRedirect += Data(";") + "tag="; sipRedirect += tagparam; } if (tokenMap.size() != 0 ) { sipRedirect += ";"; } TokenMapRedirect::iterator i = tokenMap.begin(); while (i != tokenMap.end()) { Data token1 = i->first; Data tokenValue1 = i->second; sipRedirect += token1; if (tokenValue1.length() > 0) { sipRedirect += "="; sipRedirect += tokenValue1; } ++i; if ( i != tokenMap.end()) { sipRedirect += ";"; } } Data reasonparam = getReason(); LocalScopeAllocator lo; string reasons = reasonparam.getData(lo); if (reasonparam.length() > 0) { sipRedirect += Data(";") + REASON; sipRedirect += reasonparam; } Data countparam = getCounter(); string counts = countparam.getData(lo); if (countparam.length() > 0) { sipRedirect += Data(";") + COUNTER; sipRedirect += countparam; } Data limitparam = getLimit(); string limits = limitparam.getData(lo); if (limitparam.length() > 0) { sipRedirect += Data(";") + LIMIT; sipRedirect += limitparam; } sipRedirect += CRLF; return sipRedirect;}void SipRedirect::decode(const Data& redirectdata){ Data rdata = redirectdata; try { parse(rdata); } catch (SipRedirectParserException exception) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in decode() :o( "); throw SipRedirectParserException("failed in Decode", __FILE__, __LINE__, DECODE_REDIRECT_FAILED); } }}///SipRedirect& SipRedirect::operator = (const SipRedirect& sredirect){ if (&sredirect != this) { rurl = sredirect.rurl; rcounter = sredirect.rcounter; rlimit = sredirect.rlimit; rreason = sredirect.rreason; displayName = sredirect.displayName; tag = sredirect.tag; tokenMap = sredirect.tokenMap; } return *this;}///void SipRedirect::setReason(const Data& res){ rreason = res;}///Data SipRedirect::getReason() const{ return rreason;}///void SipRedirect::setCounter(const Data& count){ rcounter = count;}///Data SipRedirect::getCounter() const{ return rcounter;}///void SipRedirect::setLimit(const Data& lim){ rlimit = lim;}///Data SipRedirect::getLimit() const{ return rlimit;}///SipUrl SipRedirect::getUrl() const{ return rurl;}///void SipRedirect::setUrl(const SipUrl& redirecturl){ rurl = redirecturl;}///bool SipRedirect::operator ==(const SipRedirect& sredirect) const{ cpLog(LOG_DEBUG_STACK, "SipRedirect ::operator =="); bool equal = (( rurl == sredirect.rurl) && ( rcounter == sredirect.rcounter) && ( rlimit == sredirect.rlimit) && ( rreason == sredirect.rreason)); bool sel = (rurl == sredirect.rurl); cpLog(LOG_DEBUG_STACK, " url equal is : %d", sel); sel = sel && ( rcounter == sredirect.rcounter); cpLog(LOG_DEBUG_STACK, " counter1 equal is : %d", sel); sel = sel && ( rlimit == sredirect.rlimit); cpLog(LOG_DEBUG_STACK, " limit1 equal is : %d", sel); sel = sel && ( rreason == sredirect.rreason); cpLog(LOG_DEBUG_STACK, " reason1 equal is : %d", sel); return equal;}voidSipRedirect::parse( const Data& redirectdata){ Data data = redirectdata; try { scanSipRedirect(data); } catch (SipRedirectParserException exception) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in Parse :o( "); throw SipRedirectParserException("failed in Decode", __FILE__, __LINE__, DECODE_REDIRECT_FAILED); } } //everything allright.}voidSipRedirect::scanSipRedirect( 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; SipUrl tUrl(data); rurl = tUrl; } if (retn == FIRST) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Decode in Constructor :o( "); throw SipRedirectParserException("failed in Decode", __FILE__, __LINE__, DECODE_REDIRECT_FAILED); } } if (retn == FOUND) { // if found then it has the Addrs-params tmpval = value; SipUrl oUrl(tmpval); rurl = oUrl; value = data; } } if (ret == FIRST) { parseUrl(data); } if (ret == FOUND) { if (sipdata.length()) { parseNameInfo(sipdata); } Data urlvalue; Data tempData = data; parseUrl(data); }}void SipRedirect::setHost(const Data& newhost){ rurl.setHost(newhost);}Data SipRedirect::getHost() const{ return rurl.getHost();}voidSipRedirect::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 SipRedirect::setDisplayName(const Data& name){ displayName = name;}voidSipRedirect::parseUrl(const Data& data){ Data urlvalue = data; Data avalue; int retur = urlvalue.match(">", &avalue, true); if (retur == NOT_FOUND) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Parse in ParseUrl() :o( "); throw SipRedirectParserException("failed in Decode", __FILE__, __LINE__, PARSE_RURL_FAILED); } } if (retur == FIRST) { if (SipParserMode::sipParserMode()) { cpLog(LOG_ERR, "Failed to Parse in ParseUrl() :o( "); throw SipRedirectParserException("failed in Decode", __FILE__, __LINE__, PARSE_RURL_FAILED); } } if (retur == FOUND) { SipUrl Url(avalue); rurl = Url; Data te = urlvalue; Data fik; int rety = te.match(";", &fik, true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -