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 /* for the cache of attribute information (which are indexed, etc.) */
19 typedef struct bdb_attrinfo {
21 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
25 slap_mask_t ai_indexmask; /* how the attr is indexed */
31 AttributeDescription *desc,
39 return ad_cmp( desc, a->ai_desc );
41 return( strcasecmp( desc, a->ai_desc ) );
52 return ad_cmp( a->ai_desc, b->ai_desc );
54 return( strcasecmp( a->ai_desc, b->ai_desc ) );
62 AttributeDescription *desc,
66 slap_mask_t *indexmask )
70 a = (AttrInfo *) avl_find( bdb->bi_attrs, desc,
71 (AVL_CMP) ainfo_type_cmp );
73 *indexmask = a != NULL ? a->ai_indexmask : 0;
77 bdb_attr_index_config(
88 char **indexes = NULL;
90 attrs = str2charray( argv[0], "," );
93 fprintf( stderr, "%s: line %d: "
94 "no attributes specified: %s\n",
95 fname, lineno, argv[0] );
96 return LDAP_PARAM_ERROR;
100 indexes = str2charray( argv[1], "," );
102 if( indexes == NULL ) {
103 fprintf( stderr, "%s: line %d: "
104 "no indexes specified: %s\n",
105 fname, lineno, argv[1] );
106 return LDAP_PARAM_ERROR;
110 if( indexes == NULL ) {
111 mask = bdb->bi_defaultmask;
116 for ( i = 0; indexes[i] != NULL; i++ ) {
118 rc = slap_str2index( indexes[i], &index );
120 if( rc != LDAP_SUCCESS ) {
121 fprintf( stderr, "%s: line %d: "
122 "index type \"%s\" undefined\n",
123 fname, lineno, indexes[i] );
124 return LDAP_PARAM_ERROR;
132 fprintf( stderr, "%s: line %d: "
133 "no indexes selected\n",
135 return LDAP_PARAM_ERROR;
138 for ( i = 0; attrs[i] != NULL; i++ ) {
140 AttributeDescription *ad;
143 if( strcasecmp( attrs[i], "default" ) == 0 ) {
144 bdb->bi_defaultmask = mask;
148 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
151 rc = slap_str2ad( attrs[i], &ad, &text );
153 if( rc != LDAP_SUCCESS ) {
154 fprintf( stderr, "%s: line %d: "
155 "index attribute \"%s\" undefined\n",
156 fname, lineno, attrs[i] );
160 if( slap_ad_is_binary( ad ) ) {
161 fprintf( stderr, "%s: line %d: "
162 "index of attribute \"%s\" disallowed\n",
163 fname, lineno, attrs[i] );
164 return LDAP_UNWILLING_TO_PERFORM;
167 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
168 ( ad->ad_type->sat_approx
169 && ad->ad_type->sat_approx->smr_indexer
170 && ad->ad_type->sat_approx->smr_filter )
171 && ( ad->ad_type->sat_equality
172 && ad->ad_type->sat_equality->smr_indexer
173 && ad->ad_type->sat_equality->smr_filter ) ) )
175 fprintf( stderr, "%s: line %d: "
176 "approx index of attribute \"%s\" disallowed\n",
177 fname, lineno, attrs[i] );
178 return LDAP_INAPPROPRIATE_MATCHING;
181 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
182 ad->ad_type->sat_equality
183 && ad->ad_type->sat_equality->smr_indexer
184 && ad->ad_type->sat_equality->smr_filter ) )
186 fprintf( stderr, "%s: line %d: "
187 "equality index of attribute \"%s\" disallowed\n",
188 fname, lineno, attrs[i] );
189 return LDAP_INAPPROPRIATE_MATCHING;
192 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
193 ad->ad_type->sat_substr
194 && ad->ad_type->sat_substr->smr_indexer
195 && ad->ad_type->sat_substr->smr_filter ) )
197 fprintf( stderr, "%s: line %d: "
198 "substr index of attribute \"%s\" disallowed\n",
199 fname, lineno, attrs[i] );
200 return LDAP_INAPPROPRIATE_MATCHING;
204 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
205 "attr_index_config: index %s 0x%04x\n",
206 ad->ad_cname.bv_val, mask ));
208 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04x\n",
209 ad->ad_cname.bv_val, mask, 0 );
216 a->ai_desc = ch_strdup( ad->ad_cname.bv_val );
219 a->ai_indexmask = mask;
221 rc = avl_insert( &bdb->bi_attrs, (caddr_t) a,
222 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
225 fprintf( stderr, "%s: line %d: duplicate index definition "
226 "for attr \"%s\" (ignored)\n",
227 fname, lineno, attrs[i] );
229 return LDAP_PARAM_ERROR;
233 charray_free( attrs );
234 if ( indexes != NULL ) charray_free( indexes );
241 ainfo_free( void *attr )
251 bdb_attr_index_destroy( Avlnode *tree )
253 avl_free( tree, ainfo_free );