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 \
-lisode_ssl -lisode_crypto -lpthread
To link this example on Windows:
cl /nologo /o read.exe read.obj \
C:\Progra~1\Isode\bin\libdua.lib
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011
00012 #include <isode/ds/dsapi/dsapi.h>
00013
00023 int main ( void )
00024 {
00025 DS_Session *ds = NULL;
00026 DS_Indication *di = NULL;
00027 DS_ErrorType t;
00028 DS_ErrorValue v;
00029 const DS_EntryList *el = NULL;
00030 const DS_Entry *e = NULL;
00031 const DS_AttrList *al = NULL;
00032 const DS_Attr *a = NULL;
00033 DS_DN *dn = NULL;
00034 const char *attrs[] = { "objectClass", "cn", "manager", NULL };
00035 DS_Status status;
00036
00037 status = DS_Initialize();
00038
00039 status = DS_String2DN( "cn=dsa,dc=example,dc=com", &dn );
00040
00041 status = DS_Session_New( "Internet=localhost+19999", 0, &ds );
00042 if ( status != DS_E_NOERROR ) {
00043 fprintf( stderr, "Failed to create session\n" );
00044 return 1;
00045 }
00046
00047 status = DS_BindAnonymousSync( ds, NULL, &di );
00048
00049 if ( DS_Indication_GetErrorCodes( di, &t, &v ) == DS_E_NOERROR &&
00050 t != DS_E_SUCCESS )
00051 status = DS_E_DSOPFAILED;
00052
00053 DS_Indication_Delete( di );
00054
00055 if ( status != DS_E_NOERROR) {
00056 DS_UnbindSync( &ds );
00057 fprintf( stderr, "Failed to bind\n" );
00058 return 1;
00059 }
00060
00061 status = DS_ReadSync( ds, dn, attrs, NULL, &di );
00062
00063 status = DS_Indication_GetEntryList( di, &el );
00064
00065 e = DS_EntryList_GetFirst( el );
00066
00067 status = DS_Entry_GetAttrList( e, &al );
00068
00069 for ( a = DS_AttrList_GetFirst( al );
00070 a != NULL;
00071 a = DS_AttrList_GetNext( a ) ) {
00072
00073 const char *name;
00074 const DS_AttrValList *vl;
00075 const DS_AttrVal *v;
00076
00077 DS_Attr_GetTypeName( a, &name );
00078 printf( "%s:\n", name );
00079
00080
00081 status = DS_Attr_GetValueList( a, &vl );
00082
00083 for ( v = DS_AttrValList_GetFirst( vl );
00084 v != NULL;
00085 v = DS_AttrValList_GetNext( v ) ) {
00086
00087 const char *val_str;
00088 size_t val_len;
00089
00090 status = DS_AttrVal_GetStringPointer( v, &val_str, &val_len );
00091 if ( status == DS_E_NOERROR )
00092 printf( "\t%s\n", val_str );
00093 else
00094 printf( "\t(No string value)\n");
00095
00096
00097 }
00098 }
00099
00100 DS_Indication_Delete( di );
00101
00102 DS_UnbindSync( &ds );
00103 return 0;
00104 }