]> git.sur5r.net Git - openldap/commitdiff
ITS#6345 cleanup: Simplify tester_ignore_err() and tester_ignore_str2err()
authorHallvard Furuseth <hallvard@openldap.org>
Wed, 21 Oct 2009 16:46:58 +0000 (16:46 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Wed, 21 Oct 2009 16:46:58 +0000 (16:46 +0000)
tests/progs/slapd-common.c

index cc686575228d7bd037c7ccfbc3157fe36c80ffbf..a4b51b0f66a707bc13489787b100dc7eac09ea4f 100644 (file)
@@ -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 );
 }
-