Apple OS X manual Finding a Node

Page 27

C H A P T E R 2

Working with Nodes

} // PrintNodeName

Finding a Node

The sample code in Listing 2-2(page 27) demonstrates how to find the node for a specific pathname. The sample code opens an Open Directory session and gets an Open Directory reference. Then it calls its own FindNodes routine and passes to it the pathname for the node that is to be found (/NetInfo/root).

The FindNodes routine calls dsBuildFromPath to build a data list for the pathname and calls dsDataBufferAllocate to allocate a data buffer in which to store the result of calling dsFindDirNodes. The routine then calls dsFindDirNodes to find the node whose name matches the specified pathname.

Then the FindNodes routine calls dsDataListAllocate to allocate a data list and provides that data list as a parameter when it calls dsGetDirNodeName. The dsGetDirNodeName function copies the node name from the data buffer filled in by dsFindDirNodes to the data list. Then the FindNodes routine calls its PrintNodeName routine to print the node name that was found. The PrintNodeName routine is described in the section Listing 2-1(page 25).

When the PrintNodeName routine returns, the FindNodes routine cleans up by calling dsDataListDeallocate and free() to deallocate the data list.

Listing 2-2Finding the node for a pathname

void main ( )

{

long dirStatus = eDSNoErr;

dirStatus = dsOpenDirService( &gDirRef ); if ( dirStatus == eDSNoErr )

{

FindNodes("/NetInfo/root");

}

if ( gDirRef != NULL )

{

dirStatus = dsCloseDirService( gDirRef );

}

}

void FindNodes ( char* inNodePath ){ bool done = false;

long dirStatus = eDSNoErr; unsigned long index = 0; unsigned long bufferCount = 0; tDataBufferPtr dataBuffer = NULL; tDataListPtr nodeName = NULL; tContextData context = NULL;

nodeName = dsBuildFromPath( gDirRef, inNodePath, "/"); if ( nodeName != NULL )

{

//Allocate a 32k buffer.

dataBuffer = dsDataBufferAllocate( gDirRef, 32 * 1024 ); if ( dataBuffer != NULL )

{

while ( (dirStatus == eDSNoErr) && (done == false) )

{

Finding a Node

27

2007-01-08 © 2007 Apple Inc. All Rights Reserved.

Image 27
Contents Open Directory Programming Guide Apple Inc Contents N T E N T S Figures, Tables, and Listings G U R E S , T a B L E S , a N D L I S T I N G S See Also Organization of This DocumentIntroduction See Also Open Directory Overview Concepts1Flow of an Open Directory request Nodes2An Open Directory request over a network Record Types Search Policies and Search NodesConstant Description Standard attribute for storing a unique ID commonly found Standard Attribute TypesNative Attribute Types AuthenticationBasic Authentication Open Directory Overview Local Windows Hash Authentication Local Cached User Authentication Disabled User Authentication Directory Proxy Directory Native AuthenticationOpen Directory, lookupd, and NetInfo 3lookupd and NetInfo interaction when using SSH Debugging Directory Service Command Line UtilityListing Registered Nodes Working with NodesWorking with Nodes Finding a Node Opening and Closing a Node Authenticating a User to a Node Authenticating using directory native authentication Directory Native AuthenticationWorking with Nodes Working with Nodes Authenticating a User to a Node Listing Records Working with RecordsListing Records Working with Records Getting Information About a Record’s AttributeGetting Information About a Record’s Attribute Setting the Name of a Record Working with Records Listing 3-3Setting the name of a record Creating a Record and Adding an Attribute Void CreateRecord const tDirNodeReference inDirNodeRef Deleting a Record Working with Records Document Revision History Document Revision History
Related manuals
Manual 32 pages 7.58 Kb