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>
16 #include "back-ldbm.h"
19 /* for the cache of attribute information (which are indexed, etc.) */
20 typedef struct ldbm_attrinfo {
22 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
26 slap_index ai_indexmask; /* how the attr is indexed */
32 AttributeDescription *desc,
40 return ad_cmp( desc, a->ai_desc );
42 return( strcasecmp( desc, a->ai_desc ) );
53 return ad_cmp( a->ai_desc, b->ai_desc );
55 return( strcasecmp( a->ai_desc, b->ai_desc ) );
63 AttributeDescription *desc,
67 slap_index *indexmask )
71 a = (AttrInfo *) avl_find( li->li_attrs, desc,
72 (AVL_CMP) ainfo_type_cmp );
74 *indexmask = a != NULL ? a->ai_indexmask : 0;
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 = li->li_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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
143 AttributeDescription *ad;
147 if( strcasecmp( attrs[i], "default" ) == 0 ) {
148 li->li_defaultmask = mask;
152 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
154 #ifdef SLAPD_SCHEMA_NOT_COMPAT
156 rc = slap_str2ad( attrs[i], &ad, &text );
158 if( rc != LDAP_SUCCESS ) {
159 fprintf( stderr, "%s: line %d: "
160 "index attribute \"%s\" undefined\n",
161 fname, lineno, attrs[i] );
165 if( slap_ad_is_binary( ad ) ) {
166 fprintf( stderr, "%s: line %d: "
167 "index of attribute \"%s\" disallowed\n",
168 fname, lineno, attrs[i] );
169 return LDAP_UNWILLING_TO_PERFORM;
172 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
173 ( ad->ad_type->sat_approx
174 && ad->ad_type->sat_approx->smr_indexer
175 && ad->ad_type->sat_approx->smr_filter )
176 && ( ad->ad_type->sat_equality
177 && ad->ad_type->sat_equality->smr_indexer
178 && ad->ad_type->sat_equality->smr_filter ) ) )
180 fprintf( stderr, "%s: line %d: "
181 "approx index of attribute \"%s\" disallowed\n",
182 fname, lineno, attrs[i] );
183 return LDAP_INAPPROPRIATE_MATCHING;
186 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
187 ad->ad_type->sat_equality
188 && ad->ad_type->sat_equality->smr_indexer
189 && ad->ad_type->sat_equality->smr_filter ) )
191 fprintf( stderr, "%s: line %d: "
192 "equality index of attribute \"%s\" disallowed\n",
193 fname, lineno, attrs[i] );
194 return LDAP_INAPPROPRIATE_MATCHING;
197 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
198 ad->ad_type->sat_substr
199 && ad->ad_type->sat_substr->smr_indexer
200 && ad->ad_type->sat_substr->smr_filter ) )
202 fprintf( stderr, "%s: line %d: "
203 "substr index of attribute \"%s\" disallowed\n",
204 fname, lineno, attrs[i] );
205 return LDAP_INAPPROPRIATE_MATCHING;
208 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04x\n",
209 ad->ad_cname->bv_val, mask, 0 );
214 a->ai_desc = ch_strdup( ad->ad_cname->bv_val );
218 a->ai_desc = ch_strdup( attrs[i] );
221 a->ai_indexmask = mask;
223 rc = avl_insert( &li->li_attrs, (caddr_t) a,
224 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
227 fprintf( stderr, "%s: line %d: duplicate index definition "
228 "for attr \"%s\" (ignored)\n",
229 fname, lineno, attrs[i] );
231 return LDAP_PARAM_ERROR;
235 charray_free( attrs );
236 if ( indexes != NULL ) charray_free( indexes );
243 ainfo_free( void *attr )
247 ad_free( ai->ai_desc, 1 );
255 attr_index_destroy( Avlnode *tree )
257 avl_free( tree, ainfo_free );