1 /* attr.c - backend routines for dealing with attributes */
4 * Copyright 1998-2002 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 {
20 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
21 slap_mask_t ai_indexmask; /* how the attr is indexed */
26 AttributeDescription *desc,
30 return desc - a->ai_desc;
39 return a->ai_desc - b->ai_desc;
45 AttributeDescription *desc,
46 slap_mask_t *indexmask )
50 a = (AttrInfo *) avl_find( bdb->bi_attrs, desc,
51 (AVL_CMP) ainfo_type_cmp );
53 *indexmask = a != NULL ? a->ai_indexmask : 0;
57 bdb_attr_index_config(
68 char **indexes = NULL;
70 attrs = ldap_str2charray( argv[0], "," );
73 fprintf( stderr, "%s: line %d: "
74 "no attributes specified: %s\n",
75 fname, lineno, argv[0] );
76 return LDAP_PARAM_ERROR;
80 indexes = ldap_str2charray( argv[1], "," );
82 if( indexes == NULL ) {
83 fprintf( stderr, "%s: line %d: "
84 "no indexes specified: %s\n",
85 fname, lineno, argv[1] );
86 return LDAP_PARAM_ERROR;
90 if( indexes == NULL ) {
91 mask = bdb->bi_defaultmask;
96 for ( i = 0; indexes[i] != NULL; i++ ) {
98 rc = slap_str2index( indexes[i], &index );
100 if( rc != LDAP_SUCCESS ) {
101 fprintf( stderr, "%s: line %d: "
102 "index type \"%s\" undefined\n",
103 fname, lineno, indexes[i] );
104 return LDAP_PARAM_ERROR;
112 fprintf( stderr, "%s: line %d: "
113 "no indexes selected\n",
115 return LDAP_PARAM_ERROR;
118 for ( i = 0; attrs[i] != NULL; i++ ) {
120 AttributeDescription *ad;
123 if( strcasecmp( attrs[i], "default" ) == 0 ) {
124 bdb->bi_defaultmask = mask;
128 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
131 rc = slap_str2ad( attrs[i], &ad, &text );
133 if( rc != LDAP_SUCCESS ) {
134 fprintf( stderr, "%s: line %d: "
135 "index attribute \"%s\" undefined\n",
136 fname, lineno, attrs[i] );
140 if( slap_ad_is_binary( ad ) ) {
141 fprintf( stderr, "%s: line %d: "
142 "index of attribute \"%s\" disallowed\n",
143 fname, lineno, attrs[i] );
144 return LDAP_UNWILLING_TO_PERFORM;
147 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
148 ( ad->ad_type->sat_approx
149 && ad->ad_type->sat_approx->smr_indexer
150 && ad->ad_type->sat_approx->smr_filter )
151 && ( ad->ad_type->sat_equality
152 && ad->ad_type->sat_equality->smr_indexer
153 && ad->ad_type->sat_equality->smr_filter ) ) )
155 fprintf( stderr, "%s: line %d: "
156 "approx index of attribute \"%s\" disallowed\n",
157 fname, lineno, attrs[i] );
158 return LDAP_INAPPROPRIATE_MATCHING;
161 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
162 ad->ad_type->sat_equality
163 && ad->ad_type->sat_equality->smr_indexer
164 && ad->ad_type->sat_equality->smr_filter ) )
166 fprintf( stderr, "%s: line %d: "
167 "equality index of attribute \"%s\" disallowed\n",
168 fname, lineno, attrs[i] );
169 return LDAP_INAPPROPRIATE_MATCHING;
172 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
173 ad->ad_type->sat_substr
174 && ad->ad_type->sat_substr->smr_indexer
175 && ad->ad_type->sat_substr->smr_filter ) )
177 fprintf( stderr, "%s: line %d: "
178 "substr index of attribute \"%s\" disallowed\n",
179 fname, lineno, attrs[i] );
180 return LDAP_INAPPROPRIATE_MATCHING;
184 LDAP_LOG( BACK_BDB, DETAIL1,
185 "attr_index_config: index %s 0x%04lx\n",
186 ad->ad_cname.bv_val, mask, 0 );
188 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
189 ad->ad_cname.bv_val, mask, 0 );
194 a->ai_indexmask = mask;
196 rc = avl_insert( &bdb->bi_attrs, (caddr_t) a,
197 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
200 fprintf( stderr, "%s: line %d: duplicate index definition "
201 "for attr \"%s\" (ignored)\n",
202 fname, lineno, attrs[i] );
204 return LDAP_PARAM_ERROR;
208 ldap_charray_free( attrs );
209 if ( indexes != NULL ) ldap_charray_free( indexes );
215 bdb_attr_index_destroy( Avlnode *tree )
217 avl_free( tree, free );