]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/config.c
Introduction of a new Berkeley DB version 2 (!) specific backend.
[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_db_config_internal(
15     Backend     *be,
16     char        *fname,
17     int         lineno,
18     int         argc,
19     char        **argv
20 )
21 {
22         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
23
24         if ( li == NULL ) {
25                 fprintf( stderr, "%s: line %d: ldbm backend info is null!\n",
26                     fname, lineno );
27                 return( 1 );
28         }
29
30         /* directory where database files live */
31         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
32                 if ( argc < 2 ) {
33                         fprintf( stderr,
34                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
35                             fname, lineno );
36                         return( 1 );
37                 }
38                 li->li_directory = ch_strdup( argv[1] );
39
40                 li->li_nextid_file =
41                         ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") );
42
43                 strcpy(li->li_nextid_file, li->li_directory);
44                 strcat(li->li_nextid_file, "/NEXTID");
45
46         /* mode with which to create new database files */
47         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
48                 if ( argc < 2 ) {
49                         fprintf( stderr,
50                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
51                             fname, lineno );
52                         return( 1 );
53                 }
54                 li->li_mode = strtol( argv[1], NULL, 0 );
55
56         /* attribute to index */
57         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
58                 if ( argc < 2 ) {
59                         fprintf( stderr,
60 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
61                             fname, lineno );
62                         return( 1 );
63                 } else if ( argc > 3 ) {
64                         fprintf( stderr,
65 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
66                             fname, lineno );
67                 }
68                 bdb2i_attr_index_config( li, fname, lineno, argc - 1, &argv[1], 0 );
69
70         /* size of the cache in entries */
71         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
72                 if ( argc < 2 ) {
73                         fprintf( stderr,
74                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
75                             fname, lineno );
76                         return( 1 );
77                 }
78                 li->li_cache.c_maxsize = atoi( argv[1] );
79
80         /* size of each dbcache in bytes */
81         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
82                 if ( argc < 2 ) {
83                         fprintf( stderr,
84                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
85                             fname, lineno );
86                         return( 1 );
87                 }
88                 li->li_dbcachesize = atoi( argv[1] );
89                 /*  we should at least have the suggested 128k  */
90                 if ( li->li_dbcachesize < DEFAULT_DBCACHE_SIZE )
91                         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
92
93         /* no write sync */
94         } else if ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) {
95                 li->li_dbcachewsync = 0;
96
97         /* anything else */
98         } else {
99                 fprintf( stderr,
100 "%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
101                     fname, lineno, argv[0] );
102         }
103
104         return 0;
105 }
106
107
108 int
109 bdb2_back_db_config(
110     Backend     *be,
111     char        *fname,
112     int         lineno,
113     int         argc,
114     char        **argv
115 )
116 {
117         struct timeval  time1, time2;
118         char   *elapsed_time;
119         int    ret;
120
121         gettimeofday( &time1, NULL );
122
123         ret = bdb2i_back_db_config_internal( be, fname, lineno, argc, argv );
124
125         if ( bdb2i_do_timing ) {
126
127                 gettimeofday( &time2, NULL);
128                 elapsed_time = bdb2i_elapsed( time1, time2 );
129                 Debug( LDAP_DEBUG_ANY, "CONFIG elapsed=%s\n",
130                                 elapsed_time, 0, 0 );
131                 free( elapsed_time );
132
133         }
134
135         return( ret );
136 }
137
138