#include <Security/cssmdb.h>
-#if 0
-// XXX Obsolete
-CSSM_RETURN AddFooToIntelList( void** theIntelListToAddItTo, unsigned long* theNumberOfThingsAlreadyInTheList, const void* theThingToAdd, size_t theSizeOfTheThingToAdd)
-{ // this is to make adding things to Intel LISTs (also called Arrays by the rest of us) easy! We do it everywhere! Join the fun!
- CSSM_RETURN result = CSSM_OK;
- void* theReallocatedBuffer = NULL;
- if( *theIntelListToAddItTo == NULL )
- {
-
- *theIntelListToAddItTo = malloc(theSizeOfTheThingToAdd);
- if(!*theIntelListToAddItTo)
- {
- result = CSSMERR_CSSM_MEMORY_ERROR;
- }
- }
- else
- {
- theReallocatedBuffer = realloc((void*)*theIntelListToAddItTo, (*theNumberOfThingsAlreadyInTheList+1) * (theSizeOfTheThingToAdd) );
- if(!theReallocatedBuffer)
- {
- result = CSSMERR_CSSM_MEMORY_ERROR;
- }
- else
- {
- *theIntelListToAddItTo = theReallocatedBuffer;
- }
- }
-
- if(result == CSSM_OK )
- {
- memcpy( (void*)((char*)*theIntelListToAddItTo+(theSizeOfTheThingToAdd * (*theNumberOfThingsAlreadyInTheList))), theThingToAdd, theSizeOfTheThingToAdd);
- (*theNumberOfThingsAlreadyInTheList)++;
- }
-
- return result;
-}
-#endif
//
// CssmDbAttributeInfo
{
for (uint32 anIndex = 0; anIndex < NumberOfValues; anIndex++)
{
- if (Value[anIndex].Length)
+ if (Value[anIndex].Data)
{
inAllocator.free(Value[anIndex].Data);
- Value[anIndex].Length = 0;
}
+
+ Value[anIndex].Length = 0;
}
inAllocator.free(Value);
ArrayBuilder<CssmDbAttributeData>::clear();
}
+
+
+static bool CompareAttributeInfos (const CSSM_DB_ATTRIBUTE_INFO &a, const CSSM_DB_ATTRIBUTE_INFO &b)
+{
+ // check the format of the names
+ if (a.AttributeNameFormat != b.AttributeNameFormat)
+ {
+ return false;
+ }
+
+ switch (a.AttributeNameFormat)
+ {
+ case CSSM_DB_ATTRIBUTE_NAME_AS_STRING:
+ {
+ return strcmp (a.Label.AttributeName, b.Label.AttributeName) == 0;
+ }
+
+ case CSSM_DB_ATTRIBUTE_NAME_AS_OID:
+ {
+ if (a.Label.AttributeOID.Length != b.Label.AttributeOID.Length)
+ {
+ return false;
+ }
+
+ return memcmp (a.Label.AttributeOID.Data, b.Label.AttributeOID.Data, a.Label.AttributeOID.Length) == 0;
+ }
+
+
+ case CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER:
+ {
+ return a.Label.AttributeID == b.Label.AttributeID;
+ }
+ }
+
+ return true; // just to keep the compiler from complaining
+}
+
+
+
+CssmDbAttributeData* CssmAutoDbRecordAttributeData::findAttribute (const CSSM_DB_ATTRIBUTE_INFO &info)
+{
+ // walk through the data, looking for an attribute of the same type
+ unsigned i;
+ for (i = 0; i < size (); ++i)
+ {
+ CssmDbAttributeData& d = at (i);
+ CSSM_DB_ATTRIBUTE_INFO &inInfo = d.info ();
+
+ if (CompareAttributeInfos (info, inInfo))
+ {
+ return &d;
+ }
+ }
+
+ // found nothing?
+ return NULL;
+}
+
+
+
+CssmDbAttributeData& CssmAutoDbRecordAttributeData::getAttributeReference (const CSSM_DB_ATTRIBUTE_INFO &info)
+{
+ // Either find an existing reference to an attribute in the list, or make a new one.
+ CssmDbAttributeData *anAttr = findAttribute (info);
+ if (anAttr) // was this already in the list?
+ {
+ // clean it up
+ anAttr->deleteValues (mValueAllocator);
+ }
+ else
+ {
+ // make a new one
+ anAttr = &add();
+ }
+
+ return *anAttr;
+}
+
+
+
CssmDbAttributeData &
CssmAutoDbRecordAttributeData::add(const CSSM_DB_ATTRIBUTE_INFO &info)
{
- CssmDbAttributeData &anAttr = add();
+ CssmDbAttributeData& anAttr = getAttributeReference (info);
anAttr.info(info);
return anAttr;
}
CssmDbAttributeData &
CssmAutoDbRecordAttributeData::add(const CSSM_DB_ATTRIBUTE_INFO &info, const CssmPolyData &value)
{
- CssmDbAttributeData &anAttr = add();
+ CssmDbAttributeData &anAttr = getAttributeReference (info);
anAttr.set(info, value, mValueAllocator);
return anAttr;
}
// CssmAutoQuery
//
CssmAutoQuery::CssmAutoQuery(const CSSM_QUERY &query, CssmAllocator &allocator)
-: ArrayBuilder<CssmSelectionPredicate>(static_cast<CssmSelectionPredicate *>(SelectionPredicate),
+: ArrayBuilder<CssmSelectionPredicate>(CssmSelectionPredicate::overlayVar(SelectionPredicate),
NumSelectionPredicates,
query.NumSelectionPredicates, allocator)
{