Back to index

openldap  2.4.31
Defines | Typedefs | Functions | Variables
bprint.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/ctype.h>
#include <ac/stdarg.h>
#include <ac/string.h>
#include "lber-int.h"

Go to the source code of this file.

Defines

#define ber_log_check(errlvl, loglvl)   ((errlvl) & (loglvl))
#define BP_OFFSET   9
#define BP_GRAPH   60
#define BP_LEN   80

Typedefs

typedef struct seqorset

Functions

intber_errno_addr (void)
void ber_error_print (LDAP_CONST char *data)
int ber_pvt_log_output (const char *subsystem, int level, const char *fmt,...)
int ber_pvt_log_printf (int errlvl, int loglvl, const char *fmt,...)
int ber_log_bprint (int errlvl, int loglvl, const char *data, ber_len_t len)
void ber_bprint (LDAP_CONST char *data, ber_len_t len)
int ber_log_dump (int errlvl, int loglvl, BerElement *ber, int inout)
void ber_dump (BerElement *ber, int inout)
int ber_log_sos_dump (int errlvl, int loglvl, Seqorset *sos)
void ber_sos_dump (Seqorset *sos)

Variables

BER_LOG_FN ber_int_log_proc = NULL
FILE * ber_pvt_err_file = NULL
BER_ERRNO_FN ber_int_errno_fn = NULL
BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print

Define Documentation

#define ber_log_check (   errlvl,
  loglvl 
)    ((errlvl) & (loglvl))

Definition at line 41 of file bprint.c.

#define BP_GRAPH   60
#define BP_LEN   80
#define BP_OFFSET   9

Typedef Documentation

typedef struct seqorset

Definition at line 279 of file bprint.c.


Function Documentation

void ber_bprint ( LDAP_CONST char *  data,
ber_len_t  len 
)

Definition at line 180 of file bprint.c.

{
       static const char hexdig[] = "0123456789abcdef";
#define BP_OFFSET 9
#define BP_GRAPH 60
#define BP_LEN       80
       char   line[BP_LEN];
       ber_len_t i;

       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 ) (*ber_pvt_log_print)( 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] = '.';
              }
       }

       (*ber_pvt_log_print)( line );
}

Here is the caller graph for this function:

void ber_dump ( BerElement *  ber,
int  inout 
)

Definition at line 252 of file bprint.c.

{
       char buf[132];
       ber_len_t len;

       assert( ber != NULL );
       assert( LBER_VALID( ber ) );

       if ( inout == 1 ) {
              len = ber_pvt_ber_remaining(ber);
       } else {
              len = ber_pvt_ber_write(ber);
       }

       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 );

       ber_bprint( ber->ber_ptr, len );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 59 of file bprint.c.

{
       static int ber_int_errno = LBER_ERROR_NONE;

       if( ber_int_errno_fn ) {
              return (*ber_int_errno_fn)();
       }

       return &ber_int_errno;
}
void ber_error_print ( LDAP_CONST char *  data)

Definition at line 73 of file bprint.c.

{
       assert( data != NULL );

       if (!ber_pvt_err_file) ber_pvt_err_file = stderr;

       fputs( data, ber_pvt_err_file );

       /* Print to both streams */
       if (ber_pvt_err_file != stderr) {
              fputs( data, stderr );
              fflush( stderr );
       }

       fflush( ber_pvt_err_file );
}
int ber_log_bprint ( int  errlvl,
int  loglvl,
const char *  data,
ber_len_t  len 
)

Definition at line 164 of file bprint.c.

{
       assert( data != NULL );

       if ( !ber_log_check( errlvl, loglvl )) {
              return 0;
       }

       ber_bprint(data, len);
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ber_log_dump ( int  errlvl,
int  loglvl,
BerElement *  ber,
int  inout 
)

Definition at line 234 of file bprint.c.

{
       assert( ber != NULL );
       assert( LBER_VALID( ber ) );

       if ( !ber_log_check( errlvl, loglvl )) {
              return 0;
       }

       ber_dump(ber, inout);
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ber_log_sos_dump ( int  errlvl,
int  loglvl,
Seqorset *  sos 
)

Definition at line 283 of file bprint.c.

{
       return 0;
}
int ber_pvt_log_output ( const char *  subsystem,
int  level,
const char *  fmt,
  ... 
)

Definition at line 96 of file bprint.c.

{
       char buf[1024];
       va_list vl;
       va_start( vl, fmt );

       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 );
              }
       }

       va_end(vl);
       return 1;
}

Here is the call graph for this function:

int ber_pvt_log_printf ( int  errlvl,
int  loglvl,
const char *  fmt,
  ... 
)

Definition at line 123 of file bprint.c.

{
       char buf[1024];
       va_list ap;

       assert( fmt != NULL );

       if ( !ber_log_check( errlvl, loglvl )) {
              return 0;
       }

       va_start( ap, fmt );

       buf[sizeof(buf) - 1] = '\0';
       vsnprintf( buf, sizeof(buf)-1, fmt, ap );

       va_end(ap);

       (*ber_pvt_log_print)( buf );
       return 1;
}

Here is the caller graph for this function:

void ber_sos_dump ( Seqorset *  sos)

Definition at line 293 of file bprint.c.

{
}

Variable Documentation

BER_ERRNO_FN ber_int_errno_fn = NULL

Definition at line 57 of file bprint.c.

Definition at line 43 of file bprint.c.

FILE* ber_pvt_err_file = NULL

Definition at line 52 of file bprint.c.

BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print

Definition at line 90 of file bprint.c.