]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/config.c
Elimination of un-used code in bdb2i_cache_open and friends.
[openldap] / servers / slapd / back-bdb2 / config.c
1 /* config.c - bdb2 backend configuration file routine */
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 bdb2i_back_config_internal(
15     BackendInfo *bi,
16     char                *fname,
17     int                 lineno,
18     int                 argc,
19     char                **argv
20 )
21 {
22         struct ldbtype  *lty = (struct ldbtype *) bi->bi_private;
23
24         if ( lty == NULL ) {
25                 fprintf( stderr, "%s: line %d: ldbm backend type info is null!\n",
26                     fname, lineno );
27                 return( 1 );
28         }
29
30         /* directory where DB control files live */
31         if ( strcasecmp( argv[0], "home" ) == 0 ) {
32                 if ( argc < 2 ) {
33                         fprintf( stderr,
34                 "%s: line %d: missing dir in \"home <dir>\" line\n",
35                             fname, lineno );
36                         return( 1 );
37                 }
38                 lty->lty_dbhome = ch_strdup( argv[1] );
39
40         /* size of the DB memory pool */
41         } else if ( strcasecmp( argv[0], "mpoolsize" ) == 0 ) {
42                 if ( argc < 2 ) {
43                         fprintf( stderr,
44                         "%s: line %d: missing size in \"mpoolsize <size>\" line\n",
45                             fname, lineno );
46                         return( 1 );
47                 }
48                 lty->lty_mpsize = (size_t) atoi( argv[1] );
49                 /*  we should at least have the suggested 128k  */
50                 if ( lty->lty_mpsize < DEFAULT_DBCACHE_SIZE )
51                         lty->lty_mpsize = DEFAULT_DBCACHE_SIZE;
52
53         /* anything else */
54         } else {
55                 fprintf( stderr,
56 "%s: line %d: unknown directive \"%s\" in ldbm backend definition (ignored)\n",
57                     fname, lineno, argv[0] );
58         }
59
60         return 0;
61 }
62
63
64 int
65 bdb2_back_config(
66     BackendInfo *bi,
67     char        *fname,
68     int         lineno,
69     int         argc,
70     char        **argv
71 )
72 {
73         struct timeval  time1, time2;
74         char   *elapsed_time;
75         int    ret;
76
77         gettimeofday( &time1, NULL );
78
79         ret = bdb2i_back_config_internal( bi, fname, lineno, argc, argv );
80
81         if ( bdb2i_do_timing ) {
82
83                 gettimeofday( &time2, NULL);
84                 elapsed_time = bdb2i_elapsed( time1, time2 );
85                 Debug( LDAP_DEBUG_TRACE, "BE-CONFIG elapsed=%s\n",
86                                 elapsed_time, 0, 0 );
87                 free( elapsed_time );
88
89         }
90
91         return( ret );
92 }
93
94
95 static int
96 bdb2i_back_db_config_internal(
97     BackendDB   *be,
98     char        *fname,
99     int         lineno,
100     int         argc,
101     char        **argv
102 )
103 {
104         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
105
106         if ( li == NULL ) {
107                 fprintf( stderr, "%s: line %d: ldbm database info is null!\n",
108                     fname, lineno );
109                 return( 1 );
110         }
111
112         /* directory where database files live */
113         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
114                 if ( argc < 2 ) {
115                         fprintf( stderr,
116                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
117                             fname, lineno );
118                         return( 1 );
119                 }
120                 li->li_directory = ch_strdup( argv[1] );
121
122                 li->li_nextid_file =
123                         ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") + 1 );
124
125                 strcpy(li->li_nextid_file, li->li_directory);
126                 strcat(li->li_nextid_file, "/NEXTID");
127
128         /* mode with which to create new database files */
129         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
130                 if ( argc < 2 ) {
131                         fprintf( stderr,
132                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
133                             fname, lineno );
134                         return( 1 );
135                 }
136                 li->li_mode = strtol( argv[1], NULL, 0 );
137
138         /* attribute to index */
139         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
140                 if ( argc < 2 ) {
141                         fprintf( stderr,
142 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
143                             fname, lineno );
144                         return( 1 );
145                 } else if ( argc > 3 ) {
146                         fprintf( stderr,
147 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
148                             fname, lineno );
149                 }
150                 bdb2i_attr_index_config( li, fname, lineno, argc - 1, &argv[1], 0 );
151
152         /* size of the cache in entries */
153         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
154                 if ( argc < 2 ) {
155                         fprintf( stderr,
156                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
157                             fname, lineno );
158                         return( 1 );
159                 }
160                 li->li_cache.c_maxsize = atoi( argv[1] );
161
162         /* size of each dbcache in bytes */
163         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
164                 if ( argc < 2 ) {
165                         fprintf( stderr,
166                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
167                             fname, lineno );
168                         return( 1 );
169                 }
170                 li->li_dbcachesize = atoi( argv[1] );
171                 /*  we should at least have the suggested 128k  */
172                 if ( li->li_dbcachesize < DEFAULT_DBCACHE_SIZE )
173                         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
174
175         /* no write sync */
176         } else if ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) {
177                 li->li_dbcachewsync = 0;
178
179         /* anything else */
180         } else {
181                 fprintf( stderr,
182 "%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
183                     fname, lineno, argv[0] );
184         }
185
186         return 0;
187 }
188
189
190 int
191 bdb2_back_db_config(
192     BackendDB   *be,
193     char        *fname,
194     int         lineno,
195     int         argc,
196     char        **argv
197 )
198 {
199         struct timeval  time1, time2;
200         char   *elapsed_time;
201         int    ret;
202
203         gettimeofday( &time1, NULL );
204
205         ret = bdb2i_back_db_config_internal( be, fname, lineno, argc, argv );
206
207         if ( bdb2i_do_timing ) {
208
209                 gettimeofday( &time2, NULL);
210                 elapsed_time = bdb2i_elapsed( time1, time2 );
211                 Debug( LDAP_DEBUG_ANY, "DB-CONFIG elapsed=%s\n",
212                                 elapsed_time, 0, 0 );
213                 free( elapsed_time );
214
215         }
216
217         return( ret );
218 }
219
220