1 /* backover.c - backend overlay routines */
4 * Copyright 2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9 * Functions to overlay other modules over a backend.
18 #include <ac/string.h>
19 #include <ac/socket.h>
24 static slap_overinst *overlays;
26 enum db_which { db_open = 0, db_close, db_destroy };
34 slap_overinfo *oi = (slap_overinfo *) be->bd_info;
35 slap_overinst *on = oi->oi_list;
40 func = &oi->oi_bd.bd_info->bi_db_open;
42 rc = func[which]( &oi->oi_bd );
47 for (; on; on=on->on_next) {
48 bd.bd_info = &on->on_bi;
49 func = &on->on_bi.bi_db_open;
51 rc = func[which]( &bd );
67 slap_overinfo *oi = (slap_overinfo *) be->bd_info;
68 slap_overinst *on = oi->oi_list;
72 if ( oi->oi_bd.bd_info->bi_db_config ) {
73 rc = oi->oi_bd.bd_info->bi_db_config( &oi->oi_bd, fname, lineno,
79 for (; on; on=on->on_next) {
80 bd.bd_info = &on->on_bi;
81 if (on->on_bi.bi_db_config) {
82 rc = on->on_bi.bi_db_config( &bd, fname, lineno,
95 return over_db_func( be, db_open );
103 return over_db_func( be, db_close );
111 slap_overinfo *oi = (slap_overinfo *) be->bd_info;
112 slap_overinst *on = oi->oi_list, *next;
115 rc = over_db_func( be, db_destroy );
117 for (next = on->on_next; on; on=next) {
126 over_back_response ( Operation *op, SlapReply *rs )
128 slap_overinfo *oi = (slap_overinfo *) op->o_bd->bd_info;
129 slap_overinst *on = oi->oi_list;
130 int rc = SLAP_CB_CONTINUE;
131 BackendDB *be = op->o_bd, db = *op->o_bd;
132 slap_callback *sc = op->o_callback->sc_private;
133 slap_callback *s0 = op->o_callback;
137 for (; on; on=on->on_next ) {
138 if ( on->on_response ) {
139 db.bd_info = (BackendInfo *)on;
140 rc = on->on_response( op, rs );
141 if ( rc != SLAP_CB_CONTINUE ) break;
144 if ( sc && (rc == SLAP_CB_CONTINUE) ) {
145 rc = sc->sc_response( op, rs );
152 enum op_which { op_bind = 0, op_unbind, op_search, op_compare,
153 op_modify, op_modrdn, op_add, op_delete, op_abandon,
154 op_cancel, op_extended };
163 slap_overinfo *oi = (slap_overinfo *) op->o_bd->bd_info;
164 slap_overinst *on = oi->oi_list;
166 BackendDB *be = op->o_bd, db = *op->o_bd;
167 slap_callback cb = {over_back_response, NULL};
168 int rc = SLAP_CB_CONTINUE;
171 cb.sc_private = op->o_callback;
172 op->o_callback = &cb;
174 for (; on; on=on->on_next ) {
175 func = &on->on_bi.bi_op_bind;
177 db.bd_info = (BackendInfo *)on;
178 rc = func[which]( op, rs );
179 if ( rc != SLAP_CB_CONTINUE ) break;
184 func = &oi->oi_bd.bd_info->bi_op_bind;
185 if ( func[which] && rc == SLAP_CB_CONTINUE ) {
186 rc = func[which]( op, rs );
188 /* should not fall thru this far without anything happening... */
189 if ( rc == SLAP_CB_CONTINUE ) {
190 rc = LDAP_UNWILLING_TO_PERFORM;
192 op->o_callback = cb.sc_private;
197 over_op_bind( Operation *op, SlapReply *rs )
199 return over_op_func( op, rs, op_bind );
203 over_op_unbind( Operation *op, SlapReply *rs )
205 return over_op_func( op, rs, op_unbind );
209 over_op_search( Operation *op, SlapReply *rs )
211 return over_op_func( op, rs, op_search );
215 over_op_compare( Operation *op, SlapReply *rs )
217 return over_op_func( op, rs, op_compare );
221 over_op_modify( Operation *op, SlapReply *rs )
223 return over_op_func( op, rs, op_modify );
227 over_op_modrdn( Operation *op, SlapReply *rs )
229 return over_op_func( op, rs, op_modrdn );
233 over_op_add( Operation *op, SlapReply *rs )
235 return over_op_func( op, rs, op_add );
239 over_op_delete( Operation *op, SlapReply *rs )
241 return over_op_func( op, rs, op_delete );
245 over_op_abandon( Operation *op, SlapReply *rs )
247 return over_op_func( op, rs, op_abandon );
251 over_op_cancel( Operation *op, SlapReply *rs )
253 return over_op_func( op, rs, op_cancel );
257 over_op_extended( Operation *op, SlapReply *rs )
259 return over_op_func( op, rs, op_extended );
267 on->on_next = overlays;
272 static const char overtype[] = "over";
274 /* add an overlay to a particular backend. */
276 overlay_config( BackendDB *be, const char *ov )
278 slap_overinst *on, *on2, *prev;
282 for ( on = overlays; on; on=on->on_next ) {
283 if (!strcmp( ov, on->on_bi.bi_type ) )
287 Debug( LDAP_DEBUG_ANY, "overlay %s not found\n", ov, 0, 0 );
291 /* If this is the first overlay on this backend, set up the
292 * overlay info structure
294 if ( be->bd_info->bi_type != overtype ) {
295 oi = ch_malloc( sizeof(slap_overinfo) );
297 oi->oi_bi = *be->bd_info;
299 bi = (BackendInfo *)oi;
301 bi->bi_type = (char *)overtype;
303 bi->bi_db_config = over_db_config;
304 bi->bi_db_open = over_db_open;
305 bi->bi_db_close = over_db_close;
306 bi->bi_db_destroy = over_db_destroy;
308 bi->bi_op_bind = over_op_bind;
309 bi->bi_op_unbind = over_op_unbind;
310 bi->bi_op_search = over_op_search;
311 bi->bi_op_compare = over_op_compare;
312 bi->bi_op_modify = over_op_modify;
313 bi->bi_op_modrdn = over_op_modrdn;
314 bi->bi_op_add = over_op_add;
315 bi->bi_op_delete = over_op_delete;
316 bi->bi_op_abandon = over_op_abandon;
317 bi->bi_op_cancel = over_op_cancel;
318 bi->bi_extended = over_op_extended;
323 /* Walk to the end of the list of overlays, add the new
326 oi = (slap_overinfo *) be->bd_info;
327 for ( prev=NULL, on2 = oi->oi_list; on2; prev=on2, on2=on2->on_next );
328 on2 = ch_calloc( 1, sizeof(slap_overinst) );
338 /* Any initialization needed? */
339 if ( on->on_bi.bi_db_init ) {
340 be->bd_info = (BackendInfo *)on2;
341 on2->on_bi.bi_db_init( be );
342 be->bd_info = (BackendInfo *)oi;