2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
21 // classes for the DL related data structures
24 #ifndef _H_CDSA_UTILITIES_CSSMDB
25 #define _H_CDSA_UTILITIES_CSSMDB
27 #include <Security/cssmdata.h>
28 #include <Security/cssmalloc.h>
29 #include <Security/walkers.h>
30 #include <Security/DbName.h>
41 // Template class to build and maintain external arrays.
42 // Feel free to add and vector<> member functions and behaviours as needed.
44 // This class differs from vector mainly because it does not construct or
45 // destruct any of the elements it contains. Rather it zero fills the
46 // storage and returns references to elements.
47 // Also it does not implement insert(), erase() or assign(). It does implement
48 // which is equivalent to calling *insert(end()) on a vector.
53 typedef _Tp value_type
;
54 typedef value_type
* pointer
;
55 typedef const value_type
* const_pointer
;
56 typedef value_type
* iterator
;
57 typedef const value_type
* const_iterator
;
58 typedef value_type
& reference
;
59 typedef const value_type
& const_reference
;
60 typedef uint32 size_type
;
61 typedef ptrdiff_t difference_type
;
63 typedef reverse_iterator
<const_iterator
> const_reverse_iterator
;
64 typedef reverse_iterator
<iterator
> reverse_iterator
;
67 void insert_aux(iterator __position
, const _Tp
& __x
);
68 void insert_aux(iterator __position
);
71 iterator
begin() { return mArray
; }
72 const_iterator
begin() const { return mArray
; }
73 iterator
end() { return &mArray
[mSize
]; }
74 const_iterator
end() const { return &mArray
[mSize
]; }
76 reverse_iterator
rbegin()
77 { return reverse_iterator(end()); }
78 const_reverse_iterator
rbegin() const
79 { return const_reverse_iterator(end()); }
80 reverse_iterator
rend()
81 { return reverse_iterator(begin()); }
82 const_reverse_iterator
rend() const
83 { return const_reverse_iterator(begin()); }
85 // Must be defined in base class.
86 //size_type size() const
88 size_type
max_size() const
89 { return size_type(-1) / sizeof(_Tp
); }
90 size_type
capacity() const
93 { return begin() == end(); }
95 ArrayBuilder(pointer
&array
, size_type
&size
, size_type capacity
= 0, CssmAllocator
&allocator
= CssmAllocator::standard()) :
96 mArray(array
), mSize(size
), mCapacity(capacity
), mAllocator(allocator
)
99 mArray
= reinterpret_cast<pointer
>(mAllocator
.malloc(sizeof(value_type
) * mCapacity
));
101 mArray
= reinterpret_cast<pointer
>(mAllocator
.malloc(sizeof(value_type
) * mCapacity
));
102 //mArray = mAllocator.alloc(mCapacity);
104 memset(mArray
, 0, sizeof(value_type
) * mCapacity
);
107 ~ArrayBuilder() { mAllocator
.free(mArray
); }
109 reference
front() { return *begin(); }
110 const_reference
front() const { return *begin(); }
111 reference
back() { return *(end() - 1); }
112 const_reference
back() const { return *(end() - 1); }
114 void reserve(size_type newCapacity
)
116 if (newCapacity
> mCapacity
)
119 mArray
= reinterpret_cast<pointer
>(mAllocator
.realloc(mArray
, sizeof(value_type
) * newCapacity
));
121 mArray
= reinterpret_cast<pointer
>(mAllocator
.realloc(mArray
, sizeof(value_type
) * newCapacity
));
122 //mArray = mAllocator.realloc<value_type>(mArray, newCapacity));
124 memset(&mArray
[mCapacity
], 0, sizeof(value_type
) * (newCapacity
- mCapacity
));
125 mCapacity
= newCapacity
;
129 // XXX Replace by push_back and insert.
132 if (mSize
>= mCapacity
)
133 reserve(max(mSize
+ 1, mCapacity
? 2 * mCapacity
: 1));
135 return mArray
[mSize
++];
138 const_pointer
get() const { return mArray
; }
139 pointer
release() { const_pointer array
= mArray
; mArray
= NULL
; return array
; }
140 void clear() { if (mSize
) { memset(mArray
, 0, sizeof(value_type
) * mSize
); } mSize
= 0; }
142 // Must be defined in base class.
143 //reference at(size_type ix) { return mArray[ix]; }
144 //const_reference at(size_type ix) const { return mArray[ix]; }
145 //reference operator[] (size_type ix) { assert(ix < size()); return at(ix); }
146 //const_reference operator[] (size_type ix) const { assert(ix < size()); return at(ix); }
148 CssmAllocator
&allocator() const { return mAllocator
; }
155 CssmAllocator
&mAllocator
;
160 // CssmDbAttributeInfo pod wrapper for CSSM_DB_ATTRIBUTE_INFO
162 class CssmDbAttributeInfo
: public PodWrapper
<CssmDbAttributeInfo
, CSSM_DB_ATTRIBUTE_INFO
>
165 CssmDbAttributeInfo(const CSSM_DB_ATTRIBUTE_INFO
&attr
)
166 { (CSSM_DB_ATTRIBUTE_INFO
&)*this = attr
; }
168 CSSM_DB_ATTRIBUTE_NAME_FORMAT
nameFormat() const { return AttributeNameFormat
; }
169 void nameFormat(CSSM_DB_ATTRIBUTE_NAME_FORMAT nameFormat
) { AttributeNameFormat
= nameFormat
; }
171 CSSM_DB_ATTRIBUTE_FORMAT
format() const { return AttributeFormat
; }
172 void format(CSSM_DB_ATTRIBUTE_FORMAT format
) { AttributeFormat
= format
; }
174 operator const char *() const
176 assert(nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_STRING
);
177 return Label
.AttributeName
;
179 operator const CssmOid
&() const
181 assert(nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_OID
);
182 return CssmOid::overlay(Label
.AttributeOID
);
184 operator uint32() const
186 assert(nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER
);
187 return Label
.AttributeID
;
190 bool operator <(const CssmDbAttributeInfo
& other
) const;
191 bool operator ==(const CssmDbAttributeInfo
& other
) const;
192 bool operator !=(const CssmDbAttributeInfo
& other
) const
193 { return !(*this == other
); }
195 // XXX Add setting member functions.
199 // CssmDbRecordAttributeInfo pod wrapper for CSSM_DB_RECORD_ATTRIBUTE_INFO
201 class CssmDbRecordAttributeInfo
: public PodWrapper
<CssmDbRecordAttributeInfo
, CSSM_DB_RECORD_ATTRIBUTE_INFO
>
204 CssmDbRecordAttributeInfo()
205 { DataRecordType
= CSSM_DL_DB_RECORD_ANY
; }
207 CssmDbRecordAttributeInfo(CSSM_DB_RECORDTYPE recordType
, uint32 numberOfAttributes
,
208 CSSM_DB_ATTRIBUTE_INFO_PTR attributeInfo
)
210 DataRecordType
= recordType
;
211 NumberOfAttributes
= numberOfAttributes
;
212 AttributeInfo
= attributeInfo
;
215 CSSM_DB_RECORDTYPE
recordType() const { return DataRecordType
; }
216 void recordType(CSSM_DB_RECORDTYPE recordType
) { DataRecordType
= recordType
; }
218 uint32
size() const { return NumberOfAttributes
; }
220 // Attributes by position
221 CssmDbAttributeInfo
&at(uint32 ix
)
222 { return CssmDbAttributeInfo::overlay(AttributeInfo
[ix
]); }
223 const CssmDbAttributeInfo
&at(uint32 ix
) const
224 { return CssmDbAttributeInfo::overlay(AttributeInfo
[ix
]); }
226 CssmDbAttributeInfo
&operator [](uint32 ix
)
227 { assert(ix
< size()); return at(ix
); }
228 const CssmDbAttributeInfo
&operator [](uint32 ix
) const
229 { assert(ix
< size()); return at(ix
); }
233 // CssmAutoDbRecordAttributeInfo pod wrapper for CSSM_DB_RECORD_ATTRIBUTE_INFO
235 class CssmAutoDbRecordAttributeInfo
: public CssmDbRecordAttributeInfo
, public ArrayBuilder
<CssmDbAttributeInfo
>
238 CssmAutoDbRecordAttributeInfo(uint32 capacity
= 0, CssmAllocator
&allocator
= CssmAllocator::standard()) :
239 CssmDbRecordAttributeInfo(),
240 ArrayBuilder
<CssmDbAttributeInfo
>(CssmDbAttributeInfo::overlayVar(AttributeInfo
),
241 NumberOfAttributes
, capacity
, allocator
) {}
246 // CssmDbAttributeData pod wrapper for CSSM_DB_ATTRIBUTE_DATA
248 class CssmDbAttributeData
: public PodWrapper
<CssmDbAttributeData
, CSSM_DB_ATTRIBUTE_DATA
>
251 CssmDbAttributeData() { NumberOfValues
= 0; Value
= NULL
; }
252 CssmDbAttributeData(const CSSM_DB_ATTRIBUTE_DATA
&attr
)
253 { (CSSM_DB_ATTRIBUTE_DATA
&)*this = attr
; }
254 CssmDbAttributeData(const CSSM_DB_ATTRIBUTE_INFO
&info
)
255 { Info
= info
; NumberOfValues
= 0; Value
= NULL
; }
257 CssmDbAttributeInfo
&info() { return CssmDbAttributeInfo::overlay(Info
); }
258 const CssmDbAttributeInfo
&info() const { return CssmDbAttributeInfo::overlay(Info
); }
259 void info (const CSSM_DB_ATTRIBUTE_INFO
&inInfo
) { Info
= inInfo
; }
261 CSSM_DB_ATTRIBUTE_FORMAT
format() const { return info().format(); }
263 uint32
size() const { return NumberOfValues
; }
266 T
at(unsigned int ix
) const { return CssmDLPolyData(Value
[ix
], format()); }
269 T
operator [](unsigned int ix
) const
270 { if (ix
>= size()) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
); return at(ix
); }
272 // this is intentionally unspecified since it could lead to bugs; the
273 // data is not guaranteed to be NULL-terminated
274 // operator const char *() const;
276 // XXX Don't use assert, but throw an exception.
277 operator string() const
279 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
280 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_STRING
);
281 return Value
[0].Length
? string(reinterpret_cast<const char *>(Value
[0].Data
), Value
[0].Length
) : string();
283 operator bool() const
285 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
286 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_UINT32
|| format() == CSSM_DB_ATTRIBUTE_FORMAT_SINT32
);
287 return *reinterpret_cast<uint32
*>(Value
[0].Data
);
289 operator uint32() const
291 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
292 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_UINT32
);
293 return *reinterpret_cast<uint32
*>(Value
[0].Data
);
295 operator const uint32
*() const
297 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
298 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32
);
299 return reinterpret_cast<const uint32
*>(Value
[0].Data
);
301 operator sint32() const
303 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
304 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_SINT32
);
305 return *reinterpret_cast<sint32
*>(Value
[0].Data
);
307 operator double() const
309 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
310 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_REAL
);
311 return *reinterpret_cast<double *>(Value
[0].Data
);
313 operator CssmData
&() const
315 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
316 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_STRING
317 || format() == CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM
318 || format() == CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE
319 || format() == CSSM_DB_ATTRIBUTE_FORMAT_BLOB
320 || format() == CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32
);
321 return CssmData::overlay(Value
[0]);
324 // Set the value of this Attr (assuming it was not set before).
325 void set(const CSSM_DB_ATTRIBUTE_INFO
&inInfo
, const CssmPolyData
&inValue
,
326 CssmAllocator
&inAllocator
)
330 Value
= inAllocator
.alloc
<CSSM_DATA
>();
332 Value
[0].Data
= inAllocator
.alloc
<uint8
>(inValue
.Length
);
333 Value
[0].Length
= inValue
.Length
;
334 memcpy(Value
[0].Data
, inValue
.Data
, inValue
.Length
);
338 // Set the value of this Attr (assuming it was not set before).
339 void set(const CSSM_DB_ATTRIBUTE_DATA
&other
, CssmAllocator
&inAllocator
)
342 Value
= inAllocator
.alloc
<CSSM_DATA
>(other
.NumberOfValues
);
343 NumberOfValues
= other
.NumberOfValues
;
344 for (NumberOfValues
= 0; NumberOfValues
< other
.NumberOfValues
; NumberOfValues
++)
346 Value
[NumberOfValues
].Length
= 0;
347 Value
[NumberOfValues
].Data
= inAllocator
.alloc
<uint8
>(other
.Value
[NumberOfValues
].Length
);
348 Value
[NumberOfValues
].Length
= other
.Value
[NumberOfValues
].Length
;
349 memcpy(Value
[NumberOfValues
].Data
, other
.Value
[NumberOfValues
].Data
,
350 other
.Value
[NumberOfValues
].Length
);
354 // Add a value to this attribute.
355 void add(const CssmPolyData
&inValue
, CssmAllocator
&inAllocator
)
357 Value
= reinterpret_cast<CSSM_DATA
*>(inAllocator
.realloc(Value
, sizeof(*Value
) * (NumberOfValues
+ 1)));
358 Value
[NumberOfValues
].Length
= 0;
359 Value
[NumberOfValues
].Data
= inAllocator
.alloc
<uint8
>(inValue
.Length
);
360 Value
[NumberOfValues
].Length
= inValue
.Length
;
361 memcpy(Value
[NumberOfValues
++].Data
, inValue
.Data
, inValue
.Length
);
364 void add(const CssmDbAttributeData
&src
, CssmAllocator
&inAllocator
);
366 // delete specific values if they are present in this attribute data
367 bool deleteValue(const CssmData
&src
, CssmAllocator
&inAllocator
);
368 void deleteValues(const CssmDbAttributeData
&src
, CssmAllocator
&inAllocator
);
370 void deleteValues(CssmAllocator
&inAllocator
);
372 bool operator <(const CssmDbAttributeData
& other
) const;
377 // CssmDbRecordAttributeData pod wrapper for CSSM_DB_RECORD_ATTRIBUTE_DATA
379 class CssmDbRecordAttributeData
: public PodWrapper
<CssmDbRecordAttributeData
, CSSM_DB_RECORD_ATTRIBUTE_DATA
>
382 CssmDbRecordAttributeData()
383 { DataRecordType
= CSSM_DL_DB_RECORD_ANY
; SemanticInformation
= 0; }
385 CSSM_DB_RECORDTYPE
recordType() const { return DataRecordType
; }
386 void recordType(CSSM_DB_RECORDTYPE recordType
) { DataRecordType
= recordType
; }
388 uint32
semanticInformation() const { return SemanticInformation
; }
389 void semanticInformation(uint32 semanticInformation
) { SemanticInformation
= semanticInformation
; }
391 uint32
size() const { return NumberOfAttributes
; }
393 // Attributes by position
394 CssmDbAttributeData
&at(unsigned int ix
)
395 { return CssmDbAttributeData::overlay(AttributeData
[ix
]); }
396 const CssmDbAttributeData
&at(unsigned int ix
) const
397 { return CssmDbAttributeData::overlay(AttributeData
[ix
]); }
399 CssmDbAttributeData
&operator [](unsigned int ix
)
400 { assert(ix
< size()); return at(ix
); }
401 const CssmDbAttributeData
&operator [](unsigned int ix
) const
402 { assert(ix
< size()); return at(ix
); }
404 void deleteValues(CssmAllocator
&allocator
)
405 { for (uint32 ix
= 0; ix
< size(); ++ix
) at(ix
).deleteValues(allocator
); }
407 CssmDbAttributeData
*find(const CSSM_DB_ATTRIBUTE_INFO
&inInfo
);
409 bool operator <(const CssmDbRecordAttributeData
& other
) const;
414 // CssmAutoDbRecordAttributeData
416 class CssmAutoDbRecordAttributeData
: public CssmDbRecordAttributeData
, public ArrayBuilder
<CssmDbAttributeData
>
419 CssmAutoDbRecordAttributeData(uint32 capacity
= 0,
420 CssmAllocator
&valueAllocator
= CssmAllocator::standard(),
421 CssmAllocator
&dataAllocator
= CssmAllocator::standard()) :
422 CssmDbRecordAttributeData(),
423 ArrayBuilder
<CssmDbAttributeData
>(CssmDbAttributeData::overlayVar(AttributeData
),
424 NumberOfAttributes
, capacity
, dataAllocator
),
425 mValueAllocator(valueAllocator
) {}
426 ~CssmAutoDbRecordAttributeData();
429 void deleteValues() { CssmDbRecordAttributeData::deleteValues(mValueAllocator
); }
431 CssmDbAttributeData
&add() { return ArrayBuilder
<CssmDbAttributeData
>::add(); } // XXX using doesn't work here.
432 CssmDbAttributeData
&add(const CSSM_DB_ATTRIBUTE_INFO
&info
);
433 CssmDbAttributeData
&add(const CSSM_DB_ATTRIBUTE_INFO
&info
, const CssmPolyData
&value
);
435 // So clients can pass this as the allocator argument to add()
436 operator CssmAllocator
&() const { return mValueAllocator
; }
438 CssmAllocator
&mValueAllocator
;
440 CssmDbAttributeData
* findAttribute (const CSSM_DB_ATTRIBUTE_INFO
&info
);
441 CssmDbAttributeData
& getAttributeReference (const CSSM_DB_ATTRIBUTE_INFO
&info
);
446 // CssmSelectionPredicate a PodWrapper for CSSM_SELECTION_PREDICATE
448 class CssmSelectionPredicate
: public PodWrapper
<CssmSelectionPredicate
, CSSM_SELECTION_PREDICATE
> {
450 CssmSelectionPredicate() { /*IFDEBUG(*/ memset(this, 0, sizeof(*this)) /*)*/ ; }
452 CSSM_DB_OPERATOR
dbOperator() const { return DbOperator
; }
453 void dbOperator(CSSM_DB_OPERATOR dbOperator
) { DbOperator
= dbOperator
; }
455 CssmSelectionPredicate(CSSM_DB_OPERATOR inDbOperator
)
456 { dbOperator(inDbOperator
); Attribute
.NumberOfValues
= 0; Attribute
.Value
= NULL
; }
458 CssmDbAttributeData
&attribute() { return CssmDbAttributeData::overlay(Attribute
); }
459 const CssmDbAttributeData
&attribute() const { return CssmDbAttributeData::overlay(Attribute
); }
461 // Set the value of this CssmSelectionPredicate (assuming it was not set before).
462 void set(const CSSM_DB_ATTRIBUTE_INFO
&inInfo
,
463 const CssmPolyData
&inValue
, CssmAllocator
&inAllocator
)
464 { attribute().set(inInfo
, inValue
, inAllocator
); }
466 // Set the value of this CssmSelectionPredicate using another CssmSelectionPredicate's value.
467 void set(const CSSM_SELECTION_PREDICATE
&other
, CssmAllocator
&inAllocator
)
468 { DbOperator
= other
.DbOperator
; attribute().set(other
.Attribute
, inAllocator
); }
470 // Add a value to the list of values for this CssmSelectionPredicate.
471 void add(const CssmPolyData
&inValue
, CssmAllocator
&inAllocator
)
472 { attribute().add(inValue
, inAllocator
); }
474 void deleteValues(CssmAllocator
&inAllocator
) { attribute().deleteValues(inAllocator
); }
477 class CssmQuery
: public PodWrapper
<CssmQuery
, CSSM_QUERY
> {
480 { memset(this, 0, sizeof(*this)) ; RecordType
= CSSM_DL_DB_RECORD_ANY
; }
481 //CssmDLQuery(const CSSM_QUERY &q) { memcpy(this, &q, sizeof(*this)); }
483 //CssmDLQuery &operator = (const CSSM_QUERY &q)
484 //{ memcpy(this, &q, sizeof(*this)); return *this; }
486 CSSM_DB_RECORDTYPE
recordType() const { return RecordType
; }
487 void recordType(CSSM_DB_RECORDTYPE recordType
) { RecordType
= recordType
; }
489 CSSM_DB_CONJUNCTIVE
conjunctive() const { return Conjunctive
; }
490 void conjunctive(CSSM_DB_CONJUNCTIVE conjunctive
) { Conjunctive
= conjunctive
; }
492 CSSM_QUERY_LIMITS
queryLimits() const { return QueryLimits
; }
493 void queryLimits(CSSM_QUERY_LIMITS queryLimits
) { QueryLimits
= queryLimits
; }
495 CSSM_QUERY_FLAGS
queryFlags() const { return QueryFlags
; }
496 void queryFlags(CSSM_QUERY_FLAGS queryFlags
) { QueryFlags
= queryFlags
; }
498 uint32
size() const { return NumSelectionPredicates
; }
500 CssmSelectionPredicate
&at(uint32 ix
)
501 { return CssmSelectionPredicate::overlay(SelectionPredicate
[ix
]); }
502 const CssmSelectionPredicate
&at(uint32 ix
) const
503 { return CssmSelectionPredicate::overlay(SelectionPredicate
[ix
]); }
505 CssmSelectionPredicate
&operator[] (uint32 ix
) { assert(ix
< size()); return at(ix
); }
506 const CssmSelectionPredicate
&operator[] (uint32 ix
) const { assert(ix
< size()); return at(ix
); }
508 void deleteValues(CssmAllocator
&allocator
)
509 { for (uint32 ix
= 0; ix
< size(); ++ix
) at(ix
).deleteValues(allocator
); }
513 class CssmAutoQuery
: public CssmQuery
, public ArrayBuilder
<CssmSelectionPredicate
> {
515 CssmAutoQuery(const CSSM_QUERY
&query
, CssmAllocator
&allocator
= CssmAllocator::standard());
516 CssmAutoQuery(uint32 capacity
= 0, CssmAllocator
&allocator
= CssmAllocator::standard()) :
517 ArrayBuilder
<CssmSelectionPredicate
>(CssmSelectionPredicate::overlayVar(SelectionPredicate
),
518 NumSelectionPredicates
,
519 capacity
, allocator
) {}
522 void deleteValues() { CssmQuery::deleteValues(allocator()); }
524 CssmSelectionPredicate
&add() { return ArrayBuilder
<CssmSelectionPredicate
>::add(); }
525 CssmSelectionPredicate
&add(CSSM_DB_OPERATOR dbOperator
, const CSSM_DB_ATTRIBUTE_INFO
&info
, const CssmPolyData
&value
);
527 // So clients can pass this as the allocator argument to add()
528 operator CssmAllocator
&() const { return allocator(); }
538 class Impl
: public RefCount
542 Impl(const CSSM_SUBSERVICE_UID
&ssuid
,const char *DbName
,const CSSM_NET_ADDRESS
*DbLocation
) :
543 mCssmSubserviceUid(ssuid
),mDbName(DbName
,DbLocation
) {}
545 ~Impl() {} // Must be public since RefPointer uses it.
548 const CssmSubserviceUid
&ssuid() const { return mCssmSubserviceUid
; }
549 const char *dbName() const { return mDbName
.dbName().c_str(); }
550 const CssmNetAddress
*dbLocation() const { return mDbName
.dbLocation(); }
552 // comparison (simple lexicographic)
553 bool operator < (const Impl
&other
) const
554 { return mCssmSubserviceUid
< other
.mCssmSubserviceUid
||
555 (mCssmSubserviceUid
== other
.mCssmSubserviceUid
&& mDbName
< other
.mDbName
); }
557 bool operator == (const Impl
&other
) const
558 { return mCssmSubserviceUid
== other
.mCssmSubserviceUid
&& mDbName
== other
.mDbName
; }
561 // Private member variables
562 CssmSubserviceUid mCssmSubserviceUid
;
569 DLDbIdentifier(const CSSM_SUBSERVICE_UID
&ssuid
,const char *DbName
,const CSSM_NET_ADDRESS
*DbLocation
)
570 : mImpl(new Impl(ssuid
, DbName
, DbLocation
)) {}
572 // Conversion Operators
573 bool operator !() const { return !mImpl
; }
574 operator bool() const { return mImpl
; }
577 bool operator <(const DLDbIdentifier
&other
) const
578 { return mImpl
&& other
.mImpl
? *mImpl
< *other
.mImpl
: mImpl
.get() < other
.mImpl
.get(); }
579 bool operator ==(const DLDbIdentifier
&other
) const
580 { return mImpl
&& other
.mImpl
? *mImpl
== *other
.mImpl
: mImpl
.get() == other
.mImpl
.get(); }
581 DLDbIdentifier
&operator =(const DLDbIdentifier
&other
)
582 { mImpl
= other
.mImpl
; return *this; }
585 const CssmSubserviceUid
&ssuid() const { return mImpl
->ssuid(); }
586 const char *dbName() const { return mImpl
->dbName(); }
587 const CssmNetAddress
*dbLocation() const { return mImpl
->dbLocation(); }
589 RefPointer
<Impl
> mImpl
;
592 // Wrappers for index-related CSSM objects.
594 class CssmDbIndexInfo
: public PodWrapper
<CssmDbIndexInfo
, CSSM_DB_INDEX_INFO
>
597 CssmDbIndexInfo(const CSSM_DB_INDEX_INFO
&attr
)
598 { (CSSM_DB_INDEX_INFO
&)*this = attr
; }
600 CSSM_DB_INDEX_TYPE
indexType() const { return IndexType
; }
601 void indexType(CSSM_DB_INDEX_TYPE indexType
) { IndexType
= indexType
; }
603 CSSM_DB_INDEXED_DATA_LOCATION
dataLocation() const { return IndexedDataLocation
; }
604 void dataLocation(CSSM_DB_INDEXED_DATA_LOCATION dataLocation
)
606 IndexedDataLocation
= dataLocation
;
609 const CssmDbAttributeInfo
&attributeInfo() const
611 return CssmDbAttributeInfo::overlay(Info
);
616 namespace DataWalkers
620 // DLDbIdentifiers don't walk directly because they have Impl structure and use strings.
621 // Happily, they are easily transcribed into a walkable form.
623 struct DLDbFlatIdentifier
{
624 const CssmSubserviceUid
*uid
; // module reference
625 const char *name
; // string name
626 const CssmNetAddress
*address
; // optional network address
628 DLDbFlatIdentifier(const DLDbIdentifier
&ident
)
629 : uid(&ident
.ssuid()), name(ident
.dbName()), address(ident
.dbLocation()) { }
631 operator DLDbIdentifier () { return DLDbIdentifier(*uid
, name
, address
); }
634 template<class Action
>
635 DLDbFlatIdentifier
*walk(Action
&operate
, DLDbFlatIdentifier
* &ident
)
639 walk(operate
, ident
->uid
);
640 walk(operate
, ident
->name
);
642 walk(operate
, ident
->address
);
646 } // end namespace DataWalkers
648 } // end namespace Security
650 #ifdef _CPP_UTILITIES
655 #endif // _H_CDSA_UTILITIES_CSSMDB