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;
82 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
83 *syntaxmask = attr_syntax( type );
85 *syntaxmask = a->ai_syntaxmask;
100 char **attrs, **indexes;
103 attrs = str2charray( argv[0], "," );
105 indexes = str2charray( argv[1], "," );
107 for ( i = 0; attrs[i] != NULL; i++ ) {
108 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
109 a->ai_type = ch_strdup( attrs[i] );
110 a->ai_syntaxmask = attr_syntax( a->ai_type );
112 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
113 INDEX_APPROX | INDEX_SUB);
116 for ( j = 0; indexes[j] != NULL; j++ ) {
117 if ( strncasecmp( indexes[j], "pres", 4 )
119 a->ai_indexmask |= INDEX_PRESENCE;
120 } else if ( strncasecmp( indexes[j], "eq", 2 )
122 a->ai_indexmask |= INDEX_EQUALITY;
123 } else if ( strncasecmp( indexes[j], "approx",
125 a->ai_indexmask |= INDEX_APPROX;
126 } else if ( strncasecmp( indexes[j], "sub", 3 )
128 a->ai_indexmask |= INDEX_SUB;
129 } else if ( strncasecmp( indexes[j], "none", 4 )
131 if ( a->ai_indexmask != 0 ) {
133 "%s: line %d: index type \"none\" cannot be combined with other types\n",
139 "%s: line %d: unknown index type \"%s\" (ignored)\n",
140 fname, lineno, indexes[j] );
142 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
147 a->ai_indexmask |= INDEX_FROMINIT;
150 switch (avl_insert( &li->li_attrs, (caddr_t) a,
151 (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
153 case 1: /* duplicate - updating init version */
158 case 2: /* user duplicate - ignore and warn */
160 "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
161 fname, lineno, a->ai_type );
166 default:; /* inserted ok */
170 charray_free( attrs );
172 charray_free( indexes );
177 ainfo_free( void *attr )
185 attr_index_destroy( Avlnode *tree )
187 avl_free( tree, ainfo_free );