00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 {
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;
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 }