mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-08 08:02:16 -05:00
Added ber_flatten2 - uses passed in struct berval, allocates copy or
directly re-uses existing ber buf.
This commit is contained in:
parent
4ab720eefa
commit
6a37f1ae80
2 changed files with 51 additions and 20 deletions
|
|
@ -469,6 +469,12 @@ ber_flatten LDAP_P((
|
|||
BerElement *ber,
|
||||
struct berval **bvPtr ));
|
||||
|
||||
LBER_F( int )
|
||||
ber_flatten2 LDAP_P((
|
||||
BerElement *ber,
|
||||
struct berval *bv,
|
||||
int alloc ));
|
||||
|
||||
/*
|
||||
* LBER ber accessor functions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -362,24 +362,21 @@ ber_init( struct berval *bv )
|
|||
|
||||
/* New C-API ber_flatten routine */
|
||||
/* 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.
|
||||
**
|
||||
** 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,
|
||||
struct berval **bvPtr)
|
||||
struct berval *bv,
|
||||
int alloc )
|
||||
{
|
||||
struct berval *bv;
|
||||
|
||||
assert( bvPtr != NULL );
|
||||
assert( bv != NULL );
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if(bvPtr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bv = LBER_MALLOC( sizeof(struct berval) );
|
||||
if ( bv == NULL ) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -393,21 +390,49 @@ int ber_flatten(
|
|||
/* copy the berval */
|
||||
ber_len_t len = ber_pvt_ber_write( ber );
|
||||
|
||||
bv->bv_val = (char *) LBER_MALLOC( len + 1 );
|
||||
if ( bv->bv_val == NULL ) {
|
||||
LBER_FREE( bv );
|
||||
return -1;
|
||||
if ( alloc ) {
|
||||
bv->bv_val = (char *) LBER_MALLOC( len + 1 );
|
||||
if ( bv->bv_val == NULL ) {
|
||||
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_len = len;
|
||||
}
|
||||
|
||||
*bvPtr = bv;
|
||||
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
|
||||
ber_reset( BerElement *ber, int was_writing )
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue