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