home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xdsa1.exe
/
DSACCESS.C
next >
Wrap
Text File
|
1994-10-21
|
31KB
|
916 lines
/*****************************************************************************
** File: dsaccess.c
**
** Description:
** Contains source for DSSearchOpen, DSSearchSeek, DSRead, and DSClose.
** These functions provide a streams type interface to NDS x.500
** compliant calls, simplifying searches for information in the directory.
**
** Disclaimer:
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** Programmers:
**
** Ini Who Firm
** ------------------------------------------------------------------------
** MDO Mark D. Oberg Novell Developer Support
**
**
** History:
**
** When Who What
** ------------------------------------------------------------------------
** 09-22-94 MDO Begin
** 10-03-94 MDO Tested
**
*/
/*****************************************************************************
** Include files and macro definitions
*/
/*-------------------------------------------------------------------------
** ANSI Includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*-------------------------------------------------------------------------
** NetWare Includes
*/
#include <nwdsapi.h>
#include <nwdsmisc.h>
#include <nwdsdc.h>
#include <nwconn.h>
#include <nwenvrn.h>
#include <nwcntask.h>
/*-------------------------------------------------------------------------
** SRCHMAN
*/
#include "dsaccess.h"
/*****************************************************************************
** Function Prototypes used only in this module.
*/
NWDSCCODE DSAllocAndInitAttrNamesBuffer(DS_HANDLE *dsHandle, char **attrNames);
NWDSCCODE _DSSearch(DS_HANDLE *dsHandle);
NWDSCCODE _DSRead(DS_HANDLE *dsHandle);
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** DS_HANDLE *DSSearchOpen(
** NWDSContextHandle context,
** char *attrNames[],
** TOKEN_ENTRY tokens[]);
**
** Parameters:
** context
** input-Provides a directory services context for calls to use.
**
** attrNames[]
** input-Tells DSSearch what attributes to return during the
** search. Initialize the last entry with NULL value to
** terminate the array. If NULL is passed in, all attributes
** will be returned on subsequest DSSearch and DSRead calls.
**
** tokens[]
** input-Describes the expression tree to be used to select
** what objects information will be returned. Each entry
** will be used as parameters to a call to NWDSAddFilterToken.
** The last entry should be a FTOK_END, this terminates the
** array as well as the expression tree.
**
** Return Value:
** A pointer to a DS_HANDLE which includes all buffers and
** interation handles setup to execute a DSSearch call.
** NULL if unsuccessful.
**
** Remarks: DSClose is called after the handle is no longer needed.
**
*/
DS_HANDLE *DSSearchOpen(NWDSContextHandle cx,
char **attrNames,
TOKEN_ENTRY *tokent)
{
NWDSCCODE ccode;
NWCOUNT tokenCount; /* 1-4G */
DS_HANDLE *dsHandle;
NWDS_FILTER_CURSOR *cur;
/*-------------------------------------------------------------------------
** calculate size and allocate the buffers first.
*/
if(NULL==(dsHandle=malloc(sizeof(DS_HANDLE))))
goto Exit0;
/*-------------------------------------------------------------------------
** Save context in handle because the same context needs to be used
** in setting up filters and doing the NWDSSearch.
*/
dsHandle->context=cx;
dsHandle->countObjectsToSearch=0; /* not currently used. */
dsHandle->handleType=DSV_SEARCH; /* doing NWDSSearch*/
dsHandle->objectInfoSize=DEFAULT_MESSAGE_LEN; /* 4K */
/*-------------------------------------------------------------------------
** attrNames specify what attribute names values are wanted to be returned
** during a search. If none are specified DSSearch will return names
** for all values.
*/
ccode=DSAllocAndInitAttrNamesBuffer(dsHandle, attrNames);
if(ccode)
goto Exit1;
/*-------------------------------------------------------------------------
** objectInfo holds the object names, attribute names and attribute
** values returned by a NWDSSearch or NWDSRead. objectInfo starts
** out at a default size of 4K. If a value can't fit into the 4K buffer
** during a search or read, the buffer should be re-allocated until it
** fits. Values have a maximum size of 64K, (Streams is an exception to
** this and is only limited by disk space.) If NWDSSearch or NWDSRead
** returns ERR_INSUFFICIENT_BUFFER, the buffer should be reallocated and
** the search or read attempted again until the buffer reaches a size of
** 64K. At that point something else must be wrong.
*/
ccode=NWDSAllocBuf(
/* size_t size, */ dsHandle->objectInfoSize,
/* Buf_T NWFAR * NWFAR *buf */ &dsHandle->objectInfo );
if(ccode)
goto Exit2;
/*-------------------------------------------------------------------------
** Allocate and initialize the filter for search.
*/
ccode=NWDSAllocBuf(
/* size_t size, */ DEFAULT_MESSAGE_LEN , /* 4K, modify later to be optimized. */
/* Buf_T NWFAR * NWFAR *buf */ &dsHandle->filter );
if(ccode)
goto Exit3;
ccode=NWDSInitBuf(
/* NWDSContextHandle context, */ cx,
/* uint32 operation, */ DSV_SEARCH_FILTER,
/* Buf_T NWFAR *buf */ dsHandle->filter );
if(ccode)
goto Exit4;
if(tokent)
{
ccode=NWDSAllocFilter(&cur);
if(ccode)
goto Exit4;
/*----------------------------------------------------------------------
** put in the filter tokens.
*/
tokenCount=0;
do
{
ccode = NWDSAddFilterToken(cur, tokent[tokenCount].tok,
tokent[tokenCount].val, tokent[tokenCount].syn);
if(ccode)
goto Exit5;
}while(FTOK_END!=tokent[tokenCount++].tok);
}
else
goto Exit4;
/*-------------------------------------------------------------------------
** Transfer the filter tree to the filter buffer. This frees filter
** cursor.
*/
ccode=NWDSPutFilter(cx, dsHandle->filter, cur, NULL);
if(ccode)
goto Exit4; /* do not Free Filter if failure on NWDSPutFilter */
return(dsHandle); /* Success! */
Exit5:
NWDSFreeFilter(cur,NULL);
Exit4:
NWDSFreeBuf(dsHandle->filter);
Exit3:
NWDSFreeBuf(dsHandle->objectInfo);
Exit2:
if(dsHandle->attrNames)
NWDSFreeBuf(dsHandle->attrNames);
Exit1:
free(dsHandle);
Exit0:
return(NULL); /* Failure.... */
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** NWDSCCODE DSSearchSeek(
** DS_HANDLE *dsHandle,
** char *baseObjectName,
** NWDS_SEARCH_SCOPE scope,
** NWFLAGS searchAliases,
** NWDS_TYPE infoType );
** Parameters:
** dsHandle
** input-takes the search handle returned by a call to
** DSSeekOpen.
**
** baseObjectName
** input-specifies where to start the search from. Can be a
** container or a specific object.
**
** scope
** input-specifies how to search from the base object. Options
** are DS_SEARCH_ENTRY (searches the baseObjectName only),
** DS_SEARCH_SUBORDINATES (searches the baseObjectName and
** immediate subordinates if baseObjectName is a container), or
** DS_SEARCH_SUBTREEE (searches baseObjectNameand all objects
** below the baseObjectName.)
**
** searchAliases
** input-accepts a value of TRUE or FALSE. TRUE tells NWDSSearch
** to continue searches in the container of aliased objects.
** FALSE is the recommeded setting to avoid possible
** circular searches.
**
** infoType
** input-accepts a value of 0 or 1. 0 specifies to return
** attribute names only. 1 specifies to return attribute
** names and values. Attribute names and values allowed
** to be returned are described in the DSSearchOpen call by
** the attrNames field.
**
** Return Value:
** DSSearchSeek returns zero if no error, otherwise returns
** ccode from the NWDSSearch call, consult netware error
** codes for interpretation.
**
** Remarks: DSSearchSeek causes NDS to be queried and receives object names, object
** information, attribute names and attribute values in a buffer
** that may be read by DSRead. Information contained in the buffer
** after a DSSeek call meets the search criteria specified in the
** DSSearchOpen's tokens field. Only attribute names and values
** specified in the DSSearchOpen's attrNames field are returned. A
** NULL value passed into the DSSearchOpen's attrNames field specifies
** to return all attribute names and values for all attributes of a
** found object.
**
**
*/
NWDSCCODE DSSearchSeek(
DS_HANDLE *dsHandle,
char *baseObjectName,
NWDS_SEARCH_SCOPE scope,
NWFLAGS searchAliases,
NWDS_TYPE infoType )
{
/*-------------------------------------------------------------------------
** save this information for future interations of search.
*/
strcpy(dsHandle->baseObjectName,baseObjectName);
dsHandle->scope=scope;
dsHandle->searchAliases=searchAliases;
dsHandle->infoType=infoType;
dsHandle->iteration=NO_MORE_ITERATIONS; /* setup for first NWDSSearch */
dsHandle->readState=NEW_SEARCH;
return(_DSSearch(dsHandle));
}
/*****************************************************************************
** used in DSSearchSeek and DSRead.
*/
NWDSCCODE _DSSearch(DS_HANDLE *dsHandle)
{
NWDSCCODE ccode;
do
{
ccode=NWDSSearch(
/* NWDSContextHandle context, */ dsHandle->context,
/* char NWFAR *baseObjectName, */ dsHandle->baseObjectName,
/* int scope, */ dsHandle->scope,
/* uint8 searchAliases, */ dsHandle->searchAliases,
/* Buf_T NWFAR *filter, */ dsHandle->filter,
/* uint32 infoType, */ dsHandle->infoType,
/* uint8 allAttrs, */ dsHandle->attrNames ? FALSE : TRUE,
/* Buf_T NWFAR *attrNames, */ dsHandle->attrNames,
/* int32 NWFAR *iterationHandle, */ &dsHandle->iteration,
/* int32 countObjectsToSearch, */ dsHandle->countObjectsToSearch,
/* int32 NWFAR *countObjectsSearched, */ &dsHandle->countObjectsSearched,
/* Buf_T NWFAR *objectInfo */ dsHandle->objectInfo );
if(ERR_INSUFFICIENT_BUFFER==ccode)
{
dsHandle->objectInfoSize<<=1; /* double buffer size */
/*-------------------------------------------------------------------
** max attribute value size is 64k-room for object and attribute
** name. something else must be wrong.
*/
if(0x10000<dsHandle->objectInfoSize)
return(ERR_SYSTEM_FAILURE);
free(dsHandle->objectInfo); /* return and will alloc again */
ccode=NWDSAllocBuf(
/* size_t size, */ dsHandle->objectInfoSize,
/* Buf_T NWFAR * NWFAR *buf */ &dsHandle->objectInfo );
if(ccode)
dsHandle->objectInfo=NULL; /* if not alloced, let DSClose know it */
else
ccode=ERR_INSUFFICIENT_BUFFER; /* success, try DSSearch again */
}
}while (ERR_INSUFFICIENT_BUFFER==ccode);
return(ccode); /* normal exit may be an error */
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** DS_HANDLE *DSReadOpen(
** NWDSContextHandle context,
** char *attrNames[] );
**
** Parameters:
** context
** input-Provides a directory services context for calls to use.
**
** attrNames[]
** input-Tells DSSearch what attributes to return during the
** search. Initialize the last entry with NULL value to
** terminate the array.
**
** Return Value:
** A pointer to a DS_HANDLE which includes all buffers and
** interation handles setup to execute a NWDSRead.
** NULL if unsuccessful.
**
** Remarks: DSClose is called after the handle is no longer needed.
**
*/
DS_HANDLE *DSReadOpen(NWDSContextHandle cx,
char **attrNames)
{
NWDSCCODE ccode;
DS_HANDLE *rHand;
/*-------------------------------------------------------------------------
** Allocate DS_HANDLE
*/
if(NULL==(rHand=malloc(sizeof(DS_HANDLE))))
goto Exit0;
/*-------------------------------------------------------------------------
** Save context in handle because the same context needs to be used
** in setting up filters and doing the NWDSSearch.
*/
rHand->context=cx;
rHand->objectInfoSize=DEFAULT_MESSAGE_LEN; /* 4K Initial size */
rHand->handleType=DSV_READ; /* doing an NWDSRead */
/*-------------------------------------------------------------------------
** Allocate and initialize the attr names buffer.
*/
ccode=DSAllocAndInitAttrNamesBuffer( rHand, attrNames);
if(ccode)
goto Exit1;
/*-------------------------------------------------------------------------
** objectInfo holds the object names, attribute names and attribute
** values returned by a NWDSSearch or NWDSRead. objectInfo starts
** out at a default size of 4K. If a value can't fit into the 4K buffer
** during a search or read, the buffer should be re-allocated until it
** fits. Values have a maximum size of 64K, (Streams is an exception to
** this and is only limited by disk space.) If NWDSSearch or NWDSRead
** returns ERR_INSUFFICIENT_BUFFER, the buffer should be reallocated and
** the search or read attempted again until the buffer reaches a size of
** 64K. At that point something else must be wrong.
*/
ccode=NWDSAllocBuf(
/* size_t size, */ rHand->objectInfoSize,
/* Buf_T NWFAR * NWFAR *buf */ &rHand->objectInfo );
if(ccode)
goto Exit2;
return(rHand);
Exit2:
NWDSFreeBuf(rHand->attrNames);
Exit1:
free(rHand);
Exit0:
return(NULL);
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** NWDSCCODE DSReadSeek(
** DS_HANDLE *dsHandle,
** char *objectName,
** NWDS_TYPE infoType );
** Parameters:
** dsHandle
** input-takes the search handle returned by a call to
** DSSeekOpen.
**
** objectName
** input-specifies which object to read.
**
** infoType
** input-accepts a value of 0 or 1. 0 specifies to return
** attribute names only. 1 specifies to return attribute
** names and values. Attribute names and values allowed
** to be returned are described in the DSSearchOpen call by
** the attrNames field.
**
** Return Value:
** DSReadSeek returns zero if no error, otherwise returns
** ccode from the NWDSRead call, consult netware error
** codes for interpretation.
**
** Remarks: DSReadSeek causes NDS to be queried and receives object name, object
** information, attribute names and attribute values in a buffer
** that may be read by DSRead. Only attribute names and values
** specified in the DSReadOpen's attrNames field are returned. A
** NULL value passed into the DSReadOpen's attrNames field specifies
** to return all attribute names and values for all attributes of a
** found object.
**
**
*/
NWDSCCODE DSReadSeek(
DS_HANDLE *dsHandle,
char *objectName,
NWDS_TYPE infoType )
{
/*-------------------------------------------------------------------------
** save this information for future interations of NWDSRead.
*/
strcpy(dsHandle->baseObjectName,objectName);
dsHandle->infoType=infoType;
dsHandle->iteration=NO_MORE_ITERATIONS; /* setup for first NWDSSearch */
dsHandle->readState=NEW_READ;
return(_DSRead(dsHandle));
}
/*****************************************************************************
** used in DSReadSeek and DSRead
*/
NWDSCCODE _DSRead(DS_HANDLE *dsHandle)
{
NWDSCCODE ccode;
do
{
ccode=NWDSRead(
/* NWDSContextHandle context, */ dsHandle->context,
/* char NWFAR *objectName, */ dsHandle->baseObjectName,
/* uint32 infoType, */ dsHandle->infoType,
/* uint8 allAttrs, */ dsHandle->attrNames ? FALSE : TRUE,
/* Buf_T NWFAR *attrNames, */ dsHandle->attrNames,
/* int32 NWFAR *iterationHandle, */ &dsHandle->iteration,
/* Buf_T NWFAR *objectInfo */ dsHandle->objectInfo );
if(ERR_INSUFFICIENT_BUFFER==ccode)
{
dsHandle->objectInfoSize<<=1; /* double buffer size */
/*-------------------------------------------------------------------
** max attribute value size is 64k-room for object and attribute
** name. something else must be wrong.
*/
if(0x10000<dsHandle->objectInfoSize)
return(ERR_SYSTEM_FAILURE);
free(dsHandle->objectInfo); /* return and will alloc again */
ccode=NWDSAllocBuf(
/* size_t size, */ dsHandle->objectInfoSize,
/* Buf_T NWFAR * NWFAR *buf */ &dsHandle->objectInfo );
if(ccode)
dsHandle->objectInfo=NULL; /* tell DSClose not alloc'ed. */
else
ccode=ERR_INSUFFICIENT_BUFFER; /* success, try search again */
}
}while (ERR_INSUFFICIENT_BUFFER==ccode);
return(ccode); /* normal exit may be an error */
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** DS_HANDLE *DSListOpen(
** NWDSContextHandle context );
**
** Parameters:
** context
** input-Provides a directory services context for calls to use.
**
** attrNames[]
** input-Tells DSSearch what attributes to return during the
** search. Initialize the last entry with NULL value to
** terminate the array.
**
** Return Value:
** A pointer to a DS_HANDLE which includes all buffers and
** interation handles setup to execute a NWDSRead.
** NULL if unsuccessful.
**
** Remarks: DSClose is called after the handle is no longer needed.
**
*/
DS_HANDLE *DSListOpen(NWDSContextHandle cx)
{
NWDSCCODE ccode;
DS_HANDLE *dsHandle;
/*-------------------------------------------------------------------------
** Allocate DS_HANDLE
*/
if(NULL==(dsHandle=malloc(sizeof(DS_HANDLE))))
goto Exit0;
/*-------------------------------------------------------------------------
** Save context in handle because the same context needs to be used
** in setting up filters and doing the NWDSSearch.
*/
dsHandle->context=cx;
dsHandle->objectInfoSize=DEFAULT_MESSAGE_LEN; /* 4K Initial size */
dsHandle->handleType=DSV_LIST; /* doing an NWDSList */
/*-------------------------------------------------------------------------
** objectInfo holds the object names, attribute names and attribute
** values returned by a NWDSSearch or NWDSRead. objectInfo starts
** out at a default size of 4K. If a value can't fit into the 4K buffer
** during a search or read, the buffer should be re-allocated until it
** fits. Values have a maximum size of 64K, (Streams is an exception to
** this and is only limited by disk space.) If NWDSSearch or NWDSRead
** returns ERR_INSUFFICIENT_BUFFER, the buffer should be reallocated and
** the search or read attempted again until the buffer reaches a size of
** 64K. At that point something else must be wrong.
*/
ccode=NWDSAllocBuf(
/* size_t size, */ dsHandle->objectInfoSize,
/* Buf_T NWFAR * NWFAR *buf */ &dsHandle->objectInfo );
if(ccode)
goto Exit1;
return(dsHandle);
Exit1:
free(dsHandle);
Exit0:
return(NULL);
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** NWDSCCODE DSListSeek(
** DS_HANDLE *dsHandle,
** char *objectName );
** Parameters:
** dsHandle
** input-takes the search handle returned by a call to
** DSSeekOpen.
**
** objectName
** input-specifies which object to read.
**
** Return Value:
** DSListSeek returns zero if no error, otherwise returns
** ccode from the NWDSList call, consult netware error
** codes for interpretation.
**
** Remarks: DSListSeek causes NDS to be queried and receives object names
** for objects found immediately subordinate to objectName.
**
*/
NWDSCCODE DSListSeek(
DS_HANDLE *dsHandle,
char *objectName)
{
/*-------------------------------------------------------------------------
** save this information for future interations of NWDSRead.
*/
strcpy(dsHandle->baseObjectName,objectName);
dsHandle->iteration=NO_MORE_ITERATIONS; /* setup for first NWDSSearch */
dsHandle->readState=NEW_LIST;
dsHandle->attrNames=NULL; /* tell DSClose not to try and free this. */
return(_DSList(dsHandle));
}
/*****************************************************************************
** used in DSReadSeek and DSRead
*/
NWDSCCODE _DSList(DS_HANDLE *dsHandle)
{
NWDSCCODE ccode;
ccode=NWDSList(
/* NWDSContextHandle context, */ dsHandle->context,
/* char NWFAR *objectName, */ dsHandle->baseObjectName,
/* int32 NWFAR *iterationHandle, */ &dsHandle->iteration,
/* Buf_T NWFAR *objectInfo */ dsHandle->objectInfo );
return(ccode); /* normal exit may be an error */
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** READ_DATA DSRead(
** DS_HANDLE *dsHandle,
** );
**
**
** Return Value:
** EOF -1 if no data to read.
** NULL if critical error occured during call.
** Pointer to a allocated READ_DATA structure.
**
** Remarks:
** DSList is called iteratively until it returns EOF. DSList
** allocates and fills a READ_DATA structure with an object,
** attribute, or attribute value. READ_DATA strucutures should
** be freed by a call to the regular free() call. The READ_DATA's
** readType indicates what type of information is returned.
** Possible data types are OBJECT, ATTR, or ATTR_VALUE for object,
** attribute or attribute value. Objects appear before
** any attributes. Attributes may appear after an object,
** attribute or attribute value. Attribute values appear
** after attributes or other attribute values. READ_DATA
** provides a union that allows for reading the contents
** respective to their type. The union fields are selected
** by addressing the object, attr, and attrVal fields
** (refer to search.h for a definition of the READ_DATA
** structure.
**
*/
READ_DATA *DSRead(DS_HANDLE *dsHandle)
{
READ_DATA *readData;
NWSIZE attrValSize;
NWDSCCODE ccode;
RE_EVALUATE_SWITCH:
switch (dsHandle->readState)
{
case NEW_SEARCH:
case NEW_LIST:
ccode=NWDSGetObjectCount(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->objectInfo,
/* uint32 NWFAR *objectCount */ &dsHandle->objectCount );
if(ccode)
goto Exit1;
case READ_OBJECT_NAME:
NEXT_READ_OBJECT_NAME: /* Easy to jump here if no attrValue */
if(dsHandle->objectCount--)
{
if(NULL==(readData=malloc(sizeof(READ_DATA))))
return(NULL);
ccode=NWDSGetObjectName(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->objectInfo,
/* char NWFAR *objectName,*/ &readData->read.object.name,
/* uint32 NWFAR *attrCount, */ &dsHandle->attrCount,
/* Object_Info_T NWFAR *objectInfo */ &readData->read.object.objectInfo );
if(ccode)
goto Exit1;
dsHandle->readState=READ_ATTR_NAME;
readData->readType=OBJECT;
}
else /* exit the function EOF meaning no more to read. */
{
/*----------------------------------------------------------------
** add here iterative NWDSSearch call.
*/
if(NO_MORE_ITERATIONS==dsHandle->iteration)
return((void *)EOF);
else
{
switch(dsHandle->handleType)
{
case DSV_SEARCH:
ccode=_DSSearch(dsHandle);
dsHandle->readState=NEW_SEARCH;
break;
case DSV_READ:
ccode=_DSRead(dsHandle);
dsHandle->readState=NEW_READ;
break;
case DSV_LIST:
ccode=_DSList(dsHandle);
dsHandle->readState=NEW_LIST;
}
if(ccode)
return(NULL);
else
goto RE_EVALUATE_SWITCH; /* new buffer to get stuff from */
}
}
break;
case NEW_READ:
ccode=NWDSGetAttrCount(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->objectInfo,
/* uint32 NWFAR *attrCount */ &dsHandle->attrCount );
dsHandle->objectCount=0; /* read only returns one object name */
case READ_ATTR_NAME:
if(dsHandle->attrCount--)
{
if(NULL==(readData=malloc(sizeof(READ_DATA))))
return(NULL);
ccode=NWDSGetAttrName(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->objectInfo,
/* char NWFAR *attrName, */ &readData->read.attr.name,
/* uint32 NWFAR *attrValCount, */ &dsHandle->attrValCount,
/* uint32 NWFAR *syntaxID */ &readData->read.attr.syntaxID);
if(ccode)
goto Exit1;
dsHandle->syntaxID=readData->read.attr.syntaxID;
dsHandle->readState=READ_ATTR_VALUE;
readData->readType=ATTR;
}
else
goto NEXT_READ_OBJECT_NAME;
break;
case READ_ATTR_VALUE:
if(dsHandle->attrValCount--)
{
ccode=NWDSComputeAttrValSize(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->objectInfo,
/* uint32 syntaxID, */ dsHandle->syntaxID,
/* uint32 NWFAR *attrValSize */ &attrValSize );
if(ccode)
goto Exit1;
if(NULL==(readData=malloc(sizeof(READ_DATA)+attrValSize)))
return(NULL);
/*----------------------------------------------------------------
** initialize value to point to attrValue area of buffer.
*/
readData->read.attrVal.value=readData+1;
ccode=NWDSGetAttrVal(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->objectInfo,
/* uint32 syntaxID, */ dsHandle->syntaxID,
/* void NWFAR *attrVal */ readData->read.attrVal.value);
if(ccode)
goto Exit1;
readData->read.attrVal.syntaxID=dsHandle->syntaxID;
readData->readType=ATTR_VALUE;
}
else
goto NEXT_READ_OBJECT_NAME;
}
return(readData); /* normal exit */
Exit1: /* critical error exit */
free(readData);
return(NULL);
}
/*****************************************************************************
** Syntax: #include <dsaccess.h>
**
** void DSClose( DS_HANDLE *dsHandle );
**
**
** Remarks: Deallocates all memory allocated by DSSearchOpen.
**
*/
void DSClose( DS_HANDLE *dsHandle )
{
if(DSV_SEARCH == dsHandle->handleType)
NWDSFreeBuf(dsHandle->filter);
if(dsHandle->attrNames)
NWDSFreeBuf(dsHandle->attrNames);
if(dsHandle->objectInfo)
NWDSFreeBuf(dsHandle->objectInfo);
free(dsHandle);
}
/*****************************************************************************
** Syntax: prototype in this module.
**
** NWDSCCODE DSAllocAndInitAttrNamesBuffer(
** DS_HANDLE *dsHandle,
** char **attrNames);
**
** Parameters:
** dsHandle
** input/output-Uses handleType to initialize the attrNames
** buffer. Stores an attrNames buffer in the handle.
**
** attrNames[]
** input-Tells NWDSSearch and NWDSRead what attributes to return
** in the objectInfo buffer. Initialize the last entry
** with NULL value to terminate the array.
**
** Return Value:
** A completion code which correcponds to any NWDS calls that
** might have failed.
**
** Remarks: DSClose takes care of freeing the attrNames buffer when the handle
** is closed.
**
*/
NWDSCCODE DSAllocAndInitAttrNamesBuffer(DS_HANDLE *dsHandle, char **attrNames)
{
NWDSCCODE ccode;
NWCOUNT nameCount;
/*-------------------------------------------------------------------------
** attrNames specify what attribute names values are wanted to be returned
** during a search. If none are specified DSSearch will return names
** for all values.
*/
if(attrNames)
{
for(nameCount=0;attrNames[nameCount];nameCount++); /* list is delimited by a NULL */
ccode=NWDSAllocBuf(
/* size_t size, */ sizeof(NWDS_BUFFER)+MAX_SCHEMA_NAME_CHARS*nameCount, /*room for names*/
/* Buf_T NWFAR * NWFAR *buf */ &dsHandle->attrNames );
if(ccode)
goto Exit0;
ccode=NWDSInitBuf(
/* NWDSContextHandle context, */ dsHandle->context,
/* uint32 operation, */ dsHandle->handleType,
/* Buf_T NWFAR *buf */ dsHandle->attrNames);
if(ccode)
goto Exit1;
/*----------------------------------------------------------------------
** put in the return attr names.
*/
for(nameCount=0;attrNames[nameCount];nameCount++)
{
ccode=NWDSPutAttrName(
/* NWDSContextHandle context, */ dsHandle->context,
/* Buf_T NWFAR *buf, */ dsHandle->attrNames,
/* char NWFAR *attrName */ attrNames[nameCount] );
if(ccode)
goto Exit1;
}
}
else
dsHandle->attrNames=NULL; /* no specified attributes will be used. */
return(EXIT_SUCCESS); /* SUCCESS */
Exit1:
NWDSFreeBuf(dsHandle->attrNames);
Exit0:
return(ccode);
}