/* $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.
*
BackendDB *rcb_bd;
} relay_callback;
-int
+static int
relay_back_cleanup_cb( Operation *op, SlapReply *rs )
{
op->o_bd = ((relay_callback *) op->o_callback)->rcb_bd;
return SLAP_CB_CONTINUE;
}
-int
+static int
relay_back_response_cb( Operation *op, SlapReply *rs )
{
relay_callback *rcb = (relay_callback *) op->o_callback;
return SLAP_CB_CONTINUE;
}
-#define relay_back_add_cb( rcb, op, bd ) \
- { \
+#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,
} else if ( (func = (&bd->be_bind)[which]) != 0 ) {
relay_callback rcb;
- relay_back_add_cb( &rcb, op, bd );
-
+ relay_back_add_cb( &rcb, op );
RELAY_WRAP_OP( op, bd, which, {
rc = func( op, rs );
});
-
- if ( op->o_callback == (slap_callback *) &rcb ) {
- op->o_callback = op->o_callback->sc_next;
- }
+ relay_back_remove_cb( &rcb, op );
} else if ( fail_mode & RB_OPERR ) {
rs->sr_err = rc;