1 /* attr.c - backend routines for dealing with attributes */
6 #include <sys/socket.h>
10 extern char **str2charray();
18 return( strcasecmp( type, a->ai_type ) );
27 return( strcasecmp( a->ai_type, b->ai_type ) );
31 * Called when a duplicate "index" line is encountered.
33 * returns 1 => original from init code, indexmask updated
34 * 2 => original not from init code, warn the user
44 * if the duplicate definition is because we initialized the attr,
45 * just add what came from the config file. otherwise, complain.
47 if ( a->ai_indexmask & INDEX_FROMINIT ) {
48 a->ai_indexmask |= b->ai_indexmask;
68 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
69 ainfo_type_cmp )) == NULL ) {
70 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
71 ainfo_type_cmp )) == NULL ) {
75 *indexmask = a->ai_indexmask;
76 if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
77 *syntaxmask = attr_syntax( type );
79 *syntaxmask = a->ai_syntaxmask;
94 char **attrs, **indexes;
97 attrs = str2charray( argv[0], "," );
99 indexes = str2charray( argv[1], "," );
101 for ( i = 0; attrs[i] != NULL; i++ ) {
102 a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
103 a->ai_type = strdup( attrs[i] );
104 a->ai_syntaxmask = attr_syntax( a->ai_type );
106 a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
107 INDEX_APPROX | INDEX_SUB);
110 for ( j = 0; indexes[j] != NULL; j++ ) {
111 if ( strncasecmp( indexes[j], "pres", 4 )
113 a->ai_indexmask |= INDEX_PRESENCE;
114 } else if ( strncasecmp( indexes[j], "eq", 2 )
116 a->ai_indexmask |= INDEX_EQUALITY;
117 } else if ( strncasecmp( indexes[j], "approx",
119 a->ai_indexmask |= INDEX_APPROX;
120 } else if ( strncasecmp( indexes[j], "sub", 3 )
122 a->ai_indexmask |= INDEX_SUB;
123 } else if ( strncasecmp( indexes[j], "none", 4 )
125 if ( a->ai_indexmask != 0 ) {
127 "%s: line %d: index type \"none\" cannot be combined with other types\n",
133 "%s: line %d: unknown index type \"%s\" (ignored)\n",
134 fname, lineno, indexes[j] );
136 "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
141 a->ai_indexmask |= INDEX_FROMINIT;
144 switch (avl_insert( &li->li_attrs, a, ainfo_cmp, ainfo_dup )) {
145 case 1: /* duplicate - updating init version */
150 case 2: /* user duplicate - ignore and warn */
152 "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
153 fname, lineno, a->ai_type );
158 default:; /* inserted ok */
162 charray_free( attrs );
164 charray_free( indexes );