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

📄 registrationmanager.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 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 RegistrationManager_cxx_Version =    "$Id: RegistrationManager.cxx,v 1.27 2002/11/12 20:25:13 veer Exp $";#include "SipVia.hxx"#include "SystemInfo.hxx"#include "RegistrationManager.hxx"#include "UaConfiguration.hxx"using namespace Vocal;///RegistrationManager::RegistrationManager( Sptr < SipTransceiver > sipstack ){    sipStack = sipstack;    cpLog(LOG_DEBUG, "Starting Registration Mananger");    //start the registration thread    registrationThread.spawn(registrationThreadWrapper, this);    cpLog( LOG_DEBUG, "Spawning the registration thread");    UaConfiguration* config = UaConfiguration::instance();    NetworkAddress rs( config->getRegisterTo() );    // The first REGISTER message    RegisterMsg registerMsg;    // Set Request line    SipRequestLine reqLine = registerMsg.getRequestLine();    Data reqUrlString = Data( string("sip:") + config->getRegisterTo() );    if(config->getSipTransport() == "TCP")    {        reqUrlString += ";transport=tcp;";    }    Sptr< SipUrl > reqUrl = new SipUrl( reqUrlString );    assert( reqUrl != 0 );    reqLine.setUrl( reqUrl );    registerMsg.setRequestLine( reqLine );    // Set From header    const Data regFromUrlStr = Data(string("sip:") + config->getRegisterFrom());    SipUrl regFromUrl( regFromUrlStr );    SipFrom sipfrom = registerMsg.getFrom();    sipfrom.setDisplayName( config->getDisplayName() );    sipfrom.setUser( config->getUserName() );    sipfrom.setHost( regFromUrl.getHost() );    sipfrom.setPort( regFromUrl.getPort() );    registerMsg.setFrom( sipfrom );    // Set To header    const Data regToUrlStr = Data( string("sip:") + config->getRegisterTo());    SipUrl regToUrl( regToUrlStr );    SipTo sipto = registerMsg.getTo();    sipto.setDisplayName( config->getDisplayName() );    sipto.setUser( config->getUserName() );    sipto.setHost( regToUrl.getHost() );    sipto.setPortData( regToUrl.getPort() );    registerMsg.setTo( sipto );    // Set Via header    SipVia sipvia = registerMsg.getVia();    sipvia.setPort( Data( config->getLocalSipPort() ).convertInt() );    sipvia.setTransport(  Data(config->getSipTransport()) );    registerMsg.removeVia();    registerMsg.setVia( sipvia );    // Set Contact header    Sptr< SipUrl > contactUrl = new SipUrl;    contactUrl->setUserValue( config->getUserName(), "phone" );    contactUrl->setHost( Data( theSystem.gethostAddress() ) );    contactUrl->setPort( config->getLocalSipPort() );    if(config->getSipTransport() == "TCP")    {        contactUrl->setTransportParam( Data("tcp") );    }    SipContact myContact;    myContact.setUrl( contactUrl );    //myContact.setAction( config->getRegisterAction() );    registerMsg.setNumContact( 0 );    registerMsg.setContact(myContact);    // Set Expires header    SipExpires sipExpires;    sipExpires.setDelta( Data(config->getRegisterExpires() ));    registerMsg.setExpires( sipExpires );    Registration registration( registerMsg );    addRegistration( registration );    startRegistration();}///RegistrationManager::~RegistrationManager(){    registrationThread.join();    flushRegistrationList();}///void*RegistrationManager::registrationThreadWrapper(void *regSession){    assert( regSession );    RegistrationManager* regManager = static_cast < RegistrationManager* > (regSession);    regManager->registrationMain();    return 0;}///voidRegistrationManager::registrationMain(){    cpLog(LOG_DEBUG, "RegistrationManager::registrationMain: starting registrationMain");    while (1)    {        cpLog(LOG_DEBUG, "RegistrationManager::registrationMain: getting next registration event");        Registration* registration = registrationFifo.getNext();        if ( 0 == registration )            continue;        registrationMutex.lock();        RegisterMsg registerMsg = registration->getNextRegistrationMsg();        if ( 0 != sipStack )        {            cpLog(LOG_DEBUG, "sending register message");            sipStack->sendAsync( registerMsg );        }        FifoEventIdMap::iterator pos;        pos = fifoEventIdMap.find(registration);        if ( fifoEventIdMap.end() != pos )            fifoEventIdMap.erase(pos);        pos = fifoEventIdMap.find(registration);        //only do this if there is no another registration message in the queue        if ( fifoEventIdMap.end() == pos )        {            //add another to the fifo in the event that response never came            int delay = registration->getDelay();            FifoEventId eventId = registrationFifo.addDelayMs(registration, delay);            fifoEventIdMap[registration] = eventId;        }        registrationMutex.unlock();    }}///Registration*RegistrationManager::findRegistration(const StatusMsg& statusMsg){    Registration* registration = 0;    RegistrationList::iterator iter = registrationList.begin();    while ( iter != registrationList.end() )    {        RegisterMsg regMsg = (*iter)->getRegistrationMsg();        if ( regMsg.computeCallLeg() == statusMsg.computeCallLeg() )        {            registration = (*iter);            break;        }        iter++;    }    return registration;}///voidRegistrationManager::addRegistration(const Registration& item){    Registration* registration = new Registration(item);    if ( 0 != registration )        registrationList.push_back(registration);}///voidRegistrationManager::flushRegistrationList(){    RegistrationList::iterator iter = registrationList.begin();    while ( iter != registrationList.end() )    {        if ( *iter )            delete (*iter);        iter++;    }    registrationList.clear();}///boolRegistrationManager::handleRegistrationResponse(const StatusMsg& statusMsg){    Registration* registration = findRegistration(statusMsg);    if ( !registration )        return false;    registrationMutex.lock();    bool ret = true;    cpLog(LOG_DEBUG, "RegistrationManager::handling response to a register message");    FifoEventIdMap::iterator pos;    pos = fifoEventIdMap.find(registration);    if ( fifoEventIdMap.end() != pos )    {        FifoEventId eventId = fifoEventIdMap[registration];        registrationFifo.cancel(eventId);        fifoEventIdMap.erase(pos);    }    cpLog(LOG_DEBUG, "RegistrationManager::updating registration information");    int delay = registration->updateRegistrationMsg(statusMsg);    if( registration->getStatusCode() == 100 )    {	const int DEFAULT_DELAY = 60000;   // 60 sec.	delay = DEFAULT_DELAY;    }    if ( registration->getStatusCode() > 200 )    {        ret = false;    }    cpLog(LOG_DEBUG, "The new delay is %d", delay);    FifoEventId eventId = registrationFifo.addDelayMs(registration, delay);    fifoEventIdMap[registration] = eventId;    registrationMutex.unlock();    return ret;}///voidRegistrationManager::startRegistration(){    RegistrationList::iterator iter = registrationList.begin();    while ( iter != registrationList.end() )    {        FifoEventId eventId = registrationFifo.addDelayMs((*iter), 0);        fifoEventIdMap.erase((*iter));        fifoEventIdMap[(*iter)] = eventId;        iter++;    }}

⌨️ 快捷键说明

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