SdpConnection.hxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:6k
- #ifndef _SDPCONNECTION_H
- #define _SDPCONNECTION_H
- /* ====================================================================
- * 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 SdpConnectionVersion =
- "$Id: SdpConnection.hxx,v 1.15 2001/06/14 16:28:24 chok Exp $";
- #include <vector>
- #include <strstream>
- //#include <assert.h>
- #include <cassert>
- #include "SdpExterns.hxx"
- #include "cpLog.h"
- ///
- enum TransportType
- {
- TransportTypeUnknown,
- TransportTypeRTP,
- TransportTypeUDP
- };
- ///
- enum AddressType
- {
- AddressTypeUnknown,
- AddressTypeIPV4,
- AddressTypeIPV6
- };
- ///
- enum NetworkType
- {
- NetworkTypeUnknown,
- NetworkTypeInternet
- };
- const int MulticastTtlValMin = 0;
- const int MulticastTtlValMax = 255;
- const int MaxAddressLen = 128;
- const string HOLD = "0.0.0.0";
- /** Muticast address and the paramemter that goes with it
- * in the connection details.
- */
- class SdpMulticast
- {
- public:
- ///
- SdpMulticast();
- ///
- SdpMulticast(const char* addr, int ttlval = 0, int numAddr = 1)
- {
- setAddress(addr);
- setTtl(ttlval);
- setnumAddr(numAddr);
- }
- ///
- void setTtl(int ttlval)
- {
- if ( (ttlval < MulticastTtlValMin) ||
- (ttlval > MulticastTtlValMax) )
- cpLog(LOG_ERR, "ttl out of range");
- else
- ttl = ttlval;
- }
- ///
- int getTtl()
- {
- return ttl;
- }
- ///
- void setnumAddr(int numAddr)
- {
- numAddress = numAddr;
- }
- ///
- int getnumAddr()
- {
- return numAddress;
- }
- ///
- char* getAddress()
- {
- return address;
- }
- ///
- void setAddress(const char* addr)
- {
- strcpy(address, addr);
- }
- ///
- void encode (ostrstream& s);
- private:
- char address[MaxAddressLen];
- int ttl;
- int numAddress;
- };
- /** Connection details
- * For unicast address:
- * c=<network type> <address type> <connection address>
- * For multicast address:
- * c=IN IP4 <base multicast address>/<ttl>/<number of addresses>
- */
- class SdpConnection
- {
- public:
- ///
- SdpConnection();
- ///
- SdpConnection(string& str);
- ///
- SdpConnection( const SdpConnection& connection );
- ///
- void setUnicast(const char* addr)
- {
- strcpy(address, addr);
- }
- ///
- void setMulticast(const char* addr, int ttl, int numAddr = 1)
- {
- if (!multicast)
- {
- multicast = new SdpMulticast(addr, ttl, numAddr);
- }
- else
- {
- multicast->setAddress(addr);
- multicast->setTtl(ttl);
- multicast->setnumAddr(numAddr);
- }
- }
- ///
- SdpMulticast* getMulticast() const
- {
- return multicast;
- }
- ///
- string getUnicast() const
- {
- return address;
- }
- ///
- void setNetworkType(NetworkType networkType)
- {
- networktype = networkType;
- }
- ///
- NetworkType getNetworkType() const
- {
- return networktype;
- }
- ///
- void setAddressType(AddressType addressType)
- {
- addresstype = addressType;
- }
- ///
- AddressType getAddressType() const
- {
- return addresstype;
- }
- ///
- SdpConnection& operator=(const SdpConnection& connection);
- ///
- ~SdpConnection()
- {
- if (multicast)
- delete multicast;
- }
- ///
- void encode (ostrstream& s);
- /// Implement INVITE(HOLD)
- void setHold(); // set <connection address> to "0.0.0.0"
- bool isHold();
- private:
- ///
- string networkTypeString();
- ///
- string addressTypeString();
- NetworkType networktype;
- AddressType addresstype;
- /// Unicast address
- char address[MaxAddressLen];
- SdpMulticast* multicast;
- };
- #endif