]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/attr.c
slap_set_time() is no longer necessary.
[openldap] / servers / slapd / back-bdb2 / attr.c
1 /* attr.c - backend routines for dealing with attributes */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12
13 static int
14 ainfo_type_cmp(
15     char                *type,
16     struct attrinfo     *a
17 )
18 {
19         return( strcasecmp( type, a->ai_type ) );
20 }
21
22 static int
23 ainfo_cmp(
24     struct attrinfo     *a,
25     struct attrinfo     *b
26 )
27 {
28         return( strcasecmp( a->ai_type, b->ai_type ) );
29 }
30
31 /*
32  * Called when a duplicate "index" line is encountered.
33  *
34  * returns 1 => original from init code, indexmask updated
35  *         2 => original not from init code, warn the user
36  */
37
38 static int
39 ainfo_dup(
40     struct attrinfo     *a,
41     struct attrinfo     *b
42 )
43 {
44         /*
45          * if the duplicate definition is because we initialized the attr,
46          * just add what came from the config file. otherwise, complain.
47          */
48         if ( a->ai_indexmask & INDEX_FROMINIT ) {
49                 a->ai_indexmask |= b->ai_indexmask;
50
51                 return( 1 );
52         }
53
54         return( 2 );
55 }
56
57 void
58 bdb2i_attr_masks(
59     struct ldbminfo     *li,
60     char                *type,
61     int                 *indexmask,
62     int                 *syntaxmask
63 )
64 {
65         struct attrinfo *a;
66
67         *indexmask = 0;
68         *syntaxmask = 0;
69         if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
70             (AVL_CMP) ainfo_type_cmp )) == NULL ) {
71                 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
72                     (AVL_CMP) ainfo_type_cmp )) == NULL ) {
73                         return;
74                 }
75         }
76         *indexmask = a->ai_indexmask;
77         if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
78                 *syntaxmask = attr_syntax( type );
79         } else {
80                 *syntaxmask = a->ai_syntaxmask;
81         }
82 }
83
84
85 /*  BDB2 changed  */
86 void
87 bdb2i_attr_index_config(
88     struct ldbminfo     *li,
89     char                *fname,
90     int                 lineno,
91     int                 argc,
92     char                **argv,
93     int                 init
94 )
95 {
96         int             i, j;
97         char            **attrs, **indexes;
98         struct attrinfo *a;
99
100         attrs = str2charray( argv[0], "," );
101         if ( argc > 1 ) {
102                 indexes = str2charray( argv[1], "," );
103         }
104         for ( i = 0; attrs[i] != NULL; i++ ) {
105                 a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
106                 a->ai_type = ch_strdup( attrs[i] );
107                 a->ai_syntaxmask = attr_syntax( a->ai_type );
108                 if ( argc == 1 ) {
109                         a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
110                             INDEX_APPROX | INDEX_SUB);
111                 } else {
112                         a->ai_indexmask = 0;
113                         for ( j = 0; indexes[j] != NULL; j++ ) {
114                                 if ( strncasecmp( indexes[j], "pres", 4 )
115                                     == 0 ) {
116                                         a->ai_indexmask |= INDEX_PRESENCE;
117                                 } else if ( strncasecmp( indexes[j], "eq", 2 )
118                                     == 0 ) {
119                                         a->ai_indexmask |= INDEX_EQUALITY;
120                                 } else if ( strncasecmp( indexes[j], "approx",
121                                     6 ) == 0 ) {
122                                         a->ai_indexmask |= INDEX_APPROX;
123                                 } else if ( strncasecmp( indexes[j], "sub", 3 )
124                                     == 0 ) {
125                                         a->ai_indexmask |= INDEX_SUB;
126                                 } else if ( strncasecmp( indexes[j], "none", 4 )
127                                     == 0 ) {
128                                         if ( a->ai_indexmask != 0 ) {
129                                                 fprintf( stderr,
130 "%s: line %d: index type \"none\" cannot be combined with other types\n",
131                                                     fname, lineno );
132                                         }
133                                         a->ai_indexmask = 0;
134                                 } else {
135                                         fprintf( stderr,
136                         "%s: line %d: unknown index type \"%s\" (ignored)\n",
137                                             fname, lineno, indexes[j] );
138                                         fprintf( stderr,
139         "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
140                                 }
141                         }
142                 }
143                 if ( init ) {
144                         a->ai_indexmask |= INDEX_FROMINIT;
145                 } else {
146                         if ( a->ai_indexmask )
147                                 bdb2i_txn_attr_config( li, a->ai_type, 0 );
148                 }
149
150                 switch (avl_insert( &li->li_attrs, (caddr_t) a,
151                         (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
152                 {
153                 case 1:         /* duplicate - updating init version */
154                         free( a->ai_type );
155                         free( (char *) a );
156                         break;
157
158                 case 2:         /* user duplicate - ignore and warn */
159                         fprintf( stderr,
160     "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
161                             fname, lineno, a->ai_type );
162                         free( a->ai_type );
163                         free( (char *) a );
164                         break;
165
166                 default:;       /* inserted ok */
167                         /* FALL */
168                 }
169         }
170         charray_free( attrs );
171         if ( argc > 1 )
172                 charray_free( indexes );
173 }