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

📄 registrationagent.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 RegistrationAgent_cxx_Version =    "$Id: RegistrationAgent.cxx,v 1.4.2.1 2003/03/13 01:10:12 sprajpat Exp $";#include "RegistrationAgent.hxx"#include "SipWwwAuthenticate.hxx"#include "SipProxyAuthenticate.hxx"#include "SipContact.hxx"#include "B2bConfig.hxx"#include "SipVia.hxx"using namespace Vocal;RegistrationAgent* RegistrationAgent::myInstance = 0;RegistrationAgent::RegistrationAgent(Sptr<SipTransceiver> transceiver,                                      Data host, int port)   : myTransceiver(transceiver),     myHost(host),     myPort(port){}RegistrationAgent::~RegistrationAgent(){    myShutdownFlag = true;    SipCallLeg cLeg;    }#if 0void*RegistrationAgent::cleanupThread(void* args){    RegistrationAgent* self = static_cast<RegistrationAgent*>(args);    while(1)    {        SipCallLeg cLeg = self->myFriedFifo.getNext();        if(self->myShutdownFlag) break;        self->remove(cLeg);    }}#endifRegistrationAgent& RegistrationAgent::instance(){    assert(myInstance != 0);    return *myInstance;} RegistrationAgent& RegistrationAgent::instance(Sptr<SipTransceiver> transceiver,                             Data host, int port){    assert(myInstance == 0);    if(myInstance == 0)    {        myInstance = new RegistrationAgent(transceiver, host, port);    }    return *myInstance;} void RegistrationAgent::processRegister(Sptr<RegisterMsg> src ){    SipCallLeg cLeg =src->computeCallLeg();    {        Lock lock(myMutex);        if(!myPendingRegistration.count(cLeg))        {            cpLog(LOG_DEBUG, "Adding registration for (%s)", cLeg.encode().logData());            myPendingRegistration[cLeg] = src;            //First schedule it for collection after 32 seconds            //myFriedFifo.addDelayMS(cLeg, 32000);        }    }    //Check to see if Registration exists in the pending    //list, if so, we may want to filter it or pass it as is    //Modify the contact     // user@FQDN to user%FQDN@B2bUaAddress    Sptr<RegisterMsg> registerMsg = new RegisterMsg(*src);    Data registerOn = B2bConfig::instance().getStr(B2bConfig::SIP_REG_REGISTER).c_str();    registerOn.uppercase();    string regAddr = B2bConfig::instance().getStr(B2bConfig::SIP_REG_ADDR);    int regPort = B2bConfig::instance().getInt(B2bConfig::SIP_REG_PORT);    int numContact = src->getNumContact();    if(numContact && (registerOn == "YES"))    {        registerMsg->setNumContact(0);        //Modify the contacts        SipContactList cList = src->getContactList();        for(SipContactList::iterator itr = cList.begin();                    itr != cList.end(); itr++)        {            SipContact newContact = *(*itr);            Sptr<SipUrl> sUrl;            sUrl.dynamicCast(newContact.getUrl());            if(sUrl != 0)            {                Data modUserHost(sUrl->getUserValue());                if(modUserHost.length() == 0)                {                    //Get the To header user value                    modUserHost = src->getTo().getUser();                 }                modUserHost += "%";                modUserHost += sUrl->getHost();                if(sUrl->getPort().length())                {                    modUserHost += ":";                    modUserHost += sUrl->getPort();                }                //Add b2b Host and port                sUrl->setUserValue(modUserHost);                sUrl->setHost(myHost);                sUrl->setPort( Data(myPort) );                newContact.setUrl(sUrl);                registerMsg->setContact(newContact);             }        }    }    //Modify the Via    string useTransport = B2bConfig::instance().getStr(B2bConfig::SIP_LOCAL_TRANSPORT);    registerMsg->setNumVia(0);    SipVia via;    via.setHost(myHost);    via.setPort(myPort);    via.setTransport(useTransport);    registerMsg->setVia(via);    SipRequestLine& rLine = registerMsg->getMutableRequestLine();        rLine.setHost(regAddr);    rLine.setPort( Data(regPort) );    rLine.setTransportParam(useTransport);    //Send it to the Registrar    cpLog(LOG_DEBUG, "Sending registration \n%s", registerMsg->encode().logData());    myTransceiver->sendAsync(registerMsg);} void RegistrationAgent::processResponse(Sptr<StatusMsg> sipStatus){    Lock lock(myMutex);    if(sipStatus->getCSeq().getMethod() != REGISTER_METHOD)    {        return;    }        //Check to see if status is for a pending registation,    //if so construct the response again from the pending    //Register and set the vias approvpriately    int statusCode = sipStatus->getStatusLine().getStatusCode();    SipCallLeg cLeg = sipStatus->computeCallLeg();    if(myPendingRegistration.count(cLeg) == 0)    {        cpLog(LOG_ERR, "Spurious response for Register message, dropping..");        return;    }    //Retrieve the save Register message    Sptr<RegisterMsg> savedMsg = myPendingRegistration[cLeg];    //Sand back the response    Sptr<StatusMsg> replyMsg = new StatusMsg(*savedMsg, statusCode);    if(statusCode >= 200)    {        //copy back the Authorization or Proxy-Authorization header        if(statusCode == 401)        {            SipWwwAuthenticate wwwAuth = sipStatus->getWwwAuthenticate();            replyMsg->setWwwAuthenticate(wwwAuth);                    }        else if(statusCode == 407)        {            SipProxyAuthenticate proxyAuth = sipStatus->getProxyAuthenticate();             replyMsg->setProxyAuthenticate(proxyAuth);        }        else if(statusCode == 200)        {            int numContact = savedMsg->getNumContact();            if(numContact)            {                replyMsg->setNumContact(0);                SipContactList cList = savedMsg->getContactList();                for(SipContactList::iterator itr = cList.begin();                            itr != cList.end(); itr++)                {                    Sptr<SipContact> newContact = (*itr);                    replyMsg->setContact(*newContact);                }            }            //get the expire field from the response            const SipExpires& sipexp = sipStatus->getExpires();            if(sipexp.getDelta().length())            {                replyMsg->setExpires(sipexp);            }        }        remove(cLeg);    }    cpLog(LOG_DEBUG, "Saved registration message \n%s", savedMsg->encode().logData());    cpLog(LOG_DEBUG, "Sending registration response \n%s", replyMsg->encode().logData());    myTransceiver->sendReply(replyMsg);}voidRegistrationAgent::remove(SipCallLeg& cLeg){    PendingRegistration::iterator itr = myPendingRegistration.find(cLeg);    if(itr != myPendingRegistration.end())    {        cpLog(LOG_DEBUG,  "Removing id:%s ",cLeg.encode().logData());        myPendingRegistration.erase(itr);    }} 

⌨️ 快捷键说明

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