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
  

00001 /* 
00002  * Copyright (c) 2005-2006, Isode Limited, London, England.
00003  * All rights reserved.
00004  * 
00005  * Acquisition and use of this software and related materials for any
00006  * purpose requires a written licence agreement from Isode Limited,
00007  * or a written licence from an organisation licenced by Isode Limited
00008  * to grant such a licence.
00009  */
00010 #include <stdio.h>
00011 #ifdef _WIN32
00012 # include <stdlib.h>
00013 # define sleep _sleep
00014 #else
00015 # include <unistd.h>
00016 #endif
00017 
00018 #include <isode/ds/dsapi/dsapi.h>
00019 
00029 int main ( void )
00030 {
00031     DS_Session         *ds;
00032     DS_Indication      *di;
00033     const DS_EntryList *el;
00034     const DS_Entry     *e;
00035     const DS_AttrList  *al;
00036     const DS_Attr      *a;
00037     DS_DN              *dn;
00038     int                 op_id;
00039     int                 i;
00040     const char         *attrs[] = { "objectClass", "cn", "manager", NULL };
00041     DS_Status           status;
00042 
00043     status = DS_Initialize();
00044 
00045     status = DS_String2DN( "cn=dsa,dc=example,dc=com", &dn );
00046 
00047     status = DS_BindSync_Anonymous( "Internet=localhost+19999", &ds );
00048 
00049     status = DS_ReadAsync( ds, dn, attrs, NULL, &op_id );
00050 
00051     di = NULL;
00052     
00053     for ( i = 0; i < 5; i++ ) {
00054         
00055         sleep( 1 );
00056 
00057         status = DS_Poll( ds, op_id, &di );
00058 
00059         if ( status == DS_E_NOERROR )
00060             break;
00061     }
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         /* Don't free name */
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             /* Don't free val_str */
00096 
00097         }
00098     }
00099 
00100     DS_Indication_Delete( di );
00101     
00102     DS_UnbindSync( &ds );
00103     return 0;
00104 }
Copyright © 2008 Isode privacy   feedback Subscribe to our rss newsfeed