C H A P T E R 3

Working with Records

dirStatus = dsGetRecordList( nodeRef, dataBuffer, &recNames, eDSExact, &recTypes, &attrTypes, false, &recCount, &context );

for ( i = 1; i <= recCount; i++ )

{

dirStatus

= dsGetRecordEntry( nodeRef, dataBuffer,

i,

&attrListRef, &pRecEntry

);

 

for ( j =

1; j <= pRecEntry->fRecordAttributeCount;

j++ )

{

 

 

dirStatus = dsGetAttributeEntry( nodeRef, dataBuffer, attrListRef, j, &valueRef, &pAttrEntry );

for ( k = 1; k <= pAttrEntry->fAttributeValueCount; k++ )

{

dirStatus = dsGetAttributeValue( nodeRef, dataBuffer, k, valueRef, &pValueEntry );

printf( "%s\t- %lu\n", pValueEntry->fAttributeValueData.fBufferData, pValueEntry->fAttributeValueID );

dirStatus = dsDeallocAttributeValueEntry( gDirRef,

pValueEntry );

pValueEntry = NULL;

//Deallocate pAttrEntry, pValueEntry, and pRecEntry

//by calling dsDeallocAttributeEntry,

//dsDeallocAttributeValueEntry, and

//dsDeallocRecordEntry, respectively.

}

dirStatus = dsCloseAttributeValueList( valueRef ); valueRef = NULL;

dirStatus = dsDeallocAttributeEntry( gDirRef, pAttrEntry); pAttrEntry = NULL;

}

dirStatus = dsCloseAttributeList( attrListRef ); attrListRef = NULL;

dirStatus = dsDeallocRecordEntry( gDirRef, pRecEntry ); pRecEntry = NULL;

}

}while (context != NULL); // Loop until all data has been obtained. // Call dsDataListDeallocate to deallocate recNames, recTypes, and // attrTypes.

// Deallocate dataBuffer by calling dsDataBufferDeAllocate. dsDataListDeallocate ( gDirRef, &recNames ); dsDataListDeallocate ( gDirRef, &recTypes ); dsDataListDeallocate ( gDirRef, &attrTypes ); dsDataBufferDeAllocate ( gDirRef, dataBuffer ); dataBuffer = NULL;

}

return dirStatus; } // GetRecordList

Getting Information About a Record’s Attribute

The sample code in Listing 3-2(page 36) demonstrates how to get information about a record’s attribute. The sample code opens an Open Directory session and gets an Open Directory reference. Then it calls its MyOpenDirNode routine and passes to it the address of the node reference (nodeRef) that it has allocated. The MyOpenDirNode routine is described in the section “Opening and Closing a Node” (page 28).

Getting Information About a Record’s Attribute

35

2007-01-08 © 2007 Apple Inc. All Rights Reserved.

Page 35
Image 35
Apple OS X manual Getting Information About a Record’s Attribute, Working with Records