]> git.sur5r.net Git - openldap/commitdiff
code cleanup
authorKurt Zeilenga <kurt@openldap.org>
Tue, 8 Jul 2003 03:46:20 +0000 (03:46 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 8 Jul 2003 03:46:20 +0000 (03:46 +0000)
libraries/liblber/bprint.c
libraries/liblber/debug.c
libraries/liblber/decode.c
libraries/liblber/encode.c
libraries/liblber/etest.c
libraries/liblber/io.c
libraries/liblber/memory.c
libraries/liblber/nt_err.c
libraries/liblber/sockbuf.c
libraries/liblber/stdio.c

index 5ba264ae6f559cde2f95714fc4b22648643e9eb6..9c80a5126a934397df24f9b6a31865bb98608e88 100644 (file)
@@ -75,31 +75,30 @@ int ber_pvt_log_output(
        const char *fmt,
        ... )
 {
-       char buf[ 1024 ];
+       char buf[1024];
        va_list vl;
        va_start( vl, fmt );
 
-       if ( ber_int_log_proc != NULL )
-       {
+       if ( ber_int_log_proc != NULL ) {
                ber_int_log_proc( ber_pvt_err_file, subsystem, level, fmt, vl );
+
+       } else {
+               int level;
+               ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level );
+               buf[sizeof(buf) - 1] = '\0';
+               vsnprintf( buf, sizeof(buf)-1, fmt, vl );
+               if ( ber_log_check( LDAP_DEBUG_BER, level ) ) {
+                       (*ber_pvt_log_print)( buf );
+               }
        }
-       else
-       {
-            int level;
-            ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level );
-            buf[sizeof(buf) - 1] = '\0';
-            vsnprintf( buf, sizeof(buf)-1, fmt, vl );
-            if ( ber_log_check( LDAP_DEBUG_BER, level ) )
-                (*ber_pvt_log_print)( buf );
-        }
-       va_end(vl);
 
+       va_end(vl);
        return 1;
 }
        
 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
 {
-       char buf[ 1024 ];
+       char buf[1024];
        va_list ap;
 
        assert( fmt != NULL );
@@ -158,11 +157,11 @@ ber_bprint(
        LDAP_CONST char *data,
        ber_len_t len )
 {
-       static const char       hexdig[] = "0123456789abcdef";
+       static const char hexdig[] = "0123456789abcdef";
 #define BP_OFFSET 9
 #define BP_GRAPH 60
 #define BP_LEN 80
-       char    line[ BP_LEN ];
+       char    line[BP_LEN];
        ber_len_t i;
 
        assert( data != NULL );
@@ -183,23 +182,23 @@ ber_bprint(
 
                        off = i % 0x0ffffU;
 
-                       line[ 2 ] = hexdig[ 0x0f & (off >> 12) ];
-                       line[ 3 ] = hexdig[ 0x0f & (off >>  8) ];
-                       line[ 4 ] = hexdig[ 0x0f & (off >>  4) ];
-                       line[ 5 ] = hexdig[ 0x0f & off ];
-                       line[ 6 ] = ':';
+                       line[2] = hexdig[0x0f & (off >> 12)];
+                       line[3] = hexdig[0x0f & (off >>  8)];
+                       line[4] = hexdig[0x0f & (off >>  4)];
+                       line[5] = hexdig[0x0f & off];
+                       line[6] = ':';
                }
 
                off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
-               line[ off   ] = hexdig[ 0x0f & ( data[i] >> 4 ) ];
-               line[ off+1 ] = hexdig[ 0x0f & data[i] ];
+               line[off] = hexdig[0x0f & ( data[i] >> 4 )];
+               line[off+1] = hexdig[0x0f & data[i]];
                
                off = BP_GRAPH + n + ((n >= 8)?1:0);
 
                if ( isprint( (unsigned char) data[i] )) {
-                       line[ BP_GRAPH + n ] = data[i];
+                       line[BP_GRAPH + n] = data[i];
                } else {
-                       line[ BP_GRAPH + n ] = '.';
+                       line[BP_GRAPH + n] = '.';
                }
        }
 
@@ -258,23 +257,23 @@ int ber_output_dump(
             
             off = i % 0x0ffffU;
 
-            line[ 2 ] = hexdig[ 0x0f & (off >> 12) ];
-            line[ 3 ] = hexdig[ 0x0f & (off >>  8) ];
-            line[ 4 ] = hexdig[ 0x0f & (off >>  4) ];
-            line[ 5 ] = hexdig[ 0x0f & off ];
-            line[ 6 ] = ':';
+            line[2] = hexdig[0x0f & (off >> 12)];
+            line[3] = hexdig[0x0f & (off >>  8)];
+            line[4] = hexdig[0x0f & (off >>  4)];
+            line[5] = hexdig[0x0f & off ];
+            line[6] = ':';
         }
 
         off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
-        line[ off   ] = hexdig[ 0x0f & ( data[i] >> 4 ) ];
-        line[ off+1 ] = hexdig[ 0x0f & data[i] ];
+        line[off] = hexdig[ 0x0f & ( data[i] >> 4 ) ];
+        line[off+1] = hexdig[ 0x0f & data[i] ];
         
         off = BP_GRAPH + n + ((n >= 8)?1:0);
         
         if ( isprint( (unsigned char) data[i] )) {
-            line[ BP_GRAPH + n ] = data[i];
+            line[BP_GRAPH + n] = data[i];
         } else {
-            line[ BP_GRAPH + n ] = '.';
+            line[BP_GRAPH + n] = '.';
         }
     }
 
index ff844feb70ba8e365732960ea955182cc0578f2f..d08ec0cab918682ca778dab34f8d5fe855e19f6f 100644 (file)
@@ -39,84 +39,77 @@ static int use_syslog = 0;
 
 static int debug2syslog(int l) {
        switch (l) {
-       case LDAP_LEVEL_EMERG:  return LOG_EMERG;
-       case LDAP_LEVEL_ALERT:  return LOG_ALERT;
-       case LDAP_LEVEL_CRIT:   return LOG_CRIT;
-       case LDAP_LEVEL_ERR:    return LOG_ERR;
-       case LDAP_LEVEL_WARNING:        return LOG_WARNING;
-       case LDAP_LEVEL_NOTICE: return LOG_NOTICE;
-       case LDAP_LEVEL_INFO:   return LOG_INFO;
+       case LDAP_LEVEL_EMERG: return LOG_EMERG;
+       case LDAP_LEVEL_ALERT: return LOG_ALERT;
+       case LDAP_LEVEL_CRIT: return LOG_CRIT;
+       case LDAP_LEVEL_ERR: return LOG_ERR;
+       case LDAP_LEVEL_WARNING: return LOG_WARNING;
+       case LDAP_LEVEL_NOTICE: return LOG_NOTICE;
+       case LDAP_LEVEL_INFO: return LOG_INFO;
        }
        return LOG_DEBUG;
 }
 #endif
 
-static char *lutil_levels[] = {"emergency", "alert", "critical",
-                          "error", "warning", "notice",
-                          "information", "entry", "args",
-                          "results", "detail1", "detail2",
-                          NULL};
-
-static char *lutil_subsys[LDAP_SUBSYS_NUM] = {"global","operation", "transport",
-                               "connection", "filter", "ber", 
-                               "config", "acl", "cache", "index", 
-                               "ldif", "tools", "slapd", "slurpd",
-                               "backend", "back_bdb", "back_ldbm", 
-                               "back_ldap", "back_meta", "back_mon" };
+static char *lutil_levels[] = {
+       "emergency", "alert", "critical",
+       "error", "warning", "notice",
+       "information", "entry", "args",
+       "results", "detail1", "detail2",
+       NULL };
+
+static char *lutil_subsys[LDAP_SUBSYS_NUM] = {
+       "global","operation", "transport",
+       "connection", "filter", "ber", 
+       "config", "acl", "cache", "index", 
+       "ldif", "tools", "slapd", "slurpd",
+       "backend", "back_bdb", "back_ldbm", 
+       "back_ldap", "back_meta", "back_mon" };
 
 int lutil_mnem2subsys( const char *subsys )
 {
-    int i;
-    for( i = 0; i < LDAP_SUBSYS_NUM; i++ )
-    {
-               if ( !strcasecmp( subsys, lutil_subsys[i] ) )
-               {
-               return i;
+       int i;
+       for( i = 0; i < LDAP_SUBSYS_NUM; i++ ) {
+               if ( !strcasecmp( subsys, lutil_subsys[i] ) ) {
+                       return i;
                }
-    }
-    return -1;
+       }
+       return -1;
 }
 
 void lutil_set_all_backends( int level )
 {
-    int i;
+       int i;
 
-    for( i = 0; i < LDAP_SUBSYS_NUM; i++ )
-    {
-               if ( !strncasecmp( "back_", lutil_subsys[i], strlen("back_") ) )
-               {
+       for( i = 0; i < LDAP_SUBSYS_NUM; i++ ) {
+               if ( !strncasecmp( "back_", lutil_subsys[i], strlen("back_") ) ) {
                        ldap_loglevels[i] = level;
                }
-    }
+       }
 }
 
 int lutil_mnem2level( const char *level )
 {
-    int i;
-    for( i = 0; lutil_levels[i] != NULL; i++ )
-    {
-       if ( !strcasecmp( level, lutil_levels[i] ) )
-       {
-           return i;
+       int i;
+       for( i = 0; lutil_levels[i] != NULL; i++ ) {
+               if ( !strcasecmp( level, lutil_levels[i] ) ) {
+                       return i;
+               }
        }
-    }
-    return -1;
+       return -1;
 }
 
 static int addSubsys( const char *subsys, int level )
 {
        int subsys_num;
 
-       if ( !strcasecmp( subsys, "backend" ) )
-       {
+       if ( !strcasecmp( subsys, "backend" ) ) {
                lutil_set_all_backends( level );
                return level;
-       }
-       else
-       {
+
+       } else {
                subsys_num = lutil_mnem2subsys(subsys);
-               if(subsys_num < 0)
-               {
+               if(subsys_num < 0) {
                        fprintf(stderr, _("Unknown Subsystem name [ %s ] - Discarded\n"), 
                                subsys);
                        fflush(stderr);
@@ -131,7 +124,7 @@ static int addSubsys( const char *subsys, int level )
 
 int lutil_set_debug_level( const char* subsys, int level )
 {
-    return( addSubsys( subsys, level ) );
+       return( addSubsys( subsys, level ) );
 }
 
 int lutil_debug_file( FILE *file )
@@ -157,8 +150,9 @@ void lutil_log_int(
 
        t_subsys = strdup(subsys);
        
-       for(tmp = t_subsys, i = 0; i < strlen(t_subsys); i++, tmp++)
+       for(tmp = t_subsys, i = 0; i < strlen(t_subsys); i++, tmp++) {
                *tmp = TOUPPER( (unsigned char) *tmp );
+       }
 
 #ifdef LDAP_SYSLOG
        /* we're configured to use syslog */
@@ -179,11 +173,10 @@ void lutil_log_int(
        if( log_file == NULL ) {
                log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "openldap.log", "w" );
 
-               if ( log_file == NULL )
+               if ( log_file == NULL ) {
                        log_file = fopen( "openldap.log", "w" );
-
-               if ( log_file == NULL )
-                       return;
+                       if ( log_file == NULL ) return;
+               }
 
                ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, log_file );
        }
@@ -203,7 +196,7 @@ void lutil_log_int(
         * Stick the time in the buffer to output when using Winsock
         * as NT can't pipe to a timestamp program like Unix can.
         * This, of course, makes some logs hard to read.
-     */
+        */
        time( &now );
        today = localtime( &now );
        fprintf( file, "%4d%02d%02d:%02d:%02d:%02d ",
@@ -238,53 +231,50 @@ void lutil_log( const int subsys, int level, const char *fmt, ... )
 
 void lutil_log_initialize(int argc, char **argv)
 {
-    int i;
-    /*
-     * Start by setting the hook for the libraries to use this logging
-     * routine.
-     */
-    ber_set_option( NULL, LBER_OPT_LOG_PROC, (void*)lutil_log_int );
-
-    if ( argc == 0 ) return;
-    /*
-     * Now go through the command line options to set the debugging
-     * levels
-     */
-    for( i = 0; i < argc; i++ )
-    {
+       int i;
+       /*
+        * Start by setting the hook for the libraries to use this logging
+        * routine.
+        */
+       ber_set_option( NULL, LBER_OPT_LOG_PROC, (void*)lutil_log_int );
+
+       if ( argc == 0 ) return;
+
+       /*
+        * Now go through the command line options to set the debugging
+        * levels
+        */
+       for( i = 0; i < argc; i++ ) {
                char *next = argv[i];
        
-               if ( i < argc-1 && next[0] == '-' && next[1] == 'd' )
-               {
-                       char subsys[64];
-                       int level;
-               char *optarg = argv[i+1];
-               char *index = strchr( optarg, '=' );
-               if ( index != NULL )
-               {
+               if ( i < argc-1 && next[0] == '-' && next[1] == 'd' ) {
+                       char subsys[64];
+                       int level;
+                       char *optarg = argv[i+1];
+                       char *index = strchr( optarg, '=' );
+
+                       if ( index != NULL ) {
                                *index = 0;
                                strcpy ( subsys, optarg );
                                level = atoi( index+1 );
                                if ( level <= 0 ) level = lutil_mnem2level( index + 1 );
                                lutil_set_debug_level( subsys, level );
                                *index = '=';
-               }
-               else
-               {
+
+                       } else {
                                global_level = atoi( optarg );
                                ldap_loglevels[0] = global_level;
                                /* 
                                * if a negative number was used, make the global level the
                                * maximum sane level.
                                */
-                               if ( global_level < 0 ) 
-                               {
+                               if ( global_level < 0 ) {
                                        global_level = 65535;
                                        ldap_loglevels[0] = 65535;
-                       }
-               }
+                               }
+                       }
                }
-    }
+       }
 }
 
 void (lutil_debug)( int debug, int level, const char *fmt, ... )
@@ -292,18 +282,16 @@ void (lutil_debug)( int debug, int level, const char *fmt, ... )
        char buffer[4096];
        va_list vl;
 
-       if ( !(level & debug ) )
-               return;
+       if ( !(level & debug ) ) return;
 
 #ifdef HAVE_WINSOCK
        if( log_file == NULL ) {
                log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "openldap.log", "w" );
 
-               if ( log_file == NULL )
+               if ( log_file == NULL ) {
                        log_file = fopen( "openldap.log", "w" );
-
-               if ( log_file == NULL )
-                       return;
+                       if ( log_file == NULL ) return;
+               }
 
                ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, log_file );
        }
index ae0b963b033614af71f9eaf62fb267db599f3fa7..456c17e0ec9e8d1cfc6a6da13cb28ad5d2270a3e 100644 (file)
@@ -48,10 +48,11 @@ ber_get_tag( BerElement *ber )
                return LBER_DEFAULT;
        }
 
-       if ( ber->ber_ptr == ber->ber_buf )
+       if ( ber->ber_ptr == ber->ber_buf ) {
                tag = *(unsigned char *)ber->ber_ptr;
-       else
+       } else {
                tag = ber->ber_tag;
+       }
        ber->ber_ptr++;
 
        if ( (tag & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) {
@@ -118,8 +119,9 @@ ber_skip_tag( BerElement *ber, ber_len_t *len )
         * greater than what we can hold in a ber_len_t.
         */
 
-       if ( ber_read( ber, (char *) &lc, 1 ) != 1 )
+       if ( ber_read( ber, (char *) &lc, 1 ) != 1 ) {
                return LBER_DEFAULT;
+       }
 
        if ( lc & 0x80U ) {
                noctets = (lc & 0x7fU);
@@ -320,8 +322,7 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
        tag = b->ber->ber_tag;
 
        if ( ber_first_element( b->ber, &len, &last ) != LBER_DEFAULT ) {
-               for ( ; b->ber->ber_ptr < last; i++ )
-               {
+               for ( ; b->ber->ber_ptr < last; i++ ) {
                        if (ber_skip_tag( b->ber, &len ) == LBER_DEFAULT) break;
                        b->ber->ber_ptr += len;
                        b->ber->ber_tag = *(unsigned char *)b->ber->ber_ptr;
@@ -330,8 +331,7 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
 
        if ( rlen ) *rlen = i;
 
-       if ( i == 0 )
-       {
+       if ( i == 0 ) {
                *b->res.c = NULL;
                return 0;
        }
@@ -341,27 +341,26 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
        /* Allocate the result vector */
        switch (b->choice) {
        case ChArray:
-               *b->res.c = ber_memalloc_x( (n+1) * sizeof( char * ), b->ber->ber_memctx);
-               if ( *b->res.c == NULL )
-                       return LBER_DEFAULT;
+               *b->res.c = ber_memalloc_x( (n+1)*sizeof( char * ),
+                       b->ber->ber_memctx);
+               if ( *b->res.c == NULL ) return LBER_DEFAULT;
                (*b->res.c)[n] = NULL;
                break;
        case BvArray:
-               *b->res.ba = ber_memalloc_x( (n+1) * sizeof( struct berval ), b->ber->ber_memctx);
-               if ( *b->res.ba == NULL )
-                       return LBER_DEFAULT;
+               *b->res.ba = ber_memalloc_x( (n+1)*sizeof( struct berval ),
+                       b->ber->ber_memctx);
+               if ( *b->res.ba == NULL ) return LBER_DEFAULT;
                (*b->res.ba)[n].bv_val = NULL;
                break;
        case BvVec:
-               *b->res.bv = ber_memalloc_x( (n+1) * sizeof( struct berval *), b->ber->ber_memctx);
-               if ( *b->res.bv == NULL )
-                       return LBER_DEFAULT;
+               *b->res.bv = ber_memalloc_x( (n+1)*sizeof( struct berval *),
+                       b->ber->ber_memctx);
+               if ( *b->res.bv == NULL ) return LBER_DEFAULT;
                (*b->res.bv)[n] = NULL;
                break;
        case BvOff:
                *b->res.ba = ber_memalloc_x( (n+1) * b->siz, b->ber->ber_memctx );
-               if ( *b->res.ba == NULL )
-                       return LBER_DEFAULT;
+               if ( *b->res.ba == NULL ) return LBER_DEFAULT;
                ((struct berval *)((long)(*b->res.ba) + n*b->siz +
                        b->off))->bv_val = NULL;
                break;
@@ -373,8 +372,9 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
        for (n=0; n<i; n++)
        {
                tag = ber_next_element( b->ber, &len, last );
-               if ( ber_get_stringbv( b->ber, &bv, b->alloc ) == LBER_DEFAULT )
+               if ( ber_get_stringbv( b->ber, &bv, b->alloc ) == LBER_DEFAULT ) {
                        goto nomem;
+               }
 
                /* store my result */
                switch (b->choice) {
@@ -399,17 +399,23 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
                }
        }
        return tag;
+
 nomem:
-       if (b->alloc || b->choice == BvVec)
-       {
-               for (--n; n>=0; n--)
-               {
+       if (b->alloc || b->choice == BvVec) {
+               for (--n; n>=0; n--) {
                        switch(b->choice) {
-                       case ChArray: LBER_FREE((*b->res.c)[n]); break;
-                       case BvArray: LBER_FREE((*b->res.ba)[n].bv_val); break;
-                       case BvVec: LBER_FREE((*b->res.bv)[n]->bv_val);
-                               LBER_FREE((*b->res.bv)[n]); break;
-                       default: break;
+                       case ChArray:
+                               LBER_FREE((*b->res.c)[n]);
+                               break;
+                       case BvArray:
+                               LBER_FREE((*b->res.ba)[n].bv_val);
+                               break;
+                       case BvVec:
+                               LBER_FREE((*b->res.bv)[n]->bv_val);
+                               LBER_FREE((*b->res.bv)[n]);
+                               break;
+                       default:
+                               break;
                        }
                }
        }
@@ -438,12 +444,15 @@ ber_get_stringbv( BerElement *ber, struct berval *bv, int alloc )
        }
 
        if ( alloc ) {
-               if ( (bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1, ber->ber_memctx )) == NULL ) {
+               bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1,
+                       ber->ber_memctx );
+               if ( bv->bv_val == NULL ) {
                        return LBER_DEFAULT;
                }
 
                if ( bv->bv_len > 0 && (ber_len_t) ber_read( ber, bv->bv_val,
-                       bv->bv_len ) != bv->bv_len ) {
+                       bv->bv_len ) != bv->bv_len )
+               {
                        LBER_FREE( bv->bv_val );
                        bv->bv_val = NULL;
                        return LBER_DEFAULT;
@@ -480,7 +489,8 @@ ber_get_stringal( BerElement *ber, struct berval **bv )
        assert( ber != NULL );
        assert( bv != NULL );
 
-       *bv = (struct berval *) ber_memalloc_x( sizeof(struct berval), ber->ber_memctx );
+       *bv = (struct berval *) ber_memalloc_x( sizeof(struct berval),
+               ber->ber_memctx );
        if ( *bv == NULL ) {
                return LBER_DEFAULT;
        }
@@ -515,7 +525,8 @@ ber_get_bitstringa(
        }
        --datalen;
 
-       if ( (*buf = (char *) ber_memalloc_x( datalen, ber->ber_memctx )) == NULL ) {
+       *buf = (char *) ber_memalloc_x( datalen, ber->ber_memctx );
+       if ( *buf == NULL ) {
                return LBER_DEFAULT;
        }
 
@@ -649,8 +660,9 @@ ber_scanf ( BerElement *ber,
 #ifdef NEW_LOGGING
        LDAP_LOG( BER, ENTRY, "ber_scanf fmt (%s) ber:\n", fmt, 0, 0 );
 
-       if ( LDAP_LOGS_TEST(BER, DETAIL2 ))
+       if ( LDAP_LOGS_TEST(BER, DETAIL2 )) {
                        BER_DUMP(( "liblber", LDAP_LEVEL_DETAIL2, ber, 1 ));
+       }
 #else
        ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
                "ber_scanf fmt (%s) ber:\n", fmt );
@@ -815,13 +827,13 @@ ber_scanf ( BerElement *ber,
 
        va_end( ap );
        if ( rc == LBER_DEFAULT ) {
-           /*
-            * Error.  Reclaim malloced memory that was given to the caller.
-            * Set allocated pointers to NULL, "data length" outvalues to 0.
-            */
-           va_start( ap, fmt );
+               /*
+                * Error.  Reclaim malloced memory that was given to the caller.
+                * Set allocated pointers to NULL, "data length" outvalues to 0.
+                */
+               va_start( ap, fmt );
 
-           for ( ; fmt_reset < fmt; fmt_reset++ ) {
+               for ( ; fmt_reset < fmt; fmt_reset++ ) {
                switch ( *fmt_reset ) {
                case '!': { /* Hook */
                                BERDecodeCallback *f;
@@ -904,9 +916,9 @@ ber_scanf ( BerElement *ber,
                        /* format should be good */
                        assert( 0 );
                }
-           }
+               }
 
-           va_end( ap );
+               va_end( ap );
        }
 
        return rc;
index 5e2fecf69f710a6ed48473b3b45610713d4a5b76..3b86dc0d4f03f69262545c080e2f09c100ba8353 100644 (file)
@@ -97,20 +97,16 @@ ber_calc_lenlen( ber_len_t len )
         * with bit 8 0.
         */
 
-       if ( len <= (ber_len_t) 0x7FU )
-               return 1;
+       if ( len <= (ber_len_t) 0x7FU ) return 1;
 
        /*
         * long len otherwise - one byte with bit 8 set, giving the
         * length of the length, followed by the length itself.
         */
 
-       if ( len <= (ber_len_t) 0xffU )
-               return 2;
-       if ( len <= (ber_len_t) 0xffffU )
-               return 3;
-       if ( len <= (ber_len_t) 0xffffffU )
-               return 4;
+       if ( len <= (ber_len_t) 0xffU ) return 2;
+       if ( len <= (ber_len_t) 0xffffU ) return 3;
+       if ( len <= (ber_len_t) 0xffffffU ) return 4;
 
        return 5;
 }
@@ -149,14 +145,12 @@ ber_put_len( BerElement *ber, ber_len_t len, int nosos )
                if ( len & mask ) break;
        }
        lenlen = (unsigned char) ++i;
-       if ( lenlen > 4 )
-               return -1;
+       if ( lenlen > 4 ) return -1;
 
        lenlen |= 0x80UL;
 
        /* write the length of the length */
-       if ( ber_write( ber, &lenlen, 1, nosos ) != 1 )
-               return -1;
+       if ( ber_write( ber, &lenlen, 1, nosos ) != 1 ) return -1;
 
        for( j=0; j<i; j++) {
                netlen[(sizeof(ber_len_t)-1) - j] = (unsigned char)(len & 0xffU);
@@ -220,8 +214,9 @@ ber_put_int_or_enum(
                return -1;
        }
 
-       if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 )
+       if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 ) {
                return -1;
+       }
        i++;
 
        for( j=0; j<i; j++ ) {
@@ -291,7 +286,8 @@ ber_put_ostring(
                return -1;
 
        if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 ||
-               (ber_len_t) ber_write( ber, str, len, 0 ) != len ) {
+               (ber_len_t) ber_write( ber, str, len, 0 ) != len )
+       {
                rc = -1;
        } else {
                /* return length of tag + length + contents */
@@ -421,9 +417,7 @@ ber_put_boolean(
 
        c = boolval ? (unsigned char) ~0U : (unsigned char) 0U;
 
-       if ( ber_write( ber, (char *) &c, 1, 0 )
-               != 1 )
-       {
+       if ( ber_write( ber, (char *) &c, 1, 0 ) != 1 ) {
                return -1;
        }
 
@@ -823,10 +817,11 @@ ber_printf( BerElement *ber, LDAP_CONST char *fmt, ... )
                        break;
                }
 
-               if ( ber->ber_usertag == 0 )
+               if ( ber->ber_usertag == 0 ) {
                        ber->ber_tag = LBER_DEFAULT;
-               else
+               } else {
                        ber->ber_usertag = 0;
+               }
        }
 
        va_end( ap );
index 25db4cdc5d66aa100c47d2201ad94ca15967ed39..31f788b159707acbcd25d72a5307ccfff5fa3d04 100644 (file)
@@ -34,11 +34,9 @@ static char* getbuf( void ) {
        char *p;
        static char buf[1024];
 
-       if ( fgets( buf, sizeof(buf), stdin ) == NULL )
-               return NULL;
+       if ( fgets( buf, sizeof(buf), stdin ) == NULL ) return NULL;
 
-       if ( (p = strchr( buf, '\n' )) != NULL )
-               *p = '\0';
+       if ( (p = strchr( buf, '\n' )) != NULL ) *p = '\0';
 
        return buf;
 }
index 179940f24aa9634c6f87dd86cbc9f3622e9d5049..bb32aec6decad3a6286784de724692c219a58b2e 100644 (file)
@@ -72,8 +72,7 @@ ber_write(
 
        if ( nosos || ber->ber_sos == NULL ) {
                if ( ber->ber_ptr + len > ber->ber_end ) {
-                       if ( ber_realloc( ber, len ) != 0 )
-                               return( -1 );
+                       if ( ber_realloc( ber, len ) != 0 ) return( -1 );
                }
                AC_MEMCPY( ber->ber_ptr, buf, (size_t)len );
                ber->ber_ptr += len;
@@ -81,8 +80,7 @@ ber_write(
 
        } else {
                if ( ber->ber_sos->sos_ptr + len > ber->ber_end ) {
-                       if ( ber_realloc( ber, len ) != 0 )
-                               return( -1 );
+                       if ( ber_realloc( ber, len ) != 0 ) return( -1 );
                }
                AC_MEMCPY( ber->ber_sos->sos_ptr, buf, (size_t)len );
                ber->ber_sos->sos_ptr += len;
@@ -183,8 +181,7 @@ ber_free( BerElement *ber, int freebuf )
                return;
        }
 
-       if( freebuf )
-               ber_free_buf( ber );
+       if( freebuf ) ber_free_buf( ber );
 
        ber_memfree_x( (char *) ber, ber->ber_memctx );
 }
@@ -240,8 +237,7 @@ ber_flush( Sockbuf *sb, BerElement *ber, int freeit )
                ber->ber_rwptr += rc;
        } 
 
-       if ( freeit )
-               ber_free( ber, 1 );
+       if ( freeit ) ber_free( ber, 1 );
 
        return( 0 );
 }
@@ -582,8 +578,7 @@ ber_get_next(
 #endif                 
                                return LBER_DEFAULT;
                        }
-                       for (i=0; i<llen; i++)
-                       {
+                       for (i=0; i<llen; i++) {
                                tlen <<=8;
                                tlen |= *p++;
                        }
@@ -594,10 +589,11 @@ ber_get_next(
 
                /* Are there leftover data bytes inside ber->ber_len? */
                if (ber->ber_ptr < (char *)&ber->ber_usertag) {
-                       if (ber->ber_rwptr < (char *)&ber->ber_usertag)
+                       if (ber->ber_rwptr < (char *)&ber->ber_usertag) {
                                sblen = ber->ber_rwptr - ber->ber_ptr;
-                       else
+                       } else {
                                sblen = (char *)&ber->ber_usertag - ber->ber_ptr;
+                       }
                        AC_MEMCPY(buf, ber->ber_ptr, sblen);
                        ber->ber_ptr += sblen;
                } else {
index c4c8d74a02b7cbba2d07487c2d1a39d26a337037..97e3dff57b61f9fb24d2bdf8f9004d57398e12d5 100644 (file)
@@ -608,8 +608,9 @@ ber_mem2bv_x(
        if ( dup ) {
                if ( (new->bv_val = ber_memalloc_x( new->bv_len+1, ctx )) == NULL ) {
                        ber_errno = LBER_ERROR_MEMORY;
-                       if ( !bv )
+                       if ( !bv ) {
                                ber_memfree_x( new, ctx );
+                       }
                        return NULL;
                }
 
@@ -692,7 +693,7 @@ ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx )
        }
 
        AC_MEMCPY( p, s, len );
-       p[ len ] = '\0';
+       p[len] = '\0';
        return p;
 }
 
index 7ae2f4fe22b52a77f72bdd525c5645b77e202ab7..1a41cfb46cf88459b1d4b1fd1a42bd95accbf885 100644 (file)
@@ -15,8 +15,7 @@
 
 char *ber_pvt_wsa_err2string( int err )
 {
-       switch( err )
-       {
+       switch( err ) {
                LBER_RETSTR( WSAEINTR )
                LBER_RETSTR( WSAEBADF )
                LBER_RETSTR( WSAEACCES )
@@ -84,4 +83,4 @@ char *ber_pvt_wsa_err2string( int err )
                LBER_RETSTR( WSANO_DATA )
        }
        return "unknown WSA error";
-}
\ No newline at end of file
+}
index 62af5e3690fa7e86a3eb6ccce3015e3d88df150b..eca111a8dd8eae725e784959a5e8c0bb66edf404 100644 (file)
@@ -144,8 +144,7 @@ ber_sockbuf_ctrl( Sockbuf *sb, int opt, void *arg )
                        break;
 
                default:
-                       ret = sb->sb_iod->sbiod_io->sbi_ctrl( sb->sb_iod,
-                               opt, arg );
+                       ret = sb->sb_iod->sbiod_io->sbi_ctrl( sb->sb_iod, opt, arg );
                        break;
    }
 
@@ -182,11 +181,11 @@ ber_sockbuf_add_io( Sockbuf *sb, Sockbuf_IO *sbio, int layer, void *arg )
        memset( &d->sbiod_pvt, '\0', sizeof( d->sbiod_pvt ) );
        d->sbiod_next = p;
        *q = d;
-      
+
        if ( sbio->sbi_setup != NULL && ( sbio->sbi_setup( d, arg ) < 0 ) ) {
                return -1;
        }
-      
+
        return 0;
 }
    
@@ -360,9 +359,7 @@ ber_int_sb_close( Sockbuf *sb )
    
        p = sb->sb_iod;
        while ( p ) {
-               if ( p->sbiod_io->sbi_close &&
-                       p->sbiod_io->sbi_close( p ) < 0 )
-               {
+               if ( p->sbiod_io->sbi_close && p->sbiod_io->sbi_close( p ) < 0 ) {
                        return -1;
                }
                p = p->sbiod_next;
@@ -450,7 +447,7 @@ sb_stream_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
  * MacTCP/OpenTransport
  */
        return tcpread( sbiod->sbiod_sb->sb_fd, 0, (unsigned char *)buf,
-                  len, NULL );
+               len, NULL );
 
 #elif defined( HAVE_PCNFS ) || \
    defined( HAVE_WINSOCK ) || defined ( __BEOS__ )
@@ -814,21 +811,20 @@ sb_debug_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
        ber_slen_t              ret;
 
        ret = LBER_SBIOD_READ_NEXT( sbiod, buf, len );
-       if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
-       {
-           int err = errno;
-           if ( ret < 0 ) {
-               ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
-                       "%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt,
-                       (long)len, STRERROR( errno ) );
-           } else {
-               ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
-                       "%sread: want=%ld, got=%ld\n", (char *)sbiod->sbiod_pvt,
-                       (long)len, (long)ret );
-               ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
-                       (const char *)buf, ret );
-           }
-           errno = err;
+       if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) {
+               int err = errno;
+               if ( ret < 0 ) {
+                       ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
+                               "%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt,
+                               (long)len, STRERROR( errno ) );
+               } else {
+                       ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
+                               "%sread: want=%ld, got=%ld\n", (char *)sbiod->sbiod_pvt,
+                               (long)len, (long)ret );
+                       ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
+                               (const char *)buf, ret );
+               }
+               errno = err;
        }
        return ret;
 }
@@ -839,23 +835,22 @@ sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
        ber_slen_t              ret;
 
        ret = LBER_SBIOD_WRITE_NEXT( sbiod, buf, len );
-       if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
-       {
-           int err = errno;
-           if ( ret < 0 ) {
-               ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
-                       "%swrite: want=%ld error=%s\n",
-                       (char *)sbiod->sbiod_pvt, (long)len,
-                       STRERROR( errno ) );
+       if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS) {
+               int err = errno;
+               if ( ret < 0 ) {
+                       ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
+                               "%swrite: want=%ld error=%s\n",
+                               (char *)sbiod->sbiod_pvt, (long)len,
+                               STRERROR( errno ) );
+                       errno = err;
+               } else {
+                       ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
+                               "%swrite: want=%ld, written=%ld\n",
+                               (char *)sbiod->sbiod_pvt, (long)len, (long)ret );
+                       ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
+                               (const char *)buf, ret );
+               }
                errno = err;
-           } else {
-               ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
-                       "%swrite: want=%ld, written=%ld\n",
-                       (char *)sbiod->sbiod_pvt, (long)len, (long)ret );
-               ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
-                       (const char *)buf, ret );
-           }
-           errno = err;
        }
 
        return ret;
@@ -888,8 +883,7 @@ sb_dgram_setup( Sockbuf_IO_Desc *sbiod, void *arg )
        assert( sbiod != NULL);
        assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
 
-       if ( arg != NULL )
-               sbiod->sbiod_sb->sb_fd = *((int *)arg);
+       if ( arg != NULL ) sbiod->sbiod_sb->sb_fd = *((int *)arg);
        return 0;
 }
 
@@ -907,8 +901,7 @@ sb_dgram_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
        addrlen = sizeof( struct sockaddr );
        src = buf;
        buf += addrlen;
-       rc = recvfrom( sbiod->sbiod_sb->sb_fd, buf, len, 0, src,
-               &addrlen );
+       rc = recvfrom( sbiod->sbiod_sb->sb_fd, buf, len, 0, src, &addrlen );
 
        return rc > 0 ? rc+sizeof(struct sockaddr) : rc;
 }
@@ -928,15 +921,14 @@ sb_dgram_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
        len -= sizeof( struct sockaddr );
    
        rc = sendto( sbiod->sbiod_sb->sb_fd, buf, len, 0, dst,
-            sizeof( struct sockaddr ) );
+               sizeof( struct sockaddr ) );
 
-       if ( rc < 0 )
-               return -1;
+       if ( rc < 0 ) return -1;
    
        /* fake error if write was not atomic */
        if (rc < len) {
 # ifdef EMSGSIZE
-       errno = EMSGSIZE;
+               errno = EMSGSIZE;
 # endif
                return -1;
        }
index 7188ccf887c16d29b4072217c56f52eaf6594fb7..57a743679305b489bcc77c0dedbf6a1537195897 100644 (file)
@@ -128,10 +128,11 @@ int ber_pvt_vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
        ptr = (char *)fmt;
        s2 = str;
        fm2[0] = '%';
-       if (n)
+       if (n) {
                end = str + n;
-       else
+       } else {
                end = NULL;
+       }
 
        for (pct = strchr(ptr, '%'); pct; pct = strchr(ptr, '%')) {
                len = pct-ptr;
@@ -145,8 +146,9 @@ int ber_pvt_vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
                if (len < pct-ptr) return -1;
                for (pct++, f2 = fm2+1; isdigit(*pct);) *f2++ = *pct++;
                if (*pct == 'l') *f2++ = *pct++;
-               if (*pct == '%') *s2++ = '%';
-               else {
+               if (*pct == '%') {
+                       *s2++ = '%';
+               } else {
                        *f2++ = *pct;
                        *f2 = '\0';
                        if (*pct == 's') {
@@ -166,8 +168,9 @@ int ber_pvt_vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
                                } else {
                                        s2 += sprintf(s2, fm2, ss);
                                }
-                       } else
+                       } else {
                                s2 += sprintf(s2, fm2, va_arg(ap, int));
+                       }
                }
                ptr = pct + 1;
        }