From: Hallvard Furuseth Date: Wed, 21 Oct 2009 16:46:58 +0000 (+0000) Subject: ITS#6345 cleanup: Simplify tester_ignore_err() and tester_ignore_str2err() X-Git-Tag: ACLCHECK_0~175 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=02fa0b02350617fbd8e9c1c6599dc8eccaa8e698;p=openldap ITS#6345 cleanup: Simplify tester_ignore_err() and tester_ignore_str2err() --- diff --git a/tests/progs/slapd-common.c b/tests/progs/slapd-common.c index cc68657522..a4b51b0f66 100644 --- a/tests/progs/slapd-common.c +++ b/tests/progs/slapd-common.c @@ -38,13 +38,17 @@ pid_t pid; static char progname[ BUFSIZ ]; tester_t progtype; -#define TESTER_SERVER_LAST (LDAP_OTHER + 1) -#define TESTER_CLIENT_LAST (- LDAP_REFERRAL_LIMIT_EXCEEDED + 1) -static int ignore_server[ TESTER_SERVER_LAST ]; -static int ignore_client[ TESTER_CLIENT_LAST ]; +/* + * ignore_count[] is indexed by result code: + * negative for OpenLDAP client-side errors, positive for protocol codes. + */ +#define TESTER_CLIENT_FIRST LDAP_REFERRAL_LIMIT_EXCEEDED /* negative */ +#define TESTER_SERVER_LAST LDAP_OTHER +static int ignore_base [ -TESTER_CLIENT_FIRST + TESTER_SERVER_LAST + 1 ]; +#define ignore_count (ignore_base - TESTER_CLIENT_FIRST) -static struct { - char *name; +static const struct { + const char *name; int err; } ignore_str2err[] = { { "OPERATIONS_ERROR", LDAP_OPERATIONS_ERROR }, @@ -130,15 +134,9 @@ tester_ignore_str2err( const char *err ) if ( strcmp( err, "ALL" ) == 0 ) { for ( i = 0; ignore_str2err[ i ].name != NULL; i++ ) { - int err = ignore_str2err[ i ].err; - - if ( err > 0 ) { - ignore_server[ err ] = 1; - - } else if ( err < 0 ) { - ignore_client[ -err ] = 1; - } + ignore_count[ ignore_str2err[ i ].err ] = 1; } + ignore_count[ LDAP_SUCCESS ] = 0; return 0; } @@ -156,11 +154,8 @@ tester_ignore_str2err( const char *err ) if ( strcmp( err, ignore_str2err[ i ].name ) == 0 ) { int err = ignore_str2err[ i ].err; - if ( err > 0 ) { - ignore_server[ err ] = ignore; - - } else if ( err < 0 ) { - ignore_client[ -err ] = ignore; + if ( err != LDAP_SUCCESS ) { + ignore_count[ err ] = ignore; } return err; @@ -191,26 +186,10 @@ tester_ignore_err( int err ) { int rc = 1; - if ( err > 0 ) { - if ( err < TESTER_SERVER_LAST ) { - rc = ignore_server[ err ]; - if ( rc > 0 ) { - ignore_server[ err ]++; - - } else if ( rc < 0 ) { - ignore_server[ err ]--; - } - } - - } else if ( err < 0 ) { - if ( -err < TESTER_CLIENT_LAST ) { - rc = ignore_client[ -err ]; - if ( rc > 0 ) { - ignore_client[ -err ]++; - - } else if ( rc < 0 ) { - ignore_client[ -err ]--; - } + if ( err && TESTER_CLIENT_FIRST <= err && err <= TESTER_SERVER_LAST ) { + rc = ignore_count[ err ]; + if ( rc != 0 ) { + ignore_count[ err ] = rc + (rc > 0 ? 1 : -1); } } @@ -319,4 +298,3 @@ tester_error( const char *msg ) { fprintf( stderr, "%s: %s\n", progname, msg ); } -