1 /* attr.c - backend routines for dealing with attributes */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/socket.h>
12 #include <ac/string.h>
15 #include "back-ldbm.h"
23 return( strcasecmp( type, a->ai_type ) );
32 return( strcasecmp( a->ai_type, b->ai_type ) );
36 * Called when a duplicate "index" line is encountered.
38 * returns 1 => original from init code, indexmask updated
39 * 2 => original not from init code, warn the user
49 * if the duplicate definition is because we initialized the attr,
50 * just add what came from the config file. otherwise, complain.
52 if ( a->ai_indexmask & INDEX_FROMINIT ) {
53 a->ai_indexmask |= b->ai_indexmask;
73 if ( (a = (AttrInfo *) avl_find( li->li_attrs, type,
74 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
75 if ( (a = (AttrInfo *) avl_find( li->li_attrs, "default",
76 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
80 *indexmask = a->ai_indexmask;
81 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
82 *syntaxmask = attr_syntax( type );
84 *syntaxmask = a->ai_syntaxmask;
99 char **attrs, **indexes;
102 attrs = str2charray( argv[0], "," );
104 indexes = str2charray( argv[1], "," );
106 for ( i = 0; attrs[i] != NULL; i++ ) {
107 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
108 a->ai_type = ch_strdup( attrs[i] );
109 a->ai_syntaxmask = attr_syntax( a->ai_type );
111 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
112 INDEX_APPROX | INDEX_SUB);
115 for ( j = 0; indexes[j] != NULL; j++ ) {
116 if ( strncasecmp( indexes[j], "pres", 4 )
118 a->ai_indexmask |= INDEX_PRESENCE;
119 } else if ( strncasecmp( indexes[j], "eq", 2 )
121 a->ai_indexmask |= INDEX_EQUALITY;
122 } else if ( strncasecmp( indexes[j], "approx",
124 a->ai_indexmask |= INDEX_APPROX;
125 } else if ( strncasecmp( indexes[j], "sub", 3 )
127 a->ai_indexmask |= INDEX_SUB;
128 } else if ( strncasecmp( indexes[j], "none", 4 )
130 if ( a->ai_indexmask != 0 ) {
132 "%s: line %d: index type \"none\" cannot be combined with other types\n",
138 "%s: line %d: unknown index type \"%s\" (ignored)\n",
139 fname, lineno, indexes[j] );
141 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
146 a->ai_indexmask |= INDEX_FROMINIT;
149 switch (avl_insert( &li->li_attrs, (caddr_t) a,
150 (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
152 case 1: /* duplicate - updating init version */
157 case 2: /* user duplicate - ignore and warn */
159 "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
160 fname, lineno, a->ai_type );
165 default:; /* inserted ok */
169 charray_free( attrs );
171 charray_free( indexes );
178 ainfo_free( void *attr )
186 attr_index_destroy( Avlnode *tree )
188 avl_free( tree, ainfo_free );
191 #endif /* SLAP_CLEANUP */