From 13916cd3811fd5ebc7da6fcae019ae1e56fcee98 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Wed, 11 Dec 2013 14:40:45 +0100 Subject: [PATCH] ITS#6758 Rewrite code for contrib:wrap_slap_ops. Tweak slapd code so wrap_slap_ops can process it: Use pointers BackendInfo *bi instead of array "func" = &bi->bi_op_bind. In slapo-chain, keep a slap_operation_t instead of a function ptr. --- servers/slapd/back-ldap/chain.c | 35 +++++++++++++++++---------------- servers/slapd/back-relay/op.c | 6 +++--- servers/slapd/backglue.c | 11 ++++------- servers/slapd/backover.c | 17 ++++++++-------- servers/slapd/overlays/pcache.c | 7 +++---- servers/slapd/slapi/slapi_ops.c | 6 +----- 6 files changed, 37 insertions(+), 45 deletions(-) diff --git a/servers/slapd/back-ldap/chain.c b/servers/slapd/back-ldap/chain.c index 3ecc3b673c..79e4ae882b 100644 --- a/servers/slapd/back-ldap/chain.c +++ b/servers/slapd/back-ldap/chain.c @@ -118,7 +118,7 @@ static int ldap_chain_db_open_one( BackendDB *be ); typedef struct ldap_chain_cb_t { ldap_chain_status_t lb_status; ldap_chain_t *lb_lc; - BI_op_func *lb_op_f; + slap_operation_t lb_op_type; int lb_depth; } ldap_chain_cb_t; @@ -126,7 +126,7 @@ static int ldap_chain_op( Operation *op, SlapReply *rs, - BI_op_func *op_f, + slap_operation_t op_type, BerVarray ref, int depth ); @@ -316,7 +316,8 @@ ldap_chain_cb_search_response( Operation *op, SlapReply *rs ) && lb->lb_depth < lb->lb_lc->lc_max_depth && rs->sr_ref != NULL ) { - rs->sr_err = ldap_chain_op( op, rs, lb->lb_op_f, rs->sr_ref, lb->lb_depth ); + rs->sr_err = ldap_chain_op( op, rs, lb->lb_op_type, + rs->sr_ref, lb->lb_depth ); } /* back-ldap tried to send result */ @@ -356,7 +357,8 @@ retry:; case LDAP_REFERRAL: if ( lb->lb_depth < lb->lb_lc->lc_max_depth && rs->sr_ref != NULL ) { - rs->sr_err = ldap_chain_op( op, rs, lb->lb_op_f, rs->sr_ref, lb->lb_depth ); + rs->sr_err = ldap_chain_op( op, rs, lb->lb_op_type, + rs->sr_ref, lb->lb_depth ); goto retry; } @@ -391,7 +393,7 @@ static int ldap_chain_op( Operation *op, SlapReply *rs, - BI_op_func *op_f, + slap_operation_t op_type, BerVarray ref, int depth ) { @@ -602,10 +604,10 @@ Document: RFC 4511 op->o_log_prefix, ref->bv_val, temporary ? "temporary" : "caching" ); } - lb->lb_op_f = op_f; + lb->lb_op_type = op_type; lb->lb_depth = depth + 1; - rc = op_f( op, &rs2 ); + rc = (&lback->bi_op_bind)[ op_type ]( op, &rs2 ); /* note the first error */ if ( first_rc == -1 ) { @@ -873,7 +875,7 @@ ldap_chain_search( op->o_log_prefix, ref->bv_val, temporary ? "temporary" : "caching" ); } - lb->lb_op_f = lback->bi_op_search; + lb->lb_op_type = op_search; lb->lb_depth = depth + 1; /* FIXME: should we also copy filter and scope? @@ -1041,30 +1043,30 @@ ldap_chain_response( Operation *op, SlapReply *rs ) /* FIXME: can we really get a referral for binds? */ op->o_req_ndn = slap_empty_bv; op->o_conn = NULL; - rc = ldap_chain_op( op, rs, lback->bi_op_bind, ref, 0 ); + rc = ldap_chain_op( op, rs, op_bind, ref, 0 ); op->o_req_ndn = rndn; op->o_conn = conn; } break; case LDAP_REQ_ADD: - rc = ldap_chain_op( op, rs, lback->bi_op_add, ref, 0 ); + rc = ldap_chain_op( op, rs, op_add, ref, 0 ); break; case LDAP_REQ_DELETE: - rc = ldap_chain_op( op, rs, lback->bi_op_delete, ref, 0 ); + rc = ldap_chain_op( op, rs, op_delete, ref, 0 ); break; case LDAP_REQ_MODRDN: - rc = ldap_chain_op( op, rs, lback->bi_op_modrdn, ref, 0 ); + rc = ldap_chain_op( op, rs, op_modrdn, ref, 0 ); break; case LDAP_REQ_MODIFY: - rc = ldap_chain_op( op, rs, lback->bi_op_modify, ref, 0 ); + rc = ldap_chain_op( op, rs, op_modify, ref, 0 ); break; case LDAP_REQ_COMPARE: - rc = ldap_chain_op( op, rs, lback->bi_op_compare, ref, 0 ); + rc = ldap_chain_op( op, rs, op_compare, ref, 0 ); if ( rs->sr_err == LDAP_COMPARE_TRUE || rs->sr_err == LDAP_COMPARE_FALSE ) { rc = LDAP_SUCCESS; } @@ -1081,8 +1083,7 @@ ldap_chain_response( Operation *op, SlapReply *rs ) * to check limits, to make sure safe defaults * are in place */ if ( op->ors_limit != NULL || limits_check( op, rs ) == 0 ) { - rc = ldap_chain_op( op, rs, lback->bi_op_search, ref, 0 ); - + rc = ldap_chain_op( op, rs, op_search, ref, 0 ); } else { rc = SLAP_CB_CONTINUE; } @@ -1090,7 +1091,7 @@ ldap_chain_response( Operation *op, SlapReply *rs ) break; case LDAP_REQ_EXTENDED: - rc = ldap_chain_op( op, rs, lback->bi_extended, ref, 0 ); + rc = ldap_chain_op( op, rs, op_extended, ref, 0 ); /* FIXME: ldap_back_extended() by design * doesn't send result; frontend is expected * to send it... */ diff --git a/servers/slapd/back-relay/op.c b/servers/slapd/back-relay/op.c index 7c8b4aecbf..89093bc034 100644 --- a/servers/slapd/back-relay/op.c +++ b/servers/slapd/back-relay/op.c @@ -194,7 +194,7 @@ static int relay_back_op( Operation *op, SlapReply *rs, int which ) { BackendDB *bd; - BI_op_bind *func; + BackendInfo *bi; slap_mask_t fail_mode = relay_fail_modes[which].rf_op; int rc = ( fail_mode & RB_ERR_MASK ); @@ -203,12 +203,12 @@ relay_back_op( Operation *op, SlapReply *rs, int which ) if ( fail_mode & RB_BDERR ) return rs->sr_err; /* sr_err was set above */ - } else if ( (func = (&bd->be_bind)[which]) != 0 ) { + } else if ( (&( bi = bd->bd_info )->bi_op_bind)[which] ) { relay_callback rcb; relay_back_add_cb( &rcb, op ); RELAY_WRAP_OP( op, bd, which, { - rc = func( op, rs ); + rc = (&bi->bi_op_bind)[which]( op, rs ); }); relay_back_remove_cb( &rcb, op ); diff --git a/servers/slapd/backglue.c b/servers/slapd/backglue.c index 8f0d12a1ef..1c066d1854 100644 --- a/servers/slapd/backglue.c +++ b/servers/slapd/backglue.c @@ -225,8 +225,7 @@ glue_op_func ( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; BackendDB *b0 = op->o_bd; - BackendInfo *bi0 = op->o_bd->bd_info; - BI_op_modify **func; + BackendInfo *bi0 = op->o_bd->bd_info, *bi1; slap_operation_t which = op_bind; int rc; @@ -247,11 +246,9 @@ glue_op_func ( Operation *op, SlapReply *rs ) default: assert( 0 ); break; } - func = &op->o_bd->bd_info->bi_op_bind; - if ( func[which] ) - rc = func[which]( op, rs ); - else - rc = SLAP_CB_BYPASS; + bi1 = op->o_bd->bd_info; + rc = (&bi1->bi_op_bind)[ which ] ? + (&bi1->bi_op_bind)[ which ]( op, rs ) : SLAP_CB_BYPASS; op->o_bd = b0; op->o_bd->bd_info = bi0; diff --git a/servers/slapd/backover.c b/servers/slapd/backover.c index 02dc5125cb..4cf47cdcc8 100644 --- a/servers/slapd/backover.c +++ b/servers/slapd/backover.c @@ -669,26 +669,26 @@ int overlay_op_walk( slap_overinst *on ) { - BI_op_bind **func; + BackendInfo *bi; int rc = SLAP_CB_CONTINUE; for (; on; on=on->on_next ) { if ( on->on_bi.bi_flags & SLAPO_BFLAG_DISABLED ) continue; - func = &on->on_bi.bi_op_bind; - if ( func[which] ) { + bi = &on->on_bi; + if ( (&bi->bi_op_bind)[ which ] ) { op->o_bd->bd_info = (BackendInfo *)on; - rc = func[which]( op, rs ); + rc = (&bi->bi_op_bind)[ which ]( op, rs ); if ( rc != SLAP_CB_CONTINUE ) break; } } if ( rc == SLAP_CB_BYPASS ) rc = SLAP_CB_CONTINUE; - func = &oi->oi_orig->bi_op_bind; - if ( func[which] && rc == SLAP_CB_CONTINUE ) { - op->o_bd->bd_info = oi->oi_orig; - rc = func[which]( op, rs ); + bi = oi->oi_orig; + if ( (&bi->bi_op_bind)[ which ] && rc == SLAP_CB_CONTINUE ) { + op->o_bd->bd_info = bi; + rc = (&bi->bi_op_bind)[ which ]( op, rs ); } /* should not fall thru this far without anything happening... */ if ( rc == SLAP_CB_CONTINUE ) { @@ -1451,4 +1451,3 @@ overlay_config( BackendDB *be, const char *ov, int idx, BackendInfo **res, Confi return 0; } - diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 8356e49bc3..cd81a68ed2 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -2792,17 +2792,16 @@ pcache_op_privdb( /* map tag to operation */ type = slap_req2op( op->o_tag ); if ( type != SLAP_OP_LAST ) { - BI_op_func **func; + BackendInfo *bi = cm->db.bd_info; int rc; /* execute, if possible */ - func = &cm->db.be_bind; - if ( func[ type ] != NULL ) { + if ( (&bi->bi_op_bind)[ type ] ) { Operation op2 = *op; op2.o_bd = &cm->db; - rc = func[ type ]( &op2, rs ); + rc = (&bi->bi_op_bind)[ type ]( &op2, rs ); if ( type == SLAP_OP_BIND && rc == LDAP_SUCCESS ) { op->o_conn->c_authz_cookie = cm->db.be_private; } diff --git a/servers/slapd/slapi/slapi_ops.c b/servers/slapd/slapi/slapi_ops.c index 7db0c315ad..326c57b7ce 100644 --- a/servers/slapd/slapi/slapi_ops.c +++ b/servers/slapd/slapi/slapi_ops.c @@ -384,7 +384,6 @@ slapi_int_connection_done_pb( Slapi_PBlock *pb ) static int slapi_int_func_internal_pb( Slapi_PBlock *pb, slap_operation_t which ) { - BI_op_bind **func; SlapReply *rs = pb->pb_rs; int rc; @@ -397,9 +396,7 @@ slapi_int_func_internal_pb( Slapi_PBlock *pb, slap_operation_t which ) } pb->pb_op->o_bd = frontendDB; - func = &frontendDB->be_bind; - - return func[which]( pb->pb_op, pb->pb_rs ); + return (&frontendDB->be_bind)[which]( pb->pb_op, pb->pb_rs ); } int @@ -953,4 +950,3 @@ slapi_delete_internal( } #endif /* LDAP_SLAPI */ - -- 2.39.2