groupsock/GroupEId.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // Copyright (c) 1996-2008, Live Networks, Inc.  All rights reserved
00017 // "Group Endpoint Id"
00018 // Implementation
00019 
00020 #include "GroupEId.hh"
00021 #include "strDup.hh"
00022 #include <string.h>
00023 
00025 
00026 void Scope::assign(u_int8_t ttl, const char* publicKey) {
00027   fTTL = ttl;
00028 
00029   fPublicKey = strDup(publicKey == NULL ? "nokey" : publicKey);
00030 }
00031 
00032 void Scope::clean() {
00033   delete[] fPublicKey;
00034   fPublicKey = NULL;
00035 }
00036 
00037 
00038 Scope::Scope(u_int8_t ttl, const char* publicKey) {
00039   assign(ttl, publicKey);
00040 }
00041 
00042 Scope::Scope(const Scope& orig) {
00043   assign(orig.ttl(), orig.publicKey());
00044 }
00045 
00046 Scope& Scope::operator=(const Scope& rightSide) {
00047   if (&rightSide != this) {
00048     if (publicKey() == NULL
00049         || strcmp(publicKey(), rightSide.publicKey()) != 0) {
00050       clean();
00051       assign(rightSide.ttl(), rightSide.publicKey());
00052     } else { // need to assign TTL only
00053       fTTL = rightSide.ttl();
00054     }
00055   }
00056 
00057   return *this;
00058 }
00059 
00060 Scope::~Scope() {
00061   clean();
00062 }
00063 
00064 unsigned Scope::publicKeySize() const {
00065   return fPublicKey == NULL ? 0 : strlen(fPublicKey);
00066 }
00067 
00069 
00070 GroupEId::GroupEId(struct in_addr const& groupAddr,
00071                    portNumBits portNum, Scope const& scope,
00072                    unsigned numSuccessiveGroupAddrs) {
00073   struct in_addr sourceFilterAddr;
00074   sourceFilterAddr.s_addr = ~0; // indicates no source filter
00075 
00076   init(groupAddr, sourceFilterAddr, portNum, scope, numSuccessiveGroupAddrs);
00077 }
00078 
00079 GroupEId::GroupEId(struct in_addr const& groupAddr,
00080                    struct in_addr const& sourceFilterAddr,
00081                    portNumBits portNum,
00082                    unsigned numSuccessiveGroupAddrs) {
00083   init(groupAddr, sourceFilterAddr, portNum, 255, numSuccessiveGroupAddrs);
00084 }
00085 
00086 GroupEId::GroupEId() {
00087 }
00088 
00089 Boolean GroupEId::isSSM() const {
00090   return fSourceFilterAddress.s_addr != netAddressBits(~0);
00091 }
00092 
00093 
00094 void GroupEId::init(struct in_addr const& groupAddr,
00095                     struct in_addr const& sourceFilterAddr,
00096                     portNumBits portNum,
00097                     Scope const& scope,
00098                     unsigned numSuccessiveGroupAddrs) {
00099   fGroupAddress = groupAddr;
00100   fSourceFilterAddress = sourceFilterAddr;
00101   fNumSuccessiveGroupAddrs = numSuccessiveGroupAddrs;
00102   fPortNum = portNum;
00103   fScope = scope;
00104 }

Generated on Tue Oct 7 15:38:08 2008 for live by  doxygen 1.5.2