4.8 Positioning the Iterator with Typedown: Example
/* itrtypdn.c
Example of NDS 8 Iterator Typedown and GetCurrent functions. */
#include <stdio.h>
#include <stdlib.h>
#include <nwnet.h>
#include <nwcalls.h>
#define BASECLASS "User"
void main(int argc, char *argv[])
{
NWDSContextHandle context =
(NWDSContextHandle)ERR_CONTEXT_CREATION;
nstr8 strAbbreviatedName[MAX_DN_CHARS+1];
pBuf_T pb = NULL;
NWDSCCODE ccode;
nuint32 flags;
nuint32 iter=0;
nint32 iterHandle = -1;
nstr8 objName[MAX_DN_CHARS+1];
nuint32 objCount, attrCount;
Object_Info_T objectInfo;
/* Check arguments */
if(argc != 3)
{
printf("\nUsage: itrtypdn <base object> <typedown string>");
printf("\nExample: itrtypdn myou.myorg d");
exit(1);
}
/* Initialize NWCalls and unicode tables */
ccode = NWCallsInit(NULL,NULL);
if(ccode) exit(1);
/* Create NDS Context */
ccode = NWDSCreateContextHandle(&context);
if(ccode) exit(1);
/* Set flags to get object names in typeless format. */
NWDSGetContext(context, DCK_FLAGS, &flags);
flags |= DCV_TYPELESS_NAMES;
NWDSSetContext(context, DCK_FLAGS, &flags);
printf("itrtypdn: Sample program for NDS 8 Iterator List\n");
printf("Container to list: %s\n", argv[1]);
printf("Typedown string: %s\n", argv[2]);
/* Convert the directory name (passed in as first arg) to its
shortest form relative to the name context */
ccode = NWDSAbbreviateName(context, argv[1], strAbbreviatedName);
if(ccode) goto error;
/* Allocate the output buffer. */
ccode = NWDSAllocBuf(MAX_MESSAGE_LEN, &pb);
if(ccode) goto error;
/* ———— Create the Iterator ————-
A list iterator is ordered first by Base Class,
then by RDN within a base class.
*/
ccode = NWDSItrCreateList(
context, /* context for this search */
strAbbreviatedName, /* container to search */
BASECLASS, /* class name filter */
NULL, /* subordinate name filter */
DS_ITR_ANY_SERVER, /* scalability requirement */
0, /* no timeout */
&iter); /* returned Iterator ptr */
if (ccode)
goto error;
/* For a List Iterator the BaseClass,RDN index is used. Typedown
on this index uses the RDN field. The iterator should thus be
restricted to a single baseclass.
*/
ccode = NWDSItrTypeDown(
iter, /* Iterator Ptr */
NULL, /* Reserved */
argv[2], /* Typedown string. RDN value */
flags, /* Context flags indicate Byte mode */
0); /* Timeout */
if (ccode) goto error;
/* Get the object name at the current position. */
ccode = NWDSItrGetCurrent(iter, &iterHandle, pb);
if (ccode == ERR_EOF_HIT)
printf("\nNo objects in list were greater or equal to
typedown string.\n\ Iterator is positioned at EOF\n");
if (ccode) goto error;
ccode = NWDSGetObjectCount (context,pb,&objCount);
if (ccode) goto error;
ccode = NWDSGetObjectName (context,
pb,
objName,
&attrCount,
&objectInfo);
if (ccode) goto error;
printf("\nTyped down to object: %s\n", objName);
/* Clean up, normal or error termination. */
error:
printf("\n\nccode = %d.",ccode);
if (iter)
NWDSItrDestroy(iter); /* Destroy the Iterator when done. */
if (pb)
NWDSFreeBuf(pb);
NWDSFreeContext(context);
}