]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
Fix NO_THREADS issues
[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                 if ( argc < 2 ) {
72                         fprintf( stderr, "%s: line %d: "
73                                 "missing parameters in \"lockDetect <policy>\" line\n",
74                                 fname, lineno );
75                         return 1;
76                 }
77
78                 if( strcasecmp( argv[1], "default" ) == 0 ) {
79                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
80
81                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
82                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
83
84                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
85                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
86
87                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
88                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
89
90                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
91                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
92
93                 } else {
94                         fprintf( stderr, "%s: line %d: "
95                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
96                                 fname, lineno, argv[1] );
97                         return 1;
98                 }
99
100         /* mode with which to create new database files */
101         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
102                 if ( argc < 2 ) {
103                         fprintf( stderr, "%s: line %d: "
104                                 "missing mode in \"mode <mode>\" line\n",
105                                 fname, lineno );
106                         return 1;
107                 }
108                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
109
110         /* attribute to index */
111         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
112                 int rc;
113                 if ( argc < 2 ) {
114                         fprintf( stderr, "%s: line %d: "
115                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
116                                 fname, lineno );
117                         return 1;
118                 } else if ( argc > 3 ) {
119                         fprintf( stderr, "%s: line %d: "
120                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
121                                 "line (ignored)\n",
122                                 fname, lineno );
123                 }
124                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
125
126                 if( rc != LDAP_SUCCESS ) return 1;
127
128         /* size of the cache in entries */
129          } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
130                  if ( argc < 2 ) {
131                          fprintf( stderr,
132                  "%s: line %d: missing size in \"cachesize <size>\" line\n",
133                              fname, lineno );
134                          return( 1 );
135                  }
136                  bdb->bi_cache.c_maxsize = atoi( argv[1] );
137
138         /* anything else */
139         } else {
140                 fprintf( stderr, "%s: line %d: "
141                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
142                         fname, lineno, argv[0] );
143         }
144
145         return 0;
146 }