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