Apple OS X Server User Manual


 
dirStatus = dsFindDirNodes( gDirRef, dataBuffer, nodeName,
eDSContains, &bufferCount, &context );
if ( dirStatus == eDSNoErr )
{
for ( index = 1; index <= bufferCount; index++ )
{
dirStatus = dsGetDirNodeName( gDirRef, dataBuffer,
index, &nodeName );
if ( dirStatus == eDSNoErr )
{
printf( "#%4ld ", index );
PrintNodeName( nodeName );
//Deallocate the nodes.
dirStatus = dsDataListDeallocate( gDirRef, nodeName
);
free(nodeName);
}
else
{
printf("dsGetDirNodeName error = %ld\n", dirStatus
);
}
}
}
done = (context == NULL);
}
dirStatus = dsDataBufferDeAllocate( gDirRef, dataBuffer );
dataBuffer = NULL;
}
}
} // FindNodes
Opening and Closing a Node
The sample code in Listing 2-3 demonstrateshow to open and close 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 prints a prompt that solicits the entry of a node to open and calls scanf() to
get the node’s name. It then calls dsBuildFromPath to build a data list containing the node name that was
entered. It specifies the slash (/) character as the path delimiter. Then the MyOpenDirNode routine calls
dsOpenDirNode to open the node. If the node can be opened, dsOpenDirNode stores in the node reference
parameter a node reference that the application can use in subsequent calls to Open Directory functions
that operate on the open node.
The MyOpenDirNode routine cleans up by calling dsCloseDirNode to close the node that was opened.
Listing 2-3 Opening a node
void main ( )
{
long dirStatus = eDSNoErr;
tDirNodeReference nodeRef = NULL;
dirStatus = dsOpenDirService( &gDirRef );
28
Opening and Closing a Node
2007-01-08 | © 2007 Apple Inc. All Rights Reserved.
CHAPTER 2
Working with Nodes