/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2004-2009 The OpenLDAP Foundation.
+ * Copyright 2004-2011 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
};
/*
- * Callbacks: Caller set op->o_bd to underlying BackendDB and sc_private
- * to Relay BackendDB. sc_response swaps them, sc_cleanup swaps them back.
+ * Callbacks: Caller changed op->o_bd from Relay to underlying
+ * BackendDB. sc_response sets it to Relay BackendDB, sc_cleanup puts
+ * back underlying BackendDB. Caller will restore Relay BackendDB.
*/
+
+typedef struct relay_callback {
+ slap_callback rcb_sc;
+ BackendDB *rcb_bd;
+} relay_callback;
+
static int
-relay_back_swap_bd( Operation *op, SlapReply *rs )
+relay_back_cleanup_cb( Operation *op, SlapReply *rs )
{
- slap_callback *cb = op->o_callback;
- BackendDB *be = op->o_bd;
+ op->o_bd = ((relay_callback *) op->o_callback)->rcb_bd;
+ return SLAP_CB_CONTINUE;
+}
- op->o_bd = cb->sc_private;
- cb->sc_private = be;
+static int
+relay_back_response_cb( Operation *op, SlapReply *rs )
+{
+ relay_callback *rcb = (relay_callback *) op->o_callback;
+ rcb->rcb_sc.sc_cleanup = relay_back_cleanup_cb;
+ rcb->rcb_bd = op->o_bd;
+ op->o_bd = op->o_callback->sc_private;
return SLAP_CB_CONTINUE;
}
-#define relay_back_add_cb( cb, op ) \
- { \
- (cb)->sc_next = (op)->o_callback; \
- (cb)->sc_response = relay_back_swap_bd; \
- (cb)->sc_cleanup = relay_back_swap_bd; \
- (cb)->sc_private = (op)->o_bd; \
- (op)->o_callback = (cb); \
- }
+#define relay_back_add_cb( rcb, op ) { \
+ (rcb)->rcb_sc.sc_next = (op)->o_callback; \
+ (rcb)->rcb_sc.sc_response = relay_back_response_cb; \
+ (rcb)->rcb_sc.sc_cleanup = 0; \
+ (rcb)->rcb_sc.sc_private = (op)->o_bd; \
+ (op)->o_callback = (slap_callback *) (rcb); \
+}
+
+#define relay_back_remove_cb( rcb, op ) { \
+ slap_callback **sc = &(op)->o_callback; \
+ for ( ;; sc = &(*sc)->sc_next ) \
+ if ( *sc == (slap_callback *) (rcb) ) { \
+ *sc = (*sc)->sc_next; break; \
+ } else if ( *sc == NULL ) break; \
+}
/*
* Select the backend database with the operation's DN. On failure,
return bd;
}
- bd = NULL;
Debug( LDAP_DEBUG_ANY,
"%s: back-relay for DN=\"%s\" would call self.\n",
op->o_log_prefix, op->o_req_dn.bv_val, 0 );
return rs->sr_err; /* sr_err was set above */
} else if ( (func = (&bd->be_bind)[which]) != 0 ) {
- slap_callback cb;
-
- relay_back_add_cb( &cb, op );
+ relay_callback rcb;
+ relay_back_add_cb( &rcb, op );
RELAY_WRAP_OP( op, bd, which, {
rc = func( op, rs );
});
-
- if ( op->o_callback == &cb ) {
- op->o_callback = op->o_callback->sc_next;
- }
+ relay_back_remove_cb( &rcb, op );
} else if ( fail_mode & RB_OPERR ) {
rs->sr_err = rc;
return rc;
}
-#if 0
+#if 0 /* Give the RB_SENDREF flag a nonzero value if implementing this */
/*
* NOTE: even the existence of this function is questionable: we cannot
* pass the bi_chk_referrals() call thru the rwm overlay because there