C H A P T E R 2
Working with Nodes
This chapter provides sample code that shows how to work with nodes. Finding a specific node, opening a session with the node, and authenticating a user to the node are fundamental Open Directory tasks.
Listing Registered Nodes
The sample code in Listing
The ListNodes routine calls dsGetDirNodeCount to get the number of registered nodes. If the number of registered nodes is not zero, ListNodes calls dsDataBufferAllocate to allocate a data buffer and then calls dsGetDirNodeList to fill the buffer with the list of registered node names. The ListNodes routine then calls dsDataListAllocate to allocate a data list and dsGetDirNodeName to fill the data list with registered node names from the data buffer. The ListNodes routine then calls its own PrintNodeName routine to print the node names and passes to it a pointer to the data list.
The PrintNodeName routine calls dsGetPathFromList to get a node name from the data list and prints the name.
When the PrintNodeName routine returns, the ListNodes routine cleans up by calling dsDataListDeallocate and free() to deallocate the data list.
Listing | Listing registered nodes |
|
tDirReference gDirRef = NULL; |
| |
void main ( ) |
| |
{ |
|
|
long dirStatus = eDSNoErr; |
| |
dirStatus = dsOpenDirService( &gDirRef ); |
| |
if ( dirStatus == eDSNoErr ) |
| |
{ |
|
|
ListNodes(); |
| |
} |
|
|
if ( gDirRef != NULL ) |
| |
{ |
|
|
dirStatus = dsCloseDirService( gDirRef ); |
| |
} |
|
|
} |
|
|
void ListNodes ( void ) { |
| |
bool done = false; |
| |
long dirStatus = eDSNoErr; |
| |
unsigned long index = 0; |
| |
unsigned long nodeCount = 0; |
| |
unsigned long bufferCount = 0; |
| |
tDataBufferPtr dataBuffer = NULL; |
| |
tDataListPtr nodeName = NULL; |
| |
Listing Registered Nodes | 25 |