1 /* attr.c - backend routines for dealing with attributes */
12 #include "back-bdb2.h"
20 return( strcasecmp( type, a->ai_type ) );
29 return( strcasecmp( a->ai_type, b->ai_type ) );
33 * Called when a duplicate "index" line is encountered.
35 * returns 1 => original from init code, indexmask updated
36 * 2 => original not from init code, warn the user
46 * if the duplicate definition is because we initialized the attr,
47 * just add what came from the config file. otherwise, complain.
49 if ( a->ai_indexmask & INDEX_FROMINIT ) {
50 a->ai_indexmask |= b->ai_indexmask;
70 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
71 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
72 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
73 (AVL_CMP) ainfo_type_cmp )) == NULL ) {
77 *indexmask = a->ai_indexmask;
78 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
79 *syntaxmask = attr_syntax( type );
81 *syntaxmask = a->ai_syntaxmask;
88 bdb2i_attr_index_config(
98 char **attrs, **indexes;
101 attrs = str2charray( argv[0], "," );
103 indexes = str2charray( argv[1], "," );
105 for ( i = 0; attrs[i] != NULL; i++ ) {
106 a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
107 a->ai_type = ch_strdup( attrs[i] );
108 a->ai_syntaxmask = attr_syntax( a->ai_type );
110 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
111 INDEX_APPROX | INDEX_SUB);
114 for ( j = 0; indexes[j] != NULL; j++ ) {
115 if ( strncasecmp( indexes[j], "pres", 4 )
117 a->ai_indexmask |= INDEX_PRESENCE;
118 } else if ( strncasecmp( indexes[j], "eq", 2 )
120 a->ai_indexmask |= INDEX_EQUALITY;
121 } else if ( strncasecmp( indexes[j], "approx",
123 a->ai_indexmask |= INDEX_APPROX;
124 } else if ( strncasecmp( indexes[j], "sub", 3 )
126 a->ai_indexmask |= INDEX_SUB;
127 } else if ( strncasecmp( indexes[j], "none", 4 )
129 if ( a->ai_indexmask != 0 ) {
131 "%s: line %d: index type \"none\" cannot be combined with other types\n",
137 "%s: line %d: unknown index type \"%s\" (ignored)\n",
138 fname, lineno, indexes[j] );
140 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
145 a->ai_indexmask |= INDEX_FROMINIT;
147 if ( a->ai_indexmask )
148 bdb2i_txn_attr_config( li, a->ai_type, 0 );
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 );