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"
24 return( strcasecmp( type, a->ai_type ) );
33 return( strcasecmp( a->ai_type, b->ai_type ) );
37 * Called when a duplicate "index" line is encountered.
39 * returns 1 => original from init code, indexmask updated
40 * 2 => original not from init code, warn the user
50 * if the duplicate definition is because we initialized the attr,
51 * just add what came from the config file. otherwise, complain.
53 if ( a->ai_indexmask & INDEX_FROMINIT ) {
54 a->ai_indexmask |= b->ai_indexmask;
74 if ( (a = (AttrInfo *) avl_find( li->li_attrs, type,
75 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
76 if ( (a = (AttrInfo *) avl_find( li->li_attrs, "default",
77 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
81 *indexmask = a->ai_indexmask;
83 #ifdef SLAPD_SCHEMA_COMPAT
84 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
85 *syntaxmask = attr_syntax( type );
87 *syntaxmask = a->ai_syntaxmask;
103 char **attrs, **indexes;
106 attrs = str2charray( argv[0], "," );
108 indexes = str2charray( argv[1], "," );
110 for ( i = 0; attrs[i] != NULL; i++ ) {
111 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
112 a->ai_type = ch_strdup( attrs[i] );
113 #ifdef SLAPD_SCHEMA_COMPAT
114 a->ai_syntaxmask = attr_syntax( a->ai_type );
117 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
118 INDEX_APPROX | INDEX_SUB);
121 for ( j = 0; indexes[j] != NULL; j++ ) {
122 if ( strncasecmp( indexes[j], "pres", 4 )
124 a->ai_indexmask |= INDEX_PRESENCE;
125 } else if ( strncasecmp( indexes[j], "eq", 2 )
127 a->ai_indexmask |= INDEX_EQUALITY;
128 } else if ( strncasecmp( indexes[j], "approx",
130 a->ai_indexmask |= INDEX_APPROX;
131 } else if ( strncasecmp( indexes[j], "sub", 3 )
133 a->ai_indexmask |= INDEX_SUB;
134 } else if ( strncasecmp( indexes[j], "none", 4 )
136 if ( a->ai_indexmask != 0 ) {
138 "%s: line %d: index type \"none\" cannot be combined with other types\n",
144 "%s: line %d: unknown index type \"%s\" (ignored)\n",
145 fname, lineno, indexes[j] );
147 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
152 a->ai_indexmask |= INDEX_FROMINIT;
155 switch (avl_insert( &li->li_attrs, (caddr_t) a,
156 (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
158 case 1: /* duplicate - updating init version */
163 case 2: /* user duplicate - ignore and warn */
165 "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
166 fname, lineno, a->ai_type );
171 default:; /* inserted ok */
175 charray_free( attrs );
177 charray_free( indexes );
182 ainfo_free( void *attr )
190 attr_index_destroy( Avlnode *tree )
192 avl_free( tree, ainfo_free );