📄 sipcommand.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, plelase 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 SipCommand_cxx_version = "$Id: SipCommand.cxx,v 1.139.2.1 2003/02/25 01:18:17 bko Exp $";#include "global.h"#include <cstdlib>#include <vector>#include <cstring>#include "BaseUrl.hxx"#include "SipAllow.hxx"#include "SipAlso.hxx"#include "SipAuthorization.hxx"#include "SipBasic.hxx"#include "SipCommand.hxx"#include "SipContact.hxx"#include "SipContentDisposition.hxx"#include "SipDigest.hxx"#include "SipHide.hxx"#include "SipMaxForwards.hxx"#include "SipOrganization.hxx"#include "SipOsp.hxx"#include "SipOspAuthorization.hxx"#include "SipPriority.hxx"#include "SipProxyAuthorization.hxx"#include "SipProxyRequire.hxx"#include "SipRequire.hxx"#include "SipResponseKey.hxx"#include "SipRecordRoute.hxx"#include "SipRoute.hxx"#include "SipSubject.hxx"#include "SipSubsNotifyEvent.hxx"#include "SipSupported.hxx"#include "SipTransferTo.hxx"#include "SipUserAgent.hxx"#include "SipVia.hxx"#include "StatusMsg.hxx"#include "SystemInfo.hxx"#include "digest.hxx"#include "vmd5.h"#include "RandomHex.hxx"using namespace Vocal;SipCommand::SipCommand() : SipMsg(), myRequestLine(){}SipCommand::SipCommand(const SipCommand& src) : SipMsg(src), myRequestLine(src.myRequestLine){}SipCommand::SipCommand(const SipCommand& src, const SipVia& via, const SipCSeq& cseq) : SipMsg(), myRequestLine(){ // src should be a message that this UAS received myVersion = src.myVersion; // reverse To and From SipFrom from(src.getTo()); setFrom(from); SipTo to(src.getFrom()); setTo(to); copyHeader(src, SIP_CALLID_HDR); setCSeq(cseq); SipMaxForwards smf; setMaxForwards(smf); setVia(via,0); if (src.getNumRoute() == 0) { if (src.getNumContact() == 1) { myRequestLine.setUrl(src.getContact(0).getUrl()); SipRecordRouteList rrList = src.getrecordrouteList(); SipRecordRouteList::iterator iter = rrList.begin(); // Copy the recordRoute list and form a route list while ( iter != rrList.end() ) { SipRoute* route = new SipRoute(**iter); routePushBack(*route); iter++; } } }}SipCommand::SipCommand(const StatusMsg& status) : SipMsg(), myRequestLine(){ myVersion = DEFAULT_VERSION; copyHeader(status, SIP_FROM_HDR); copyHeader(status, SIP_TO_HDR); copyHeader(status, SIP_CALLID_HDR); copyHeader(status, SIP_CSEQ_HDR); incrementCSeq(); // client can overwrite if this is incorrect SipMaxForwards smf; setMaxForwards(smf); //setVia(via,0); if(status.getNumContact() >= 1) { myRequestLine.setUrl(status.getContact(0).getUrl()); } // why do this for only range 180 <-> 300? !jf! // because it deals with the route list -- only 18x and 2xx can // have the record-route set, so only those can be acked w/ // record-route if (status.getStatusLine().getStatusCode() >= 180 && status.getStatusLine().getStatusCode() < 300) { SipRecordRouteList rrList = status.getrecordrouteList(); SipRecordRouteList::iterator iter = rrList.begin(); // Reverse the recordRoute list and form a route list // Record-Route (A,B,C) -> Route (C,B,A) while ( iter != rrList.end() ) { SipRoute* route = new SipRoute(**iter); routePushFront(*route); iter++; } } // record-route to route // let the application set the via}SipCommand::~SipCommand(){}SipCommand& SipCommand::operator =(const SipCommand& src){ if (&src != this) { SipMsg::operator=(src); myRequestLine = src.myRequestLine; } return (*this);}bool SipCommand::operator ==(const SipCommand& src) const{ bool equal = (SipMsg::operator==(src) && (myRequestLine == src.myRequestLine)); cpLog(LOG_DEBUG_STACK, "SipCommand::operator== returns %s", equal ? "true" : "false"); return equal;}boolSipCommand::parseStartLine(const Data& line1){ Data header; Data line2=line1; Data fg; line2.match(LF,&fg,true); int fieldvalue = line2.match(SP, &header, false); if (fieldvalue == FOUND) { line2.removeSpaces(); try { myRequestLine.decode(line2); } catch(SipRequestLineParserException&) { // xxx if this is bad, need to indicate failure return true; } } return false;}boolSipCommand::decode(const Data& inputData){ // new, revised decode // get the first line, and parse Data rawMsg = inputData; bool noMatch = false; Data line = rawMsg.getLine(&noMatch); bool requestLineError = parseStartLine(line); bool headerError = false; // pass the rest up to SipMsg::parse() try { headerError = SipMsg::parse(rawMsg); } catch(VException& e) { cpLog(LOG_ERR, "Failed to parse the SIP msg, since: %s", e.getDescription().c_str()); throw SipParserException(e.getDescription(), __FILE__, __LINE__); } catch(...) { cpLog(LOG_ERR, "Failed to parse the SIP msg for unknown reason"); throw SipParserException("unknown reason", __FILE__, __LINE__); } return requestLineError || headerError;}const SipRequestLine&SipCommand::getRequestLine() const{ return myRequestLine;}SipRequestLine&SipCommand::getMutableRequestLine() { return myRequestLine;}voidSipCommand::setRequestLine(const SipRequestLine& req){ myRequestLine = req;}voidSipCommand::setViaBranch( int i ){ int numvia = getNumVia(); if (numvia == 0) { throw SipCommandException(COMMAND_VIA_NOT_PRESENT); } if ( (i < 0) || (i >= numvia) ) { throw SipCommandException(COMMAND_INDEX_OUT_OF_BOUND); } SipVia via = getVia(i); Data token(i); via.setBranch(token);}int SipCommand::getViaBranch(){ int numvia = getNumVia(); if (numvia == 0) { throw SipCommandException(COMMAND_VIA_NOT_PRESENT); } else { SipVia via = getVia(0); Data token; token = via.getBranch(); LocalScopeAllocator lo; int value = strtol(token.getData(lo), (char**)NULL, 10); return value; }}/*--------------------------- SipAuthorization ---------------------------*/const SipAuthorization& SipCommand::getAuthorization() const{ Sptr<SipAuthorization> x; myHeaderList.getParsedHeader(x, SIP_AUTHORIZATION_HDR); return *x;}void SipCommand::setAuthorization( const SipAuthorization& author){ Sptr<SipAuthorization> x; myHeaderList.getParsedHeader(x, SIP_AUTHORIZATION_HDR); *x = author;} void SipCommand::setAuthorization( const Data& author){ Sptr<SipAuthorization> x; myHeaderList.getParsedHeader(x, SIP_AUTHORIZATION_HDR); x->decode(author);}/*--------------------------- SipHide ---------------------------*/const SipHide& SipCommand::getHide() const{ Sptr<SipHide> x; myHeaderList.getParsedHeader(x, SIP_HIDE_HDR); return *x;}void SipCommand::setHide( const SipHide& newhide){ Sptr<SipHide> x; myHeaderList.getParsedHeader(x, SIP_HIDE_HDR); *x = newhide;} void SipCommand::setHide( const Data& newhide){ Sptr<SipHide> x; myHeaderList.getParsedHeader(x, SIP_HIDE_HDR); x->decode(newhide);} /*--------------------------- SipAlso ---------------------------*/const SipAlso& SipCommand::getAlso() const{ Sptr<SipAlso> x; myHeaderList.getParsedHeader(x, SIP_ALSO_HDR); return *x;}void SipCommand::setAlso( const SipAlso& newalso){ Sptr<SipAlso> x; myHeaderList.getParsedHeader(x, SIP_ALSO_HDR); *x = newalso;}/*--------------------------- SipContentDisposition ---------------------------*/const SipContentDisposition& SipCommand::getContentDisposition() const{ Sptr<SipContentDisposition> x; myHeaderList.getParsedHeader(x, SIP_CONTENT_DISPOSITION_HDR); return *x;} void SipCommand::setContentDisposition( const SipContentDisposition& newa){ Sptr<SipContentDisposition> x; myHeaderList.getParsedHeader(x, SIP_CONTENT_DISPOSITION_HDR); *x = newa;} void SipCommand::setContentDisposition( const Data& newvalue){ Sptr<SipContentDisposition> x; myHeaderList.getParsedHeader(x, SIP_CONTENT_DISPOSITION_HDR); x->decode(newvalue);}/*------------------------------ SipMaxForwards ------------------------------*/ const SipMaxForwards& SipCommand::getMaxForwards() const{ Sptr<SipMaxForwards> x; myHeaderList.getParsedHeader(x, SIP_MAX_FORWARDS_HDR); return *x;}void SipCommand::setMaxForwards( const SipMaxForwards& newmaxForwards){ Sptr<SipMaxForwards> x; myHeaderList.getParsedHeader(x, SIP_MAX_FORWARDS_HDR); *x = newmaxForwards;} void SipCommand::setMaxForwards( const Data& newmaxForwards){ Sptr<SipMaxForwards> x; myHeaderList.getParsedHeader(x, SIP_MAX_FORWARDS_HDR); x->decode(newmaxForwards);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -