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

📄 opbeingxferred.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 OpBeingXferred_cxx_Version =    "$Id: OpBeingXferred.cxx,v 1.30 2002/11/12 20:25:13 veer Exp $";#include "global.h"#include "SipEvent.hxx"#include "TransferMsg.hxx"#include "OpBeingXferred.hxx"#include "UaCallInfo.hxx"#include "UaConfiguration.hxx"#include "UaDevice.hxx"#include "Sdp2Session.hxx"#include "Sdp2Connection.hxx"#include "Sdp2Media.hxx"#include "SipTransferTo.hxx"#include "SipVia.hxx"using namespace Vocal;using Vocal::SDP::SdpSession;using Vocal::SDP::SdpConnection;using Vocal::SDP::SdpMedia;using Vocal::SDP::MediaAttributes;using Vocal::SDP::ValueAttribute;using Vocal::SDP::SdpRtpMapAttribute;OpBeingXferred::OpBeingXferred(){}OpBeingXferred::~OpBeingXferred(){}const char* constOpBeingXferred::name() const{    return "OpBeingXferred";}const Sptr < State >OpBeingXferred::process( const Sptr < SipProxyEvent > event ){    cpLog( LOG_DEBUG, "OpBeingXferred operation" );    Sptr < SipEvent > sipEvent;    sipEvent.dynamicCast( event );    assert( event != 0 );    Sptr < SipMsg > sipMsg = sipEvent->getSipMsg();    assert( sipMsg != 0 );    Sptr < TransferMsg > msg;    msg.dynamicCast( sipMsg );    assert( msg != 0 );    Sptr < UaCallInfo > call;    call.dynamicCast( event->getCallInfo() );    assert( call != 0 );    //save the transfer msg;    call->setXferMsg(msg);    //get to person to be tranferred to    SipTransferTo xferTo = msg->getTransferTo();    //form an invite to that person    string sipPort = UaConfiguration::instance()->getLocalSipPort();    Sptr< BaseUrl > baseUrl = xferTo.getUrl();    assert( baseUrl != 0 );    if( baseUrl->getType() == TEL_URL )    {	cpLog( LOG_ERR, "TEL_URL currently not supported\n" );	assert( 0 );    }    // Assume we have a SIP_URL    Sptr< SipUrl > xferUrl;    xferUrl.dynamicCast( baseUrl );    assert( xferUrl != 0 );    InviteMsg inviteMsg( xferUrl, atoi( sipPort.c_str() ) );    SipCallId callId;    callId = call->getContact()->getInviteMsg().getCallId();    inviteMsg.setCallId( callId );    SipTo to = inviteMsg.getTo();    baseUrl = to.getUrl();    assert( baseUrl != 0 );    if( baseUrl->getType() == TEL_URL )    {	cpLog( LOG_ERR, "TEL_URL currently not supported\n" );	assert( 0 );    }    // Assume we have a SIP_URL    Sptr< SipUrl > toUrl;    toUrl.dynamicCast( baseUrl );    assert( toUrl != 0 );    to.setDisplayName( xferTo.getDisplayName() );    inviteMsg.setTo( to );    //force invite to go through proxy server if a proxy exists    string proxyUrlStr = UaConfiguration::instance()->getProxyServer();    if ( proxyUrlStr.length() > 0 )    {        Data urlStr = Data( string("sip:") + proxyUrlStr );        Sptr< SipUrl > proxyUrl = new SipUrl( urlStr );        SipRequestLine msRequestLine = inviteMsg.getRequestLine();	baseUrl = msRequestLine.getUrl();	assert( baseUrl != 0 );	// Assume we have a SIP_URL	Sptr< SipUrl > msUrl;	msUrl.dynamicCast( baseUrl );	assert( msUrl != 0 );        msUrl->setHost( proxyUrl->getHost() );        msUrl->setPort( proxyUrl->getPort() );        msRequestLine.setUrl( msUrl );        inviteMsg.setRequestLine( msRequestLine );        toUrl->setHost( proxyUrl->getHost() );        toUrl->setPort( proxyUrl->getPort() );    }    SipFrom from = inviteMsg.getFrom();    from.setUser( Data( UaConfiguration::instance()->getUserName() ) );    from.setDisplayName( Data( UaConfiguration::instance()->getDisplayName() ) );    inviteMsg.setFrom( from );    // Set transport in Via:    SipVia via = inviteMsg.getVia();    inviteMsg.removeVia();    via.setTransport( UaConfiguration::instance()->getSipTransport() );    inviteMsg.setVia( via );    // Set Contact: header    Sptr< SipUrl > myUrl = new SipUrl;//    myUrl.setPhoneNumber( UaConfiguration::instance()->getUserName() );    myUrl->setUserValue( UaConfiguration::instance()->getUserName(), "phone" );    myUrl->setHost( Data( theSystem.gethostAddress() ) );    myUrl->setPort( UaConfiguration::instance()->getLocalSipPort() );    SipContact me;    me.setUrl( myUrl );    inviteMsg.setNumContact( 0 );    // Clear    inviteMsg.setContact( me );    Sptr<SipSdp> sipSdp;    sipSdp.dynamicCast ( inviteMsg.getContentData( 0 ) );    if ( sipSdp != 0 )    {        SdpSession sdpDesc = sipSdp->getSdpDescriptor();        list < SdpMedia* > mediaList;        mediaList = sdpDesc.getMediaList();        list < SdpMedia* > ::iterator mediaIterator = mediaList.begin();        MediaAttributes* mediaAttrib;        mediaAttrib = (*mediaIterator)->getMediaAttributes();        if ( mediaAttrib == 0 )        {            mediaAttrib = new MediaAttributes();            assert( mediaAttrib );            (*mediaIterator)->setMediaAttributes( mediaAttrib );        }        ValueAttribute* attrib = new ValueAttribute();        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 );        sipSdp->setSdpDescriptor( sdpDesc );        //sipSdp->setRtpPort( atoi (UaConfiguration::instance()->getLocalRtpPort().c_str() )  );        sipSdp->setRtpPort( UaDevice::instance()->getRtpPort() );        call->setLocalSdp( new SipSdp( *sipSdp ) );	int tmp;        cpLog( LOG_DEBUG, "Local SDP:\n%s", call->getLocalSdp()->encodeBody(tmp).logData() );    }    // Save INVITE    call->setRingInvite( new InviteMsg( inviteMsg ) );    // Send INVITE    sipEvent->getSipStack()->sendAsync( inviteMsg );    Sptr < Contact > contact = new Contact( inviteMsg );    // Set as current contact    call->setContact( contact );    // Add to contact list    call->addContact( contact );    return 0;}/* 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 + -