Thesample code then calls its GetRecInfo routine and passes to it the node reference (nodeRef) obtained
bycalling its MyOpenDirNode routine.
TheGetRecInfo routine calls dsDataNodeAllocateString to allocate two data nodes: one named
recNameallocated using the string “admin” and one named recType using the constant
kDSStdRecordTypeGroups.Then the GetRecInfo routine calls dsOpenRecord to open the record whose
nameand record type match recName and recType.
IfdsOpenRecord returns successfully, the GetRecInfo routine calls dsDataNodeAllocateString to
allocatea data node (attrType) containing the constant kDS1AttrPrimaryGroupID. It then calls
dsGetRecordAttributeInfousing attrType to specify which attribute to get information for. The
dsGetRecordAttributeInfofunction stores the attribute’sinformation in a tAttributeEntry structure.
Toclean up, GetRecInfo calls dsDeallocAttributeEntry to deallocate the memory associated with
pAttrInfoand call dsDataNodeDeAllocate to reclaim the memory asociated with attrType,recName,
andrecType.
Whenthe GetRecInfo routine returns, the sample code in Listing 3-2 calls dsCloseDirNode to close the
nodethat it opened in order to get the information about a record’s attribute.
Listing3-2 Gettinginformation about a record’s attribute
void main ( )
{
long dirStatus = eDSNoErr;
tDirNodeReference nodeRef = NULL;
dirStatus = dsOpenDirService( &gDirRef );
if ( dirStatus == eDSNoErr )
{
dirStatus = MyOpenDirNode( &nodeRef );
if ( dirStatus == eDSNoErr )
{
GetRecInfo(nodeRef);
dsCloseDirNode( nodeRef );
}
}
if ( gDirRef != NULL )
{
dirStatus = dsCloseDirService( gDirRef );
}
}
void GetRecInfo ( const tDirNodeReference inDirNodeRef )
{
long dirStatus = eDSNoErr;
tRecordReference recRef = NULL;
tAttributeEntryPtr pAttrInfo = NULL;
tDataNodePtr recName = NULL;
tDataNodePtr recType = NULL;
tDataNodePtr attrType = NULL;
recName = dsDataNodeAllocateString( gDirRef, "admin" );
if ( recName != NULL )
{
recType = dsDataNodeAllocateString( gDirRef, kDSStdRecordTypeGroups);
if ( recType != NULL )
{
dirStatus = dsOpenRecord( inDirNodeRef, recType, recName, &recRef
);
36 Getting Information About a RecordsAttribute
2007-01-08 | ©2007 Apple Inc. All Rights Reserved.
CHAPTER 3
Working with Records