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

📄 opanswercall.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 OpAnswerCall_cxx_version =    "$Id: OpAnswerCall.cxx,v 1.44 2002/11/12 20:25:13 veer Exp $";#include "global.h"#include "OpAnswerCall.hxx"#include "ResGwDevice.hxx"#include "UaDeviceEvent.hxx"#include "UaStateMachine.hxx"#include "UaCallInfo.hxx"#include "UaDevice.hxx"#include "UaConfiguration.hxx"#include "SdpHandler.hxx"#include "Sdp2Media.hxx"#include "SystemInfo.hxx"#include "SipSdp.hxx"using namespace Vocal;using Vocal::SDP::SdpSession;using Vocal::SDP::SdpMedia;using Vocal::SDP::MediaAttributes;using Vocal::SDP::ValueAttribute;using Vocal::SDP::SdpRtpMapAttribute;OpAnswerCall::OpAnswerCall(){}OpAnswerCall::~OpAnswerCall(){}const char* constOpAnswerCall::name() const{    return "OpAnswerCall";}const Sptr < State >OpAnswerCall::process( const Sptr < SipProxyEvent > event ){    cpLog( LOG_DEBUG, "OpAnswerCall operation" );    Sptr < UaDeviceEvent > deviceEvent;    deviceEvent.dynamicCast( event );    if ( deviceEvent == 0 )    {        return 0;    }    if ( deviceEvent->type != DeviceEventHookUp &&            deviceEvent->type != DeviceEventFlash )    {        return 0;    }    cpLog( LOG_DEBUG, "Answer Call" );    Sptr < UaCallInfo > call;    call.dynamicCast( event->getCallInfo() );    assert( call != 0 );    Sptr < InviteMsg > msg = call->getRingInvite();    assert( msg != 0 );    SipCallId callId = msg->getCallId();    if ( UaDevice::instance()->isMyHardware( callId ) == false )    {        Sptr < SipCallId > callWaitingId = UaDevice::instance()->getCallWaitingId();        if ( callWaitingId == 0 )        {            cpLog( LOG_ERR, "No call on call waiting ");            cpLog( LOG_ERR, "Ignore flash hook");            return 0;        }        if ( *callWaitingId != callId )        {            cpLog( LOG_ERR, "The call on call waiting is not this call ");            cpLog( LOG_ERR, "Ignore flash hook");            return 0;        }        if ( UaDevice::instance()->getHardwareStatus() ==                HARDWARE_UNAVAILABLE )        {            cpLog( LOG_ERR, "Hardware not available" );            cpLog( LOG_ERR, "Ignore flash hook");            return 0;        }        // grab the hardware        UaDevice::instance()->setCallId( callWaitingId );        UaDevice::instance()->removeCallWaitingId( *callWaitingId );    }    // Get remote SDP from message    Sptr<SipSdp> remoteSdp;    remoteSdp.dynamicCast ( msg->getContentData(0) );    if ( remoteSdp == 0 )    {        cpLog( LOG_DEBUG, "No remote SDP in INVITE" );   	cpLog( LOG_DEBUG, "msg: %s", msg->encode().logData() );    }    else    {        call->setRemoteSdp( new SipSdp( *remoteSdp ) );    }    StatusMsg status( *msg, 200/*OK*/ );    // Add myself to the contact    Sptr< SipUrl > myUrl = new SipUrl;    myUrl->setUserValue( UaConfiguration::instance()->getUserName() );    myUrl->setHost( Data( theSystem.gethostAddress() ) );    myUrl->setPort( UaConfiguration::instance()->getLocalSipPort() );    if(UaConfiguration::instance()->getSipTransport() == "TCP")    {        myUrl->setTransportParam( Data("tcp"));    }    SipContact me;    me.setUrl( myUrl );    status.setNumContact( 0 );    // Clear    status.setContact( me );    // Create local SDP base on remote SDP    Sptr<SipSdp> localSdp;    localSdp.dynamicCast ( status.getContentData(0) );    if ( localSdp != 0 )    {	cpLog(LOG_DEBUG, "localSdp != 0");	localSdp->setRtpPort( UaDevice::instance()->getRtpPort() );	// Set rtpPacketSize to default in ua.cfg file	int rtpPacketSize = UaConfiguration::instance()->getNetworkRtpRate();        SdpSession sdpDesc = localSdp->getSdpDescriptor();        list < SdpMedia* > mediaList;        mediaList = sdpDesc.getMediaList();        list < SdpMedia* > ::iterator mediaIterator = mediaList.begin();        vector < Data > * formatList = (*mediaIterator)->getStringFormatList();        if ( formatList != 0 )        {            formatList->clear();        }        //using the default codec        (*mediaIterator)->addFormat( 0 );        MediaAttributes* mediaAttrib;        mediaAttrib = (*mediaIterator)->getMediaAttributes();        if ( mediaAttrib != 0 )        {	    cpLog(LOG_DEBUG, "at least one mediaAttrib");            vector < ValueAttribute* > * valueAttribList = mediaAttrib->getValueAttributes();            vector < ValueAttribute* > ::iterator attribIterator = valueAttribList->begin();            while ( attribIterator != valueAttribList->end() )            {                char* attribName = (*attribIterator)->getAttribute();                if ( strcmp( attribName, "ptime" ) == 0 )                {                    rtpPacketSize = Data((*attribIterator)->getValue()).convertInt();                    break;                }                attribIterator++;            }            mediaAttrib->flushValueAttributes();            mediaAttrib->flushrtpmap();            ValueAttribute* attrib = new ValueAttribute();            attrib->setAttribute( "ptime" );            LocalScopeAllocator lo;            attrib->setValue( Data( rtpPacketSize ).getData(lo) );            //add the rtpmap attribute for the default codec            SdpRtpMapAttribute* rtpMapAttrib = new SdpRtpMapAttribute();            rtpMapAttrib->setPayloadType( 0 );            rtpMapAttrib->setEncodingName( "PCMU" );            rtpMapAttrib->setClockRate( 8000 );            mediaAttrib->addValueAttribute( attrib );            mediaAttrib->addmap( rtpMapAttrib );        }        else        {	    cpLog(LOG_DEBUG, "no mediaAttrib");            mediaAttrib = new MediaAttributes();            assert(mediaAttrib);            (*mediaIterator)->setMediaAttributes(mediaAttrib);            // create the new value attribute object            ValueAttribute* attrib = new ValueAttribute();            // set the attribute and its value            attrib->setAttribute("ptime");            LocalScopeAllocator lo;            attrib->setValue( Data( UaConfiguration::instance()->getNetworkRtpRate() ).getData(lo) );            //add the rtpmap attribute for the default codec            SdpRtpMapAttribute* rtpMapAttrib = new SdpRtpMapAttribute();            rtpMapAttrib->setPayloadType(0);            rtpMapAttrib->setEncodingName("PCMU");            rtpMapAttrib->setClockRate(8000);            // add the value attribute just created to the media attribute object            mediaAttrib->addValueAttribute(attrib);            mediaAttrib->addmap(rtpMapAttrib);        }        localSdp->setSdpDescriptor(sdpDesc);        call->setLocalSdp( new SipSdp( *localSdp ) );        deviceEvent->getSipStack()->sendReply( status );    }    else  // localSdp == 0    {	cpLog(LOG_DEBUG, "localSdp == 0");        // May not have SDP in original INVITE for 3rd party call control        SipSdp sdp;	Data hostAddr = theSystem.gethostAddress();        if(UaConfiguration::instance()->getNATAddress() != "")        {            hostAddr = UaConfiguration::instance()->getNATAddress();        }	int rtpPort = UaDevice::instance()->getRtpPort();        doAnswerStuff(sdp, remoteSdp, hostAddr, rtpPort);        status.setContentData( &sdp, 0 );        call->setLocalSdp( new SipSdp( sdp ) );        deviceEvent->getSipStack()->sendReply( status );    }    Sptr < UaStateMachine > stateMachine;    stateMachine.dynamicCast( event->getCallInfo()->getFeature() );    assert( stateMachine != 0 );    return stateMachine->findState( "StateInCall" );}/* 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 + -