]> git.sur5r.net Git - openldap/commitdiff
Added ldap_xxx2bv schema functions
authorHoward Chu <hyc@openldap.org>
Wed, 26 Dec 2001 12:31:44 +0000 (12:31 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 26 Dec 2001 12:31:44 +0000 (12:31 +0000)
include/ldap_schema.h
libraries/libldap/schema.c
servers/slapd/at.c
servers/slapd/mr.c
servers/slapd/oc.c
servers/slapd/syntax.c

index 9b8446a05b632257e464da2d1f698d57927e2eff..ab75f7062a48652ad6db7cccac8abd8e4547ed81 100644 (file)
@@ -198,22 +198,42 @@ LDAP_F( char * )
 ldap_objectclass2str LDAP_P((
        LDAPObjectClass * oc ));
 
+LDAP_F( struct berval * )
+ldap_objectclass2bv LDAP_P((
+       LDAPObjectClass * oc, struct berval *bv ));
+
 LDAP_F( char * )
 ldap_attributetype2str LDAP_P((
        LDAPAttributeType * at ));
 
+LDAP_F( struct berval * )
+ldap_attributetype2bv LDAP_P((
+       LDAPAttributeType * at, struct berval *bv ));
+
 LDAP_F( char * )
 ldap_syntax2str LDAP_P((
        LDAPSyntax * syn ));
 
+LDAP_F( struct berval * )
+ldap_syntax2bv LDAP_P((
+       LDAPSyntax * syn, struct berval *bv ));
+
 LDAP_F( char * )
 ldap_matchingrule2str LDAP_P((
        LDAPMatchingRule * mr ));
 
+LDAP_F( struct berval * )
+ldap_matchingrule2bv LDAP_P((
+       LDAPMatchingRule * mr, struct berval *bv ));
+
 LDAP_F( char * )
 ldap_matchingruleuse2str LDAP_P((
        LDAPMatchingRuleUse * mru ));
 
+LDAP_F( struct berval * )
+ldap_matchingruleuse2bv LDAP_P((
+       LDAPMatchingRuleUse * mru, struct berval *bv ));
+
 LDAP_F( char * )
 ldap_scherr2str LDAP_P((
        int code )) LDAP_GCCATTR((const));
index dac2eb267ba43d5bad32fe35a07dd0747db48398..40e92caac042c0daf34766e4ea1ea229e97e27d5 100644 (file)
@@ -110,6 +110,17 @@ safe_string_val(safe_string * ss)
        return(ss->val);
 }
 
+static char *
+safe_strdup(safe_string * ss)
+{
+       char *ret = LDAP_MALLOC(ss->pos+1);
+       if (!ret)
+               return NULL;
+       AC_MEMCPY(ret, ss->val, ss->pos);
+       ret[ss->pos] = '\0';
+       return ret;
+}
+
 static int
 append_to_safe_string(safe_string * ss, char * s)
 {
@@ -297,9 +308,18 @@ print_extensions(safe_string *ss, LDAPSchemaExtensionItem **extensions)
 
 char *
 ldap_syntax2str( LDAPSyntax * syn )
+{
+       struct berval bv;
+       if (ldap_syntax2bv( syn, &bv ))
+               return(bv.bv_val);
+       else
+               return NULL;
+}
+
+struct berval *
+ldap_syntax2bv( LDAPSyntax * syn, struct berval *bv )
 {
        safe_string * ss;
-       char * retstring;
        
        ss = new_safe_string(256);
        if ( !ss )
@@ -322,16 +342,26 @@ ldap_syntax2str( LDAPSyntax * syn )
 
        print_literal(ss,/*(*/ ")");
 
-       retstring = LDAP_STRDUP(safe_string_val(ss));
+       bv->bv_val = safe_strdup(ss);
+       bv->bv_len = ss->pos;
        safe_string_free(ss);
-       return(retstring);
+       return(bv);
 }
 
 char *
 ldap_matchingrule2str( LDAPMatchingRule * mr )
+{
+       struct berval bv;
+       if (ldap_matchingrule2bv( mr, &bv ))
+               return(bv.bv_val);
+       else
+               return NULL;
+}
+
+struct berval *
+ldap_matchingrule2bv( LDAPMatchingRule * mr, struct berval *bv )
 {
        safe_string * ss;
-       char * retstring;
        
        ss = new_safe_string(256);
        if ( !ss )
@@ -371,16 +401,26 @@ ldap_matchingrule2str( LDAPMatchingRule * mr )
 
        print_literal(ss,/*(*/")");
 
-       retstring = LDAP_STRDUP(safe_string_val(ss));
+       bv->bv_val = safe_strdup(ss);
+       bv->bv_len = ss->pos;
        safe_string_free(ss);
-       return(retstring);
+       return(bv);
 }
 
 char *
 ldap_matchingruleuse2str( LDAPMatchingRuleUse * mru )
+{
+       struct berval bv;
+       if (ldap_matchingruleuse2bv( mru, &bv ))
+               return(bv.bv_val);
+       else
+               return NULL;
+}
+
+struct berval *
+ldap_matchingruleuse2bv( LDAPMatchingRuleUse * mru, struct berval *bv )
 {
        safe_string * ss;
-       char * retstring;
        
        ss = new_safe_string(256);
        if ( !ss )
@@ -420,16 +460,26 @@ ldap_matchingruleuse2str( LDAPMatchingRuleUse * mru )
 
        print_literal(ss,/*(*/")");
 
-       retstring = LDAP_STRDUP(safe_string_val(ss));
+       bv->bv_val = safe_strdup(ss);
+       bv->bv_len = ss->pos;
        safe_string_free(ss);
-       return(retstring);
+       return(bv);
 }
 
 char *
 ldap_objectclass2str( LDAPObjectClass * oc )
+{
+       struct berval bv;
+       if (ldap_objectclass2bv( oc, &bv ))
+               return(bv.bv_val);
+       else
+               return NULL;
+}
+
+struct berval *
+ldap_objectclass2bv( LDAPObjectClass * oc, struct berval *bv )
 {
        safe_string * ss;
-       char * retstring;
        
        ss = new_safe_string(256);
        if ( !ss )
@@ -499,16 +549,26 @@ ldap_objectclass2str( LDAPObjectClass * oc )
 
        print_literal(ss, /*(*/")");
 
-       retstring = LDAP_STRDUP(safe_string_val(ss));
+       bv->bv_val = safe_strdup(ss);
+       bv->bv_len = ss->pos;
        safe_string_free(ss);
-       return(retstring);
+       return(bv);
 }
 
 char *
-ldap_attributetype2str(  LDAPAttributeType * at )
+ldap_attributetype2str( LDAPAttributeType * at )
+{
+       struct berval bv;
+       if (ldap_attributetype2bv( at, &bv ))
+               return(bv.bv_val);
+       else
+               return NULL;
+}
+
+struct berval *
+ldap_attributetype2bv(  LDAPAttributeType * at, struct berval *bv )
 {
        safe_string * ss;
-       char * retstring;
        
        ss = new_safe_string(256);
        if ( !ss )
@@ -602,9 +662,10 @@ ldap_attributetype2str(  LDAPAttributeType * at )
 
        print_literal(ss,/*(*/")");
 
-       retstring = LDAP_STRDUP(safe_string_val(ss));
+       bv->bv_val = safe_strdup(ss);
+       bv->bv_len = ss->pos;
        safe_string_free(ss);
-       return(retstring);
+       return(bv);
 }
 
 /*
index 977cb1a618b52352a5f2eee29ee525aa905222a3..e9a294d1627be5dfc94e54a979654e8fcd05b282 100644 (file)
@@ -415,11 +415,9 @@ at_schema_info( Entry *e )
        vals[1] = NULL;
 
        for ( at = attr_list; at; at = at->sat_next ) {
-               val.bv_val = ldap_attributetype2str( &at->sat_atype );
-               if ( val.bv_val == NULL ) {
+               if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) {
                        return -1;
                }
-               val.bv_len = strlen( val.bv_val );
 #if 0
                Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
                       (long) val.bv_len, val.bv_val, 0 );
index 52bdbe96eb252a759c0e66e12c63b11f72bad2e8..1b693a5c6ef145c8642a7acc56cd4c74f24ac668 100644 (file)
@@ -270,13 +270,9 @@ int mr_schema_info( Entry *e )
                        continue;
                }
 
-               val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
-
-               if ( val.bv_val == NULL ) {
+               if ( ldap_matchingrule2bv( &mr->smr_mrule, &val ) == NULL ) {
                        return -1;
                }
-
-               val.bv_len = strlen( val.bv_val );
 #if 0
                Debug( LDAP_DEBUG_TRACE, "Merging mr [%ld] %s\n",
               (long) val.bv_len, val.bv_val, 0 );
index aac10ef95db6ca62029b0a3d72042200a9d4cdbc..470247d4e27d1b60ee72a1bf5f4cae64a4ef0340 100644 (file)
@@ -482,11 +482,9 @@ oc_schema_info( Entry *e )
        vals[1] = NULL;
 
        for ( oc = oc_list; oc; oc = oc->soc_next ) {
-               val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
-               if ( val.bv_val == NULL ) {
+               if ( ldap_objectclass2bv( &oc->soc_oclass, &val ) == NULL ) {
                        return -1;
                }
-               val.bv_len = strlen( val.bv_val );
 #if 0
                Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
               (long) val.bv_len, val.bv_val, 0 );
index 78bddd3276f7e6e8f2a83cda1de046f21bd458f4..07bd49730dc7fac390c0e6ecd882f2945ab802d7 100644 (file)
@@ -218,11 +218,9 @@ syn_schema_info( Entry *e )
                        continue;
                }
 
-               val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
-               if ( val.bv_val == NULL ) {
+               if ( ldap_syntax2bv( &syn->ssyn_syn, &val ) == NULL ) {
                        return -1;
                }
-               val.bv_len = strlen( val.bv_val );
 #if 0
 #ifdef NEW_LOGGING
                LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,