📄 uastateincall.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 UaStateInCall_cxx_Version = "$Id: UaStateInCall.cxx,v 1.11.2.2 2003/03/13 22:55:04 sprajpat Exp $";#include "UaStateInCall.hxx"#include "UaStateFactory.hxx"#include "SystemInfo.hxx"#include "BasicAgent.hxx"#include "AckMsg.hxx"#include "SystemInfo.hxx"#include "CancelMsg.hxx"#include "UaBase.hxx"using namespace Vocal::UA;using namespace Vocal;void UaStateInCall::recvRequest(UaBase& agent, Sptr<SipMsg> msg) throw (CInvalidStateException&){ cpLog(LOG_DEBUG, "UaStateInCall::recvRequest"); Sptr<SipCommand> sipCmd; sipCmd.dynamicCast(msg); assert(sipCmd != 0); switch(msg->getType()) { case SIP_INFO: { cpLog(LOG_DEBUG, "UaStateInCall, processing SIP_INFO"); //Send 200 status msg agent.sendReplyForRequest(msg, 200); //Notify CC if(agent.getControllerAgent()) agent.getControllerAgent()->receivedRequest(agent, msg); } break; case SIP_BYE: { cpLog(LOG_DEBUG, "UaStateInCall, processing SIP_BYE"); //Send 200 agent.sendReplyForRequest(msg, 200); //Notify CC of the call end if(agent.getControllerAgent()) { agent.getControllerAgent()->endCall(); agent.getControllerAgent()->receivedRequest(agent, msg); } //Transit to Idle changeState(agent, UaStateFactory::instance().getState(U_STATE_IDLE)); } break; case SIP_ACK: { cpLog(LOG_DEBUG, "UaStateInCall, processing SIP_ACK"); //Save the Ack message for future BYE agent.setAck(msg); //Notify CC if(agent.getControllerAgent()) agent.getControllerAgent()->receivedRequest(agent, msg); } break; case SIP_INVITE: { cpLog(LOG_DEBUG, "UaStateInCall, processing SIP_INVITE"); //Send 100 status msg agent.sendReplyForRequest(msg, 100); agent.setRequest(msg); //Notify CC if(agent.getControllerAgent()) agent.getControllerAgent()->hold(agent, msg); changeState(agent, UaStateFactory::instance().getState(U_STATE_HOLD)); } break; case SIP_CANCEL: { cpLog(LOG_WARNING, "UaStateInCall, processing SIP_CANCEL, this is incorrect"); //Send 200 agent.sendReplyForRequest(msg, 200); agent.sendReplyForRequest(msg, 487); //Notify CC of the call end if(agent.getControllerAgent()) { //Notify CC agent.getControllerAgent()->receivedRequest(agent, msg); agent.getControllerAgent()->endCall(); } //Transit to Idle changeState(agent, UaStateFactory::instance().getState(U_STATE_FAILURE)); } case SIP_OPTIONS: { cpLog(LOG_DEBUG, "UaStateInCall, processing SIP_INFO"); //Send 200 status msg agent.sendReplyForRequest(msg, 200); //Notify CC if(agent.getControllerAgent()) agent.getControllerAgent()->receivedRequest(agent, msg); } break; break; default: cpLog(LOG_WARNING, "Do not know what to do with message type %d:" , msg->getType()); break; }}void UaStateInCall::sendRequest(UaBase& agent, Sptr<SipMsg> msg) throw (CInvalidStateException&){ cpLog(LOG_DEBUG, "UaStateInCall::sendRequest"); //Send request switch(msg->getType()) { case SIP_BYE: { agent.sendBye(); //Transit to End changeState(agent, UaStateFactory::instance().getState(U_STATE_END)); } break; case SIP_INVITE: { Sptr<InviteMsg> srcMsg; srcMsg.dynamicCast(msg); Sptr<InviteMsg> invMsg ; invMsg = agent.createReInvite(srcMsg); invMsg->setCallId(agent.getRequest()->getCallId()); cpLog(LOG_DEBUG, "(%s) Building re-invite %s", agent.className().c_str(), invMsg->encode().logData()); //Set the To tag from the previous final response SipTo to = invMsg->getTo(); if(to.getUser() == agent.getResponse()->getTo().getUser()) { cpLog(LOG_DEBUG, "(%s) Building re-invite The To Tag: %s", agent.className().c_str(), agent.getResponse()->getTo().getTag().logData()); cpLog(LOG_DEBUG, "(%s) Building re-invite The response: %s", agent.className().c_str(), agent.getResponse()->encode().logData()); to.setTag(agent.getResponse()->getTo().getTag()); } else { cpLog(LOG_DEBUG, "(%s) Building re-invite %s", agent.className().c_str(), agent.getResponse()->getFrom().getTag().logData()); to.setTag(agent.getResponse()->getFrom().getTag()); } invMsg->setTo(to); SipFrom from = invMsg->getFrom(); if(from.getUser() == agent.getResponse()->getFrom().getUser()) { from.setTag(agent.getResponse()->getFrom().getTag()); } else { from.setTag(agent.getResponse()->getTo().getTag()); } invMsg->setFrom(from); cpLog(LOG_DEBUG, "(%s) Sending re-invite %s", agent.className().c_str(), invMsg->encode().logData()); agent.getSipTransceiver()->sendAsync(invMsg); changeState(agent, UaStateFactory::instance().getState(U_STATE_HOLD)); } break; case SIP_ACK: { //Generate ACK of the StatusMsg Sptr<StatusMsg> sMsg; sMsg.dynamicCast(agent.getResponse()); assert(sMsg != 0); agent.ackStatus(sMsg); Sptr<AckMsg> ackMsg = new AckMsg(*sMsg); //addSelfInVia(ackMsg); //agent.getSipTransceiver()->sendAsync(ackMsg); cpLog(LOG_DEBUG, "(%s) Sending Ack %s", agent.className().c_str(), ackMsg->encode().logData()); } break; case SIP_CANCEL: { cpLog(LOG_WARNING, "UaStateInCall, processing SIP_CANCEL, this is incorrect"); Sptr<SipCommand> sipCmd; sipCmd.dynamicCast(agent.getRequest()); Sptr<CancelMsg> cMsg = new CancelMsg(*sipCmd); agent.getSipTransceiver()->sendAsync(cMsg); //Transit to End changeState(agent, UaStateFactory::instance().getState(U_STATE_END)); } break; default: { cpLog(LOG_WARNING, "Wrong message type (%d) to handle in In Call, ignoring..", msg->getType()); } break; }}void UaStateInCall::recvStatus(UaBase& agent, Sptr<SipMsg> msg) throw (CInvalidStateException&){ cpLog(LOG_DEBUG, "UaStateInCall::recvStatus"); Sptr<StatusMsg> statusMsg; statusMsg.dynamicCast(msg); assert(statusMsg != 0); int statusCode = statusMsg->getStatusLine().getStatusCode(); if(statusCode > 200) { //Send Ack Sptr<AckMsg> ackMsg = new AckMsg(*statusMsg); SipRequestLine& ackRequestLine = ackMsg->getMutableRequestLine(); Sptr<SipCommand> sCommand; sCommand.dynamicCast(agent.getRequest()); assert(sCommand != 0); addSelfInVia(ackMsg); ackMsg->setRouteList(agent.getRouteList()); //Remove the top route ackMsg->removeRoute(0); ackRequestLine.setUrl(sCommand->getRequestLine().getUrl()); agent.getSipTransceiver()->sendAsync(ackMsg); } if(statusCode == 200) { if(statusMsg->getCSeq().getMethod() == INVITE_METHOD) { Sptr<AckMsg> ackMsg = new AckMsg(*statusMsg); addSelfInVia(ackMsg); ackMsg->setRouteList(agent.getRouteList()); //Remove the top route ackMsg->removeRoute(0); //Sync up the sequence number agent.getResponse()->setCSeq(statusMsg->getCSeq()); agent.setLocalCSeq(statusMsg->getCSeq()); } } //Notify CC if(agent.getControllerAgent()) agent.getControllerAgent()->receivedStatus(agent, msg);}void UaStateInCall::sendStatus(UaBase& agent, Sptr<SipMsg> msg) throw (CInvalidStateException&){ cpLog(LOG_DEBUG, "UaStateInCall::sendStatus"); Sptr<StatusMsg> statusMsg; statusMsg.dynamicCast(msg); assert(statusMsg != 0); int statusCode = statusMsg->getStatusLine().getStatusCode(); if(statusCode == 200) { Sptr<SipContentData> sdpData = msg->getContentData(0); Sptr<SipCommand> sipCmd; sipCmd.dynamicCast(agent.getRequest()); assert(sipCmd != 0); Sptr<StatusMsg> sendSMsg = new StatusMsg(*sipCmd, statusCode); if(sdpData != 0) { sendSMsg->setNumContentData(0); sendSMsg->setContentData(sdpData.getPtr()); } Sptr<BaseUrl> bUrl = sipCmd->getTo().getUrl(); Sptr<SipUrl> mUrl; mUrl.dynamicCast(bUrl); assert(mUrl != 0); mUrl->setHost((UaBase::myNAThost)); //theSystem.gethostAddress()); mUrl->setPort(Data(UaBase::mySipPort)); SipContact me; me.setUrl(mUrl); sendSMsg->setNumContact( 0 ); sendSMsg->setContact( me ); agent.getSipTransceiver()->sendReply(sendSMsg); } else if(statusCode > 200) { agent.sendReplyForRequest(agent.getRequest(), statusCode); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -