read.c

This is an example of doing a synchronous read operation, and how to process the returned results.

To compile this example on Unix:

cc -I /opt/isode/include -c read.c 

To compile this example on Windows:

cl /nologo /I C:\Progra~1\Isode\include /c read.c

To link this example on Unix:

cc -o read read.o -L/opt/isode/lib \
    -ldua -lisode -libase -lldap -llber \
    -lssl -lcrypto -lpthread

To link this example on Windows:

cl /nologo /o read.exe read.obj \
    C:\Progra~1\Isode\bin\libdua.lib
/*
* Copyright (c) 2005-2009, Isode Limited, London, England.
* All rights reserved.
*
* Acquisition and use of this software and related materials for any
* purpose requires a written licence agreement from Isode Limited,
* or a written licence from an organisation licenced by Isode Limited
* to grant such a licence.
*/
#include <stdio.h>
int main ( void )
{
DS_Session *ds = NULL;
DS_Indication *di = NULL;
const DS_EntryList *el = NULL;
const DS_Entry *e = NULL;
const DS_AttrList *al = NULL;
const DS_Attr *a = NULL;
DS_DN *dn = NULL;
const char *attrs[] = { "objectClass", "cn", "manager", NULL };
DS_Status status;
status = DS_Initialize();
status = DS_String2DN( "cn=dsa,dc=example,dc=com", &dn );
status = DS_Session_New( "Internet=localhost+19999", 0, &ds );
if ( status != DS_E_NOERROR ) {
fprintf( stderr, "Failed to create session\n" );
return 1;
}
status = DS_BindAnonymousSync( ds, NULL, &di );
if ( DS_Indication_GetErrorCodes( di, &t, &v ) == DS_E_NOERROR &&
t != DS_E_SUCCESS )
status = DS_E_DSOPFAILED;
if ( status != DS_E_NOERROR) {
DS_UnbindSync( &ds );
fprintf( stderr, "Failed to bind\n" );
return 1;
}
status = DS_ReadSync( ds, dn, attrs, NULL, &di );
status = DS_Indication_GetEntryList( di, &el );
status = DS_Entry_GetAttrList( e, &al );
for ( a = DS_AttrList_GetFirst( al );
a != NULL;
a = DS_AttrList_GetNext( a ) ) {
const char *name;
const DS_AttrValList *vl;
const DS_AttrVal *v;
DS_Attr_GetTypeName( a, &name );
printf( "%s:\n", name );
/* Don't free name */
status = DS_Attr_GetValueList( a, &vl );
for ( v = DS_AttrValList_GetFirst( vl );
v != NULL;
const char *val_str;
size_t val_len;
status = DS_AttrVal_GetStringPointer( v, &val_str, &val_len );
if ( status == DS_E_NOERROR )
printf( "\t%s\n", val_str );
else
printf( "\t(No string value)\n");
/* Don't free val_str */
}
}
DS_UnbindSync( &ds );
return 0;
}
struct DS_Attr DS_AttrList
Definition: dsapi_types.h:127
DS_Status DS_AttrVal_GetStringPointer(const DS_AttrVal *value, const char **str_p, size_t *str_len_p)
Return a pointer to the stored LDAPv3 format string encoding.
const DS_Attr * DS_AttrList_GetNext(const DS_Attr *attr)
Get the next attribute in a list.
DS_Status DS_Indication_GetEntryList(DS_Indication *indication, const DS_EntryList **entry_list_p)
Return the set of entries contained in the operation outcome.
struct DS_DN DS_DN
Definition: dsapi_types.h:103
DS_Status
Definition: dsapi_const.h:66
DS_Status DS_Attr_GetTypeName(const DS_Attr *attr, const char **str_p)
Return the type name of a given attribute.
DS_Status DS_Entry_GetAttrList(const DS_Entry *entry, const DS_AttrList **attr_list_p)
Get the entry attribute list.
struct DS_AttrVal DS_AttrVal
Definition: dsapi_types.h:69
const DS_AttrVal * DS_AttrValList_GetNext(const DS_AttrVal *value)
Get the next attribute in a list.
struct DS_Entry DS_EntryList
Definition: dsapi_types.h:145
DS_ErrorType
Definition: dsapi_const.h:138
void DS_UnbindSync(DS_Session **session_p)
Perform a synchronous directory unbind.
const DS_Entry * DS_EntryList_GetFirst(const DS_EntryList *entry_list)
Get the first entry in a list of entries.
@ DS_E_DSOPFAILED
Definition: dsapi_const.h:103
@ DS_E_NOERROR
Definition: dsapi_const.h:67
DS_Status DS_Indication_GetErrorCodes(DS_Indication *indication, DS_ErrorType *type_p, DS_ErrorValue *value_p)
Get the directory (operation) error type and value codes.
struct DS_AttrVal DS_AttrValList
Definition: dsapi_types.h:133
struct DS_Entry DS_Entry
Definition: dsapi_types.h:81
DS_Status DS_Session_New(const char *address, int force_tls, DS_Session **session_p)
Create an unbound directory session, validating the specified address.
Methods for session management and invoking directory operations.
struct DS_Indication DS_Indication
Definition: dsapi_types.h:121
DS_Status DS_Attr_GetValueList(const DS_Attr *attr, const DS_AttrValList **val_list_p)
Get an attribute's value list.
const DS_AttrVal * DS_AttrValList_GetFirst(const DS_AttrValList *value_list)
Get the first attribute in a list.
struct DS_Session DS_Session
Definition: dsapi_types.h:44
DS_Status DS_BindAnonymousSync(DS_Session *session, DS_CommonArgs *common_args, DS_Indication **indication_p)
Perform an anonymous synchronous directory bind.
DS_ErrorValue
Definition: dsapi_const.h:190
const DS_Attr * DS_AttrList_GetFirst(const DS_AttrList *attr_list)
Get the first attribute in an attribute list.
DS_Status DS_String2DN(const char *str_dn, DS_DN **dn_p)
Convert an LDAPv3 string formatted DN to the API structure.
struct DS_Attr DS_Attr
Definition: dsapi_types.h:75
void DS_Indication_Delete(DS_Indication *indication)
Free a DS_Indication structure.
DS_Status DS_ReadSync(DS_Session *session, const DS_DN *dn, const char *attr_selection[], DS_CommonArgs *common_args, DS_Indication **indication_p)
Perform a synchronous directory read entry operation.
DS_Status DS_Initialize(void)
Initialize the Simple Directory API.

All rights reserved © 2002 - 2024 Isode Ltd.