atnds_test.c
This extended example shows how to convert AFTN address to the corresponding AMHS form, and vice versa. The example also makes use of DSAPI to connect to the directory and manipulate directory data.
To compile this example on Unix machines:
cc -c -I/opt/isode/include/isode/ds/atnds/ -I/opt/isode/include
-I/opt/isode/include/h
To link this example on Unix machines:
cc -o atnds_test atnds_test.o -L/opt/isode/lib \
-latnds -ldua -lisode -libase -lmdldap -lmdlber -lssl -lcrypto
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #include <stdio.h>
00071 #include <string.h>
00072 #include <isode/ds/atnds/atnds.h>
00073
00084 DS_Session *ds;
00085
00086 static int read_atn_user (DS_DN *user_dn);
00087
00088 int main( int argc, char *argv[] )
00089 {
00090
00091 const char *addr = "Internet=localhost+19999";
00092 const char *registry_dn_str = "o=Isode-MD-Register";
00093 DS_DN *registry_dn;
00094 DS_DN *user_dn;
00095 char *aftn_addr;
00096 const char *caas_aftn_addr = "LFCIZPZX";
00097 const char *xf_aftn_addr = "ESMANUZX";
00098 char *orbuf;
00099 size_t orbuf_len;
00100 DS_Status status;
00101 char *dnbuf;
00102 size_t dnbuf_len;
00103 char aftnbuf[9];
00104
00105
00106 printf( "\nTEST: initializing DUA library %s.\n", addr );
00107 printf( "----------------------------------------------------------------\n" );
00108
00109 status = DS_Initialize();
00110 if ( status != DS_E_NOERROR ) {
00111 printf( "FAIL: couldn't initialize DUA library.\n" );
00112 return status;
00113 }
00114
00115
00116 printf( "\nTEST: bind (to %s)\n", addr );
00117 printf( "----------------------------------------------------------------\n" );
00118
00119 status = DS_BindSync_Anonymous( addr, &ds );
00120 if ( status != DS_E_NOERROR ) {
00121 printf( "FAIL: couldn't bind to directory.\n" );
00122 return status;
00123 }
00124
00125 printf( "SUCCESS: bound to directory\n" );
00126
00127
00128
00129 status = DS_String2DN( registry_dn_str, ®istry_dn );
00130 if ( status != DS_E_NOERROR ) {
00131
00132 printf ( "FAIL: DN conversion failed (%s).\n", registry_dn_str );
00133 return DS_E_BADDN;
00134
00135 }
00136
00137
00138 if ( argc > 1 ) {
00139
00140 aftn_addr = argv[1];
00141 if ( strlen(aftn_addr) != 8 ) {
00142 printf ( "FAIL: AFTN address is not 8 characters long (%s).\n", aftn_addr );
00143 return DS_E_BADPARAM;
00144 }
00145
00146 printf( "\nTEST: convert AFTN to X.400 (%s)\n", aftn_addr );
00147 status = ATNds_AFTN2AMHS
00148 ( ds, registry_dn, aftn_addr, &orbuf, &orbuf_len, &user_dn );
00149
00150 } else {
00151
00152 printf( "\nTEST: convert AFTN to X.400 (CAAS) (%s)\n", caas_aftn_addr );
00153 status = ATNds_AFTN2AMHS
00154 ( ds, registry_dn, caas_aftn_addr, &orbuf, &orbuf_len, &user_dn );
00155
00156 }
00157 printf( "----------------------------------------------------------------\n" );
00158
00159 if ( status != DS_E_NOERROR ) {
00160
00161 switch ( status ) {
00162
00163 case DS_E_NOTFOUND:
00164
00165 printf
00166 ( "FAIL: conversion data not found in the ATN directory.\n" );
00167
00168 return status;
00169
00170
00171 default:
00172
00173 printf ( "FAIL: conversion failed (%d - no error message available).\n", status );
00174 return status;
00175
00176 }
00177
00178 }
00179
00180 printf( "SUCCESS: conversion succeeded.\n" );
00181 printf( "DETAIL: O/R address is %s\n\n", orbuf );
00182
00183 if ( user_dn != NULL ) {
00184
00185 status = DS_DN2String( user_dn, &dnbuf, &dnbuf_len );
00186 if ( status != DS_E_NOERROR ) {
00187 printf( "DETAIL: Failed to display aMHSUser entry DN.\n" );
00188 } else {
00189 printf( "DETAIL: aMHSUser entry DN is %s.\n", dnbuf );
00190 ATNds_free( dnbuf );
00191 }
00192
00193 DS_DN_Delete( user_dn );
00194
00195 } else {
00196 printf( "DETAIL: no aMHSUser entry DN could be computed.\n");
00197 }
00198
00199
00200 printf( "\nTEST: performing reverse conversion\n(from %s)\n", orbuf );
00201 printf( "----------------------------------------------------------------\n" );
00202
00203 status = ATNds_AMHS2AFTN
00204 ( ds, registry_dn, orbuf, aftnbuf, &user_dn );
00205
00206 ATNds_free( ( void * ) orbuf );
00207
00208 if ( status != DS_E_NOERROR ) {
00209
00210 switch ( status ) {
00211
00212 case DS_E_NOTFOUND:
00213
00214 printf
00215 ( "FAIL: conversion data not available.\n" );
00216
00217 return status;
00218
00219
00220 default:
00221
00222 printf ( "FAIL: conversion failed (no error message available).\n" );
00223 return status;
00224
00225 }
00226
00227 }
00228
00229 printf( "SUCCESS: conversion succeeded.\n" );
00230 printf( "DETAIL: AFTN address is %s\n", aftnbuf );
00231
00232 if ( user_dn != NULL ) {
00233
00234 status = DS_DN2String( user_dn, &dnbuf, &dnbuf_len );
00235 if ( status != DS_E_NOERROR ) {
00236 printf( "DETAIL: Failed to display aMHSUser entry DN.\n" );
00237 } else {
00238 printf( "DETAIL: aMHSUser entry DN is %s.\n", dnbuf );
00239 ATNds_free( dnbuf );
00240 }
00241
00242 read_atn_user( user_dn );
00243
00244 DS_DN_Delete( user_dn );
00245
00246 } else {
00247 printf( "DETAIL: no aMHSUser entry DN could be computed.\n");
00248 }
00249
00250
00251 printf( "\nTEST: convert AFTN to X.400 (XF) (%s)\n", xf_aftn_addr );
00252 printf( "----------------------------------------------------------------\n" );
00253
00254 status = ATNds_AFTN2AMHS
00255 ( ds, registry_dn, xf_aftn_addr, &orbuf, &orbuf_len, &user_dn );
00256
00257 if ( status != DS_E_NOERROR ) {
00258
00259 switch ( status ) {
00260
00261 case DS_E_NOTFOUND:
00262
00263 printf
00264 ( "FAIL: conversion data not found in the ATN directory.\n" );
00265
00266 return status;
00267
00268
00269 default:
00270
00271 printf ( "FAIL: conversion failed (no error message available).\n" );
00272 return status;
00273
00274 }
00275
00276 }
00277
00278 printf( "SUCCESS: conversion succeeded.\n" );
00279 printf( "DETAIL: O/R address is %s\n", orbuf );
00280
00281 if ( user_dn != NULL ) {
00282
00283 status = DS_DN2String( user_dn, &dnbuf, &dnbuf_len );
00284 if ( status != DS_E_NOERROR ) {
00285 printf( "DETAIL: Failed to display aMHSUser entry DN.\n" );
00286 } else {
00287 printf( "DETAIL: aMHSUser entry DN is %s.\n", dnbuf );
00288 ATNds_free( dnbuf );
00289 }
00290
00291 read_atn_user( user_dn );
00292
00293 DS_DN_Delete( user_dn );
00294
00295 } else {
00296 printf( "DETAIL: no aMHSUser entry DN could be computed.\n");
00297 }
00298
00299
00300 printf( "\nTEST: performing reverse conversion\n(from %s)\n", orbuf );
00301 printf( "----------------------------------------------------------------\n" );
00302
00303 status = ATNds_AMHS2AFTN
00304 ( ds, registry_dn, orbuf, aftnbuf, &user_dn );
00305
00306 ATNds_free( ( void * ) orbuf );
00307
00308 if ( status != DS_E_NOERROR ) {
00309
00310 switch ( status ) {
00311
00312 case DS_E_NOTFOUND:
00313
00314 printf
00315 ( "FAIL: conversion data not available.\n" );
00316
00317 return status;
00318
00319
00320 default:
00321
00322 printf ( "FAIL: conversion failed (no error message available).\n" );
00323 return status;
00324
00325 }
00326
00327 }
00328
00329 printf( "SUCCESS: conversion succeeded.\n" );
00330 printf( "DETAIL: AFTN address is %s\n", aftnbuf );
00331
00332 if ( user_dn != NULL ) {
00333
00334 status = DS_DN2String( user_dn, &dnbuf, &dnbuf_len );
00335 if ( status != DS_E_NOERROR ) {
00336 printf( "DETAIL: Failed to display aMHSUser entry DN.\n" );
00337 } else {
00338 printf( "DETAIL: aMHSUser entry DN is %s.\n", dnbuf );
00339 ATNds_free( dnbuf );
00340 }
00341
00342 read_atn_user( user_dn );
00343
00344 DS_DN_Delete( user_dn );
00345
00346 } else {
00347 printf( "DETAIL: no aMHSUser entry DN could be computed.\n");
00348 }
00349
00350
00351 DS_DN_Delete( registry_dn );
00352
00353
00354 DS_UnbindSync( &ds );
00355
00356
00357 return 0;
00358
00359 }
00360
00361
00362 static int
00363 read_atn_user ( DS_DN *user_dn ) {
00364
00365 DS_Indication *di;
00366 const DS_EntryList *el;
00367 const DS_Entry *e;
00368 const DS_AttrList *al;
00369 const DS_Attr *a;
00370 DS_ErrorType type_p;
00371 int status;
00372
00373
00374 status = DS_ReadSync( ds, user_dn , NULL, NULL, &di );
00375 if ( status != DS_E_NOERROR ) {
00376 if ( di != NULL ) {
00377 DS_Indication_GetStatus ( di, &type_p ) ;
00378 DS_Indication_Delete ( di );
00379 if ( type_p == DS_E_NAME ) {
00380 printf( "No DSA entry for this ATN User entry\n");
00381 return 0;
00382 }
00383 }
00384 printf( "Failed to read ATN User entry (status=%d)\n", status);
00385 return 1;
00386 }
00387
00388 status = DS_Indication_GetEntryList( di, &el );
00389 if ( status != DS_E_NOERROR ) {
00390 DS_Indication_Delete ( di );
00391 printf( "Failed to read ATN User entry Indication\n");
00392 return 2;
00393 }
00394
00395 e = DS_EntryList_GetFirst( el );
00396
00397 status = DS_Entry_GetAttrList( e, &al );
00398 if ( status != DS_E_NOERROR ) {
00399 DS_Indication_Delete ( di );
00400 printf( "Failed to read attribute list for ATN User entry\n");
00401 return 3;
00402 }
00403
00404 for ( a = DS_AttrList_GetFirst( al );
00405 a != NULL;
00406 a = DS_AttrList_GetNext( a ) ) {
00407
00408 const char *name;
00409 const DS_AttrValList *vl;
00410 const DS_AttrVal *v;
00411
00412 DS_Attr_GetTypeName( a, &name );
00413 printf( "%s:\n", name );
00414
00415
00416 status = DS_Attr_GetValueList( a, &vl );
00417
00418 for ( v = DS_AttrValList_GetFirst( vl );
00419 v != NULL;
00420 v = DS_AttrValList_GetNext( v ) ) {
00421
00422 const char *val_str;
00423 size_t val_len;
00424
00425 status = DS_AttrVal_GetStringPointer( v, &val_str, &val_len );
00426 if ( status == DS_E_NOERROR )
00427 printf( "\t%s\n", val_str );
00428 else
00429 printf( "\t(No string value)\n");
00430
00431
00432 }
00433 }
00434 DS_Indication_Delete ( di );
00435 return 0;
00436 }