]> git.sur5r.net Git - openldap/commitdiff
Merged ber_bvstr and ber_bvstrdup into ber_str2bv.
authorHoward Chu <hyc@openldap.org>
Wed, 26 Dec 2001 10:06:19 +0000 (10:06 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 26 Dec 2001 10:06:19 +0000 (10:06 +0000)
include/lber.h
libraries/liblber/memory.c
servers/slapd/aclparse.c

index 327c40acb3c4f7690f6752be2626774f974198bc..cd986f72b03578f90ac1666c53fce23141fd8f34 100644 (file)
@@ -549,12 +549,11 @@ ber_bvdup LDAP_P((
        LDAP_CONST struct berval *bv ));
 
 LBER_F( struct berval * )
-ber_bvstr LDAP_P((
-       LDAP_CONST char * ));
+ber_str2bv LDAP_P((
+       LDAP_CONST char *, int dup, struct berval *bv ));
 
-LBER_F( struct berval * )
-ber_bvstrdup LDAP_P((
-       LDAP_CONST char * ));
+#define        ber_bvstr(a)    ber_str2bv(a, 0, NULL)
+#define        ber_bvstrdup(a) ber_str2bv(a, 1, NULL)
 
 LBER_F( char * )
 ber_strdup LDAP_P((
index d836dcc6eab3ad0f55b38c7cc14bde3e0b01369e..0e8f4e071a437b0a44e6b3bec2aa4cca0fe17223 100644 (file)
@@ -483,8 +483,8 @@ ber_bvdup(
 }
 
 struct berval *
-ber_bvstr(
-       LDAP_CONST char *s )
+ber_str2bv(
+       LDAP_CONST char *s, int dup, struct berval *bv )
 {
        struct berval *new;
 
@@ -495,45 +495,31 @@ ber_bvstr(
                return NULL;
        }
 
-       if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) {
-               ber_errno = LBER_ERROR_MEMORY;
-               return NULL;
+       if( bv ) {
+               new = bv;
+       } 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 );
+       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;
+               }
 
-       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 );
+               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 );
 }
 
 char *
index e9039552adbbc559e7aa10fbba9f49154ea1ff86..84054905901b211dabb657993414b21e092a2402 100644 (file)
@@ -172,24 +172,16 @@ parse_acl(
                                                }
                                        } else if ( strcasecmp( style, "base" ) == 0 ) {
                                                a->acl_dn_style = ACL_STYLE_BASE;
-                                               a->acl_dn_pat.bv_val = ch_strdup( right );
-                                               a->acl_dn_pat.bv_len = strlen( right );
-
+                                               ber_str2bv( right, 1, &a->acl_dn_pat );
                                        } else if ( strcasecmp( style, "one" ) == 0 ) {
                                                a->acl_dn_style = ACL_STYLE_ONE;
-                                               a->acl_dn_pat.bv_val = ch_strdup( right );
-                                               a->acl_dn_pat.bv_len = strlen( right );
-
+                                               ber_str2bv( right, 1, &a->acl_dn_pat );
                                        } else if ( strcasecmp( style, "subtree" ) == 0 ) {
                                                a->acl_dn_style = ACL_STYLE_SUBTREE;
-                                               a->acl_dn_pat.bv_val = ch_strdup( right );
-                                               a->acl_dn_pat.bv_len = strlen( right );
-
+                                               ber_str2bv( right, 1, &a->acl_dn_pat );
                                        } else if ( strcasecmp( style, "children" ) == 0 ) {
                                                a->acl_dn_style = ACL_STYLE_CHILDREN;
-                                               a->acl_dn_pat.bv_val = ch_strdup( right );
-                                               a->acl_dn_pat.bv_len = strlen( right );
-
+                                               ber_str2bv( right, 1, &a->acl_dn_pat );
                                        } else {
                                                fprintf( stderr,
        "%s: line %d: unknown dn style \"%s\" in to clause\n",
@@ -366,8 +358,7 @@ parse_acl(
                                                acl_usage();
 
                                        } else {
-                                               bv.bv_val = ch_strdup( right );
-                                               bv.bv_len = strlen( right );
+                                               ber_str2bv( right, 1, &bv );
                                        }
 
                                } else {
@@ -479,8 +470,7 @@ parse_acl(
                                                b->a_group_pat = bv;
                                        } else {
                                                struct berval *ndn = NULL;
-                                               bv.bv_val = right;
-                                               bv.bv_len = strlen( right );
+                                               ber_str2bv( right, 0, &bv );
                                                dnNormalize( NULL, &bv, &ndn );
                                                b->a_group_pat = *ndn;
                                                free(ndn);
@@ -712,8 +702,7 @@ parse_acl(
                                        }
 
                                        b->a_set_style = sty;
-                                       b->a_set_pat.bv_val = ch_strdup(right);
-                                       b->a_set_pat.bv_len = strlen(right);
+                                       ber_str2bv( right, 1, &b->a_set_pat );
 
                                        continue;
                                }
@@ -1205,7 +1194,7 @@ acl_regex_normalized_dn(
                                for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
                                        /* DO NOTHING */ ;
                                }
-                               AC_MEMCPY( &p[ 1 ], &q[ 0 ], strlen( q ) + 1 );
+                               AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
                        }
                }
        }