From: Howard Chu Date: Wed, 26 Dec 2001 12:31:44 +0000 (+0000) Subject: Added ldap_xxx2bv schema functions X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~504 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a1460e74ce5ea6a58982d0acb0c1f61d7eb8462e;p=openldap Added ldap_xxx2bv schema functions --- diff --git a/include/ldap_schema.h b/include/ldap_schema.h index 9b8446a05b..ab75f7062a 100644 --- a/include/ldap_schema.h +++ b/include/ldap_schema.h @@ -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)); diff --git a/libraries/libldap/schema.c b/libraries/libldap/schema.c index dac2eb267b..40e92caac0 100644 --- a/libraries/libldap/schema.c +++ b/libraries/libldap/schema.c @@ -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); } /* diff --git a/servers/slapd/at.c b/servers/slapd/at.c index 977cb1a618..e9a294d162 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -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 ); diff --git a/servers/slapd/mr.c b/servers/slapd/mr.c index 52bdbe96eb..1b693a5c6e 100644 --- a/servers/slapd/mr.c +++ b/servers/slapd/mr.c @@ -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 ); diff --git a/servers/slapd/oc.c b/servers/slapd/oc.c index aac10ef95d..470247d4e2 100644 --- a/servers/slapd/oc.c +++ b/servers/slapd/oc.c @@ -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 ); diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index 78bddd3276..07bd49730d 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -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,