From 0bfaa8b4aefebb921ef22b433c2f929f4e6ae109 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 16 Nov 2001 07:45:37 +0000 Subject: [PATCH] Changed AttributeType.sat_cname from char * to struct berval. (will fix up back-bdb next.) --- servers/slapd/at.c | 3 +- servers/slapd/back-ldap/search.c | 4 +- servers/slapd/back-ldbm/attr.c | 39 ++-------- servers/slapd/back-ldbm/filterindex.c | 37 +++------ servers/slapd/back-ldbm/index.c | 93 +++++++++++++---------- servers/slapd/back-ldbm/proto-back-ldbm.h | 4 +- servers/slapd/back-meta/search.c | 4 +- servers/slapd/schema_check.c | 8 +- servers/slapd/slap.h | 2 +- 9 files changed, 80 insertions(+), 114 deletions(-) diff --git a/servers/slapd/at.c b/servers/slapd/at.c index 4bec7c1054..63f5f629c4 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -276,7 +276,8 @@ at_add( sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) ); AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType)); - sat->sat_cname = cname; + sat->sat_cname.bv_val = cname; + sat->sat_cname.bv_len = strlen( cname ); ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex); if ( at->at_sup_oid ) { diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 0de3e828fc..c28302833d 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -507,12 +507,12 @@ ldap_send_entry( "[rw] searchResult on" " attr=%s:" " \"%s\" -> \"%s\"\n", - attr->a_desc->ad_type->sat_cname, + attr->a_desc->ad_type->sat_cname.bv_val, bv->bv_val, newval )); #else /* !NEW_LOGGING */ Debug( LDAP_DEBUG_ARGS, "rw> searchResult on attr=%s: \"%s\" -> \"%s\"\n", - attr->a_desc->ad_type->sat_cname, + attr->a_desc->ad_type->sat_cname.bv_val, bv->bv_val, newval ); #endif /* !NEW_LOGGING */ diff --git a/servers/slapd/back-ldbm/attr.c b/servers/slapd/back-ldbm/attr.c index 7aef298fa5..8241e12601 100644 --- a/servers/slapd/back-ldbm/attr.c +++ b/servers/slapd/back-ldbm/attr.c @@ -18,29 +18,17 @@ /* for the cache of attribute information (which are indexed, etc.) */ typedef struct ldbm_attrinfo { -#ifdef SLAPD_USE_AD - AttributeDescription *ai_desc; /* attribute description cn;lang-en */ -#else - char *ai_desc; -#endif + AttributeDescription *ai_desc; /* attribute description cn;lang-en */ slap_mask_t ai_indexmask; /* how the attr is indexed */ } AttrInfo; static int ainfo_type_cmp( -#ifdef SLAPD_USE_AD AttributeDescription *desc, -#else - char *desc, -#endif AttrInfo *a ) { -#ifdef SLAPD_USE_AD - return ad_cmp( desc, a->ai_desc ); -#else - return( strcasecmp( desc, a->ai_desc ) ); -#endif + return desc - a->ai_desc; } static int @@ -49,21 +37,13 @@ ainfo_cmp( AttrInfo *b ) { -#ifdef SLAPD_USE_AD - return ad_cmp( a->ai_desc, b->ai_desc ); -#else - return( strcasecmp( a->ai_desc, b->ai_desc ) ); -#endif + return a->ai_desc - b->ai_desc; } void attr_mask( struct ldbminfo *li, -#ifdef SLAPD_USE_AD - AttributeDescription *desc, -#else - const char *desc, -#endif + AttributeDescription *desc, slap_mask_t *indexmask ) { AttrInfo *a; @@ -211,11 +191,7 @@ attr_index_config( #endif -#ifdef SLAPD_USE_AD a->ai_desc = ad; -#else - a->ai_desc = ch_strdup( ad->ad_cname.bv_val ); -#endif a->ai_indexmask = mask; @@ -241,11 +217,7 @@ attr_index_config( static void ainfo_free( void *attr ) { - AttrInfo *ai = attr; -#ifndef SLAPD_USE_AD - free( ai->ai_desc ); -#endif - free( ai ); + free( attr ); } void @@ -253,4 +225,3 @@ attr_index_destroy( Avlnode *tree ) { avl_free( tree, ainfo_free ); } - diff --git a/servers/slapd/back-ldbm/filterindex.c b/servers/slapd/back-ldbm/filterindex.c index 67d2454789..55f873ba01 100644 --- a/servers/slapd/back-ldbm/filterindex.c +++ b/servers/slapd/back-ldbm/filterindex.c @@ -212,7 +212,7 @@ presence_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval *prefix; + struct berval prefix = {0}; #ifdef NEW_LOGGING LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY, @@ -221,7 +221,6 @@ presence_candidates( Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 ); #endif - idl = idl_allids( be ); rc = index_param( be, desc, LDAP_FILTER_PRESENT, @@ -252,7 +251,6 @@ presence_candidates( 0, 0, 0 ); #endif - ber_bvfree( prefix ); return idl; } @@ -269,15 +267,14 @@ presence_candidates( dbname, LDBM_SUFFIX, 0 ); #endif - ber_bvfree( prefix ); return idl; } - if( prefix != NULL ) { + if( prefix.bv_val != NULL ) { idl_free( idl ); idl = NULL; - rc = key_read( be, db, prefix, &idl ); + rc = key_read( be, db, &prefix, &idl ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING @@ -304,7 +301,6 @@ presence_candidates( } ldbm_cache_close( be, db ); - ber_bvfree( prefix ); #ifdef NEW_LOGGING LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY, @@ -330,7 +326,7 @@ equality_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval *prefix; + struct berval prefix = {0}; struct berval **keys = NULL; MatchingRule *mr; @@ -371,18 +367,15 @@ equality_candidates( 0, 0, 0 ); #endif - ber_bvfree( prefix ); return idl; } mr = ava->aa_desc->ad_type->sat_equality; if( !mr ) { - ber_bvfree( prefix ); return idl; } if( !mr->smr_filter ) { - ber_bvfree( prefix ); return idl; } @@ -391,12 +384,10 @@ equality_candidates( mask, ava->aa_desc->ad_type->sat_syntax, mr, - prefix, + &prefix, ava->aa_value, &keys ); - ber_bvfree( prefix ); - if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG(( "filter", LDAP_LEVEL_ERR, @@ -514,7 +505,7 @@ approx_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval *prefix; + struct berval prefix = {0}; struct berval **keys = NULL; MatchingRule *mr; @@ -555,7 +546,6 @@ approx_candidates( 0, 0, 0 ); #endif - ber_bvfree( prefix ); return idl; } @@ -566,12 +556,10 @@ approx_candidates( } if( !mr ) { - ber_bvfree( prefix ); return idl; } if( !mr->smr_filter ) { - ber_bvfree( prefix ); return idl; } @@ -580,12 +568,10 @@ approx_candidates( mask, ava->aa_desc->ad_type->sat_syntax, mr, - prefix, + &prefix, ava->aa_value, &keys ); - ber_bvfree( prefix ); - if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG(( "filter", LDAP_LEVEL_ERR, @@ -760,7 +746,7 @@ substring_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval *prefix; + struct berval prefix = {0}; struct berval **keys = NULL; MatchingRule *mr; @@ -801,19 +787,16 @@ substring_candidates( 0, 0, 0 ); #endif - ber_bvfree( prefix ); return idl; } mr = sub->sa_desc->ad_type->sat_substr; if( !mr ) { - ber_bvfree( prefix ); return idl; } if( !mr->smr_filter ) { - ber_bvfree( prefix ); return idl; } @@ -822,12 +805,10 @@ substring_candidates( mask, sub->sa_desc->ad_type->sat_syntax, mr, - prefix, + &prefix, sub, &keys ); - ber_bvfree( prefix ); - if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG(( "filter", LDAP_LEVEL_ERR, diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index 1ab7d47bfb..c937178135 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -19,47 +19,54 @@ static slap_mask_t index_mask( Backend *be, AttributeDescription *desc, char **dbname, - char **atname ) + struct berval *atname ) { AttributeType *at; slap_mask_t mask = 0; - attr_mask( be->be_private, desc->ad_cname.bv_val, &mask ); + attr_mask( be->be_private, desc, &mask ); if( mask ) { - *atname = desc->ad_cname.bv_val; + *atname = desc->ad_cname; *dbname = desc->ad_cname.bv_val; return mask; } - if( slap_ad_is_lang( desc ) ) { + /* If there is a language tag, did we ever index the base + * type? If so, check for mask, otherwise it's not there. + */ + if( slap_ad_is_lang( desc ) && desc != desc->ad_type->sat_ad ) { /* has language tag */ - attr_mask( be->be_private, desc->ad_type->sat_cname, &mask ); + attr_mask( be->be_private, desc->ad_type->sat_ad, &mask ); if( mask & SLAP_INDEX_AUTO_LANG ) { - *atname = desc->ad_cname.bv_val; - *dbname = desc->ad_type->sat_cname; + *atname = desc->ad_cname; + *dbname = desc->ad_type->sat_cname.bv_val; return mask; } if( mask & SLAP_INDEX_LANG ) { *atname = desc->ad_type->sat_cname; - *dbname = desc->ad_type->sat_cname; + *dbname = desc->ad_type->sat_cname.bv_val; return mask; } } /* see if supertype defined mask for its subtypes */ for( at = desc->ad_type; at != NULL ; at = at->sat_sup ) { - attr_mask( be->be_private, at->sat_cname, &mask ); + /* If no AD, we've never indexed this type */ + if (!at->sat_ad) + continue; + + attr_mask( be->be_private, at->sat_ad, &mask ); if( mask & SLAP_INDEX_AUTO_SUBTYPES ) { *atname = desc->ad_type->sat_cname; - *dbname = at->sat_cname; + *dbname = at->sat_cname.bv_val; return mask; } if( mask & SLAP_INDEX_SUBTYPES ) { *atname = at->sat_cname; - *dbname = at->sat_cname; + *dbname = at->sat_cname.bv_val; return mask; } @@ -75,13 +82,12 @@ int index_param( int ftype, char **dbnamep, slap_mask_t *maskp, - struct berval **prefixp ) + struct berval *prefixp ) { slap_mask_t mask; char *dbname; - char *atname; - mask = index_mask( be, desc, &dbname, &atname ); + mask = index_mask( be, desc, &dbname, prefixp ); if( mask == 0 ) { return LDAP_INAPPROPRIATE_MATCHING; @@ -120,7 +126,6 @@ int index_param( done: *dbnamep = dbname; - *prefixp = ber_bvstrdup( atname ); *maskp = mask; return LDAP_SUCCESS; } @@ -128,7 +133,7 @@ done: static int indexer( Backend *be, char *dbname, - char *atname, + struct berval *atname, struct berval **vals, ID id, int op, @@ -139,17 +144,13 @@ static int indexer( DBCache *db; AttributeDescription *ad = NULL; struct berval **keys; - struct berval prefix; assert( mask ); - rc = slap_str2ad( atname, &ad, &text ); + rc = slap_bv2ad( atname, &ad, &text ); if( rc != LDAP_SUCCESS ) return rc; - prefix.bv_val = atname; - prefix.bv_len = strlen( atname ); - db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); if ( db == NULL ) { @@ -167,7 +168,7 @@ static int indexer( } if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) { - key_change( be, db, &prefix, id, op ); + key_change( be, db, atname, id, op ); } if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) { @@ -176,7 +177,7 @@ static int indexer( mask, ad->ad_type->sat_syntax, ad->ad_type->sat_equality, - &prefix, vals, &keys ); + atname, vals, &keys ); if( rc == LDAP_SUCCESS && keys != NULL ) { for( i=0; keys[i] != NULL; i++ ) { @@ -192,7 +193,7 @@ static int indexer( mask, ad->ad_type->sat_syntax, ad->ad_type->sat_approx, - &prefix, vals, &keys ); + atname, vals, &keys ); if( rc == LDAP_SUCCESS && keys != NULL ) { for( i=0; keys[i] != NULL; i++ ) { @@ -208,7 +209,7 @@ static int indexer( mask, ad->ad_type->sat_syntax, ad->ad_type->sat_substr, - &prefix, vals, &keys ); + atname, vals, &keys ); if( rc == LDAP_SUCCESS && keys != NULL ) { for( i=0; keys[i] != NULL; i++ ) { @@ -232,7 +233,7 @@ static int index_at_values( char ** dbnamep, slap_mask_t *maskp ) { - slap_mask_t mask; + slap_mask_t mask = 0; slap_mask_t tmpmask = 0; int lindex = 0; @@ -244,45 +245,57 @@ static int index_at_values( dbnamep, &tmpmask ); } - attr_mask( be->be_private, type->sat_cname, &mask ); + /* If this type has no AD, we've never used it before */ + if (type->sat_ad) + attr_mask( be->be_private, type->sat_ad, &mask ); if( mask ) { - *dbnamep = type->sat_cname; + *dbnamep = type->sat_cname.bv_val; } else if ( tmpmask & SLAP_INDEX_AUTO_SUBTYPES ) { mask = tmpmask; } if( mask ) { indexer( be, *dbnamep, - type->sat_cname, + &type->sat_cname, vals, id, op, mask ); } if( lang->bv_len ) { char *dbname = NULL; - size_t tlen = strlen( type->sat_cname ); - size_t llen = lang->bv_len; - char *lname = ch_malloc( tlen + llen + sizeof(";") ); + struct berval lname; + AttributeDescription *desc; - sprintf( lname, "%s;%s", type->sat_cname, lang->bv_val ); + tmpmask = 0; + lname.bv_val = NULL; - attr_mask( be->be_private, lname, &tmpmask ); + desc = ad_find_lang(type, lang); + if (desc) + attr_mask( be->be_private, desc, &tmpmask ); if( tmpmask ) { - dbname = lname; + dbname = desc->ad_cname.bv_val; + lname = desc->ad_cname; + mask = tmpmask; } else if ( mask & SLAP_INDEX_AUTO_LANG ) { dbname = *dbnamep; - tmpmask = mask; + lname.bv_len = type->sat_cname.bv_len+lang->bv_len + 1; + lname.bv_val = ch_malloc( lname.bv_len + 1 ); + + strcpy(lname.bv_val, type->sat_cname.bv_val); + lname.bv_val[type->sat_cname.bv_len] = ';'; + strcpy(lname.bv_val+type->sat_cname.bv_len+1, + lang->bv_val); } if( dbname != NULL ) { - indexer( be, dbname, lname, + indexer( be, dbname, &lname, vals, id, op, - tmpmask ); + mask ); + if (!tmpmask) + ch_free( lname.bv_val ); } - - ch_free( lname ); } return LDAP_SUCCESS; diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index 1f9426f2a5..43a3be3015 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -34,7 +34,7 @@ Entry *deref_internal_r LDAP_P(( */ void attr_mask LDAP_P(( struct ldbminfo *li, - const char *desc, + AttributeDescription *desc, slap_mask_t *indexmask )); int attr_index_config LDAP_P(( struct ldbminfo *li, @@ -146,7 +146,7 @@ index_param LDAP_P(( int ftype, char **dbname, slap_mask_t *mask, - struct berval **prefix )); + struct berval *prefix )); extern int index_values LDAP_P(( diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index 0700f137d7..328df32985 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -725,13 +725,13 @@ meta_send_entry( "[rw] searchResult on" " attr=%s:" " \"%s\" -> \"%s\"\n", - attr->a_desc->ad_type->sat_cname, + attr->a_desc->ad_type->sat_cname.bv_val, bv->bv_val, newval )); #else /* !NEW_LOGGING */ Debug( LDAP_DEBUG_ARGS, "rw> searchResult on attr=%s:" " \"%s\" -> \"%s\"\n", - attr->a_desc->ad_type->sat_cname, + attr->a_desc->ad_type->sat_cname.bv_val, bv->bv_val, newval ); #endif /* !NEW_LOGGING */ diff --git a/servers/slapd/schema_check.c b/servers/slapd/schema_check.c index c2812d0c9e..87ba819c1d 100644 --- a/servers/slapd/schema_check.c +++ b/servers/slapd/schema_check.c @@ -202,7 +202,7 @@ oc_check_required( Entry *e, struct berval *ocname ) } /* not there => schema violation */ if ( a == NULL ) { - return at->sat_cname; + return at->sat_cname.bv_val; } } @@ -218,15 +218,15 @@ int oc_check_allowed( #ifdef NEW_LOGGING LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY, - "oc_check_allowed: type \"%s\"\n", at->sat_cname )); + "oc_check_allowed: type \"%s\"\n", at->sat_cname.bv_val )); #else Debug( LDAP_DEBUG_TRACE, "oc_check_allowed type \"%s\"\n", - at->sat_cname, 0, 0 ); + at->sat_cname.bv_val, 0, 0 ); #endif /* always allow objectClass attribute */ - if ( strcasecmp( at->sat_cname, "objectClass" ) == 0 ) { + if ( strcasecmp( at->sat_cname.bv_val, "objectClass" ) == 0 ) { return LDAP_SUCCESS; } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index bfca2373da..b3e115f085 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -370,7 +370,7 @@ struct slap_attr_desc; typedef struct slap_attribute_type { LDAPAttributeType sat_atype; - char *sat_cname; + struct berval sat_cname; struct slap_attribute_type *sat_sup; struct slap_attribute_type **sat_subtypes; MatchingRule *sat_equality; -- 2.39.5