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