r13839: Use registration mechanism for backends as well (in the same sense
[ira/wip.git] / source4 / lib / ldb / include / ldb_private.h
1 /* 
2    ldb database library
3
4    Copyright (C) Andrew Tridgell    2004
5    Copyright (C) Stefan Metzmacher  2004
6    Copyright (C) Simo Sorce         2004-2005
7
8      ** NOTE! The following LGPL license applies to the ldb
9      ** library. This does NOT imply that all of Samba is released
10      ** under the LGPL
11    
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 */
26
27 /*
28  *  Name: ldb
29  *
30  *  Component: ldb private header
31  *
32  *  Description: defines internal ldb structures used by the subsystem and modules
33  *
34  *  Author: Andrew Tridgell
35  *  Author: Stefan Metzmacher
36  */
37
38 #ifndef _LDB_PRIVATE_H_
39 #define _LDB_PRIVATE_H_ 1
40
41 struct ldb_context;
42
43 struct ldb_module_ops;
44
45 /* basic module structure */
46 struct ldb_module {
47         struct ldb_module *prev, *next;
48         struct ldb_context *ldb;
49         void *private_data;
50         const struct ldb_module_ops *ops;
51 };
52
53 /* 
54    these function pointers define the operations that a ldb module must perform
55    they correspond exactly to the ldb_*() interface 
56 */
57 struct ldb_module_ops {
58         const char *name;
59         int (*init_context) (struct ldb_module *);
60         int (*request)(struct ldb_module *, struct ldb_request *);
61         int (*start_transaction)(struct ldb_module *);
62         int (*end_transaction)(struct ldb_module *);
63         int (*del_transaction)(struct ldb_module *);
64         int (*async_wait)(struct ldb_module *, struct ldb_async_handle *, enum ldb_async_wait_type);
65 };
66
67 typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]);
68
69 /*
70   schema related information needed for matching rules
71 */
72 struct ldb_schema {
73         /* attribute handling table */
74         unsigned num_attrib_handlers;
75         struct ldb_attrib_handler *attrib_handlers;
76
77         /* objectclass information */
78         unsigned num_classes;
79         struct ldb_subclass {
80                 char *name;
81                 char **subclasses;
82         } *classes;
83 };
84
85 /*
86   every ldb connection is started by establishing a ldb_context
87 */
88 struct ldb_context {
89         /* the operations provided by the backend */
90         struct ldb_module *modules;
91
92         /* debugging operations */
93         struct ldb_debug_ops debug_ops;
94
95         /* custom utf8 functions */
96         struct ldb_utf8_fns utf8_fns;
97
98         /* backend specific opaque parameters */
99         struct ldb_opaque {
100                 struct ldb_opaque *next;
101                 const char *name;
102                 void *value;
103         } *opaque;
104
105         struct ldb_schema schema;
106
107         char *err_string;
108
109         int transaction_active;
110
111         /* a backend supplied highestCommittedUSN function */
112         uint64_t (*sequence_number)(struct ldb_context *);
113 };
114
115 #ifndef ARRAY_SIZE
116 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
117 #endif
118
119 /*
120   simplify out of memory handling
121 */
122 #define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
123
124 /* The following definitions come from lib/ldb/common/ldb_modules.c  */
125
126 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
127 int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
128 int ldb_next_start_trans(struct ldb_module *module);
129 int ldb_next_end_trans(struct ldb_module *module);
130 int ldb_next_del_trans(struct ldb_module *module);
131 int ldb_next_init(struct ldb_module *module);
132
133 void ldb_set_errstring(struct ldb_context *ldb, char *err_string);
134 void ldb_reset_err_string(struct ldb_context *ldb);
135
136 int ldb_register_module(const struct ldb_module_ops *);
137 int ldb_register_backend(const char *url_prefix, ldb_connect_fn);
138
139 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
140 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
141 void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, 
142                    const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
143
144 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
145 int ldb_should_b64_encode(const struct ldb_val *val);
146
147 int ldb_objectclass_init(void);
148 int ldb_operational_init(void);
149 int ldb_paged_results_init(void);
150 int ldb_rdn_name_init(void);
151 int ldb_schema_init(void);
152 int ldb_sort_init(void);
153 int ldb_ldap_init(void);
154 int ldb_ildap_init(void);
155 int ldb_tdb_init(void);
156 int ldb_sqlite3_init(void);
157
158 int ldb_match_msg(struct ldb_context *ldb,
159                   struct ldb_message *msg,
160                   struct ldb_parse_tree *tree,
161                   const struct ldb_dn *base,
162                   enum ldb_scope scope);
163
164 void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib);
165 const struct ldb_attrib_handler *ldb_attrib_handler_syntax(struct ldb_context *ldb,
166                                                            const char *syntax);
167 int ldb_set_attrib_handlers(struct ldb_context *ldb, 
168                             const struct ldb_attrib_handler *handlers, 
169                             unsigned num_handlers);
170 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
171 int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, 
172                                   const char *attr, const char *syntax);
173
174 /* The following definitions come from lib/ldb/common/ldb_attributes.c  */
175 const char **ldb_subclass_list(struct ldb_context *ldb, const char *class);
176 void ldb_subclass_remove(struct ldb_context *ldb, const char *class);
177 int ldb_subclass_add(struct ldb_context *ldb, const char *class, const char *subclass);
178
179 int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx,
180                      const struct ldb_val *in, struct ldb_val *out);
181 int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx,
182                           const struct ldb_val *v1, const struct ldb_val *v2);
183
184 /* The following definitions come from lib/ldb/common/ldb_controls.c  */
185 struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid);
186 int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver);
187 int check_critical_controls(struct ldb_control **controls);
188
189 /* The following definitions come from lib/ldb/common/ldb_utf8.c */
190 char *ldb_casefold_default(void *context, void *mem_ctx, const char *s);
191 #endif