Apple OS X Server User Manual


 
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 3-1 (page 34) demonstrates how to list all records in a node. 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).
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 informationcontains an attribute countthat 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
2007-01-08 | © 2007 Apple Inc. All Rights Reserved.
CHAPTER 3
Working with Records