📄 uabase.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 UaBase_cxx_Version = "$Id: UaBase.cxx,v 1.12.2.3 2003/02/13 03:30:42 sprajpat Exp $";#include "InviteMsg.hxx" #include "StatusMsg.hxx" #include "AckMsg.hxx" #include "SipRoute.hxx" #include "SystemInfo.hxx" #include "UaBase.hxx" #include "SipRecordRoute.hxx"#include "SipVia.hxx"using Vocal::InviteMsg;using Vocal::StatusMsg;using Vocal::UA::UaBase;int Vocal::UA::UaBase::mySipPort = 5060;NetworkAddress Vocal::UA::UaBase::myProxyAddress;int Vocal::UA::UaBase::myTransport;Data Vocal::UA::UaBase::myNAThost;voidVocal::UA::libSipInit(NetworkAddress& proxyAddess, int sipPort, Data NATHOST, int transport){ Vocal::UA::UaBase::myProxyAddress = proxyAddess; if(Vocal::UA::UaBase::myProxyAddress.getPort() == -1) { Vocal::UA::UaBase::myProxyAddress.setPort(5060); } Vocal::UA::UaBase::mySipPort = sipPort; Vocal::UA::UaBase::myTransport = transport; Vocal::UA::UaBase::myNAThost = NATHOST;}void UaBase::receivedMsg(const Sptr<SipMsg>& sipMsg){ cpLog(LOG_DEBUG, "(%s) received message %s ", className().c_str(), sipMsg->encode().logData()); if(sipMsg->getType() == SIP_STATUS) { myState->recvStatus(*this, sipMsg); } else { myState->recvRequest(*this, sipMsg); }}void UaBase::sendMsg(const Sptr<SipMsg>& sipMsg){ cpLog(LOG_DEBUG_STACK , "(%s) Processing message %s ", className().c_str(), sipMsg->encode().logData()); if(sipMsg->getType() == SIP_STATUS) { myState->sendStatus(*this, sipMsg); } else { myState->sendRequest(*this, sipMsg); }}Sptr<InviteMsg>UaBase::createInvite(const Sptr<InviteMsg>& invMsg, bool changeCallId){ Sptr<InviteMsg> inviteMsg = new InviteMsg(*invMsg); //Remove the contact header inviteMsg->setNumContact(0); //Set the contact as B2b Sptr<BaseUrl> bUrl = inviteMsg->getFrom().getUrl(); Sptr<SipUrl> mUrl; mUrl.dynamicCast(bUrl); //TODO - Handle the case with TelUrl assert(mUrl != 0); //mUrl->setHost(theSystem.gethostAddress()); mUrl->setHost((UaBase::myNAThost)); mUrl->setPort(Data(mySipPort)); SipContact me; me.setUrl(mUrl); inviteMsg->setContact(me); //Clear VIA and set B2b as first via inviteMsg->flushViaList(); SipVia via; via.setHost(theSystem.gethostAddress()); via.setPort(mySipPort); if(myTransport == 2) //TCP { via.setTransport("TCP"); } inviteMsg->setVia(via); inviteMsg->setNumRecordRoute(0); inviteMsg->setNumRoute(0); if(changeCallId) { //Set the new callId SipCallId id; inviteMsg->setCallId(id); //Set the request URI to outbound proxy SipRequestLine& reqLine = inviteMsg->getMutableRequestLine(); Sptr<SipUrl> sUrl; sUrl.dynamicCast(reqLine.getUrl()); sUrl->setMaddrParam(""); //Look for magic "%" in the request line //if found parse it and send it to the contact found in it string sUser = sUrl->getUserValue().logData(); string::size_type pos; if((pos = sUser.find("%")) != string::npos) { string user = sUser.substr(0, pos); string hostPort = sUser.substr(pos+1); NetworkAddress na (hostPort); string nextHopAddr = na.getIpName().convertString(); int nextHopPort = na.getPort(); if(nextHopPort == -1) nextHopPort = 5060; sUrl->setHost(nextHopAddr); sUrl->setPort(Data(nextHopPort)); } else { string outboundProxyAddr = myProxyAddress.getIpName().convertString(); int outboundProxyPort = myProxyAddress.getPort(); sUrl->setHost(outboundProxyAddr); sUrl->setPort(Data(outboundProxyPort)); if(!sUrl->getUserValue().length()) { //set the user to be to sUrl->setUserValue(inviteMsg->getTo().getUser()); } } if(myTransport == 2) //TCP { sUrl->setTransportParam("tcp"); } reqLine.setUrl(sUrl); } return inviteMsg;}Sptr<InviteMsg>UaBase::createReInvite(const Sptr<InviteMsg>& invMsg){ Sptr<InviteMsg> inviteMsg = createInvite(invMsg, false); //This is a reInvite case, will use the route we have saved in the //begining of the dialog assert(myRouteList.size()); inviteMsg->setRouteList(myRouteList); SipRoute siproute = inviteMsg->getRoute(0); inviteMsg->removeRoute(0); SipRequestLine& reqLine = inviteMsg->getMutableRequestLine(); reqLine.setUrl( siproute.getUrl() ); inviteMsg->setCallId(getRequest()->getCallId()); //Get the CSeq from the local CSeq, increment it and use it. myLocalCSeq.incrCSeq(); inviteMsg->setCSeq(myLocalCSeq); return inviteMsg;} //Sptr<StatusMsg> // VEERvoidUaBase::sendReplyForRequest(const Sptr<SipMsg>& sipMsg, int statusCode){ assert(sipMsg->getType() != SIP_STATUS); //Send status message Sptr<SipCommand> sipCmd; sipCmd.dynamicCast(sipMsg); assert(sipCmd != 0); Sptr<StatusMsg> sendSMsg = new StatusMsg(*sipCmd, statusCode); cpLog(LOG_DEBUG, "(%s) sending status %s", className().c_str(), sendSMsg->encode().logData()); myStack->sendReply(sendSMsg); setResponse(sendSMsg); // return sendSMsg; // VEER}voidUaBase::ackStatus(const Sptr<SipMsg>& msg){ Sptr<StatusMsg> sMsg; sMsg.dynamicCast(msg); assert(sMsg != 0); if(sMsg->getStatusLine().getStatusCode() >= 200) { Sptr<AckMsg> ackMsg = new AckMsg(*sMsg); //if(sMsg->getStatusLine().getStatusCode() > 200) { //Ack should have the same request line and via as the //Original invite Sptr<SipCommand> invMsg; invMsg.dynamicCast(getRequest()); assert(invMsg != 0); ackMsg->flushViaList(); SipVia via = invMsg->getVia(0); ackMsg->setVia(via, 0); ackMsg->setRouteList(myRouteList); ackMsg->removeRoute(0); Sptr<SipUrl> sUrl; sUrl.dynamicCast(invMsg->getRequestLine().getUrl()); SipRequestLine rLine(SIP_ACK, sUrl); ackMsg->setRequestLine(rLine); } myStack->sendAsync(ackMsg); }}UaBase::~UaBase(){ //cerr << "UaBase::~UaBase:" << myAgentRole << endl; clearRouteList();}voidUaBase::clearRouteList(){ //cleanup the routelist while(myRouteList.size()) { SipRoute* r = myRouteList.back(); myRouteList.pop_back(); delete r; }}void UaBase::saveRouteList(const Sptr<SipMsg>& msg, bool reverse){ clearRouteList(); SipRecordRouteList rrList = msg->getrecordrouteList(); SipRecordRouteList::iterator iter = rrList.begin(); //Reverse the recordRoute list and form a route list // (A,B,C) -> (C,B, A) while ( iter != rrList.end() ) { Sptr< BaseUrl > baseUrl = (*iter)->getUrl(); if( baseUrl->getType() == TEL_URL ) { cpLog( LOG_ERR, "TEL_URL currently not supported\n" ); continue; } Sptr< SipUrl > sipUrl; sipUrl.dynamicCast( baseUrl ); assert( sipUrl != 0 ); SipRoute* route = new SipRoute;cpLog(LOG_DEBUG, "**** Adding route %d: %s", reverse, baseUrl->encode().logData()); if(reverse) { route->setUrl( baseUrl ); myRouteList.insert( myRouteList.begin(), route ); } else { route->setUrl( baseUrl ); myRouteList.push_back( route ); } iter++; } //Append the contacts at the end of the route list int numContact = msg->getNumContact(); if ( numContact ) { SipContact contact = msg->getContact( numContact - 1 ); SipRoute* route = new SipRoute; route->setUrl( contact.getUrl() ); myRouteList.push_back( route ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -