cleanup and streamline response handling

This commit is contained in:
Pierangelo Masarati 2006-10-14 17:12:05 +00:00
parent 968da1cb14
commit f449ee6500

View File

@ -117,6 +117,10 @@ meta_search_dobind_init(
/* for some reason (e.g. because formerly in "binding"
* state, with eventual connection expiration or invalidation)
* it was not initialized as expected */
Debug( LDAP_DEBUG_ANY, "%s meta_search_dobind_init[%d] ld=NULL\n",
op->o_log_prefix, candidate, 0 );
rc = meta_back_init_one_conn( op, rs, *mcp, candidate,
LDAP_BACK_CONN_ISPRIV( *mcp ), LDAP_BACK_DONTSEND );
switch ( rc ) {
@ -175,6 +179,8 @@ meta_search_dobind_init(
}
}
assert( msc->msc_ld != NULL );
rc = ldap_sasl_bind( msc->msc_ld, binddn.bv_val, LDAP_SASL_SIMPLE, &cred,
NULL, NULL, &candidates[ candidate ].sr_msgid );
switch ( rc ) {
@ -182,8 +188,8 @@ meta_search_dobind_init(
META_BINDING_SET( &candidates[ candidate ] );
return META_SEARCH_BINDING;
down:;
case LDAP_SERVER_DOWN:
down:;
/* This is the worst thing that could happen:
* the search will wait until the retry is over. */
if ( meta_back_retry( op, rs, mcp, candidate, LDAP_BACK_DONTSEND ) ) {
@ -197,8 +203,8 @@ down:;
}
/* fall thru */
other:;
default:
other:;
rs->sr_err = rc;
rc = slap_map_api2result( rs );
@ -243,7 +249,7 @@ meta_search_dobind_result(
/* FIXME: matched? referrals? response controls? */
rc = ldap_parse_result( msc->msc_ld, res,
&candidates[ candidate ].sr_err,
NULL, NULL, NULL, NULL, 1 );
NULL, NULL, NULL, NULL, 0 );
if ( rc != LDAP_SUCCESS ) {
candidates[ candidate ].sr_err = rc;
}
@ -525,7 +531,6 @@ meta_back_search( Operation *op, SlapReply *rs )
metaconn_t *mc;
struct timeval tv = { 0, 0 };
time_t stoptime = (time_t)-1;
LDAPMessage *res = NULL, *e;
int rc = 0, sres = LDAP_SUCCESS;
char *matched = NULL;
int last = 0, ncandidates = 0,
@ -678,6 +683,7 @@ meta_back_search( Operation *op, SlapReply *rs )
for ( i = 0; i < mi->mi_ntargets; i++ ) {
metasingleconn_t *msc = &mc->mc_conns[ i ];
LDAPMessage *res = NULL, *msg;
if ( candidates[ i ].sr_msgid == META_MSGID_IGNORE ) {
continue;
@ -721,7 +727,7 @@ meta_back_search( Operation *op, SlapReply *rs )
switch ( meta_back_search_start( op, rs, &dc, &mc, i, candidates ) )
{
case META_SEARCH_CANDIDATE:
goto get_result;
break;
/* means that failed but onerr == continue */
case META_SEARCH_NOT_CANDIDATE:
@ -765,9 +771,8 @@ meta_back_search( Operation *op, SlapReply *rs )
* get a LDAP_TIMELIMIT_EXCEEDED from
* one of them ...
*/
get_result:;
rc = ldap_result( msc->msc_ld, candidates[ i ].sr_msgid,
LDAP_MSG_ONE, &tv, &res );
LDAP_MSG_RECEIVED, &tv, &res );
switch ( rc ) {
case 0:
/* FIXME: res should not need to be freed */
@ -785,7 +790,7 @@ really_bad:;
switch ( meta_back_search_start( op, rs, &dc, &mc, i, candidates ) )
{
case META_SEARCH_CANDIDATE:
goto get_result;
break;
/* means that failed but onerr == continue */
case META_SEARCH_NOT_CANDIDATE:
@ -837,7 +842,14 @@ really_bad:;
break;
}
for ( msg = ldap_first_message( msc->msc_ld, res );
msg != NULL;
msg = ldap_next_message( msc->msc_ld, msg ) )
{
rc = ldap_msgtype( msg );
if ( rc == LDAP_RES_SEARCH_ENTRY ) {
LDAPMessage *e;
if ( candidates[ i ].sr_type == REP_INTERMEDIATE ) {
/* don't retry any more... */
candidates[ i ].sr_type = REP_RESULT;
@ -845,12 +857,10 @@ really_bad:;
is_ok++;
e = ldap_first_entry( msc->msc_ld, res );
e = ldap_first_entry( msc->msc_ld, msg );
savepriv = op->o_private;
op->o_private = (void *)i;
rs->sr_err = meta_send_entry( op, rs, mc, i, e );
ldap_msgfree( res );
res = NULL;
switch ( rs->sr_err ) {
case LDAP_SIZELIMIT_EXCEEDED:
@ -859,10 +869,14 @@ really_bad:;
send_ldap_result( op, rs );
op->o_private = savepriv;
rs->sr_err = LDAP_SUCCESS;
ldap_msgfree( res );
res = NULL;
goto finish;
case LDAP_UNAVAILABLE:
rs->sr_err = LDAP_OTHER;
ldap_msgfree( res );
res = NULL;
goto finish;
}
op->o_private = savepriv;
@ -872,28 +886,6 @@ really_bad:;
tv.tv_sec = 0;
tv.tv_usec = 0;
#if 0
/*
* If scope is BASE, we need to jump out
* as soon as one entry is found; if
* the target pool is properly crafted,
* this should correspond to the sole
* entry that has the base DN
*/
/* FIXME: this defeats the purpose of
* doing a search with scope == base and
* sizelimit = 1 to determine if a
* candidate is actually unique */
if ( op->ors_scope == LDAP_SCOPE_BASE
&& rs->sr_nentries > 0 )
{
doabandon = 1;
ncandidates = 0;
sres = LDAP_SUCCESS;
break;
}
#endif
} else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
char **references = NULL;
int cnt;
@ -905,9 +897,8 @@ really_bad:;
is_ok++;
rc = ldap_parse_reference( msc->msc_ld, res,
&references, &rs->sr_ctrls, 1 );
res = NULL;
rc = ldap_parse_reference( msc->msc_ld, msg,
&references, &rs->sr_ctrls, 0 );
if ( rc != LDAP_SUCCESS ) {
continue;
@ -925,7 +916,6 @@ really_bad:;
#endif /* ! ENABLE_REWRITE */
/* FIXME: merge all and return at the end */
for ( cnt = 0; references[ cnt ]; cnt++ )
;
@ -978,20 +968,21 @@ really_bad:;
*/
/* FIXME: response controls? */
rs->sr_err = ldap_parse_result( msc->msc_ld,
res,
msg,
&candidates[ i ].sr_err,
(char **)&candidates[ i ].sr_matched,
NULL /* (char **)&candidates[ i ].sr_text */ ,
&references,
NULL /* &candidates[ i ].sr_ctrls (unused) */ ,
1 );
res = NULL;
0 );
if ( rs->sr_err != LDAP_SUCCESS ) {
ldap_get_option( msc->msc_ld,
LDAP_OPT_RESULT_CODE,
&rs->sr_err );
sres = slap_map_api2result( rs );
candidates[ i ].sr_type = REP_RESULT;
ldap_msgfree( res );
res = NULL;
goto really_bad;
}
@ -1007,7 +998,8 @@ really_bad:;
dc.target = mi->mi_targets[ i ];
if ( !ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
if ( mmatch.bv_val == match.bv_val ) {
candidates[ i ].sr_matched = ch_strdup( mmatch.bv_val );
candidates[ i ].sr_matched
= ch_strdup( mmatch.bv_val );
} else {
candidates[ i ].sr_matched = mmatch.bv_val;
@ -1102,6 +1094,8 @@ really_bad:;
op->o_private = (void *)i;
send_ldap_result( op, rs );
op->o_private = savepriv;
ldap_msgfree( res );
res = NULL;
goto finish;
}
break;
@ -1112,6 +1106,8 @@ really_bad:;
op->o_private = (void *)i;
send_ldap_result( op, rs );
op->o_private = savepriv;
ldap_msgfree( res );
res = NULL;
goto finish;
}
break;
@ -1130,7 +1126,7 @@ really_bad:;
} else if ( rc == LDAP_RES_BIND ) {
meta_search_candidate_t retcode;
retcode = meta_search_dobind_result( op, rs, &mc, i, candidates, res );
retcode = meta_search_dobind_result( op, rs, &mc, i, candidates, msg );
if ( retcode == META_SEARCH_CANDIDATE ) {
candidates[ i ].sr_msgid = META_MSGID_IGNORE;
retcode = meta_back_search_start( op, rs, &dc, &mc, i, candidates );
@ -1138,7 +1134,7 @@ really_bad:;
switch ( retcode ) {
case META_SEARCH_CANDIDATE:
goto get_result;
break;
/* means that failed but onerr == continue */
case META_SEARCH_NOT_CANDIDATE:
@ -1151,6 +1147,8 @@ really_bad:;
op->o_private = (void *)i;
send_ldap_result( op, rs );
op->o_private = savepriv;
ldap_msgfree( res );
res = NULL;
goto finish;
}
break;
@ -1162,10 +1160,16 @@ really_bad:;
} else {
assert( 0 );
ldap_msgfree( res );
res = NULL;
goto really_bad;
}
}
ldap_msgfree( res );
res = NULL;
}
/* check for abandon */
if ( op->o_abandon || doabandon ) {
for ( i = 0; i < mi->mi_ntargets; i++ ) {