async.c

This is an example of doing an asynchronous operation (a read), polling for results, and then printing them out.

Error handling has mostly been omitted for clarity.

To compile this example on Unix:

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

To compile this example on Windows:

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

To link this example on Unix:

cc -o async async.o -L/opt/isode/lib \
    -ldua -lisode -libase -lldap -llber \
    -lisode_ssl -lisode_crypto -lpthread

To link this example on Windows:

cl /nologo /o async.exe async.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>
#ifdef _WIN32
# include <stdlib.h>
# define sleep _sleep
#else
# include <unistd.h>
#endif
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;
int op_id;
int i;
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_ReadAsync( ds, dn, attrs, NULL, &op_id );
di = NULL;
for ( i = 0; i < 5; i++ ) {
sleep( 1 );
status = DS_Poll( ds, op_id, &di );
if ( status == DS_E_NOERROR )
break;
}
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;
}