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

📄 opinviteurl.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 OpInviteUrl_cxx_Version =    "$Id: OpInviteUrl.cxx,v 1.50 2002/11/19 20:32:52 sprajpat Exp $";#include "global.h"#include "InviteMsg.hxx"#include "OpInviteUrl.hxx"#include "UaDigitTimerEvent.hxx"#include "DigitCollector.hxx"#include "UaDevice.hxx"#include "UaConfiguration.hxx"#include "UaCallInfo.hxx"#include "UaStateMachine.hxx"#include "SdpHandler.hxx"#include "SystemInfo.hxx"#include "SipSdp.hxx"#include "SipVia.hxx"using namespace Vocal;OpInviteUrl::OpInviteUrl(){}OpInviteUrl::~OpInviteUrl(){}const char* constOpInviteUrl::name() const{    return "OpInviteUrl";}const Sptr < State >OpInviteUrl::process( const Sptr < SipProxyEvent > event ){    cpLog( LOG_DEBUG, "OpInviteUrl operation" );    Sptr < UaDigitTimerEvent > timerEvent;    timerEvent.dynamicCast( event );    if ( timerEvent == 0 )    {        return 0;    }    Sptr < DigitCollector > digitCollector =	UaDevice::instance()->getDigitCollector();    assert( digitCollector != 0 );    if ( !( digitCollector->isValidDial() ) )    {        return 0;    }    cpLog( LOG_DEBUG, "Dialing complete" );    cout << endl;    cpLog( LOG_DEBUG, "Request url %s", digitCollector->getUrl().c_str() );    Sptr< SipUrl > toUrl;    try    {        toUrl = new SipUrl( digitCollector->getUrl() );        if ( dial_phone == digitCollector->getDialMethod() )	{ 	    cpLog(LOG_DEBUG_STACK, "setting phone # %s", 		  toUrl->getUserValue().logData());            toUrl->setUserValue( toUrl->getUserValue(), dial_phone );	}    }    catch ( SipUrlParserException& )    {        cpLog( LOG_ERR, "Invalid url %s", digitCollector->getUrl().c_str() );        return 0;    }    assert( toUrl != 0 );    string proxyServer = UaConfiguration::instance()->getProxyServer();    cpLog(LOG_DEBUG, "proxyServer is %s", proxyServer.c_str() );    if ( toUrl->getHost().length() <= 0 && proxyServer.length() )    {        NetworkAddress na( proxyServer );        toUrl->setHost( na.getIpName() );        if( na.getPort() > 0 )        {            toUrl->setPort( Data( na.getPort() ));        }    }    //TODO clean up    Sptr< SipUrl > proxyUrl;    try    {        proxyUrl = new SipUrl( "sip:" + proxyServer );    }    catch ( SipUrlParserException& )    {        cpLog( LOG_ERR, "Invalid url %s", proxyServer.c_str() );        return 0;    }    string sipPort = UaConfiguration::instance()->getLocalSipPort();    InviteMsg msg( toUrl, atoi( sipPort.c_str() ) );    msg.setCallId( *(UaDevice::instance()->getCallId()) );    if ( proxyServer.length() > 0 )    {        SipRequestLine reqLine = msg.getRequestLine();        Sptr< BaseUrl > baseUrl = reqLine.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 > reqUrl;	reqUrl.dynamicCast( baseUrl );	assert( reqUrl != 0 );        reqUrl->setHost( proxyUrl->getHost() );        reqUrl->setPort( proxyUrl->getPort() );        if(UaConfiguration::instance()->getSipTransport() == "TCP")        {            reqUrl->setTransportParam( Data("tcp"));        }        reqLine.setUrl( reqUrl );        msg.setRequestLine( reqLine );    }    SipFrom from = msg.getFrom();    from.setDisplayName( Data( UaConfiguration::instance()->getDisplayName()));    Sptr< BaseUrl > baseUrl = from.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 > fromUrl;    fromUrl.dynamicCast( baseUrl );    assert( fromUrl != 0 );    fromUrl->setUserValue( Data( UaConfiguration::instance()->getUserName() ),			   "phone" );    from.setUrl( fromUrl );    msg.setFrom( from );    // Set transport in Via:    SipVia via = msg.getVia();    msg.removeVia();    via.setTransport( UaConfiguration::instance()->getSipTransport() );    msg.setVia( via );    // Set Contact: header    Sptr< SipUrl > myUrl = new SipUrl;    myUrl->setUserValue( UaConfiguration::instance()->getUserName(), "phone" );    myUrl->setHost( Data( theSystem.gethostAddress() ) );    myUrl->setPort( UaConfiguration::instance()->getLocalSipPort() );    if(UaConfiguration::instance()->getSipTransport() == "TCP")    {        myUrl->setTransportParam( Data("tcp"));    }    SipContact me;    me.setUrl( myUrl );    msg.setNumContact( 0 );    // Clear    msg.setContact( me );    Sptr < UaCallInfo > call;    call.dynamicCast( event->getCallInfo() );    assert( call != 0 );    addSdpToMsg(msg, 		Data(UaConfiguration::instance()->getNetworkRtpRate()),		UaDevice::instance()->getRtpPort());    Sptr<SipSdp> sipSdp;    sipSdp.dynamicCast ( msg.getContentData( 0 ) );    if ( sipSdp != 0 )    {	call->setLocalSdp( new SipSdp( *sipSdp ) );	int tmp;	cpLog( LOG_DEBUG, "Local SDP:\n%s", 	       call->getLocalSdp()->encodeBody(tmp).logData() );    }    // Save INVITE.  Needs to encode() to make sure length is correct    call->setRingInvite( new InviteMsg( msg ) );    // Send INVITE    timerEvent->getSipStack()->sendAsync( msg );    call->setContactMsg(msg);    Sptr < UaStateMachine > stateMachine;    stateMachine.dynamicCast( event->getCallInfo()->getFeature() );    assert( stateMachine != 0 );    cout << endl         << VTime::strftime("%y/%m/%d %H:%M:%S")         << " *** Calling " /*<< toUrl->encode().logData()*/ << endl << endl;    return stateMachine->findState( "StateTrying" );}/* 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 + -