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>
16 #include "back-ldbm.h"
19 /* for the cache of attribute information (which are indexed, etc.) */
20 typedef struct ldbm_attrinfo {
21 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
22 slap_mask_t ai_indexmask; /* how the attr is indexed */
27 AttributeDescription *desc,
31 return desc - a->ai_desc;
40 return a->ai_desc - b->ai_desc;
46 AttributeDescription *desc,
47 slap_mask_t *indexmask )
51 a = (AttrInfo *) avl_find( li->li_attrs, desc,
52 (AVL_CMP) ainfo_type_cmp );
54 *indexmask = a != NULL ? a->ai_indexmask : 0;
69 char **indexes = NULL;
71 attrs = str2charray( argv[0], "," );
74 fprintf( stderr, "%s: line %d: "
75 "no attributes specified: %s\n",
76 fname, lineno, argv[0] );
77 return LDAP_PARAM_ERROR;
81 indexes = str2charray( argv[1], "," );
83 if( indexes == NULL ) {
84 fprintf( stderr, "%s: line %d: "
85 "no indexes specified: %s\n",
86 fname, lineno, argv[1] );
87 return LDAP_PARAM_ERROR;
91 if( indexes == NULL ) {
92 mask = li->li_defaultmask;
97 for ( i = 0; indexes[i] != NULL; i++ ) {
99 rc = slap_str2index( indexes[i], &index );
101 if( rc != LDAP_SUCCESS ) {
102 fprintf( stderr, "%s: line %d: "
103 "index type \"%s\" undefined\n",
104 fname, lineno, indexes[i] );
105 return LDAP_PARAM_ERROR;
113 fprintf( stderr, "%s: line %d: "
114 "no indexes selected\n",
116 return LDAP_PARAM_ERROR;
119 for ( i = 0; attrs[i] != NULL; i++ ) {
121 AttributeDescription *ad;
124 if( strcasecmp( attrs[i], "default" ) == 0 ) {
125 li->li_defaultmask = mask;
129 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
132 rc = slap_str2ad( attrs[i], &ad, &text );
134 if( rc != LDAP_SUCCESS ) {
135 fprintf( stderr, "%s: line %d: "
136 "index attribute \"%s\" undefined\n",
137 fname, lineno, attrs[i] );
141 if( slap_ad_is_binary( ad ) ) {
142 fprintf( stderr, "%s: line %d: "
143 "index of attribute \"%s\" disallowed\n",
144 fname, lineno, attrs[i] );
145 return LDAP_UNWILLING_TO_PERFORM;
148 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
149 ( ad->ad_type->sat_approx
150 && ad->ad_type->sat_approx->smr_indexer
151 && ad->ad_type->sat_approx->smr_filter )
152 && ( ad->ad_type->sat_equality
153 && ad->ad_type->sat_equality->smr_indexer
154 && ad->ad_type->sat_equality->smr_filter ) ) )
156 fprintf( stderr, "%s: line %d: "
157 "approx index of attribute \"%s\" disallowed\n",
158 fname, lineno, attrs[i] );
159 return LDAP_INAPPROPRIATE_MATCHING;
162 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
163 ad->ad_type->sat_equality
164 && ad->ad_type->sat_equality->smr_indexer
165 && ad->ad_type->sat_equality->smr_filter ) )
167 fprintf( stderr, "%s: line %d: "
168 "equality index of attribute \"%s\" disallowed\n",
169 fname, lineno, attrs[i] );
170 return LDAP_INAPPROPRIATE_MATCHING;
173 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
174 ad->ad_type->sat_substr
175 && ad->ad_type->sat_substr->smr_indexer
176 && ad->ad_type->sat_substr->smr_filter ) )
178 fprintf( stderr, "%s: line %d: "
179 "substr index of attribute \"%s\" disallowed\n",
180 fname, lineno, attrs[i] );
181 return LDAP_INAPPROPRIATE_MATCHING;
185 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
186 "attr_index_config: index %s 0x%04lx\n",
187 ad->ad_cname.bv_val, mask ));
189 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
190 ad->ad_cname.bv_val, mask, 0 );
196 a->ai_indexmask = mask;
198 rc = avl_insert( &li->li_attrs, (caddr_t) a,
199 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
202 fprintf( stderr, "%s: line %d: duplicate index definition "
203 "for attr \"%s\" (ignored)\n",
204 fname, lineno, attrs[i] );
206 return LDAP_PARAM_ERROR;
210 charray_free( attrs );
211 if ( indexes != NULL ) charray_free( indexes );
217 attr_index_destroy( Avlnode *tree )
219 avl_free( tree, free );