]> git.sur5r.net Git - openldap/commitdiff
Changed dnExtractRdn to use a provided berval instead of allocating one.
authorHoward Chu <hyc@openldap.org>
Fri, 28 Dec 2001 10:04:53 +0000 (10:04 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 28 Dec 2001 10:04:53 +0000 (10:04 +0000)
Use ldap_dn2bv and ldap_rdn2bv instead of the *2str versions.

servers/slapd/back-monitor/conn.c
servers/slapd/dn.c
servers/slapd/proto-slap.h

index a91034d388b00b77767ef90735bb78cd882aab6f..3372bf135528e3a2c37d578f700a8f42b9c02b64 100644 (file)
@@ -400,7 +400,7 @@ monitor_subsys_conn_create(
 
        } else {
                char            **values;
-               struct berval   *rdn;
+               struct berval   rdn;
                unsigned long   connid;
               
                /* create exactly the required entry */
@@ -409,11 +409,11 @@ monitor_subsys_conn_create(
                        return( -1 );
                }
 
-               if ( rdn_attrs( rdn->bv_val, NULL, &values ) != LDAP_SUCCESS ) {
-                       ber_bvfree( rdn );
+               if ( rdn_attrs( rdn.bv_val, NULL, &values ) != LDAP_SUCCESS ) {
+                       free( rdn.bv_val );
                        return( -1 );
                }
-               ber_bvfree( rdn );
+               free( rdn.bv_val );
 
                assert( values );
                assert( values[ 0 ] );
index 4b3394a82223f745d2c077162819a38f73a59716..e6e4c90a850c3f51eed836e2c5a10538ddf455c6 100644 (file)
@@ -122,10 +122,9 @@ dnValidate(
         */
        if ( rc == LDAP_SUCCESS ) {
                rc = LDAPDN_validate( dn );
+               ldap_dnfree( dn );
        }
        
-       ldap_dnfree( dn );
-       
        if ( rc != LDAP_SUCCESS ) {
                return( LDAP_INVALID_SYNTAX );
        }
@@ -315,7 +314,6 @@ dnNormalize(
 
        if ( val->bv_len != 0 ) {
                LDAPDN          *dn = NULL;
-               char            *dn_out = NULL;
                int             rc;
 
                /*
@@ -337,16 +335,16 @@ dnNormalize(
                /*
                 * Back to string representation
                 */
-               rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
+               out = ch_malloc( sizeof(struct berval));
+
+               rc = ldap_dn2bv( dn, out, LDAP_DN_FORMAT_LDAPV3 );
 
                ldap_dnfree( dn );
 
                if ( rc != LDAP_SUCCESS ) {
+                       free( out );
                        return LDAP_INVALID_SYNTAX;
                }
-
-               out = ber_bvstr( dn_out );
-
        } else {
                out = ber_bvdup( val );
        }
@@ -376,7 +374,6 @@ dnPretty(
 
        if ( val->bv_len != 0 ) {
                LDAPDN          *dn = NULL;
-               char            *dn_out = NULL;
                int             rc;
 
                /* FIXME: should be liberal in what we accept */
@@ -397,17 +394,18 @@ dnPretty(
                /* RE: the default is the form that is used as
                 * an internal representation; the pretty form
                 * is a variant */
-               rc = ldap_dn2str( dn, &dn_out,
+
+               out = ch_malloc( sizeof(struct berval));
+
+               rc = ldap_dn2bv( dn, out,
                        LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
 
                ldap_dnfree( dn );
 
                if ( rc != LDAP_SUCCESS ) {
+                       free( out );
                        return LDAP_INVALID_SYNTAX;
                }
-
-               out = ber_bvstr( dn_out );
-
        } else {
                out = ber_bvdup( val );
        }
@@ -437,7 +435,6 @@ dnPrettyNormal(
 
        if ( val->bv_len != 0 ) {
                LDAPDN          *dn = NULL;
-               char            *dn_out = NULL;
                int             rc;
 
                pretty->bv_val = NULL;
@@ -459,7 +456,7 @@ dnPrettyNormal(
                        return LDAP_INVALID_SYNTAX;
                }
 
-               rc = ldap_dn2str( dn, &dn_out,
+               rc = ldap_dn2bv( dn, pretty,
                        LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
 
                if ( rc != LDAP_SUCCESS ) {
@@ -467,8 +464,6 @@ dnPrettyNormal(
                        return LDAP_INVALID_SYNTAX;
                }
 
-               ber_str2bv( dn_out, 0, 0, pretty );
-
                if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
                        ldap_dnfree( dn );
                        free( pretty->bv_val );
@@ -477,7 +472,7 @@ dnPrettyNormal(
                        return LDAP_INVALID_SYNTAX;
                }
 
-               rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
+               rc = ldap_dn2bv( dn, normal, LDAP_DN_FORMAT_LDAPV3 );
 
                ldap_dnfree( dn );
                if ( rc != LDAP_SUCCESS ) {
@@ -486,8 +481,6 @@ dnPrettyNormal(
                        pretty->bv_len = 0;
                        return LDAP_INVALID_SYNTAX;
                }
-
-               ber_str2bv( dn_out, 0, 0, normal );
        } else {
                ber_dupbv( pretty, val );
                ber_dupbv( normal, val );
@@ -686,11 +679,10 @@ dn_parent(
 int
 dnExtractRdn( 
        struct berval   *dn, 
-       struct berval   **rdn )
+       struct berval   *rdn )
 {
        LDAPRDN         *tmpRDN;
        const char      *p;
-       char            *rdnout;
        int             rc;
 
        assert( dn );
@@ -705,18 +697,12 @@ dnExtractRdn(
                return rc;
        }
 
-       rc = ldap_rdn2str( tmpRDN, &rdnout, LDAP_DN_FORMAT_LDAPV3 );
+       rc = ldap_rdn2bv( tmpRDN, rdn, LDAP_DN_FORMAT_LDAPV3 );
        ldap_rdnfree( tmpRDN );
        if ( rc != LDAP_SUCCESS ) {
                return rc;
        }
 
-       *rdn = ber_bvstr( rdnout );
-       if ( *rdn == NULL ) {
-               free( rdnout );
-               return LDAP_NO_MEMORY;
-       }
-
        return LDAP_SUCCESS;
 }
 
@@ -728,8 +714,7 @@ dn_rdnlen(
        Backend         *be,
        struct berval   *dn_in )
 {
-       struct berval   *rdn = NULL;
-       int             retval = 0;
+       struct berval   rdn;
 
        assert( dn_in );
 
@@ -749,10 +734,9 @@ dn_rdnlen(
                return 0;
        }
 
-       retval = rdn->bv_len;
-       ber_bvfree( rdn );
+       free( rdn.bv_val );
 
-       return retval;
+       return rdn.bv_len;
 }
 
 /*
@@ -762,8 +746,7 @@ char * dn_rdn(
        Backend *be,
        struct berval   *dn_in )
 {
-       struct berval   *rdn = NULL;
-       char            *retval;
+       struct berval   rdn;
 
        assert( dn_in );
 
@@ -783,10 +766,7 @@ char * dn_rdn(
                return NULL;
        }
 
-       retval = rdn->bv_val;
-       free( rdn );
-
-       return retval;
+       return rdn.bv_val;
 }
 
 /*
index ef98b8e5c3527e2fe59d6d56047f1f83cacc8587..39f2c66d47ddab05844a0a509c8dbee023e65618 100644 (file)
@@ -380,7 +380,7 @@ LDAP_SLAPD_F (int) dnIsSuffix LDAP_P((
        const struct berval *dn, const struct berval *suffix ));
 
 LDAP_SLAPD_F (int) dnExtractRdn LDAP_P((
-       struct berval *dn, struct berval **rdn ));
+       struct berval *dn, struct berval *rdn ));
 
 LDAP_SLAPD_F (int) rdnValidate LDAP_P(( struct berval * rdn ));