]> git.sur5r.net Git - openldap/blobdiff - libraries/liblber/bprint.c
Merge remote-tracking branch 'origin/mdb.master'
[openldap] / libraries / liblber / bprint.c
index 760e66bdabb18f5b77d32c190b44c1247e501b34..8f80f9f0a38ed0a7773cebe9e2912a506d0917f2 100644 (file)
@@ -1,7 +1,31 @@
 /* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2012 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
 /*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ * Copyright (c) 1991 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was originally developed by the University of Michigan
+ * (as part of U-MICH LDAP).
  */
 
 #include "portable.h"
@@ -32,10 +56,9 @@ FILE *ber_pvt_err_file = NULL;
  */
 BER_ERRNO_FN ber_int_errno_fn = NULL;
 
-static int ber_int_errno = LBER_ERROR_NONE;
-
 int * ber_errno_addr(void)
 {
+       static int ber_int_errno = LBER_ERROR_NONE;
 
        if( ber_int_errno_fn ) {
                return (*ber_int_errno_fn)();
@@ -76,31 +99,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 );
@@ -159,11 +181,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 );
@@ -184,104 +206,29 @@ 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] = '.';
                }
        }
 
        (*ber_pvt_log_print)( line );
 }
 
-#ifdef NEW_LOGGING
-int ber_output_dump(
-       const char *subsys,
-       int level,
-       BerElement *ber,
-       int inout )
-{
-    static const char  hexdig[] = "0123456789abcdef";
-    char buf[132];
-    ber_len_t len;
-    char       line[ BP_LEN ];
-    ber_len_t i;
-    char *data = ber->ber_ptr;
-
-    if ( inout == 1 ) {
-        len = ber_pvt_ber_remaining(ber);
-    } else {
-        len = ber_pvt_ber_write(ber);
-    }
-
-    sprintf( buf, "ber_dump: buf=0x%08lx ptr=0x%08lx end=0x%08lx len=%ld\n",
-             (long) ber->ber_buf,
-             (long) ber->ber_ptr,
-             (long) ber->ber_end,
-             (long) len );
-
-    (void) ber_pvt_log_output( subsys, level, "%s", buf );
-
-#define BP_OFFSET 9
-#define BP_GRAPH 60
-#define BP_LEN 80
-
-    assert( data != NULL );
-        
-    /* in case len is zero */
-    line[0] = '\n';
-    line[1] = '\0';
-       
-    for ( i = 0 ; i < len ; i++ ) {
-        int n = i % 16;
-        unsigned off;
-        
-        if( !n ) {
-            if( i ) {
-                               (void) ber_pvt_log_output( subsys, level, "%s", line );
-                       }
-            memset( line, ' ', sizeof(line)-2 );
-            line[sizeof(line)-2] = '\n';
-            line[sizeof(line)-1] = '\0';
-            
-            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 ] = ':';
-        }
-
-        off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
-        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];
-        } else {
-            line[ BP_GRAPH + n ] = '.';
-        }
-    }
-
-    return ber_pvt_log_output( subsys, level, "%s", line );
-}
-#endif
 
 int
 ber_log_dump(
@@ -318,10 +265,10 @@ ber_dump(
                len = ber_pvt_ber_write(ber);
        }
 
-       sprintf( buf, "ber_dump: buf=0x%08lx ptr=0x%08lx end=0x%08lx len=%ld\n",
-           (long) ber->ber_buf,
-               (long) ber->ber_ptr,
-               (long) ber->ber_end,
+       sprintf( buf, "ber_dump: buf=%p ptr=%p end=%p len=%ld\n",
+               ber->ber_buf,
+               ber->ber_ptr,
+               ber->ber_end,
                (long) len );
 
        (void) (*ber_pvt_log_print)( buf );
@@ -329,47 +276,21 @@ ber_dump(
        ber_bprint( ber->ber_ptr, len );
 }
 
+typedef struct seqorset Seqorset;
+
+/* Exists for binary compatibility with OpenLDAP 2.4.17-- */
 int
 ber_log_sos_dump(
        int errlvl,
        int loglvl,
        Seqorset *sos )
 {
-       assert( sos != NULL );
-
-       if ( !ber_log_check( errlvl, loglvl )) {
-               return 0;
-       }
-
-       ber_sos_dump( sos );
-       return 1;
+       return 0;
 }
 
+/* Exists for binary compatibility with OpenLDAP 2.4.17-- */
 void
 ber_sos_dump(
        Seqorset *sos )
 {
-       char buf[132];
-
-       assert( sos != NULL );
-
-       (*ber_pvt_log_print)( "*** sos dump ***\n" );
-
-       while ( sos != NULL ) {
-               sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
-                   (long) sos->sos_clen,
-                       (long) sos->sos_first,
-                       (long) sos->sos_ptr );
-               (*ber_pvt_log_print)( buf );
-
-               sprintf( buf, "              current len %ld contents:\n",
-                   (long) (sos->sos_ptr - sos->sos_first) );
-               (*ber_pvt_log_print)( buf );
-
-               ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
-
-               sos = sos->sos_next;
-       }
-
-       (*ber_pvt_log_print)( "*** end dump ***\n" );
 }