]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/test.c
ITS#399: timelimit/timeout handling
[openldap] / libraries / libldap / test.c
index 23088a116620cb41626733ebcf55085a7bc48a1b..d52859042b85d5ae88243885531cbc12a712c52a 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
@@ -6,7 +7,8 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
 #include <ac/socket.h>
@@ -112,7 +114,7 @@ static int
 file_read( char *path, struct berval *bv )
 {
        FILE            *fp;
-       long            rlen;
+       ber_slen_t      rlen;
        int             eof;
 
        if (( fp = fopen( path, "r" )) == NULL ) {
@@ -144,7 +146,7 @@ file_read( char *path, struct berval *bv )
        eof = feof( fp );
        fclose( fp );
 
-       if ( (unsigned long) rlen != bv->bv_len ) {
+       if ( (ber_len_t) rlen != bv->bv_len ) {
                perror( path );
                free( bv->bv_val );
                return( -1 );
@@ -226,7 +228,6 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 )
 }
 
 
-#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
 static int
 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
        int freeit )
@@ -261,7 +262,6 @@ bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
 
        return( LDAP_SUCCESS );
 }
-#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
 
 int
@@ -302,7 +302,7 @@ main( int argc, char **argv )
                        ldap_debug = atoi( optarg );
 #ifdef LBER_DEBUG
                        if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
-                               lber_debug = ldap_debug;
+                               ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
                        }
 #endif
 #else
@@ -344,10 +344,11 @@ main( int argc, char **argv )
 
        if ( errflg || optind < argc - 1 ) {
                fprintf( stderr, usage, argv[ 0 ] );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        }
        
-       printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
+       printf( "%s( %s, %d )\n",
+               cldapflg ? "cldap_open" : "ldap_init",
                host == NULL ? "(null)" : host, port );
 
        if ( cldapflg ) {
@@ -355,19 +356,19 @@ main( int argc, char **argv )
                ld = cldap_open( host, port );
 #endif /* LDAP_CONNECTIONLESS */
        } else {
-               ld = ldap_open( host, port );
+               ld = ldap_init( host, port );
        }
 
        if ( ld == NULL ) {
-               perror( "ldap_open" );
-               exit(1);
+               perror( cldapflg ? "cldap_open" : "ldap_init" );
+               exit( EXIT_FAILURE );
        }
 
        if ( copyfname != NULL ) {
                if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
                    0600 ))  == -1 ) {
                        perror( copyfname );
-                       exit ( 1 );
+                       exit ( EXIT_FAILURE );
                }
                ld->ld_sb.sb_options = copyoptions;
        }
@@ -486,7 +487,7 @@ main( int argc, char **argv )
                        ldap_debug = atoi( line );
 #ifdef LBER_DEBUG
                        if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
-                               lber_debug = ldap_debug;
+                               ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
                        }
 #endif
 #else
@@ -545,13 +546,11 @@ main( int argc, char **argv )
                        if ( cldapflg )
                                cldap_close( ld );
 #endif /* LDAP_CONNECTIONLESS */
-#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
-                       if ( !cldapflg )
-#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
-                       if ( !cldapflg && bound )
-#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
+
+                       if ( !cldapflg ) {
                                ldap_unbind( ld );
-                       exit( 0 );
+                       }
+                       exit( EXIT_SUCCESS );
                        break;
 
                case 'r':       /* result or remove */
@@ -577,7 +576,7 @@ main( int argc, char **argv )
                                printf( "\nresult: msgtype %d msgid %d\n",
                                    msgtype, res->lm_msgid );
                                handle_result( ld, res );
-                               res = NULLMSG;
+                               res = NULL;
                                break;
 
                        case 'm':       /* remove */
@@ -620,7 +619,7 @@ main( int argc, char **argv )
                                printf( "\nresult: msgid %d\n",
                                    res->lm_msgid );
                                handle_result( ld, res );
-                               res = NULLMSG;
+                               res = NULL;
                            }
 #endif /* LDAP_CONNECTIONLESS */
                        } else {
@@ -665,7 +664,7 @@ main( int argc, char **argv )
                        else {
                                printf( "\nresult: err %d\n", id );
                                handle_result( ld, res );
-                               res = NULLMSG;
+                               res = NULL;
                        }
                        free_list( types );
                        break;
@@ -792,7 +791,6 @@ main( int argc, char **argv )
                        }
 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
 
-#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
                        getline( line, sizeof(line), stdin,
                                "Recognize and chase referrals (0=no, 1=yes)?" );
                        if ( atoi( line ) != 0 ) {
@@ -803,7 +801,6 @@ main( int argc, char **argv )
                                        ldap_set_rebind_proc( ld, bind_prompt );
                                }
                        }
-#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
                        break;
 
                case 'O':       /* set cache options */
@@ -893,7 +890,8 @@ handle_result( LDAP *ld, LDAPMessage *lm )
                break;
 
        default:
-               printf( "Unknown result type 0x%x\n", lm->lm_msgtype );
+               printf( "Unknown result type 0x%lx\n",
+                       (unsigned long) lm->lm_msgtype );
                print_ldap_result( ld, lm, "unknown" );
        }
 }
@@ -906,7 +904,7 @@ print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
 /*
        if ( ld->ld_error != NULL && *ld->ld_error != '\0' )
                fprintf( stderr, "Additional info: %s\n", ld->ld_error );
-       if ( NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
+       if ( LDAP_NAME_ERROR( ld->ld_errno ) && ld->ld_matched != NULL )
                fprintf( stderr, "Matched DN: %s\n", ld->ld_matched );
 */
 }
@@ -916,7 +914,7 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
 {
        LDAPMessage     *e;
 
-       for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
+       for ( e = ldap_first_entry( ld, res ); e != NULL;
            e = ldap_next_entry( ld, e ) )
        {
                BerElement      *ber = NULL;
@@ -949,7 +947,7 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
                                        int     j, nonascii;
 
                                        nonascii = 0;
-                                       for ( j = 0; (unsigned long) j < vals[i]->bv_len; j++ )
+                                       for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ )
                                                if ( !isascii( vals[i]->bv_val[j] ) ) {
                                                        nonascii = 1;
                                                        break;
@@ -958,7 +956,7 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
                                        if ( nonascii ) {
                                                printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len );
 #ifdef BPRINT_NONASCII
-                                               lber_bprint( vals[i]->bv_val,
+                                               ber_bprint( vals[i]->bv_val,
                                                    vals[i]->bv_len );
 #endif /* BPRINT_NONASCII */
                                                continue;
@@ -976,6 +974,6 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
        }
 
        if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
-           || res->lm_chain != NULLMSG )
+           || res->lm_chain != NULL )
                print_ldap_result( ld, res, "search" );
 }