📄 sdp2session.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 SdpSession_cxx_Version = "$Id: Sdp2Session.cxx,v 1.6.2.2 2003/01/16 08:38:34 sprajpat Exp $";#include "global.h"#include "debug.h"#include <cstdio>#include <time.h>#include <strstream>#include <deque>#include "Sdp2Exceptions.hxx"#include "Sdp2Session.hxx"#include "Sdp2Externs.hxx"//using Vocal::SDP;using Vocal::SDP::SdpSession;using Vocal::SDP::SdpConnection;using Vocal::SDP::SdpProtocolType;using Vocal::SDP::NetworkType;using Vocal::SDP::SdpBandwidth;using Vocal::SDP::SdpTime;// Other files can include "Sdp2Externs.hxx" to reference the following// const char []sconst char Vocal::SDP::SdpNetworkTypeIN[] = "IN";const char Vocal::SDP::SdpAddressTypeIP4[] = "IP4";const char Vocal::SDP::SdpAddressTypeIP6[] = "IP6";const char Vocal::SDP::SdpMediaTransportRTPAVP[] = "RTP/AVP";const char Vocal::SDP::SdpMediaTransportUDP[] = "UDP";const char Vocal::SDP::SdpMediaTransportMPA[] = "MPA/16000";const char Vocal::SDP::SdpBandwidthModifierAS[] = "AS"; // Application specific maximumconst char Vocal::SDP::SdpBandwidthModifierCT[] = "CT"; // Conference Totalconst char Vocal::SDP::SdpBandwidthModifierRR[] = "RR"; const char Vocal::SDP::SdpMediaTypeAudio[] = "audio";const char Vocal::SDP::SdpMediaTypeVideo[] = "video";const char Vocal::SDP::SdpAttributeRecvonly[] = "recvonly";const char Vocal::SDP::SdpAttributeSendrecv[] = "sendrecv";const char Vocal::SDP::SdpAttributeSendonly[] = "sendonly";const char Vocal::SDP::SdpEncryptkeyMethodClear[] = "clear";const char Vocal::SDP::SdpEncryptkeyMethodBase64[] = "base64";const char Vocal::SDP::SdpEncryptkeyMethodURI[] = "uri";const char Vocal::SDP::SdpEncryptkeyMethodPrompt[] = "prompt";// When adding a new const char [], add the corresponding extern declaration// in "Sdp2Externs.hxx"void split(deque<Data>& slist, Data str, const char* item){ bool finished = false; while (!finished) { Data x = str.parse(item, &finished); if(finished) { x = str; } slist.push_back(x); }}///SdpSession::SdpSession() : emailList(), phoneList(), sdpTimeList(){ protocolType = SdpProtocolTypeSDP; protocolVersion = 0; username = "-"; // Use NTP time sessionId = static_cast < unsigned int > (time(NULL) + SdpTime::NTP_UX_DIFF); // Use NTP time version = static_cast < unsigned int > (time(NULL) + SdpTime::NTP_UX_DIFF); networkType = NetworkTypeInternet; addressType = AddressTypeIPV4; address = "0.0.0.0"; sessionName = "-"; sessionName = ""; uriInfo = ""; emailList.clear(); phoneList.clear(); connection = 0; attribute = 0; bandwidth = 0; encryptkey = 0; SdpTime time; sdpTimeList.push_back (time); zoneAdjustmentList.clear(); flushMediaList(); isValid = false;} // SdpSession::SdpSession///SdpSession::SdpSession (const SdpSession& x){ connection = 0; attribute = 0; bandwidth = 0; encryptkey = 0; flushMediaList(); *this = x;} // SdpSession::SdpSession///SdpSession::~SdpSession(){ if (connection) { delete connection; } if (attribute) { delete attribute; } if (bandwidth) { delete bandwidth; } if (encryptkey) { delete encryptkey; } flushMediaList();} // SdpSession::~SdpSessionSdpSession&SdpSession::operator= (const SdpSession& x){ protocolVersion = x.protocolVersion; username = x.username; sessionId = x.sessionId; version = x.version; networkType = x.networkType; addressType = x.addressType; address = x.address; sessionName = x.sessionName; sessionInfo = x.sessionInfo; uriInfo = x.uriInfo; emailList = x.emailList; phoneList = x.phoneList; if (x.connection) { if (!connection) { connection = new SdpConnection; assert(connection); } *(connection) = *(x.connection); cpLog(LOG_DEBUG_STACK, "Copied connection"); } else { if (connection) { delete connection; connection = 0; } } if (x.bandwidth) { if (!bandwidth) { bandwidth = new SdpBandwidth; assert(bandwidth); } *(bandwidth) = *(x.bandwidth); cpLog(LOG_DEBUG_STACK, "copied bandwidth"); } else { if (bandwidth) { delete bandwidth; bandwidth = 0; } } sdpTimeList.clear(); sdpTimeList = x.getSdpTimeList(); zoneAdjustmentList = x.zoneAdjustmentList;; if (x.encryptkey) { if (!encryptkey) { encryptkey = new SdpEncryptkey; assert(encryptkey); } *(encryptkey) = *(x.encryptkey); cpLog(LOG_DEBUG_STACK, "copied encryptkey"); } else { if (encryptkey) { delete encryptkey; encryptkey = 0; } } if (x.attribute) { if (!attribute) { attribute = new SdpAttributes; assert(attribute); } *(attribute) = *(x.attribute); cpLog(LOG_DEBUG_STACK, "copied attribute"); } else { if (attribute) { delete attribute; attribute = 0; } } //copy contents of objects pointed by the mediaList. // we need to flush the previous values list < SdpMedia* > newMediaList = x.getMediaList(); flushMediaList(); if (newMediaList.size() > 0) { list < SdpMedia* > ::iterator mediaiter; mediaiter = newMediaList.begin(); while (mediaiter != newMediaList.end()) { cpLog(LOG_DEBUG_STACK, "Obtained one mediaiter"); if (*mediaiter) { // create new of media and assign values. SdpMedia* media = new SdpMedia; assert(media); *media = *(*mediaiter); //store in the vector. addMedia(media); } ++mediaiter; } } buf[0] = '\0'; isValid = x.isValid; return (*this);} // SdpSession::operator=#if 0boolSdpSession::operator== (const SdpSession& x) const{ /// xxx not implemented assert(0); return false;}#endifvoidSdpSession::clearSdpTimeList (){ sdpTimeList.clear(); isValid = false;} // SdpSession::addTimevoidSdpSession::addTime (const SdpTime& time){ sdpTimeList.push_back (time); isValid = true;} // SdpSession::addTime///voidSdpSession::setBandwidth (SdpBandwidth& bw){ if (!bandwidth) { bandwidth = new SdpBandwidth; } *bandwidth = bw;} // SdpSession::setBandwidth///voidSdpSession::setNcs (){ setUserName (Data("-")); // User needs to call setAddress() setSessionName (Data("-")); // No "i=" // No "u=" // No "e=" // No "p=" SdpConnection conn; // User needs to call setUnicast() setConnection (conn); SdpBandwidth bw; setBandwidth (bw); sdpTimeList.clear(); SdpTime time; addTime (time); // No "k=" // User add attribute("a=") lines SdpMedia* media = new SdpMedia; // User needs to call SdpMedia::setPort() addMedia (media);} // SdpSession::setNcs///voidSdpSession::setProtocolType (SdpProtocolType protocol){ protocolType = protocol; // Setup this SDP according to the corresponding protocol if (protocol == SdpProtocolTypeNCS) { setNcs (); }} // SdpSession::setProtocolType///SdpProtocolTypeSdpSession::getProtocolType (){ return protocolType;} // SdpSession::getProtocolType///voidSdpSession::encodeVersion (ostrstream& s){ // v=0 by default - no other value as of now s << "v=" << protocolVersion << "\r\n";} // SdpSession::encode///DataSdpSession::networkTypeString(){ Data s; switch (networkType) { case NetworkTypeInternet: { s = SdpNetworkTypeIN; break; } default: { // Network type corrupted assert(0); break; } } return s;} // SdpSession::networkTypeString///DataSdpSession::addressTypeString(){ Data s; switch (addressType) { case AddressTypeIPV4: { s = SdpAddressTypeIP4; break; } case AddressTypeIPV6: { s = SdpAddressTypeIP6; break; } default: { // Address type corrupted assert(0); break; } } return s;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -