dbwrap: Remove calls to loadparm
[bbaumbach/samba-autobuild/.git] / lib / dbwrap / dbwrap.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Database interface wrapper around tdb
4    Copyright (C) Volker Lendecke 2005-2007
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __DBWRAP_H__
21 #define __DBWRAP_H__
22
23 #include "replace.h"
24 #include <talloc.h>
25 #include <tevent.h>
26 #include "libcli/util/ntstatus.h"
27 #include "tdb.h"
28
29 struct db_record;
30 struct db_context;
31
32 enum dbwrap_lock_order {
33         DBWRAP_LOCK_ORDER_NONE = 0, /* Don't check lock orders for this db. */
34         /*
35          * We only allow orders 1, 2, 3:
36          * These are the orders that CTDB currently supports.
37          */
38         DBWRAP_LOCK_ORDER_1 = 1,
39         DBWRAP_LOCK_ORDER_2 = 2,
40         DBWRAP_LOCK_ORDER_3 = 3
41 };
42
43 #define DBWRAP_FLAG_NONE                     0x0000000000000000ULL
44 #define DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS 0x0000000000000001ULL
45
46 enum dbwrap_req_state {
47         /**
48          * We are creating the request
49          */
50         DBWRAP_REQ_INIT,
51         /**
52          * The request is queued and waiting to be dispatched
53          */
54         DBWRAP_REQ_QUEUED,
55         /**
56          * We are waiting to receive the reply
57          */
58         DBWRAP_REQ_DISPATCHED,
59         /**
60          * The request is finished
61          */
62         DBWRAP_REQ_DONE,
63         /**
64          * The request errored out
65          */
66         DBWRAP_REQ_ERROR
67 };
68
69 /* The following definitions come from lib/dbwrap.c  */
70
71 TDB_DATA dbwrap_record_get_key(const struct db_record *rec);
72 TDB_DATA dbwrap_record_get_value(const struct db_record *rec);
73 NTSTATUS dbwrap_record_store(struct db_record *rec, TDB_DATA data, int flags);
74 NTSTATUS dbwrap_record_storev(struct db_record *rec,
75                               const TDB_DATA *dbufs, int num_dbufs, int flags);
76 NTSTATUS dbwrap_record_delete(struct db_record *rec);
77 struct db_record *dbwrap_fetch_locked(struct db_context *db,
78                                       TALLOC_CTX *mem_ctx,
79                                       TDB_DATA key);
80 struct db_record *dbwrap_try_fetch_locked(struct db_context *db,
81                                           TALLOC_CTX *mem_ctx,
82                                           TDB_DATA key);
83 struct db_context *dbwrap_record_get_db(struct db_record *rec);
84
85 NTSTATUS dbwrap_do_locked(struct db_context *db, TDB_DATA key,
86                           void (*fn)(struct db_record *rec,
87                                      void *private_data),
88                           void *private_data);
89
90 NTSTATUS dbwrap_delete(struct db_context *db, TDB_DATA key);
91 NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key,
92                       TDB_DATA data, int flags);
93 NTSTATUS dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
94                       TDB_DATA key, TDB_DATA *value);
95 bool dbwrap_exists(struct db_context *db, TDB_DATA key);
96 NTSTATUS dbwrap_traverse(struct db_context *db,
97                          int (*f)(struct db_record*, void*),
98                          void *private_data,
99                          int *count);
100 NTSTATUS dbwrap_traverse_read(struct db_context *db,
101                               int (*f)(struct db_record*, void*),
102                               void *private_data,
103                               int *count);
104 NTSTATUS dbwrap_parse_record(struct db_context *db, TDB_DATA key,
105                              void (*parser)(TDB_DATA key, TDB_DATA data,
106                                             void *private_data),
107                              void *private_data);
108 /**
109  * Async implementation of dbwrap_parse_record
110  *
111  * @param[in]  mem_ctx      talloc memory context to use.
112  *
113  * @param[in]  ev           tevent context to use
114  *
115  * @param[in]  db           Database to query
116  *
117  * @param[in]  key          Record key, the function makes a copy of this
118  *
119  * @param[in]  parser       Parser callback function
120  *
121  * @param[in]  private_data Private data for the callback function
122  *
123  * @param[out] req_state    Pointer to a enum dbwrap_req_state variable
124  *
125  * @note req_state is updated in the send function. To determine the final
126  * result of the request the caller should therefor not rely on req_state. The
127  * primary use case is to give the caller an indication whether the request is
128  * already sent to ctdb (DBWRAP_REQ_DISPATCHED) or if it's still stuck in the
129  * sendqueue (DBWRAP_REQ_QUEUED).
130  **/
131 struct tevent_req *dbwrap_parse_record_send(
132         TALLOC_CTX *mem_ctx,
133         struct tevent_context *ev,
134         struct db_context *db,
135         TDB_DATA key,
136         void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data),
137         void *private_data,
138         enum dbwrap_req_state *req_state);
139 NTSTATUS dbwrap_parse_record_recv(struct tevent_req *req);
140 int dbwrap_wipe(struct db_context *db);
141 int dbwrap_check(struct db_context *db);
142 int dbwrap_get_seqnum(struct db_context *db);
143 /* Returns 0 if unknown. */
144 int dbwrap_transaction_start(struct db_context *db);
145 NTSTATUS dbwrap_transaction_start_nonblock(struct db_context *db);
146 int dbwrap_transaction_commit(struct db_context *db);
147 int dbwrap_transaction_cancel(struct db_context *db);
148 size_t dbwrap_db_id(struct db_context *db, uint8_t *id, size_t idlen);
149 bool dbwrap_is_persistent(struct db_context *db);
150 const char *dbwrap_name(struct db_context *db);
151
152 /* The following definitions come from lib/dbwrap_util.c  */
153
154 NTSTATUS dbwrap_purge(struct db_context *db, TDB_DATA key);
155 NTSTATUS dbwrap_purge_bystring(struct db_context *db, const char *key);
156 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
157 NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
158                                TDB_DATA data, int flags);
159 NTSTATUS dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
160                                const char *key, TDB_DATA *value);
161
162 NTSTATUS dbwrap_fetch_int32(struct db_context *db, TDB_DATA key,
163                             int32_t *result);
164 NTSTATUS dbwrap_fetch_int32_bystring(struct db_context *db, const char *keystr,
165                                      int32_t *result);
166 NTSTATUS dbwrap_store_int32_bystring(struct db_context *db, const char *keystr,
167                                      int32_t v);
168 NTSTATUS dbwrap_fetch_uint32_bystring(struct db_context *db,
169                                       const char *keystr, uint32_t *val);
170 NTSTATUS dbwrap_store_uint32_bystring(struct db_context *db,
171                                       const char *keystr, uint32_t v);
172 NTSTATUS dbwrap_change_uint32_atomic_bystring(struct db_context *db,
173                                               const char *keystr,
174                                               uint32_t *oldval,
175                                               uint32_t change_val);
176 NTSTATUS dbwrap_trans_change_uint32_atomic_bystring(struct db_context *db,
177                                                     const char *keystr,
178                                                     uint32_t *oldval,
179                                                     uint32_t change_val);
180 NTSTATUS dbwrap_change_int32_atomic(struct db_context *db,
181                                     TDB_DATA key,
182                                     int32_t *oldval,
183                                     int32_t change_val);
184 NTSTATUS dbwrap_change_int32_atomic_bystring(struct db_context *db,
185                                              const char *keystr,
186                                              int32_t *oldval,
187                                              int32_t change_val);
188 NTSTATUS dbwrap_trans_change_int32_atomic_bystring(struct db_context *db,
189                                                    const char *keystr,
190                                                    int32_t *oldval,
191                                                    int32_t change_val);
192 NTSTATUS dbwrap_trans_store(struct db_context *db, TDB_DATA key, TDB_DATA dbuf,
193                             int flag);
194 NTSTATUS dbwrap_trans_delete(struct db_context *db, TDB_DATA key);
195 NTSTATUS dbwrap_trans_store_int32_bystring(struct db_context *db,
196                                            const char *keystr,
197                                            int32_t v);
198 NTSTATUS dbwrap_trans_store_uint32_bystring(struct db_context *db,
199                                             const char *keystr,
200                                             uint32_t v);
201 NTSTATUS dbwrap_trans_store_bystring(struct db_context *db, const char *key,
202                                      TDB_DATA data, int flags);
203 NTSTATUS dbwrap_trans_delete_bystring(struct db_context *db, const char *key);
204 NTSTATUS dbwrap_trans_do(struct db_context *db,
205                          NTSTATUS (*action)(struct db_context *, void *),
206                          void *private_data);
207 NTSTATUS dbwrap_trans_traverse(struct db_context *db,
208                                int (*f)(struct db_record*, void*),
209                                void *private_data);
210
211 NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key);
212 NTSTATUS dbwrap_store_bystring_upper(struct db_context *db, const char *key,
213                                      TDB_DATA data, int flags);
214 NTSTATUS dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
215                                      const char *key, TDB_DATA *value);
216
217 size_t dbwrap_marshall(struct db_context *db, uint8_t *buf, size_t bufsize);
218 NTSTATUS dbwrap_parse_marshall_buf(const uint8_t *buf, size_t buflen,
219                                    bool (*fn)(TDB_DATA key, TDB_DATA value,
220                                               void *private_data),
221                                    void *private_data);
222 NTSTATUS dbwrap_unmarshall(struct db_context *db, const uint8_t *buf,
223                            size_t buflen);
224
225 TDB_DATA dbwrap_merge_dbufs(TALLOC_CTX *mem_ctx,
226                             const TDB_DATA *dbufs, int num_dbufs);
227
228
229 /**
230  * This opens a tdb file
231  */
232 struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
233                                      const char *name,
234                                      int hash_size, int tdb_flags,
235                                      int open_flags, mode_t mode,
236                                      enum dbwrap_lock_order lock_order,
237                                      uint64_t dbwrap_flags);
238
239 #endif /* __DBWRAP_H__ */