]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/DbName.h
Security-179.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / DbName.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 #ifndef _DBNAME_H_
20 #define _DBNAME_H_ 1
21
22 #include <Security/utilities.h>
23 #include <Security/walkers.h>
24 #include <Security/cssmtype.h>
25 #include <string>
26
27 #ifdef _CPP_DBNAME
28 # pragma export on
29 #endif
30
31 // @@@ Should not use using in headers.
32 using namespace std;
33
34 namespace Security
35 {
36
37 //----------------------------------------------------------------
38 //typedef struct cssm_net_address {
39 // CSSM_NET_ADDRESS_TYPE AddressType;
40 // CSSM_DATA Address;
41 //} CSSM_NET_ADDRESS, *CSSM_NET_ADDRESS_PTR;
42 //----------------------------------------------------------------
43
44 // XXX TODO: Make CssmNetAddress use a factory to constuct netadrress objects based on CSSM_NET_ADDRESS_TYPE!
45 class CssmNetAddress : public PodWrapper<CssmNetAddress, CSSM_NET_ADDRESS>
46 {
47 public:
48 // Create a CssmNetAddress wrapper. Copies inAddress.Data
49 CssmNetAddress(CSSM_DB_RECORDTYPE inAddressType, const CssmData &inAddress);
50 CssmNetAddress(const CSSM_NET_ADDRESS &other);
51 ~CssmNetAddress();
52 CSSM_DB_RECORDTYPE addressType() const { return AddressType; }
53 const CssmData &address() const { return CssmData::overlay(Address); }
54 bool operator <(const CssmNetAddress &other) const
55 {
56 return AddressType != other.AddressType ? AddressType < other.AddressType : address() < other.address();
57 }
58 };
59
60 class DbName
61 {
62 public:
63 DbName (const char *inDbName, const CSSM_NET_ADDRESS *inDbLocation);
64 DbName(const DbName &other);
65 DbName &operator =(const DbName &other);
66 ~DbName ();
67 const string &dbName() const { return mDbName; }
68 const CssmNetAddress *dbLocation() const { return mDbLocation; }
69 bool operator <(const DbName &other) const
70 {
71 // If mDbNames are not equal return whether our mDbName is less than others mDbName.
72 if (mDbName != other.mDbName)
73 return mDbName < other.mDbName;
74
75 // DbNames are equal so check for pointer equality of DbLocations
76 if (mDbLocation == other.mDbLocation)
77 return false;
78
79 // If either DbLocations is nil the one that is nil is less than the other.
80 if (mDbLocation == nil || other.mDbLocation == nil)
81 return mDbLocation < other.mDbLocation;
82
83 // Return which mDbLocation is smaller.
84 return *mDbLocation < *other.mDbLocation;
85 }
86 bool operator ==(const DbName &other) const
87 { return (!(*this < other)) && (!(other < *this)); }
88 bool operator !=(const DbName &other) const
89 { return *this < other || other < *this; }
90
91 private:
92 string mDbName;
93 CssmNetAddress *mDbLocation;
94 };
95
96
97 namespace DataWalkers
98 {
99
100 template<class Action>
101 CssmNetAddress *walk(Action &operate, CssmNetAddress * &addr)
102 {
103 operate(addr);
104 walk(operate, addr->Address);
105 return addr;
106 }
107
108 } // end namespace DataWalkers
109
110 } // end namespace Security
111
112 #ifdef _CPP_DBNAME
113 # pragma export off
114 #endif
115
116 #endif //_DBNAME_H_