Apple OS X manual Opening and Closing a Node

Page 28

C H A P T E R 2

Working with Nodes

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 demonstrates how 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-3Opening a node

void main ( )

{

long dirStatus = eDSNoErr; tDirNodeReference nodeRef = NULL; dirStatus = dsOpenDirService( &gDirRef );

28Opening and Closing a Node

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

Image 28
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 Organization of This Document See AlsoIntroduction See Also Concepts Open Directory OverviewNodes 1Flow of an Open Directory request2An Open Directory request over a network Search Policies and Search Nodes Record TypesConstant Description Standard Attribute Types Standard attribute for storing a unique ID commonly foundAuthentication Native Attribute TypesBasic Authentication Open Directory Overview Local Windows Hash Authentication Local Cached User Authentication Disabled User Authentication Directory Native Authentication Directory ProxyOpen Directory, lookupd, and NetInfo 3lookupd and NetInfo interaction when using SSH Directory Service Command Line Utility DebuggingWorking with Nodes Listing Registered NodesWorking with Nodes Finding a Node Opening and Closing a Node Authenticating a User to a Node Directory Native Authentication Authenticating using directory native authenticationWorking with Nodes Working with Nodes Authenticating a User to a Node Working with Records Listing RecordsListing Records Getting Information About a Record’s Attribute Working with RecordsGetting 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