C H A P T E R 3
Working with Records
Using records is an essential part of using Open Directory. This chapter covers basic examples of how to interact with records.
Listing Records
The sample code in Listing
The sample code then calls its ListRecord routine and passes to it the node reference (nodeRef) obtained by calling its MyOpenDirNode routine.
The GetRecordList routine calls dsDataBufferAllocate to allocate a buffer for storing the results of calling dsGetRecordList. It also builds three data lists for determining which records to include in the list: one for record names (recNames), one for record types (recTypes), and one for attribute types (attrTypes). It sets recName to kDSRecordsAll (to include all record of any name in the list), recTypes to kDSStdRecordTypeUsers to include standard user type records in the list, and sets attrTypes to kDSAttributesAll to include all attributes of the records in the list.
Then the GetRecordList routine calls dsGetRecordList to fill the data buffer with matching records and their attributes. By specifying eDSExact as the fourth parameter (inPatternMatchType), dsGetRecordList gets records that exactly match the requirements specified by the recNames parameter. By specifying false as the seventh parameter (inAttributeInfoOnly), dsGetRecordList gets attribute values as well as attribute information.
The dsGetRecordList function returns in its recCount parameter the count of the number of records returned in its dataBuffer parameter. Using recCount as a limit, the GetRecordList routine walks through the data buffer calling dsGetRecordEntry to get the record entry information for each record.
The record entry information contains an attribute count that GetRecordList uses as a limit to walk through the record’s attributes, calling dsGetAttributeEntry for each attribute. For each attribute entry, GetRecordList calls dsGetAttributeValue and prints the attribute’s value and its attribute ID.
The GetRecordList routine continues printing attribute values and attribute IDs until dsGetRecordList returns a context parameter that is NULL. It cleans up by calling dsDeallocAttributeEntry and dsDeallocAttributeValueEntry to reclaim the memory associated with the attribute entry and attribute value entry that were created by calling dsGetAttributeEntry and dsGetAttributeValueEntry. It also calls dsDeallocRecordEntry to reclaim the memory associated with the record entry. Before it returns, GetRecordList should call dsDataListDeallocate to reclaim the memory associated with the recNames, recTypes, and attrTypes data lists. It should also call dsDataBufferDeAllocate to deallocate the data buffer.
Listing Records | 33 |