📄 opincallinvite.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 OpInCallInvite_cxx_Version = "$Id: OpInCallInvite.cxx,v 1.34 2002/11/12 20:25:13 veer Exp $";#include "global.h"#include "InviteMsg.hxx"#include "OpInCallInvite.hxx"#include "StateInCallTrying.hxx"#include "UaDigitTimerEvent.hxx"#include "DigitCollector.hxx"#include "UaDevice.hxx"#include "UaConfiguration.hxx"#include "UaCallInfo.hxx"#include "UaStateMachine.hxx"#include "Sdp2Session.hxx"#include "SipSdp.hxx"#include "SystemInfo.hxx"#include "Sdp2Media.hxx"#include "SipVia.hxx"using namespace Vocal;using Vocal::SDP::SdpSession;using Vocal::SDP::SdpMedia;using Vocal::SDP::MediaAttributes;using Vocal::SDP::ValueAttribute;using Vocal::SDP::SdpRtpMapAttribute;OpInCallInvite::OpInCallInvite(){}OpInCallInvite::~OpInCallInvite(){}const char* constOpInCallInvite::name() const{ return "OpInCallInvite";}const Sptr < State >OpInCallInvite::process( const Sptr < SipProxyEvent > event ){ cpLog( LOG_DEBUG, "OpInCallInvite 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; Sptr< SipUrl > toUrl = new SipUrl; try { Sptr< SipUrl > tmpUrl = new SipUrl( digitCollector->getUrl() ); string dialMethod = digitCollector->getDialMethod();// if ( dialMethod == "phone" )// toUrl.setPhoneNumber( tmpUrl.getUser() );// else// toUrl.setUser( tmpUrl.getUser() ); toUrl->setUserValue( tmpUrl->getUserValue(), "phone" ); toUrl->setHost( tmpUrl->getHost() ); toUrl->setPort( tmpUrl->getPort() ); } catch ( SipUrlParserException& ) { cpLog( LOG_ERR, "Invalid url %s", digitCollector->getUrl().c_str() ); return 0; } string proxyServer = UaConfiguration::instance()->getProxyServer(); Sptr < SipUrl > proxyUrl = new SipUrl; try { proxyUrl = new SipUrl( "sip:" + proxyServer ); } catch ( SipUrlParserException& ) { cpLog( LOG_ERR, "Invalid url %s", proxyServer.c_str() ); return 0; } if ( toUrl->getHost().length() <= 0 ) { toUrl->setHost( proxyUrl->getHost() ); toUrl->setPort( proxyUrl->getPort() ); } string sipPort = UaConfiguration::instance()->getLocalSipPort(); Sptr < UaCallInfo > call; call.dynamicCast( event->getCallInfo() ); assert( call != 0 ); //invite message InviteMsg msg( toUrl, atoi( sipPort.c_str() ) ); Sptr < Contact > contact = call->getContact(); assert( contact != 0 ); // get the original invite message const InviteMsg& oldMsg = contact->getInviteMsg(); if ( &oldMsg == 0 ) { cpLog( LOG_DEBUG, "No previous invite message"); return 0; } //use the same call ID msg.setCallId( oldMsg.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() ); reqLine.setUrl( reqUrl ); msg.setRequestLine( reqLine ); } unsigned int cseq = contact->getCSeqNum(); contact->setCSeqNum( ++cseq ); SipCSeq sipCSeq = msg.getCSeq(); sipCSeq.setCSeq( cseq ); msg.setCSeq( sipCSeq ); SipFrom from = msg.getFrom(); from.setDisplayName( Data( UaConfiguration::instance()->getDisplayName())); Sptr< BaseUrl > baseUrl = from.getUrl(); assert( baseUrl != 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() ); SipContact me; me.setUrl( myUrl ); msg.setNumContact( 0 ); // Clear msg.setContact( me ); Sptr < UaStateMachine > stateMachine; stateMachine.dynamicCast( event->getCallInfo()->getFeature() ); assert( stateMachine != 0 ); // Compare both old & new invite msgs to make sure // we aren't calling the same person SipTo oldTo = oldMsg.getTo(); SipFrom oldFrom = oldMsg.getFrom(); SipTo to = msg.getTo(); if ( oldTo.getUrl() == to.getUrl() || oldFrom.getUrl() == to.getUrl() ) { return stateMachine->findState( "StateInCallFastBusy" ); } Sptr<SipSdp> sipSdp; sipSdp.dynamicCast ( msg.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( UaDevice::instance()->getRtpPort() ); call->setLocal2Sdp( new SipSdp( *sipSdp ) ); int tmp; cpLog( LOG_DEBUG, "Local SDP:\n%s", call->getLocalSdp() ->encodeBody(tmp).logData() ); } // Save the invite call->setRing2Invite( new InviteMsg( msg ) ); cpLog( LOG_DEBUG, "sending the following invite"); cpLog( LOG_DEBUG, "%s", msg.encode().logData() ); // Send INVITE timerEvent->getSipStack()->sendAsync( msg ); // Set the new contact Sptr < Contact > newContact = new Contact(msg); call->setContact( newContact ); // Add to contact list call->addContact( newContact ); return stateMachine->findState( "StateInCallTrying" );}/* 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 + -