r10918: - fixed standalone ldb build
[kai/samba.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 th esubsystem 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 (*search_bytree)(struct ldb_module *, const struct ldb_dn *, enum ldb_scope,
60                              struct ldb_parse_tree *, const char * const [], struct ldb_message ***);
61         int (*add_record)(struct ldb_module *, const struct ldb_message *);
62         int (*modify_record)(struct ldb_module *, const struct ldb_message *);
63         int (*delete_record)(struct ldb_module *, const struct ldb_dn *);
64         int (*rename_record)(struct ldb_module *, const struct ldb_dn *, const struct ldb_dn *);
65         int (*start_transaction)(struct ldb_module *);
66         int (*end_transaction)(struct ldb_module *);
67         int (*del_transaction)(struct ldb_module *);
68 };
69
70
71 /*
72   schema related information needed for matching rules
73 */
74 struct ldb_schema {
75         /* attribute handling table */
76         unsigned num_attrib_handlers;
77         struct ldb_attrib_handler *attrib_handlers;
78
79         /* objectclass information */
80         unsigned num_classes;
81         struct ldb_subclass {
82                 char *name;
83                 char **subclasses;
84         } *classes;
85 };
86
87 /*
88   every ldb connection is started by establishing a ldb_context
89 */
90 struct ldb_context {
91         /* the operations provided by the backend */
92         struct ldb_module *modules;
93
94         /* debugging operations */
95         struct ldb_debug_ops debug_ops;
96
97         /* backend specific opaque parameters */
98         struct ldb_opaque {
99                 struct ldb_opaque *next;
100                 const char *name;
101                 void *value;
102         } *opaque;
103
104         struct ldb_schema schema;
105
106         char *err_string;
107
108         int transaction_active;
109 };
110
111 /* the modules init function */
112 typedef struct ldb_module *(*ldb_module_init_function)(struct ldb_context *ldb, const char *options[]);
113
114 #ifndef ARRAY_SIZE
115 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
116 #endif
117
118 /*
119   simplify out of memory handling
120 */
121 #define ldb_oom(ldb) ldb_debug(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
122
123 /* The following definitions come from lib/ldb/common/ldb_modules.c  */
124
125 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
126 int ldb_next_search(struct ldb_module *module, 
127                     const struct ldb_dn *base,
128                     enum ldb_scope scope,
129                     const char *expression,
130                     const char * const *attrs, struct ldb_message ***res);
131 int ldb_next_search_bytree(struct ldb_module *module, 
132                            const struct ldb_dn *base,
133                            enum ldb_scope scope,
134                            struct ldb_parse_tree *tree,
135                            const char * const *attrs, struct ldb_message ***res);
136 int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message);
137 int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message);
138 int ldb_next_delete_record(struct ldb_module *module, const struct ldb_dn *dn);
139 int ldb_next_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn);
140 int ldb_next_start_trans(struct ldb_module *module);
141 int ldb_next_end_trans(struct ldb_module *module);
142 int ldb_next_del_trans(struct ldb_module *module);
143
144 void ldb_set_errstring(struct ldb_module *module, char *err_string);
145
146 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
147 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
148 void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, 
149                    const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
150
151 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
152 int ldb_should_b64_encode(const struct ldb_val *val);
153
154 int ltdb_connect(struct ldb_context *ldb, const char *url, 
155                  unsigned int flags, 
156                  const char *options[]);
157 int lldb_connect(struct ldb_context *ldb, const char *url, 
158                  unsigned int flags, 
159                  const char *options[]);
160 int ildb_connect(struct ldb_context *ldb,
161                  const char *url, 
162                  unsigned int flags, 
163                  const char *options[]);
164 int lsqlite3_connect(struct ldb_context *ldb,
165                      const char *url, 
166                      unsigned int flags, 
167                      const char *options[]);
168 struct ldb_module *operational_module_init(struct ldb_context *ldb, const char *options[]);
169 struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[]);
170 struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]);
171
172
173 int ldb_match_msg(struct ldb_context *ldb,
174                   struct ldb_message *msg,
175                   struct ldb_parse_tree *tree,
176                   const struct ldb_dn *base,
177                   enum ldb_scope scope);
178
179 void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib);
180 const struct ldb_attrib_handler *ldb_attrib_handler_syntax(struct ldb_context *ldb,
181                                                            const char *syntax);
182 int ldb_set_attrib_handlers(struct ldb_context *ldb, 
183                             const struct ldb_attrib_handler *handlers, 
184                             unsigned num_handlers);
185 int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
186 int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, 
187                                   const char *attr, const char *syntax);
188
189 /* The following definitions come from lib/ldb/common/ldb_attributes.c  */
190 const char **ldb_subclass_list(struct ldb_context *ldb, const char *class);
191 void ldb_subclass_remove(struct ldb_context *ldb, const char *class);
192 int ldb_subclass_add(struct ldb_context *ldb, const char *class, const char *subclass);
193
194 int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx,
195                      const struct ldb_val *in, struct ldb_val *out);
196 int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx,
197                           const struct ldb_val *v1, const struct ldb_val *v2);
198
199 #endif