📄 subscribemsg.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 SubscribeMsg_cxx_Version = "$Id: SubscribeMsg.cxx,v 1.23.2.1 2003/02/12 03:12:31 sprajpat Exp $";#include "SipCallLeg.hxx"#include "SipExpires.hxx"#include "SipMsg.hxx"#include "SipRoute.hxx"#include "SipVia.hxx"#include "SubscribeMsg.hxx"#include "SystemInfo.hxx"#include "cpLog.h"#include "symbols.hxx"using namespace Vocal;SubscribeMsg::SubscribeMsg() : SipCommand(){ myRequestLine.setMethod(SUBSCRIBE_METHOD); SipCSeq cseq( SIP_SUBSCRIBE, Data(0) ); setCSeq( cseq ); //set to and from of host creating SUBSCRIBE msg SipFrom from; Data user = theSystem.getUserName(); from.setUser(user); Data dispName = theSystem.getDisplayName(); from.setDisplayName(dispName); from.setHost( Data(theSystem.gethostAddress()) ); from.setPort(Data(5060)); //port defaults to 5060 setFrom(from); SipTo to( from.getUrl()); to.setDisplayName( from.getDisplayName()); setTo(to); //use the register url from the system as the request url, if it exists. If it //doesn't exist, use the to url as the request url. Sptr <BaseUrl> requestUrl; Data registerDomain = theSystem.getRegisterDomain(); if (registerDomain.length() == 0) { //get from the To field. registerDomain = to.getHost(); } if (requestUrl.getPtr() != 0) { if (requestUrl->getType() == SIP_URL) { Sptr <SipUrl> sipUrl; (sipUrl.dynamicCast(requestUrl))->setHost(registerDomain); } } setSubscribeDetails(from.getUrl(), requestUrl);} SubscribeMsg::SubscribeMsg(const Data& data) : SipCommand(){ try { SipCommand::decode(data); } catch (SipParserException& e) { cpLog(LOG_ERR, "Failed to parse the SIP msg, since: %s", e.getDescription().c_str()); }}//call-member subscriptionsSubscribeMsg::SubscribeMsg(const SipCallLeg& callLeg, Sptr <BaseUrl> reqUrl) : SipCommand(){ //set call-id, from, and to setCallId(callLeg.getCallId()); setTo(callLeg.getTo()); setFrom(callLeg.getFrom()); //set the other headers of SUBSCRIBE message Sptr <BaseUrl> fromUrl = callLeg.getFrom().getUrl(); setSubscribeDetails(fromUrl, duplicateUrl(reqUrl));}//third-party subscriptionsSubscribeMsg::SubscribeMsg(const SipCallId& callId, const SipTo& to, int port) : SipCommand(){ //set the call-id and to setCallId(callId); setTo(to); //set from SipFrom from; Data user = theSystem.getUserName(); from.setUser(user); Data dispName = theSystem.getDisplayName(); from.setDisplayName(dispName); Data listenPort(port); from.setHost( Data(theSystem.gethostAddress()) ); from.setPort(listenPort); setFrom(from); //set the other headers of SUBSCRIBE message Sptr <BaseUrl> toUrl = to.getUrl(); Sptr <BaseUrl> fromUrl = from.getUrl(); setSubscribeDetails(fromUrl, toUrl);} //copy constructorSubscribeMsg::SubscribeMsg(const SubscribeMsg& src) : SipCommand(src){}SubscribeMsg::SubscribeMsg( const SubscribeMsg& msg, enum SubscribeMsgForward ){ *this = msg; Sptr <BaseUrl> dest = getTo().getUrl(); if ( getNumRoute() ) { int numRoute = getNumRoute(); if (numRoute != 0 ) { dest = getRoute(0).getUrl(); //remove that route. removeRoute(0); } } SipRequestLine reqLine = getRequestLine(); reqLine.setUrl( dest ); setRequestLine( reqLine );}SubscribeMsg::~SubscribeMsg(){}SubscribeMsg& SubscribeMsg::operator=(const SubscribeMsg& src){ if (&src != this) { SipCommand::operator=(src); } return (*this);} bool SubscribeMsg::operator ==(const SubscribeMsg& src) { return ( *static_cast < SipCommand* > (this) == src); }Method SubscribeMsg::getType() const{ return SIP_SUBSCRIBE;}void SubscribeMsg::setSubscribeDetails(Sptr <BaseUrl> fromUrl, Sptr <BaseUrl> toUrl){ //set the CSeq SipCSeq cseq(SIP_SUBSCRIBE, Data(1)); setCSeq(cseq); //set the Via SipVia sipVia; sipVia.setprotoVersion("2.0"); if (fromUrl.getPtr() != 0) { if (fromUrl->getType() == SIP_URL) { Sptr <SipUrl> sipUrl; sipVia.setHost((sipUrl.dynamicCast(fromUrl))->getHost()); sipVia.setPort((sipUrl.dynamicCast(fromUrl))->getPort().convertInt()); } } setVia(sipVia); //add default Expires SipExpires sipexpires; sipexpires.setDelta(Data("3600")); setExpires(sipexpires); //set the request line SipRequestLine requestLine(SIP_SUBSCRIBE, toUrl); setRequestLine(requestLine);}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -