assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 )
- return( LBER_DEFAULT );
+ if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
+ return LBER_DEFAULT;
+ }
tag = xbyte;
- if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK )
+ if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) {
return tag;
+ }
for ( i = 1; i < sizeof(ber_tag_t); i++ ) {
- if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 )
- return( LBER_DEFAULT );
+ if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
+ return LBER_DEFAULT;
+ }
tag <<= 8;
tag |= 0x00ffUL & (ber_tag_t) xbyte;
- if ( ! (xbyte & LBER_MORE_TAG_MASK) )
+ if ( ! (xbyte & LBER_MORE_TAG_MASK) ) {
break;
+ }
}
/* tag too big! */
- if ( i == sizeof(ber_tag_t) )
- return( LBER_DEFAULT );
+ if ( i == sizeof(ber_tag_t) ) {
+ return LBER_DEFAULT;
+ }
return tag;
}
* First, we read the tag.
*/
- if ( (tag = ber_get_tag( ber )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
+ if ( (tag = ber_get_tag( ber )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
/*
* Next, read the length. The first byte contains the length of
*/
if ( ber_read( ber, (char *) &lc, 1 ) != 1 )
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
if ( lc & 0x80U ) {
noctets = (lc & 0x7fU);
if ( noctets > sizeof(ber_len_t) ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
if( (unsigned) ber_read( ber, netlen, noctets ) != noctets ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
for( i = 0; i < noctets; i++ ) {
*len = lc;
}
- return( tag );
+ return tag;
}
ber_tag_t
ber_peek_tag(
- BerElement *ber_in,
+ BerElement *ber,
ber_len_t *len )
{
- ber_tag_t tag;
- BerElement *ber;
-
- assert( ber_in != NULL );
- assert( BER_VALID( ber_in ) );
-
- *len = 0;
-
- ber = ber_dup( ber_in );
-
- if( ber == NULL ) {
- return LBER_ERROR;
- }
+ /*
+ * This implementation assumes ber_skip_tag() only
+ * modifies ber_ptr field of the BerElement.
+ */
- assert( BER_VALID( ber ) );
+ char *save;
+ ber_tag_t tag;
+ save = ber->ber_ptr;
tag = ber_skip_tag( ber, len );
+ ber->ber_ptr = save;
- ber_free( ber, 0 );
- return( tag );
+ return tag;
}
static ber_len_t
assert( ber != NULL );
assert( num != NULL );
-
assert( BER_VALID( ber ) );
/*
* extend after we read it in.
*/
- if ( len > sizeof(ber_int_t) )
- return( -1 );
+ if ( len > sizeof(ber_int_t) ) {
+ return -1;
+ }
/* read into the low-order bytes of our buffer */
if ( (ber_len_t) ber_read( ber, (char *) buf, len ) != len ) {
- return( -1 );
+ return -1;
}
if( len ) {
*num = 0;
}
- return( len );
+ return len;
}
ber_tag_t
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
+ if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
- if ( ber_getnint( ber, num, len ) != len )
- return( LBER_DEFAULT );
- else
- return( tag );
+ if ( ber_getnint( ber, num, len ) != len ) {
+ return LBER_DEFAULT;
+ }
+
+ return tag;
}
ber_tag_t
ber_len_t datalen;
ber_tag_t tag;
-#ifdef STR_TRANSLATION
- char *transbuf;
-#endif /* STR_TRANSLATION */
-
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
- if ( datalen > (*len - 1) )
- return( LBER_DEFAULT );
+ if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
+ if ( datalen > (*len - 1) ) {
+ return LBER_DEFAULT;
+ }
- if ( (ber_len_t) ber_read( ber, buf, datalen ) != datalen )
- return( LBER_DEFAULT );
+ if ( (ber_len_t) ber_read( ber, buf, datalen ) != datalen ) {
+ return LBER_DEFAULT;
+ }
buf[datalen] = '\0';
-#ifdef STR_TRANSLATION
- if ( datalen > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0
- && ber->ber_decode_translate_proc ) {
- transbuf = buf;
- ++datalen;
- if ( (*(ber->ber_decode_translate_proc))( &transbuf, &datalen,
- 0 ) != 0 ) {
- return( LBER_DEFAULT );
- }
- if ( datalen > *len ) {
- LBER_FREE( transbuf );
- return( LBER_DEFAULT );
- }
- SAFEMEMCPY( buf, transbuf, datalen );
- LBER_FREE( transbuf );
- --datalen;
- }
-#endif /* STR_TRANSLATION */
-
*len = datalen;
- return( tag );
+ return tag;
}
ber_tag_t
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
- if ( (*buf = (char *) LBER_MALLOC( datalen + 1 )) == NULL )
- return( LBER_DEFAULT );
+ if ( (*buf = (char *) LBER_MALLOC( datalen + 1 )) == NULL ) {
+ return LBER_DEFAULT;
+ }
if ( (ber_len_t) ber_read( ber, *buf, datalen ) != datalen ) {
LBER_FREE( *buf );
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
(*buf)[datalen] = '\0';
-#ifdef STR_TRANSLATION
- if ( datalen > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0
- && ber->ber_decode_translate_proc ) {
- ++datalen;
- if ( (*(ber->ber_decode_translate_proc))( buf, &datalen, 1 )
- != 0 ) {
- LBER_FREE( *buf );
- *buf = NULL;
- return( LBER_DEFAULT );
- }
- }
-#endif /* STR_TRANSLATION */
-
- return( tag );
+ return tag;
}
ber_tag_t
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
*bv = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
+ }
+
+ *bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) );
+ if ( *bv == NULL ) {
+ return LBER_DEFAULT;
}
- if ( (*bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) )) == NULL )
- return( LBER_DEFAULT );
+ if( len == 0 ) {
+ (*bv)->bv_val = NULL;
+ (*bv)->bv_len = 0;
+ return tag;
+ }
- if ( ((*bv)->bv_val = (char *) LBER_MALLOC( len + 1 )) == NULL ) {
+ (*bv)->bv_val = (char *) LBER_MALLOC( len + 1 );
+ if ( (*bv)->bv_val == NULL ) {
LBER_FREE( *bv );
*bv = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
if ( (ber_len_t) ber_read( ber, (*bv)->bv_val, len ) != len ) {
ber_bvfree( *bv );
*bv = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
+
((*bv)->bv_val)[len] = '\0';
(*bv)->bv_len = len;
-#ifdef STR_TRANSLATION
- if ( len > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0
- && ber->ber_decode_translate_proc ) {
- ++len;
- if ( (*(ber->ber_decode_translate_proc))( &((*bv)->bv_val),
- &len, 1 ) != 0 ) {
- ber_bvfree( *bv );
- *bv = NULL;
- return( LBER_DEFAULT );
- }
- (*bv)->bv_len = len - 1;
- }
-#endif /* STR_TRANSLATION */
-
- return( tag );
+ return tag;
}
ber_tag_t
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
--datalen;
- if ( (*buf = (char *) LBER_MALLOC( datalen )) == NULL )
- return( LBER_DEFAULT );
+ if ( (*buf = (char *) LBER_MALLOC( datalen )) == NULL ) {
+ return LBER_DEFAULT;
+ }
if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) {
LBER_FREE( buf );
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
if ( (ber_len_t) ber_read( ber, *buf, datalen ) != datalen ) {
LBER_FREE( buf );
*buf = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
*blen = datalen * 8 - unusedbits;
- return( tag );
+ return tag;
}
ber_tag_t
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
- return( LBER_DEFAULT );
+ if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
+ return LBER_DEFAULT;
+ }
- if ( len != 0 )
- return( LBER_DEFAULT );
+ if ( len != 0 ) {
+ return LBER_DEFAULT;
+ }
return( tag );
}
rc = ber_get_int( ber, &longbool );
*boolval = longbool;
- return( rc );
+ return rc;
}
ber_tag_t
/* skip the sequence header, use the len to mark where to stop */
if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) {
*last = NULL;
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
*last = ber->ber_ptr + *len;
if ( *last == ber->ber_ptr ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
- return( ber_peek_tag( ber, len ) );
+ return ber_peek_tag( ber, len );
}
ber_tag_t
assert( BER_VALID( ber ) );
if ( ber->ber_ptr == last ) {
- return( LBER_DEFAULT );
+ return LBER_DEFAULT;
}
- return( ber_peek_tag( ber, len ) );
+ return ber_peek_tag( ber, len );
}
/* VARARGS */
fmt_reset = fmt;
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "LIBLBER", LDAP_LEVEL_ENTRY, "ber_scanf fmt (%s) ber:\n", fmt ));
+ 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 );
ber_log_dump( LDAP_DEBUG_BER, ber->ber_debug, ber, 1 );
+#endif
for ( rc = 0; *fmt && rc != LBER_DEFAULT; fmt++ ) {
/* When this is modified, remember to update
va_end( ap );
}
- return( rc );
-}
-
-
-#ifdef STR_TRANSLATION
-void
-ber_set_string_translators( BerElement *ber, BERTranslateProc encode_proc,
- BERTranslateProc decode_proc )
-{
- assert( ber != NULL );
- assert( BER_VALID( ber ) );
-
- ber->ber_encode_translate_proc = encode_proc;
- ber->ber_decode_translate_proc = decode_proc;
+ return rc;
}
-#endif /* STR_TRANSLATION */