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>
44 // some prototypes for utility functions
45 CSSM_RETURN
AddFooToIntelList( void** theIntelListToAddItTo
, unsigned long* theNumberOfThingsAlreadyInTheList
, const void* theThingToAdd
, size_t theSizeOfTheThingToAdd
);
49 // Template class to build and maintain external arrays.
50 // Feel free to add and vector<> member functions and behaviours as needed.
52 // This class differs from vector mainly because it does not construct or
53 // destruct any of the elements it contains. Rather it zero fills the
54 // storage and returns references to elements.
55 // Also it does not implement insert(), erase() or assign(). It does implement
56 // which is equivalent to calling *insert(end()) on a vector.
61 typedef _Tp value_type
;
62 typedef value_type
* pointer
;
63 typedef const value_type
* const_pointer
;
64 typedef value_type
* iterator
;
65 typedef const value_type
* const_iterator
;
66 typedef value_type
& reference
;
67 typedef const value_type
& const_reference
;
68 typedef uint32 size_type
;
69 typedef ptrdiff_t difference_type
;
71 typedef reverse_iterator
<const_iterator
> const_reverse_iterator
;
72 typedef reverse_iterator
<iterator
> reverse_iterator
;
75 void insert_aux(iterator __position
, const _Tp
& __x
);
76 void insert_aux(iterator __position
);
79 iterator
begin() { return mArray
; }
80 const_iterator
begin() const { return mArray
; }
81 iterator
end() { return &mArray
[mSize
]; }
82 const_iterator
end() const { return &mArray
[mSize
]; }
84 reverse_iterator
rbegin()
85 { return reverse_iterator(end()); }
86 const_reverse_iterator
rbegin() const
87 { return const_reverse_iterator(end()); }
88 reverse_iterator
rend()
89 { return reverse_iterator(begin()); }
90 const_reverse_iterator
rend() const
91 { return const_reverse_iterator(begin()); }
93 // Must be defined in base class.
94 //size_type size() const
96 size_type
max_size() const
97 { return size_type(-1) / sizeof(_Tp
); }
98 size_type
capacity() const
101 { return begin() == end(); }
103 ArrayBuilder(pointer
&array
, size_type
&size
, size_type capacity
= 0, CssmAllocator
&allocator
= CssmAllocator::standard()) :
104 mArray(array
), mSize(size
), mCapacity(capacity
), mAllocator(allocator
)
107 mArray
= reinterpret_cast<pointer
>(mAllocator
.malloc(sizeof(value_type
) * mCapacity
));
109 mArray
= reinterpret_cast<pointer
>(mAllocator
.malloc(sizeof(value_type
) * mCapacity
));
110 //mArray = mAllocator.alloc(mCapacity);
112 memset(mArray
, 0, sizeof(value_type
) * mCapacity
);
115 ~ArrayBuilder() { mAllocator
.free(mArray
); }
117 reference
front() { return *begin(); }
118 const_reference
front() const { return *begin(); }
119 reference
back() { return *(end() - 1); }
120 const_reference
back() const { return *(end() - 1); }
122 void reserve(size_type newCapacity
)
124 if (newCapacity
> mCapacity
)
127 mArray
= reinterpret_cast<pointer
>(mAllocator
.realloc(mArray
, sizeof(value_type
) * newCapacity
));
129 mArray
= reinterpret_cast<pointer
>(mAllocator
.realloc(mArray
, sizeof(value_type
) * newCapacity
));
130 //mArray = mAllocator.realloc<value_type>(mArray, newCapacity));
132 memset(&mArray
[mCapacity
], 0, sizeof(value_type
) * (newCapacity
- mCapacity
));
133 mCapacity
= newCapacity
;
137 // XXX Replace by push_back and insert.
140 if (mSize
>= mCapacity
)
141 reserve(max(mSize
+ 1, mCapacity
? 2 * mCapacity
: 1));
143 return mArray
[mSize
++];
146 const_pointer
get() const { return mArray
; }
147 pointer
release() { const_pointer array
= mArray
; mArray
= NULL
; return array
; }
148 void clear() { if (mSize
) { memset(mArray
, 0, sizeof(value_type
) * mSize
); } mSize
= 0; }
150 // Must be defined in base class.
151 //reference at(size_type ix) { return mArray[ix]; }
152 //const_reference at(size_type ix) const { return mArray[ix]; }
153 //reference operator[] (size_type ix) { assert(ix < size()); return at(ix); }
154 //const_reference operator[] (size_type ix) const { assert(ix < size()); return at(ix); }
156 CssmAllocator
&allocator() const { return mAllocator
; }
163 CssmAllocator
&mAllocator
;
168 // CssmDbAttributeInfo pod wrapper for CSSM_DB_ATTRIBUTE_INFO
170 class CssmDbAttributeInfo
: public PodWrapper
<CssmDbAttributeInfo
, CSSM_DB_ATTRIBUTE_INFO
>
173 CssmDbAttributeInfo(const CSSM_DB_ATTRIBUTE_INFO
&attr
)
174 { (CSSM_DB_ATTRIBUTE_INFO
&)*this = attr
; }
176 CSSM_DB_ATTRIBUTE_NAME_FORMAT
nameFormat() const { return AttributeNameFormat
; }
177 void nameFormat(CSSM_DB_ATTRIBUTE_NAME_FORMAT nameFormat
) { AttributeNameFormat
= nameFormat
; }
179 CSSM_DB_ATTRIBUTE_FORMAT
format() const { return AttributeFormat
; }
180 void format(CSSM_DB_ATTRIBUTE_FORMAT format
) { AttributeFormat
= format
; }
182 operator const char *() const
184 assert(nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_STRING
);
185 return Label
.AttributeName
;
187 operator const CssmOid
&() const
189 assert(nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_OID
);
190 return CssmOid::overlay(Label
.AttributeOID
);
192 operator uint32() const
194 assert(nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER
);
195 return Label
.AttributeID
;
198 bool operator <(const CssmDbAttributeInfo
& other
) const;
199 bool operator ==(const CssmDbAttributeInfo
& other
) const;
200 bool operator !=(const CssmDbAttributeInfo
& other
) const
201 { return !(*this == other
); }
203 // XXX Add setting member functions.
207 // CssmDbRecordAttributeInfo pod wrapper for CSSM_DB_RECORD_ATTRIBUTE_INFO
209 class CssmDbRecordAttributeInfo
: public PodWrapper
<CssmDbRecordAttributeInfo
, CSSM_DB_RECORD_ATTRIBUTE_INFO
>
212 CssmDbRecordAttributeInfo()
213 { DataRecordType
= CSSM_DL_DB_RECORD_ANY
; }
215 CssmDbRecordAttributeInfo(CSSM_DB_RECORDTYPE recordType
, uint32 numberOfAttributes
,
216 CSSM_DB_ATTRIBUTE_INFO_PTR attributeInfo
)
218 DataRecordType
= recordType
;
219 NumberOfAttributes
= numberOfAttributes
;
220 AttributeInfo
= attributeInfo
;
223 CSSM_DB_RECORDTYPE
recordType() const { return DataRecordType
; }
224 void recordType(CSSM_DB_RECORDTYPE recordType
) { DataRecordType
= recordType
; }
226 uint32
size() const { return NumberOfAttributes
; }
228 // Attributes by position
229 CssmDbAttributeInfo
&at(uint32 ix
)
230 { return CssmDbAttributeInfo::overlay(AttributeInfo
[ix
]); }
231 const CssmDbAttributeInfo
&at(uint32 ix
) const
232 { return CssmDbAttributeInfo::overlay(AttributeInfo
[ix
]); }
234 CssmDbAttributeInfo
&operator [](uint32 ix
)
235 { assert(ix
< size()); return at(ix
); }
236 const CssmDbAttributeInfo
&operator [](uint32 ix
) const
237 { assert(ix
< size()); return at(ix
); }
241 // CssmAutoDbRecordAttributeInfo pod wrapper for CSSM_DB_RECORD_ATTRIBUTE_INFO
243 class CssmAutoDbRecordAttributeInfo
: public CssmDbRecordAttributeInfo
, public ArrayBuilder
<CssmDbAttributeInfo
>
246 CssmAutoDbRecordAttributeInfo(uint32 capacity
= 0, CssmAllocator
&allocator
= CssmAllocator::standard()) :
247 CssmDbRecordAttributeInfo(),
248 ArrayBuilder
<CssmDbAttributeInfo
>(static_cast<CssmDbAttributeInfo
*>(AttributeInfo
),
249 NumberOfAttributes
, capacity
, allocator
) {}
254 // CssmDbAttributeData pod wrapper for CSSM_DB_ATTRIBUTE_DATA
256 class CssmDbAttributeData
: public PodWrapper
<CssmDbAttributeData
, CSSM_DB_ATTRIBUTE_DATA
>
259 CssmDbAttributeData() { NumberOfValues
= 0; Value
= NULL
; }
260 CssmDbAttributeData(const CSSM_DB_ATTRIBUTE_DATA
&attr
)
261 { (CSSM_DB_ATTRIBUTE_DATA
&)*this = attr
; }
262 CssmDbAttributeData(const CSSM_DB_ATTRIBUTE_INFO
&info
)
263 { Info
= info
; NumberOfValues
= 0; Value
= NULL
; }
265 CssmDbAttributeInfo
&info() { return CssmDbAttributeInfo::overlay(Info
); }
266 const CssmDbAttributeInfo
&info() const { return CssmDbAttributeInfo::overlay(Info
); }
267 void info (const CSSM_DB_ATTRIBUTE_INFO
&inInfo
) { Info
= inInfo
; }
269 CSSM_DB_ATTRIBUTE_FORMAT
format() const { return info().format(); }
271 uint32
size() const { return NumberOfValues
; }
274 T
at(unsigned int ix
) const { return CssmDLPolyData(Value
[ix
], format()); }
277 T
operator [](unsigned int ix
) const
278 { if (ix
>= size()) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
); return at(ix
); }
280 // this is intentionally unspecified since it could lead to bugs; the
281 // data is not guaranteed to be NULL-terminated
282 // operator const char *() const;
284 // XXX Don't use assert, but throw an exception.
285 operator string() const
287 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
288 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_STRING
);
289 return Value
[0].Length
? string(reinterpret_cast<const char *>(Value
[0].Data
), Value
[0].Length
) : string();
291 operator bool() const
293 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
294 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_UINT32
|| format() == CSSM_DB_ATTRIBUTE_FORMAT_SINT32
);
295 return *reinterpret_cast<uint32
*>(Value
[0].Data
);
297 operator uint32() const
299 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
300 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_UINT32
);
301 return *reinterpret_cast<uint32
*>(Value
[0].Data
);
303 operator const uint32
*() const
305 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
306 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32
);
307 return reinterpret_cast<const uint32
*>(Value
[0].Data
);
309 operator sint32() const
311 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
312 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_SINT32
);
313 return *reinterpret_cast<sint32
*>(Value
[0].Data
);
315 operator double() const
317 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
318 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_REAL
);
319 return *reinterpret_cast<double *>(Value
[0].Data
);
321 operator CssmData
&() const
323 if (size() < 1) CssmError::throwMe(CSSMERR_DL_MISSING_VALUE
);
324 assert(format() == CSSM_DB_ATTRIBUTE_FORMAT_STRING
325 || format() == CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM
326 || format() == CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE
327 || format() == CSSM_DB_ATTRIBUTE_FORMAT_BLOB
328 || format() == CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32
);
329 return CssmData::overlay(Value
[0]);
332 // Set the value of this Attr (assuming it was not set before).
333 void set(const CSSM_DB_ATTRIBUTE_INFO
&inInfo
, const CssmPolyData
&inValue
,
334 CssmAllocator
&inAllocator
)
338 Value
= inAllocator
.alloc
<CSSM_DATA
>();
340 Value
[0].Data
= inAllocator
.alloc
<uint8
>(inValue
.Length
);
341 Value
[0].Length
= inValue
.Length
;
342 memcpy(Value
[0].Data
, inValue
.Data
, inValue
.Length
);
346 // Set the value of this Attr (assuming it was not set before).
347 void set(const CSSM_DB_ATTRIBUTE_DATA
&other
, CssmAllocator
&inAllocator
)
350 Value
= inAllocator
.alloc
<CSSM_DATA
>(other
.NumberOfValues
);
351 NumberOfValues
= other
.NumberOfValues
;
352 for (NumberOfValues
= 0; NumberOfValues
< other
.NumberOfValues
; NumberOfValues
++)
354 Value
[NumberOfValues
].Length
= 0;
355 Value
[NumberOfValues
].Data
= inAllocator
.alloc
<uint8
>(other
.Value
[NumberOfValues
].Length
);
356 Value
[NumberOfValues
].Length
= other
.Value
[NumberOfValues
].Length
;
357 memcpy(Value
[NumberOfValues
].Data
, other
.Value
[NumberOfValues
].Data
,
358 other
.Value
[NumberOfValues
].Length
);
362 // Add a value to this attribute.
363 void add(const CssmPolyData
&inValue
, CssmAllocator
&inAllocator
)
365 Value
= reinterpret_cast<CSSM_DATA
*>(inAllocator
.realloc(Value
, sizeof(*Value
) * (NumberOfValues
+ 1)));
366 Value
[NumberOfValues
].Length
= 0;
367 Value
[NumberOfValues
].Data
= inAllocator
.alloc
<uint8
>(inValue
.Length
);
368 Value
[NumberOfValues
].Length
= inValue
.Length
;
369 memcpy(Value
[NumberOfValues
++].Data
, inValue
.Data
, inValue
.Length
);
372 void add(const CssmDbAttributeData
&src
, CssmAllocator
&inAllocator
);
374 // delete specific values if they are present in this attribute data
375 bool deleteValue(const CssmData
&src
, CssmAllocator
&inAllocator
);
376 void deleteValues(const CssmDbAttributeData
&src
, CssmAllocator
&inAllocator
);
378 void deleteValues(CssmAllocator
&inAllocator
);
380 bool operator <(const CssmDbAttributeData
& other
) const;
385 // CssmDbRecordAttributeData pod wrapper for CSSM_DB_RECORD_ATTRIBUTE_DATA
387 class CssmDbRecordAttributeData
: public PodWrapper
<CssmDbRecordAttributeData
, CSSM_DB_RECORD_ATTRIBUTE_DATA
>
390 CssmDbRecordAttributeData()
391 { DataRecordType
= CSSM_DL_DB_RECORD_ANY
; SemanticInformation
= 0; }
393 CSSM_DB_RECORDTYPE
recordType() const { return DataRecordType
; }
394 void recordType(CSSM_DB_RECORDTYPE recordType
) { DataRecordType
= recordType
; }
396 uint32
semanticInformation() const { return SemanticInformation
; }
397 void semanticInformation(uint32 semanticInformation
) { SemanticInformation
= semanticInformation
; }
399 uint32
size() const { return NumberOfAttributes
; }
401 // Attributes by position
402 CssmDbAttributeData
&at(unsigned int ix
)
403 { return CssmDbAttributeData::overlay(AttributeData
[ix
]); }
404 const CssmDbAttributeData
&at(unsigned int ix
) const
405 { return CssmDbAttributeData::overlay(AttributeData
[ix
]); }
407 CssmDbAttributeData
&operator [](unsigned int ix
)
408 { assert(ix
< size()); return at(ix
); }
409 const CssmDbAttributeData
&operator [](unsigned int ix
) const
410 { assert(ix
< size()); return at(ix
); }
412 void deleteValues(CssmAllocator
&allocator
)
413 { for (uint32 ix
= 0; ix
< size(); ++ix
) at(ix
).deleteValues(allocator
); }
415 CssmDbAttributeData
*find(const CSSM_DB_ATTRIBUTE_INFO
&inInfo
);
417 bool operator <(const CssmDbRecordAttributeData
& other
) const;
422 // CssmAutoDbRecordAttributeData
424 class CssmAutoDbRecordAttributeData
: public CssmDbRecordAttributeData
, public ArrayBuilder
<CssmDbAttributeData
>
427 CssmAutoDbRecordAttributeData(uint32 capacity
= 0,
428 CssmAllocator
&valueAllocator
= CssmAllocator::standard(),
429 CssmAllocator
&dataAllocator
= CssmAllocator::standard()) :
430 CssmDbRecordAttributeData(),
431 ArrayBuilder
<CssmDbAttributeData
>(static_cast<CssmDbAttributeData
*>(AttributeData
),
432 NumberOfAttributes
, capacity
, dataAllocator
),
433 mValueAllocator(valueAllocator
) {}
434 ~CssmAutoDbRecordAttributeData();
437 void deleteValues() { CssmDbRecordAttributeData::deleteValues(mValueAllocator
); }
439 CssmDbAttributeData
&add() { return ArrayBuilder
<CssmDbAttributeData
>::add(); } // XXX using doesn't work here.
440 CssmDbAttributeData
&add(const CSSM_DB_ATTRIBUTE_INFO
&info
);
441 CssmDbAttributeData
&add(const CSSM_DB_ATTRIBUTE_INFO
&info
, const CssmPolyData
&value
);
443 // So clients can pass this as the allocator argument to add()
444 operator CssmAllocator
&() const { return mValueAllocator
; }
446 CssmAllocator
&mValueAllocator
;
448 CssmDbAttributeData
* findAttribute (const CSSM_DB_ATTRIBUTE_INFO
&info
);
449 CssmDbAttributeData
& getAttributeReference (const CSSM_DB_ATTRIBUTE_INFO
&info
);
454 // CssmSelectionPredicate a PodWrapper for CSSM_SELECTION_PREDICATE
456 class CssmSelectionPredicate
: public PodWrapper
<CssmSelectionPredicate
, CSSM_SELECTION_PREDICATE
> {
458 CssmSelectionPredicate() { /*IFDEBUG(*/ memset(this, 0, sizeof(*this)) /*)*/ ; }
460 CSSM_DB_OPERATOR
dbOperator() const { return DbOperator
; }
461 void dbOperator(CSSM_DB_OPERATOR dbOperator
) { DbOperator
= dbOperator
; }
463 CssmSelectionPredicate(CSSM_DB_OPERATOR inDbOperator
)
464 { dbOperator(inDbOperator
); Attribute
.NumberOfValues
= 0; Attribute
.Value
= NULL
; }
466 CssmDbAttributeData
&attribute() { return CssmDbAttributeData::overlay(Attribute
); }
467 const CssmDbAttributeData
&attribute() const { return CssmDbAttributeData::overlay(Attribute
); }
469 // Set the value of this CssmSelectionPredicate (assuming it was not set before).
470 void set(const CSSM_DB_ATTRIBUTE_INFO
&inInfo
,
471 const CssmPolyData
&inValue
, CssmAllocator
&inAllocator
)
472 { attribute().set(inInfo
, inValue
, inAllocator
); }
474 // Set the value of this CssmSelectionPredicate using another CssmSelectionPredicate's value.
475 void set(const CSSM_SELECTION_PREDICATE
&other
, CssmAllocator
&inAllocator
)
476 { DbOperator
= other
.DbOperator
; attribute().set(other
.Attribute
, inAllocator
); }
478 // Add a value to the list of values for this CssmSelectionPredicate.
479 void add(const CssmPolyData
&inValue
, CssmAllocator
&inAllocator
)
480 { attribute().add(inValue
, inAllocator
); }
482 void deleteValues(CssmAllocator
&inAllocator
) { attribute().deleteValues(inAllocator
); }
485 class CssmQuery
: public PodWrapper
<CssmQuery
, CSSM_QUERY
> {
488 { memset(this, 0, sizeof(*this)) ; RecordType
= CSSM_DL_DB_RECORD_ANY
; }
489 //CssmDLQuery(const CSSM_QUERY &q) { memcpy(this, &q, sizeof(*this)); }
491 //CssmDLQuery &operator = (const CSSM_QUERY &q)
492 //{ memcpy(this, &q, sizeof(*this)); return *this; }
494 CSSM_DB_RECORDTYPE
recordType() const { return RecordType
; }
495 void recordType(CSSM_DB_RECORDTYPE recordType
) { RecordType
= recordType
; }
497 CSSM_DB_CONJUNCTIVE
conjunctive() const { return Conjunctive
; }
498 void conjunctive(CSSM_DB_CONJUNCTIVE conjunctive
) { Conjunctive
= conjunctive
; }
500 CSSM_QUERY_LIMITS
queryLimits() const { return QueryLimits
; }
501 void queryLimits(CSSM_QUERY_LIMITS queryLimits
) { QueryLimits
= queryLimits
; }
503 CSSM_QUERY_FLAGS
queryFlags() const { return QueryFlags
; }
504 void queryFlags(CSSM_QUERY_FLAGS queryFlags
) { QueryFlags
= queryFlags
; }
506 uint32
size() const { return NumSelectionPredicates
; }
508 CssmSelectionPredicate
&at(uint32 ix
)
509 { return CssmSelectionPredicate::overlay(SelectionPredicate
[ix
]); }
510 const CssmSelectionPredicate
&at(uint32 ix
) const
511 { return CssmSelectionPredicate::overlay(SelectionPredicate
[ix
]); }
513 CssmSelectionPredicate
&operator[] (uint32 ix
) { assert(ix
< size()); return at(ix
); }
514 const CssmSelectionPredicate
&operator[] (uint32 ix
) const { assert(ix
< size()); return at(ix
); }
516 void deleteValues(CssmAllocator
&allocator
)
517 { for (uint32 ix
= 0; ix
< size(); ++ix
) at(ix
).deleteValues(allocator
); }
521 class CssmAutoQuery
: public CssmQuery
, public ArrayBuilder
<CssmSelectionPredicate
> {
523 CssmAutoQuery(const CSSM_QUERY
&query
, CssmAllocator
&allocator
= CssmAllocator::standard());
524 CssmAutoQuery(uint32 capacity
= 0, CssmAllocator
&allocator
= CssmAllocator::standard()) :
525 ArrayBuilder
<CssmSelectionPredicate
>(static_cast<CssmSelectionPredicate
*>(SelectionPredicate
),
526 NumSelectionPredicates
,
527 capacity
, allocator
) {}
530 void deleteValues() { CssmQuery::deleteValues(allocator()); }
532 CssmSelectionPredicate
&add() { return ArrayBuilder
<CssmSelectionPredicate
>::add(); }
533 CssmSelectionPredicate
&add(CSSM_DB_OPERATOR dbOperator
, const CSSM_DB_ATTRIBUTE_INFO
&info
, const CssmPolyData
&value
);
535 // So clients can pass this as the allocator argument to add()
536 operator CssmAllocator
&() const { return allocator(); }
546 class Impl
: public RefCount
550 Impl(const CSSM_SUBSERVICE_UID
&ssuid
,const char *DbName
,const CSSM_NET_ADDRESS
*DbLocation
) :
551 mCssmSubserviceUid(ssuid
),mDbName(DbName
,DbLocation
) {}
553 ~Impl() {} // Must be public since RefPointer uses it.
556 const CssmSubserviceUid
&ssuid() const { return mCssmSubserviceUid
; }
557 const char *dbName() const { return mDbName
.dbName().c_str(); }
558 const CssmNetAddress
*dbLocation() const { return mDbName
.dbLocation(); }
561 bool operator < (const Impl
&other
) const
562 { return (mCssmSubserviceUid
< other
.mCssmSubserviceUid
||
563 (!(other
.mCssmSubserviceUid
< mCssmSubserviceUid
) && mDbName
< other
.mDbName
)); }
565 bool operator == (const Impl
&other
) const
566 { return mCssmSubserviceUid
== other
.mCssmSubserviceUid
&& mDbName
== other
.mDbName
; }
569 // Private member variables
570 CssmSubserviceUid mCssmSubserviceUid
;
577 DLDbIdentifier(const CSSM_SUBSERVICE_UID
&ssuid
,const char *DbName
,const CSSM_NET_ADDRESS
*DbLocation
)
578 : mImpl(new Impl(ssuid
, DbName
, DbLocation
)) {}
580 // Conversion Operators
581 bool operator !() const { return !mImpl
; }
582 operator bool() const { return mImpl
; }
585 bool operator <(const DLDbIdentifier
&other
) const
586 { return mImpl
&& other
.mImpl
? *mImpl
< *other
.mImpl
: mImpl
.get() < other
.mImpl
.get(); }
587 bool operator ==(const DLDbIdentifier
&other
) const
588 { return mImpl
&& other
.mImpl
? *mImpl
== *other
.mImpl
: mImpl
.get() == other
.mImpl
.get(); }
591 const CssmSubserviceUid
&ssuid() const { return mImpl
->ssuid(); }
592 const char *dbName() const { return mImpl
->dbName(); }
593 const CssmNetAddress
*dbLocation() const { return mImpl
->dbLocation(); }
595 RefPointer
<Impl
> mImpl
;
598 // Wrappers for index-related CSSM objects.
600 class CssmDbIndexInfo
: public PodWrapper
<CssmDbIndexInfo
, CSSM_DB_INDEX_INFO
>
603 CssmDbIndexInfo(const CSSM_DB_INDEX_INFO
&attr
)
604 { (CSSM_DB_INDEX_INFO
&)*this = attr
; }
606 CSSM_DB_INDEX_TYPE
indexType() const { return IndexType
; }
607 void indexType(CSSM_DB_INDEX_TYPE indexType
) { IndexType
= indexType
; }
609 CSSM_DB_INDEXED_DATA_LOCATION
dataLocation() const { return IndexedDataLocation
; }
610 void dataLocation(CSSM_DB_INDEXED_DATA_LOCATION dataLocation
)
612 IndexedDataLocation
= dataLocation
;
615 const CssmDbAttributeInfo
&attributeInfo() const
617 return CssmDbAttributeInfo::overlay(Info
);
622 namespace DataWalkers
626 // DLDbIdentifiers don't walk directly because they have Impl structure and use strings.
627 // Happily, they are easily transcribed into a walkable form.
629 struct DLDbFlatIdentifier
{
630 const CssmSubserviceUid
*uid
; // module reference
631 const char *name
; // string name
632 const CssmNetAddress
*address
; // optional network address
634 DLDbFlatIdentifier(const DLDbIdentifier
&ident
)
635 : uid(&ident
.ssuid()), name(ident
.dbName()), address(ident
.dbLocation()) { }
637 operator DLDbIdentifier () { return DLDbIdentifier(*uid
, name
, address
); }
640 template<class Action
>
641 DLDbFlatIdentifier
*walk(Action
&operate
, DLDbFlatIdentifier
* &ident
)
645 walk(operate
, ident
->uid
);
646 walk(operate
, ident
->name
);
648 walk(operate
, ident
->address
);
652 } // end namespace DataWalkers
654 } // end namespace Security
656 #ifdef _CPP_UTILITIES
661 #endif // _H_CDSA_UTILITIES_CSSMDB