From 0d2e2772d52d958880837f8191f1c73473c37e97 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 4 Sep 2006 07:17:34 +0000 Subject: [PATCH] move req2op selection into a helper --- servers/slapd/connection.c | 53 +++----------------------------------- servers/slapd/operation.c | 29 +++++++++++++++++++++ servers/slapd/proto-slap.h | 1 + servers/slapd/slap.h | 4 +-- 4 files changed, 36 insertions(+), 51 deletions(-) diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index e57977ba0e..367ddf209e 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -1006,7 +1006,7 @@ connection_operation( void *ctx, void *arg_v ) Operation *op = arg_v; SlapReply rs = {REP_RESULT}; ber_tag_t tag = op->o_tag; - int opidx = -1; + slap_op_t opidx = SLAP_OP_LAST; Connection *conn = op->o_conn; void *memctx = NULL; void *memctx_null = NULL; @@ -1089,53 +1089,8 @@ connection_operation( void *ctx, void *arg_v ) } } - switch ( tag ) { - case LDAP_REQ_BIND: - opidx = SLAP_OP_BIND; - break; - - case LDAP_REQ_UNBIND: - opidx = SLAP_OP_UNBIND; - break; - - case LDAP_REQ_ADD: - opidx = SLAP_OP_ADD; - break; - - case LDAP_REQ_DELETE: - opidx = SLAP_OP_DELETE; - break; - - case LDAP_REQ_MODRDN: - opidx = SLAP_OP_MODRDN; - break; - - case LDAP_REQ_MODIFY: - opidx = SLAP_OP_MODIFY; - break; - - case LDAP_REQ_COMPARE: - opidx = SLAP_OP_COMPARE; - break; - - case LDAP_REQ_SEARCH: - opidx = SLAP_OP_SEARCH; - break; - - case LDAP_REQ_ABANDON: - opidx = SLAP_OP_ABANDON; - break; - - case LDAP_REQ_EXTENDED: - opidx = SLAP_OP_EXTENDED; - break; - - default: - /* not reachable */ - assert( 0 ); - } - - assert( opidx > -1 ); + opidx = slap_req2op( tag ); + assert( opidx != SLAP_OP_LAST ); INCR_OP_INITIATED( opidx ); rc = (*(opfun[opidx]))( op, &rs ); @@ -1143,7 +1098,7 @@ operations_error: if ( rc == SLAPD_DISCONNECT ) { tag = LBER_ERROR; - } else if ( opidx > -1 ) { + } else if ( opidx != SLAP_OP_LAST ) { /* increment completed operations count * only if operation was initiated * and rc != SLAPD_DISCONNECT */ diff --git a/servers/slapd/operation.c b/servers/slapd/operation.c index 13bb5cf590..2ffddce841 100644 --- a/servers/slapd/operation.c +++ b/servers/slapd/operation.c @@ -165,3 +165,32 @@ slap_op_alloc( return( op ); } + +slap_op_t +slap_req2op( ber_tag_t tag ) +{ + switch ( tag ) { + case LDAP_REQ_BIND: + return SLAP_OP_BIND; + case LDAP_REQ_UNBIND: + return SLAP_OP_UNBIND; + case LDAP_REQ_ADD: + return SLAP_OP_ADD; + case LDAP_REQ_DELETE: + return SLAP_OP_DELETE; + case LDAP_REQ_MODRDN: + return SLAP_OP_MODRDN; + case LDAP_REQ_MODIFY: + return SLAP_OP_MODIFY; + case LDAP_REQ_COMPARE: + return SLAP_OP_COMPARE; + case LDAP_REQ_SEARCH: + return SLAP_OP_SEARCH; + case LDAP_REQ_ABANDON: + return SLAP_OP_ABANDON; + case LDAP_REQ_EXTENDED: + return SLAP_OP_EXTENDED; + } + + return SLAP_OP_LAST; +} diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index b320565c9c..8246077f6c 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1256,6 +1256,7 @@ LDAP_SLAPD_F (Operation *) slap_op_alloc LDAP_P(( LDAP_SLAPD_F (int) slap_op_add LDAP_P(( Operation **olist, Operation *op )); LDAP_SLAPD_F (int) slap_op_remove LDAP_P(( Operation **olist, Operation *op )); LDAP_SLAPD_F (Operation *) slap_op_pop LDAP_P(( Operation **olist )); +LDAP_SLAPD_F (slap_op_t) slap_req2op LDAP_P(( ber_tag_t tag )); /* * operational.c diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 67dca3df48..0fcbcb6291 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -2733,7 +2733,7 @@ struct slap_listener { /* * Operation indices */ -enum { +typedef enum { SLAP_OP_BIND = 0, SLAP_OP_UNBIND, SLAP_OP_ADD, @@ -2745,7 +2745,7 @@ enum { SLAP_OP_ABANDON, SLAP_OP_EXTENDED, SLAP_OP_LAST -}; +} slap_op_t; typedef struct slap_counters_t { ldap_pvt_thread_mutex_t sc_sent_mutex; -- 2.39.5