1 /* attr.c - backend routines for dealing with attributes */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
18 #if BDB_CONFIG_INDICES
20 /* for the cache of attribute information (which are indexed, etc.) */
21 typedef struct bdb_attrinfo {
23 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
27 slap_mask_t ai_indexmask; /* how the attr is indexed */
33 AttributeDescription *desc,
41 return ad_cmp( desc, a->ai_desc );
43 return( strcasecmp( desc, a->ai_desc ) );
54 return ad_cmp( a->ai_desc, b->ai_desc );
56 return( strcasecmp( a->ai_desc, b->ai_desc ) );
64 AttributeDescription *desc,
68 slap_mask_t *indexmask )
72 a = (AttrInfo *) avl_find( bdb->bi_attrs, desc,
73 (AVL_CMP) ainfo_type_cmp );
75 *indexmask = a != NULL ? a->ai_indexmask : 0;
79 bdb_attr_index_config(
90 char **indexes = NULL;
92 attrs = str2charray( argv[0], "," );
95 fprintf( stderr, "%s: line %d: "
96 "no attributes specified: %s\n",
97 fname, lineno, argv[0] );
98 return LDAP_PARAM_ERROR;
102 indexes = str2charray( argv[1], "," );
104 if( indexes == NULL ) {
105 fprintf( stderr, "%s: line %d: "
106 "no indexes specified: %s\n",
107 fname, lineno, argv[1] );
108 return LDAP_PARAM_ERROR;
112 if( indexes == NULL ) {
113 mask = bdb->bi_defaultmask;
118 for ( i = 0; indexes[i] != NULL; i++ ) {
120 rc = slap_str2index( indexes[i], &index );
122 if( rc != LDAP_SUCCESS ) {
123 fprintf( stderr, "%s: line %d: "
124 "index type \"%s\" undefined\n",
125 fname, lineno, indexes[i] );
126 return LDAP_PARAM_ERROR;
134 fprintf( stderr, "%s: line %d: "
135 "no indexes selected\n",
137 return LDAP_PARAM_ERROR;
140 for ( i = 0; attrs[i] != NULL; i++ ) {
142 AttributeDescription *ad;
145 if( strcasecmp( attrs[i], "default" ) == 0 ) {
146 bdb->bi_defaultmask = mask;
150 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
153 rc = slap_str2ad( attrs[i], &ad, &text );
155 if( rc != LDAP_SUCCESS ) {
156 fprintf( stderr, "%s: line %d: "
157 "index attribute \"%s\" undefined\n",
158 fname, lineno, attrs[i] );
162 if( slap_ad_is_binary( ad ) ) {
163 fprintf( stderr, "%s: line %d: "
164 "index of attribute \"%s\" disallowed\n",
165 fname, lineno, attrs[i] );
166 return LDAP_UNWILLING_TO_PERFORM;
169 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
170 ( ad->ad_type->sat_approx
171 && ad->ad_type->sat_approx->smr_indexer
172 && ad->ad_type->sat_approx->smr_filter )
173 && ( ad->ad_type->sat_equality
174 && ad->ad_type->sat_equality->smr_indexer
175 && ad->ad_type->sat_equality->smr_filter ) ) )
177 fprintf( stderr, "%s: line %d: "
178 "approx index of attribute \"%s\" disallowed\n",
179 fname, lineno, attrs[i] );
180 return LDAP_INAPPROPRIATE_MATCHING;
183 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
184 ad->ad_type->sat_equality
185 && ad->ad_type->sat_equality->smr_indexer
186 && ad->ad_type->sat_equality->smr_filter ) )
188 fprintf( stderr, "%s: line %d: "
189 "equality index of attribute \"%s\" disallowed\n",
190 fname, lineno, attrs[i] );
191 return LDAP_INAPPROPRIATE_MATCHING;
194 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
195 ad->ad_type->sat_substr
196 && ad->ad_type->sat_substr->smr_indexer
197 && ad->ad_type->sat_substr->smr_filter ) )
199 fprintf( stderr, "%s: line %d: "
200 "substr index of attribute \"%s\" disallowed\n",
201 fname, lineno, attrs[i] );
202 return LDAP_INAPPROPRIATE_MATCHING;
206 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
207 "attr_index_config: index %s 0x%04x\n",
208 ad->ad_cname->bv_val, mask ));
210 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04x\n",
211 ad->ad_cname->bv_val, mask, 0 );
218 a->ai_desc = ch_strdup( ad->ad_cname->bv_val );
222 a->ai_indexmask = mask;
224 rc = avl_insert( &bdb->bi_attrs, (caddr_t) a,
225 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
228 fprintf( stderr, "%s: line %d: duplicate index definition "
229 "for attr \"%s\" (ignored)\n",
230 fname, lineno, attrs[i] );
232 return LDAP_PARAM_ERROR;
236 charray_free( attrs );
237 if ( indexes != NULL ) charray_free( indexes );
244 ainfo_free( void *attr )
248 ad_free( ai->ai_desc, 1 );
256 bdb_attr_index_destroy( Avlnode *tree )
258 avl_free( tree, ainfo_free );