1 /* attr.c - backend routines for dealing with attributes */
4 * Copyright 1998-1999 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"
18 /* for the cache of attribute information (which are indexed, etc.) */
19 typedef struct ldbm_attrinfo {
20 char *ai_type; /* type name (cn, sn, ...) */
21 int ai_indexmask; /* how the attr is indexed */
30 return( strcasecmp( type, a->ai_type ) );
39 return( strcasecmp( a->ai_type, b->ai_type ) );
43 * Called when a duplicate "index" line is encountered.
45 * returns 1 => original from init code, indexmask updated
46 * 2 => original not from init code, warn the user
56 * if the duplicate definition is because we initialized the attr,
57 * just add what came from the config file. otherwise, complain.
59 if ( a->ai_indexmask & SLAP_INDEX_FROMINIT ) {
60 a->ai_indexmask |= b->ai_indexmask;
77 if ( (a = (AttrInfo *) avl_find( li->li_attrs, type,
78 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
79 if ( (a = (AttrInfo *) avl_find( li->li_attrs, "default",
80 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
84 *indexmask = a->ai_indexmask;
98 char **attrs, **indexes;
101 attrs = str2charray( argv[0], "," );
103 indexes = str2charray( argv[1], "," );
105 for ( i = 0; attrs[i] != NULL; i++ ) {
106 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
107 a->ai_type = ch_strdup( attrs[i] );
108 #ifdef SLAPD_SCHEMA_COMPAT
109 a->ai_syntaxmask = attr_syntax( a->ai_type );
113 SLAP_INDEX_PRESENCE | SLAP_INDEX_EQUALITY |
114 SLAP_INDEX_APPROX | SLAP_INDEX_SUB);
117 for ( j = 0; indexes[j] != NULL; j++ ) {
118 if ( strncasecmp( indexes[j], "pres", 4 )
120 a->ai_indexmask |= SLAP_INDEX_PRESENCE;
121 } else if ( strncasecmp( indexes[j], "eq", 2 )
123 a->ai_indexmask |= SLAP_INDEX_EQUALITY;
124 } else if ( strncasecmp( indexes[j], "approx",
126 a->ai_indexmask |= SLAP_INDEX_APPROX;
127 } else if ( strncasecmp( indexes[j], "sub", 3 )
129 a->ai_indexmask |= SLAP_INDEX_SUB;
130 } else if ( strncasecmp( indexes[j], "none", 4 )
132 if ( a->ai_indexmask != 0 ) {
134 "%s: line %d: index type \"none\" cannot be combined with other types\n",
140 "%s: line %d: unknown index type \"%s\" (ignored)\n",
141 fname, lineno, indexes[j] );
143 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
148 a->ai_indexmask |= SLAP_INDEX_FROMINIT;
151 switch (avl_insert( &li->li_attrs, (caddr_t) a,
152 (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
154 case 1: /* duplicate - updating init version */
159 case 2: /* user duplicate - ignore and warn */
161 "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
162 fname, lineno, a->ai_type );
167 default:; /* inserted ok */
171 charray_free( attrs );
173 charray_free( indexes );
178 ainfo_free( void *attr )
186 attr_index_destroy( Avlnode *tree )
188 avl_free( tree, ainfo_free );