Merged ber_bvstr and ber_bvstrdup into ber_str2bv.

This commit is contained in:
Howard Chu 2001-12-26 10:06:19 +00:00
parent d00fe773ae
commit fb3af1ccbd
3 changed files with 34 additions and 60 deletions

View File

@ -549,12 +549,11 @@ ber_bvdup LDAP_P((
LDAP_CONST struct berval *bv )); LDAP_CONST struct berval *bv ));
LBER_F( struct berval * ) LBER_F( struct berval * )
ber_bvstr LDAP_P(( ber_str2bv LDAP_P((
LDAP_CONST char * )); LDAP_CONST char *, int dup, struct berval *bv ));
LBER_F( struct berval * ) #define ber_bvstr(a) ber_str2bv(a, 0, NULL)
ber_bvstrdup LDAP_P(( #define ber_bvstrdup(a) ber_str2bv(a, 1, NULL)
LDAP_CONST char * ));
LBER_F( char * ) LBER_F( char * )
ber_strdup LDAP_P(( ber_strdup LDAP_P((

View File

@ -483,8 +483,8 @@ ber_bvdup(
} }
struct berval * struct berval *
ber_bvstr( ber_str2bv(
LDAP_CONST char *s ) LDAP_CONST char *s, int dup, struct berval *bv )
{ {
struct berval *new; struct berval *new;
@ -495,47 +495,33 @@ ber_bvstr(
return NULL; return NULL;
} }
if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) { if( bv ) {
ber_errno = LBER_ERROR_MEMORY; new = bv;
return NULL; } else {
if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) {
ber_errno = LBER_ERROR_MEMORY;
return NULL;
}
} }
new->bv_val = (char *) s;
new->bv_len = strlen( s ); new->bv_len = strlen( s );
if ( dup ) {
if ( (new->bv_val = LBER_MALLOC( new->bv_len+1 )) == NULL ) {
ber_errno = LBER_ERROR_MEMORY;
if ( !bv )
LBER_FREE( new );
return NULL;
}
AC_MEMCPY( new->bv_val, s, new->bv_len );
new->bv_val[new->bv_len] = '\0';
} else {
new->bv_val = (char *) s;
}
return( new ); return( new );
} }
struct berval *
ber_bvstrdup(
LDAP_CONST char *s )
{
struct berval *new;
char *p;
ber_int_options.lbo_valid = LBER_INITIALIZED;
if( s == NULL ) {
ber_errno = LBER_ERROR_PARAM;
return NULL;
}
p = LBER_STRDUP( s );
if( p == NULL ) {
ber_errno = LBER_ERROR_MEMORY;
return NULL;
}
new = ber_bvstr( p );
if( new == NULL || *p == '\0' ) {
LBER_FREE( p );
}
return new;
}
char * char *
ber_strdup( LDAP_CONST char *s ) ber_strdup( LDAP_CONST char *s )
{ {

View File

@ -172,24 +172,16 @@ parse_acl(
} }
} else if ( strcasecmp( style, "base" ) == 0 ) { } else if ( strcasecmp( style, "base" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_BASE; a->acl_dn_style = ACL_STYLE_BASE;
a->acl_dn_pat.bv_val = ch_strdup( right ); ber_str2bv( right, 1, &a->acl_dn_pat );
a->acl_dn_pat.bv_len = strlen( right );
} else if ( strcasecmp( style, "one" ) == 0 ) { } else if ( strcasecmp( style, "one" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_ONE; a->acl_dn_style = ACL_STYLE_ONE;
a->acl_dn_pat.bv_val = ch_strdup( right ); ber_str2bv( right, 1, &a->acl_dn_pat );
a->acl_dn_pat.bv_len = strlen( right );
} else if ( strcasecmp( style, "subtree" ) == 0 ) { } else if ( strcasecmp( style, "subtree" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_SUBTREE; a->acl_dn_style = ACL_STYLE_SUBTREE;
a->acl_dn_pat.bv_val = ch_strdup( right ); ber_str2bv( right, 1, &a->acl_dn_pat );
a->acl_dn_pat.bv_len = strlen( right );
} else if ( strcasecmp( style, "children" ) == 0 ) { } else if ( strcasecmp( style, "children" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_CHILDREN; a->acl_dn_style = ACL_STYLE_CHILDREN;
a->acl_dn_pat.bv_val = ch_strdup( right ); ber_str2bv( right, 1, &a->acl_dn_pat );
a->acl_dn_pat.bv_len = strlen( right );
} else { } else {
fprintf( stderr, fprintf( stderr,
"%s: line %d: unknown dn style \"%s\" in to clause\n", "%s: line %d: unknown dn style \"%s\" in to clause\n",
@ -366,8 +358,7 @@ parse_acl(
acl_usage(); acl_usage();
} else { } else {
bv.bv_val = ch_strdup( right ); ber_str2bv( right, 1, &bv );
bv.bv_len = strlen( right );
} }
} else { } else {
@ -479,8 +470,7 @@ parse_acl(
b->a_group_pat = bv; b->a_group_pat = bv;
} else { } else {
struct berval *ndn = NULL; struct berval *ndn = NULL;
bv.bv_val = right; ber_str2bv( right, 0, &bv );
bv.bv_len = strlen( right );
dnNormalize( NULL, &bv, &ndn ); dnNormalize( NULL, &bv, &ndn );
b->a_group_pat = *ndn; b->a_group_pat = *ndn;
free(ndn); free(ndn);
@ -712,8 +702,7 @@ parse_acl(
} }
b->a_set_style = sty; b->a_set_style = sty;
b->a_set_pat.bv_val = ch_strdup(right); ber_str2bv( right, 1, &b->a_set_pat );
b->a_set_pat.bv_len = strlen(right);
continue; continue;
} }
@ -1205,7 +1194,7 @@ acl_regex_normalized_dn(
for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) { for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
/* DO NOTHING */ ; /* DO NOTHING */ ;
} }
AC_MEMCPY( &p[ 1 ], &q[ 0 ], strlen( q ) + 1 ); AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
} }
} }
} }