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 );
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 );
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] = '.';
}
}
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] = '.';
}
}
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);
int lutil_set_debug_level( const char* subsys, int level )
{
- return( addSubsys( subsys, level ) );
+ return( addSubsys( subsys, level ) );
}
int lutil_debug_file( FILE *file )
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 */
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 );
}
* 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 ",
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, ... )
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 );
}
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 ) {
* 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);
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;
if ( rlen ) *rlen = i;
- if ( i == 0 )
- {
+ if ( i == 0 ) {
*b->res.c = NULL;
return 0;
}
/* 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;
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) {
}
}
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;
}
}
}
}
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;
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;
}
}
--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;
}
#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 );
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;
/* format should be good */
assert( 0 );
}
- }
+ }
- va_end( ap );
+ va_end( ap );
}
return rc;
* 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;
}
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);
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++ ) {
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 */
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;
}
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 );
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;
}
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;
} 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;
return;
}
- if( freebuf )
- ber_free_buf( ber );
+ if( freebuf ) ber_free_buf( ber );
ber_memfree_x( (char *) ber, ber->ber_memctx );
}
ber->ber_rwptr += rc;
}
- if ( freeit )
- ber_free( ber, 1 );
+ if ( freeit ) ber_free( ber, 1 );
return( 0 );
}
#endif
return LBER_DEFAULT;
}
- for (i=0; i<llen; i++)
- {
+ for (i=0; i<llen; i++) {
tlen <<=8;
tlen |= *p++;
}
/* 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 {
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;
}
}
AC_MEMCPY( p, s, len );
- p[ len ] = '\0';
+ p[len] = '\0';
return p;
}
char *ber_pvt_wsa_err2string( int err )
{
- switch( err )
- {
+ switch( err ) {
LBER_RETSTR( WSAEINTR )
LBER_RETSTR( WSAEBADF )
LBER_RETSTR( WSAEACCES )
LBER_RETSTR( WSANO_DATA )
}
return "unknown WSA error";
-}
\ No newline at end of file
+}
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;
}
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;
}
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;
* 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__ )
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;
}
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;
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;
}
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;
}
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;
}
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;
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') {
} else {
s2 += sprintf(s2, fm2, ss);
}
- } else
+ } else {
s2 += sprintf(s2, fm2, va_arg(ap, int));
+ }
}
ptr = pct + 1;
}