2 * Copyright (c) 2000-2001,2003-2004,2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <security_utilities/utilities.h>
29 #include <security_cdsa_utilities/walkers.h>
30 #include <Security/cssmtype.h>
37 // @@@ Should not use using in headers.
43 //----------------------------------------------------------------
44 //typedef struct cssm_net_address {
45 // CSSM_NET_ADDRESS_TYPE AddressType;
47 //} CSSM_NET_ADDRESS, *CSSM_NET_ADDRESS_PTR;
48 //----------------------------------------------------------------
50 // XXX TODO: Make CssmNetAddress use a factory to constuct netadrress objects based on CSSM_NET_ADDRESS_TYPE!
51 class CssmNetAddress
: public PodWrapper
<CssmNetAddress
, CSSM_NET_ADDRESS
>
54 // Create a CssmNetAddress wrapper. Copies inAddress.Data
55 CssmNetAddress(CSSM_DB_RECORDTYPE inAddressType
, const CssmData
&inAddress
);
56 CssmNetAddress(const CSSM_NET_ADDRESS
&other
);
58 CSSM_DB_RECORDTYPE
addressType() const { return AddressType
; }
59 const CssmData
&address() const { return CssmData::overlay(Address
); }
60 bool operator <(const CssmNetAddress
&other
) const
62 return AddressType
!= other
.AddressType
? AddressType
< other
.AddressType
: address() < other
.address();
69 DbName (const char *inDbName
= NULL
, const CSSM_NET_ADDRESS
*inDbLocation
= NULL
);
70 DbName(const DbName
&other
);
71 DbName
&operator =(const DbName
&other
);
73 const char *dbName() const { return mDbNameValid
? mDbName
.c_str() : NULL
; }
74 const char *canonicalName() const { return mDbNameValid
? mCanonicalName
.c_str() : NULL
; }
75 const CssmNetAddress
*dbLocation() const { return mDbLocation
; }
76 bool operator <(const DbName
&other
) const
78 // invalid is always smaller than valid
79 if (!mDbNameValid
|| !other
.mDbNameValid
)
80 return mDbNameValid
< other
.mDbNameValid
;
82 // If mDbNames are not equal return whether our mDbName is less than others mDbName.
83 if (canonicalName() != other
.canonicalName())
84 return mDbName
< other
.mDbName
;
86 // DbNames are equal so check for pointer equality of DbLocations
87 if (mDbLocation
== other
.mDbLocation
)
90 // If either DbLocations is nil the one that is nil is less than the other.
91 if (mDbLocation
== nil
|| other
.mDbLocation
== nil
)
92 return mDbLocation
< other
.mDbLocation
;
94 // Return which mDbLocation is smaller.
95 return *mDbLocation
< *other
.mDbLocation
;
97 bool operator ==(const DbName
&other
) const
98 { return (!(*this < other
)) && (!(other
< *this)); }
99 bool operator !=(const DbName
&other
) const
100 { return *this < other
|| other
< *this; }
103 void CanonicalizeName();
106 string mCanonicalName
;
108 CssmNetAddress
*mDbLocation
;
112 namespace DataWalkers
115 template<class Action
>
116 CssmNetAddress
*walk(Action
&operate
, CssmNetAddress
* &addr
)
119 walk(operate
, addr
->Address
);
123 } // end namespace DataWalkers
125 } // end namespace Security