]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
37bc1c389bc6a3438e05dcb2906821d9698f5e16
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14
15 int
16 bdb_db_config(
17         BackendDB       *be,
18         const char      *fname,
19         int             lineno,
20         int             argc,
21         char    **argv )
22 {
23         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
24
25         if ( bdb == NULL ) {
26                 fprintf( stderr, "%s: line %d: "
27                         "bdb database info is null!\n",
28                         fname, lineno );
29                 return 1;
30         }
31
32         /* directory is the DB_HOME */
33         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
34                 if ( argc < 2 ) {
35                         fprintf( stderr, "%s: line %d: "
36                                 "missing dir in \"directory <dir>\" line\n",
37                                 fname, lineno );
38                         return 1;
39                 }
40                 if ( bdb->bi_dbenv_home ) {
41                         free( bdb->bi_dbenv_home );
42                 }
43                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
44
45         /* turn off transactions, use CDB mode instead */
46         } else if ( strcasecmp( argv[0], "dbnotxn" ) == 0 ) {
47                 bdb->bi_txn = 0;
48
49         /* transaction checkpoint configuration */
50         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
51                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
52
53         /* transaction checkpoint configuration */
54         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
55                 if ( argc < 3 ) {
56                         fprintf( stderr, "%s: line %d: "
57                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
58                                 fname, lineno );
59                         return 1;
60                 }
61                 bdb->bi_txn_cp = 1;
62                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
63                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
64
65         /* lock detect configuration */
66         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
67 #ifndef NO_THREADS
68                 if ( argc < 3 ) {
69                         fprintf( stderr, "%s: line %d: "
70                                 "missing parameters in \"lockDetect <policy> <seconds>\" line\n",
71                                 fname, lineno );
72                         return 1;
73                 }
74
75                 if( strcasecmp( argv[1], "default" ) == 0 ) {
76                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
77
78                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
79                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
80
81                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
82                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
83
84                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
85                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
86
87                 } else {
88                         fprintf( stderr, "%s: line %d: "
89                                 "bad policy (%s) in \"lockDetect <policy> <seconds>\" line\n",
90                                 fname, lineno, argv[1] );
91                         return 1;
92                 }
93
94                 bdb->bi_lock_detect_seconds = strtol( argv[2], NULL, 0 );
95                 if( bdb->bi_lock_detect_seconds < 1 ) {
96                         fprintf( stderr, "%s: line %d: "
97                                 "bad seconds (%s) in \"lockDetect <policy> <seconds>\" line\n",
98                                 fname, lineno, argv[2] );
99                         return 1;
100                 }
101 #else
102                 fprintf( stderr, "%s: line %d: "
103                         "NO THREADS: lockDetect line ignored\n",
104                         fname, lineno );
105 #endif
106
107         /* mode with which to create new database files */
108         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
109                 if ( argc < 2 ) {
110                         fprintf( stderr, "%s: line %d: "
111                                 "missing mode in \"mode <mode>\" line\n",
112                                 fname, lineno );
113                         return 1;
114                 }
115                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
116
117 #if BDB_FILTER_INDICES
118         /* attribute to index */
119         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
120                 int rc;
121                 if ( argc < 2 ) {
122                         fprintf( stderr, "%s: line %d: "
123                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
124                                 fname, lineno );
125                         return 1;
126                 } else if ( argc > 3 ) {
127                         fprintf( stderr, "%s: line %d: "
128                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
129                                 "line (ignored)\n",
130                                 fname, lineno );
131                 }
132                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
133
134                 if( rc != LDAP_SUCCESS ) return 1;
135 #endif
136
137         /* anything else */
138         } else {
139                 fprintf( stderr, "%s: line %d: "
140                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
141                         fname, lineno, argv[0] );
142         }
143
144         return 0;
145 }