]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/init.c
New dn2id format with base/one/subtree indices (ldbm/bdb2)
[openldap] / servers / slapd / back-ldbm / init.c
1 /* init.c - initialize ldbm backend */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/string.h>
12 #include <ac/socket.h>
13
14 #include "slap.h"
15 #include "back-ldbm.h"
16
17 #ifdef SLAPD_LDBM_DYNAMIC
18
19 int back_ldbm_LTX_init_module(int argc, char *argv[]) {
20     BackendInfo bi;
21
22     memset( &bi, 0, sizeof(bi) );
23     bi.bi_type = "ldbm";
24     bi.bi_init = ldbm_back_initialize;
25
26     backend_add(&bi);
27     return 0;
28 }
29
30 #endif /* SLAPD_LDBM_DYNAMIC */
31
32 int
33 ldbm_back_initialize(
34     BackendInfo *bi
35 )
36 {
37         bi->bi_open = ldbm_back_open;
38         bi->bi_config = 0;
39         bi->bi_close = ldbm_back_close;
40         bi->bi_destroy = ldbm_back_destroy;
41
42         bi->bi_db_init = ldbm_back_db_init;
43         bi->bi_db_config = ldbm_back_db_config;
44         bi->bi_db_open = ldbm_back_db_open;
45         bi->bi_db_close = ldbm_back_db_close;
46         bi->bi_db_destroy = ldbm_back_db_destroy;
47
48         bi->bi_op_bind = ldbm_back_bind;
49         bi->bi_op_unbind = ldbm_back_unbind;
50         bi->bi_op_search = ldbm_back_search;
51         bi->bi_op_compare = ldbm_back_compare;
52         bi->bi_op_modify = ldbm_back_modify;
53         bi->bi_op_modrdn = ldbm_back_modrdn;
54         bi->bi_op_add = ldbm_back_add;
55         bi->bi_op_delete = ldbm_back_delete;
56         bi->bi_op_abandon = ldbm_back_abandon;
57
58         bi->bi_entry_release_rw = ldbm_back_entry_release_rw;
59         bi->bi_acl_group = ldbm_back_group;
60
61         /*
62          * hooks for slap tools
63          */
64         bi->bi_tool_entry_open = ldbm_tool_entry_open;
65         bi->bi_tool_entry_close = ldbm_tool_entry_close;
66         bi->bi_tool_entry_first = ldbm_tool_entry_first;
67         bi->bi_tool_entry_next = ldbm_tool_entry_next;
68         bi->bi_tool_entry_get = ldbm_tool_entry_get;
69         bi->bi_tool_entry_put = ldbm_tool_entry_put;
70         bi->bi_tool_index_attr = ldbm_tool_index_attr;
71         bi->bi_tool_index_change = ldbm_tool_index_change;
72         bi->bi_tool_sync = ldbm_tool_sync;
73
74         bi->bi_connection_init = 0;
75         bi->bi_connection_destroy = 0;
76
77         return 0;
78 }
79
80 int
81 ldbm_back_destroy(
82     BackendInfo *bi
83 )
84 {
85         return 0;
86 }
87
88 int
89 ldbm_back_open(
90     BackendInfo *bi
91 )
92 {
93         int rc;
94
95         /* initialize the underlying database system */
96         rc = ldbm_initialize();
97
98         return rc;
99 }
100
101 int
102 ldbm_back_close(
103     BackendInfo *bi
104 )
105 {
106         /* terminate the underlying database system */
107         ldbm_shutdown();
108
109         return 0;
110 }
111
112 int
113 ldbm_back_db_init(
114     Backend     *be
115 )
116 {
117         struct ldbminfo *li;
118         char            *argv[ 4 ];
119
120         /* allocate backend-database-specific stuff */
121         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
122
123         /* arrange to read nextid later (on first request for it) */
124         li->li_nextid = NOID;
125
126         /* default cache size */
127         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
128
129         /* default database cache size */
130         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
131
132         /* default cache mode is sync on write */
133         li->li_dbcachewsync = 1;
134
135         /* default file creation mode */
136         li->li_mode = DEFAULT_MODE;
137
138         /* default database directory */
139         li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY );
140
141         argv[ 0 ] = "objectclass";
142         argv[ 1 ] = "pres,eq";
143         argv[ 2 ] = NULL;
144         attr_index_config( li, "ldbm objectclass initialization",
145                 0, 2, argv, 1 );
146
147         /* initialize various mutex locks & condition variables */
148         ldap_pvt_thread_mutex_init( &li->li_root_mutex );
149         ldap_pvt_thread_mutex_init( &li->li_add_mutex );
150         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
151         ldap_pvt_thread_mutex_init( &li->li_nextid_mutex );
152         ldap_pvt_thread_mutex_init( &li->li_dbcache_mutex );
153         ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
154
155         be->be_private = li;
156
157         return 0;
158 }
159
160 int
161 ldbm_back_db_open(
162     BackendDB   *be
163 )
164 {
165         return 0;
166 }
167
168 int
169 ldbm_back_db_destroy(
170     BackendDB   *be
171 )
172 {
173         /* should free/destroy every in be_private */
174 #ifdef SLAP_CLEANUP
175         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
176         free( li->li_nextid_file );
177         free( li->li_directory );
178         attr_index_destroy( li->li_attrs );
179
180         ldap_pvt_thread_mutex_destroy( &li->li_root_mutex );
181         ldap_pvt_thread_mutex_destroy( &li->li_add_mutex );
182         ldap_pvt_thread_mutex_destroy( &li->li_cache.c_mutex );
183         ldap_pvt_thread_mutex_destroy( &li->li_nextid_mutex );
184         ldap_pvt_thread_mutex_destroy( &li->li_dbcache_mutex );
185         ldap_pvt_thread_cond_destroy( &li->li_dbcache_cv );
186 #endif /* SLAP_CLEANUP */
187         free( be->be_private );
188         be->be_private = NULL;
189         return 0;
190 }