Skip to content
Snippets Groups Projects
Commit 6a37f1ae authored by Howard Chu's avatar Howard Chu
Browse files

Added ber_flatten2 - uses passed in struct berval, allocates copy or

directly re-uses existing ber buf.
parent 4ab720ee
No related branches found
No related tags found
No related merge requests found
...@@ -469,6 +469,12 @@ ber_flatten LDAP_P(( ...@@ -469,6 +469,12 @@ ber_flatten LDAP_P((
BerElement *ber, BerElement *ber,
struct berval **bvPtr )); struct berval **bvPtr ));
LBER_F( int )
ber_flatten2 LDAP_P((
BerElement *ber,
struct berval *bv,
int alloc ));
/* /*
* LBER ber accessor functions * LBER ber accessor functions
*/ */
......
...@@ -362,24 +362,21 @@ ber_init( struct berval *bv ) ...@@ -362,24 +362,21 @@ ber_init( struct berval *bv )
/* New C-API ber_flatten routine */ /* New C-API ber_flatten routine */
/* This routine allocates a struct berval whose contents are a BER /* This routine allocates a struct berval whose contents are a BER
** encoding taken from the ber argument. The bvPtr pointer pointers to ** encoding taken from the ber argument. The bvPtr pointer points to
** the returned berval. ** the returned berval.
**
** ber_flatten2 is the same, but uses a struct berval passed by
** the caller. If alloc is 0 the returned bv uses the ber buf directly.
*/ */
int ber_flatten( int ber_flatten2(
BerElement *ber, BerElement *ber,
struct berval **bvPtr) struct berval *bv,
int alloc )
{ {
struct berval *bv; assert( bv != NULL );
assert( bvPtr != NULL );
ber_int_options.lbo_valid = LBER_INITIALIZED;
if(bvPtr == NULL) { ber_int_options.lbo_valid = LBER_INITIALIZED;
return -1;
}
bv = LBER_MALLOC( sizeof(struct berval) );
if ( bv == NULL ) { if ( bv == NULL ) {
return -1; return -1;
} }
...@@ -393,21 +390,49 @@ int ber_flatten( ...@@ -393,21 +390,49 @@ int ber_flatten(
/* copy the berval */ /* copy the berval */
ber_len_t len = ber_pvt_ber_write( ber ); ber_len_t len = ber_pvt_ber_write( ber );
bv->bv_val = (char *) LBER_MALLOC( len + 1 ); if ( alloc ) {
if ( bv->bv_val == NULL ) { bv->bv_val = (char *) LBER_MALLOC( len + 1 );
LBER_FREE( bv ); if ( bv->bv_val == NULL ) {
return -1; return -1;
}
AC_MEMCPY( bv->bv_val, ber->ber_buf, len );
} else {
bv->bv_val = ber->ber_buf;
} }
AC_MEMCPY( bv->bv_val, ber->ber_buf, len );
bv->bv_val[len] = '\0'; bv->bv_val[len] = '\0';
bv->bv_len = len; bv->bv_len = len;
} }
*bvPtr = bv;
return 0; return 0;
} }
int ber_flatten(
BerElement *ber,
struct berval **bvPtr)
{
struct berval *bv;
int rc;
assert( bvPtr != NULL );
ber_int_options.lbo_valid = LBER_INITIALIZED;
if(bvPtr == NULL) {
return -1;
}
bv = LBER_MALLOC( sizeof(struct berval) );
if ( bv == NULL ) {
return -1;
}
rc = ber_flatten2(ber, bv, 1);
if (rc == -1) {
LBER_FREE(bv);
} else {
*bvPtr = bv;
}
return rc;
}
void void
ber_reset( BerElement *ber, int was_writing ) ber_reset( BerElement *ber, int was_writing )
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment