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

📄 subscribemanager.cxx

📁 Vovida 社区开源的 SIP 协议源码
💻 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 version =    "$Id: SubscribeManager.cxx,v 1.12 2002/11/12 20:25:13 veer Exp $";#include "global.h"#include <cassert>#include <SipVia.hxx>#include "SubscribeManager.hxx"#include "UaConfiguration.hxx"#include "VCondition.h"using namespace Vocal;///SubscribeManager::SubscribeManager( Sptr < SipTransceiver > sipstack ){    cpLog(LOG_DEBUG, "Starting Subscribe Mananger");    UaConfiguration* config = UaConfiguration::instance();    // First Subscribe message    SipCallId callId;    Sptr < SipUrl > toUrl;    try    {        toUrl = new SipUrl( Data("sip:") + Data( config->getSubscribeTo() ) );    }    catch ( SipUrlParserException& )    {        cpLog( LOG_ERR, "Invalid url %s", config->getSubscribeTo().c_str() );        cpLog( LOG_ERR, "need to handle this case" );    }    SipTo to( toUrl );    to.setUser( config->getUserName() );    subscribeMsg = new SubscribeMsg( callId, to, atoi( config->getLocalSipPort().c_str() ) );    SipExpires sipExpires;    sipExpires.setDelta( Data(config->getSubscribeExpire() ));    subscribeMsg->setExpires( sipExpires );    delay = 1000 * config->getSubscribeExpire();    // add event header    SipSubsNotifyEvent notifyEvent;    notifyEvent.setEventType( EVENT_MWI );    subscribeMsg->setSubsNotifyEvent( notifyEvent );    //allocation a fifo for the subscribe messages    myQ = new Fifo < Sptr < SubscribeMsg > > ;    //add the first message to the Q    Sptr < SubscribeMsg > msg = new SubscribeMsg(*subscribeMsg);    msgId = myQ->addDelayMs( msg, 0 );    // set sipstack    sipStack = sipstack;}///SubscribeManager::~SubscribeManager(){}///voidSubscribeManager::subscribeMain(){    cpLog( LOG_DEBUG, "SubscribeManager::subscribeMain" );    cpLog(LOG_DEBUG, "SubscribeManager::subscribeMain: getting next subscribe message");    Sptr < SubscribeMsg > subMsg = myQ->getNext();    if ( subMsg == 0 )    {        //sleep for a second        vusleep( 1000000 );        return ;    }    subscribeMutex.lock();    if ( 0 != sipStack )    {        cpLog(LOG_DEBUG, "sending subscribe message");        sipStack->sendAsync( *subMsg );    }    //add another subscribe message to Q in case response never comes    SipCSeq cseq = subscribeMsg->getCSeq();    cseq.incrCSeq();    subscribeMsg->setCSeq( cseq );    Sptr < SubscribeMsg > msg = new SubscribeMsg(*subscribeMsg);    msgId = myQ->addDelayMs(msg, delay);    subscribeMutex.unlock();}///boolSubscribeManager::handleSubscribeResponse(const StatusMsg& statusMsg){    bool ret = true;    // check if response corresponds to the original subscribe message    if ( subscribeMsg->computeCallLeg() == statusMsg.computeCallLeg() )    {         subscribeMutex.lock();	 cpLog(LOG_DEBUG, "SubscribeManager::handling response to a subscribe message");	 myQ->cancel( msgId );	 cpLog(LOG_DEBUG, "SubscribeManager::updating subscribe information");	 updateSubscribeMsg(statusMsg);	 int expire;	 if ( statusMsg.getStatusLine().getStatusCode() > 200 )	 {	     cpLog( LOG_ERR, "Subscribe failed" );	     cpLog( LOG_ERR, "Subscribe will be tried again in 60 seconds" );	     expire = 60;	     ret = false;	 }	 else	 {	     expire = delay;	 }	 cpLog(LOG_DEBUG, "The new delay is %d", expire);	 msgId = myQ->addDelayMs(subscribeMsg, delay);	 subscribeMutex.unlock();          } else    {        cpLog( LOG_ERR, "the subscribe message response is for an unkown person.  Ignored" );        return ret = false;    }    return ret;}///voidSubscribeManager::updateSubscribeMsg( const StatusMsg& statusMsg ){    // for now, just update expire if status is 200    // to be done    //add another subscribe message to Q in case response never comes    SipCSeq cseq = subscribeMsg->getCSeq();    cseq.incrCSeq();    subscribeMsg->setCSeq( cseq );}///boolSubscribeManager::handleNotify( const NotifyMsg& msg ){    if ( subscribeMsg == 0 )    {        cpLog( LOG_ERR, "No existing subscribe message" );        return false;    }    if ( subscribeMsg->computeCallLeg() == msg.computeCallLeg() )    {	NotifyMsg notMsg = msg;	StatusMsg status( notMsg, 200 /*OK*/ );	sipStack->sendReply( status );		SipSubsNotifyEvent notifyEvent = msg.getSubsNotifyEvent();	if ( notifyEvent.getEventType() != EVENT_MWI )	  {	    cpLog( LOG_ERR, "This notify is not for message waiting" );	    return 0;	  }		// for now, just print something	cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;	cout << "You have new Voice Mail messages !!! " << endl;	cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;	return true;	    } else    {        cpLog( LOG_ERR, "Notify does not match subscribe" );        return false;    }}

⌨️ 快捷键说明

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