version 1.36.2.7, 2000/10/03 17:21:46
|
version 1.36.2.8, 2000/10/17 19:51:58
|
Line 1
|
Line 1
|
/* $OpenLDAP: pkg/ldap/libraries/libldap/result.c,v 1.36.2.6 2000/08/18 02:32:54 kurt Exp $ */ |
/* $OpenLDAP: pkg/ldap/libraries/libldap/result.c,v 1.36.2.7 2000/10/03 17:21:46 kurt Exp $ */ |
/* |
/* |
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. |
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
Line 63 static ber_tag_t try_read1msg LDAP_P(( L
|
Line 63 static ber_tag_t try_read1msg LDAP_P(( L
|
int all, Sockbuf *sb, LDAPConn *lc, LDAPMessage **result )); |
int all, Sockbuf *sb, LDAPConn *lc, LDAPMessage **result )); |
static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr )); |
static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr )); |
static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )); |
static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )); |
|
static LDAPMessage * chkResponseList LDAP_P(( LDAP *ld, int msgid, int all)); |
|
|
|
|
/* |
/* |
Line 89 ldap_result(
|
Line 90 ldap_result(
|
struct timeval *timeout, |
struct timeval *timeout, |
LDAPMessage **result ) |
LDAPMessage **result ) |
{ |
{ |
LDAPMessage *lm, *lastlm, *nextlm; |
LDAPMessage *lm; |
|
|
assert( ld != NULL ); |
assert( ld != NULL ); |
assert( result != NULL ); |
assert( result != NULL ); |
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_result\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_TRACE, "ldap_result msgid %d\n", msgid, 0, 0 ); |
|
|
if( ld == NULL ) { |
if( ld == NULL ) { |
return -1; |
return -1; |
Line 105 ldap_result(
|
Line 106 ldap_result(
|
return -1; |
return -1; |
} |
} |
|
|
/* |
lm = chkResponseList(ld, msgid, all); |
* First, look through the list of responses we have received on |
|
|
if ( lm == NULL ) { |
|
return( wait4msg( ld, msgid, all, timeout, result ) ); |
|
} |
|
|
|
*result = lm; |
|
ld->ld_errno = LDAP_SUCCESS; |
|
return( lm->lm_msgtype ); |
|
} |
|
|
|
static LDAPMessage * |
|
chkResponseList( LDAP *ld, |
|
int msgid, |
|
int all) |
|
{ |
|
LDAPMessage *lm, *lastlm, *nextlm; |
|
/* |
|
* Look through the list of responses we have received on |
* this association and see if the response we're interested in |
* this association and see if the response we're interested in |
* is there. If it is, return it. If not, call wait4msg() to |
* is there. If it is, return it. If not, call wait4msg() to |
* wait until it arrives or timeout occurs. |
* wait until it arrives or timeout occurs. |
*/ |
*/ |
|
|
*result = NULL; |
Debug( LDAP_DEBUG_TRACE, "chkResponseList for msgid %d, all %d\n", |
|
msgid, all, 0 ); |
lastlm = NULL; |
lastlm = NULL; |
for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) { |
for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) { |
nextlm = lm->lm_next; |
nextlm = lm->lm_next; |
|
|
if ( ldap_abandoned( ld, lm->lm_msgid ) ) { |
if ( ldap_abandoned( ld, lm->lm_msgid ) ) { |
|
Debug( LDAP_DEBUG_TRACE, "chkResponseList msg abandoned, msgid %d\n", |
|
msgid, 0, 0 ); |
ldap_mark_abandoned( ld, lm->lm_msgid ); |
ldap_mark_abandoned( ld, lm->lm_msgid ); |
|
|
if ( lastlm == NULL ) { |
if ( lastlm == NULL ) { |
|
/* Remove first entry in list */ |
ld->ld_responses = lm->lm_next; |
ld->ld_responses = lm->lm_next; |
} else { |
} else { |
lastlm->lm_next = nextlm; |
lastlm->lm_next = nextlm; |
Line 154 ldap_result(
|
Line 176 ldap_result(
|
} |
} |
lastlm = lm; |
lastlm = lm; |
} |
} |
if ( lm == NULL ) { |
if ( lm != NULL ) { |
return( wait4msg( ld, msgid, all, timeout, result ) ); |
/* Found an entry, remove it from the list */ |
} |
if ( lastlm == NULL ) { |
|
ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL |
|
? lm->lm_chain : lm->lm_next); |
|
} else { |
|
lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL |
|
? lm->lm_chain : lm->lm_next); |
|
} |
|
if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL ) |
|
{ |
|
lm->lm_chain->lm_next = lm->lm_next; |
|
lm->lm_chain = NULL; |
|
} |
|
lm->lm_next = NULL; |
|
} |
|
|
if ( lastlm == NULL ) { |
#ifdef LDAP_DEBUG |
ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL |
if( lm == NULL) { |
? lm->lm_chain : lm->lm_next); |
Debug( LDAP_DEBUG_TRACE, "chkResponseList returns NULL\n", 0, 0, 0); |
} else { |
} else { |
lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL |
Debug( LDAP_DEBUG_TRACE, "chkResponseList returns msgid %d, type %lu\n", |
? lm->lm_chain : lm->lm_next); |
lm->lm_msgid, (unsigned long) lm->lm_msgtype, 0); |
} |
|
if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL ) |
|
{ |
|
lm->lm_chain->lm_next = lm->lm_next; |
|
lm->lm_chain = NULL; |
|
} |
} |
lm->lm_next = NULL; |
#endif |
|
return lm; |
*result = lm; |
|
ld->ld_errno = LDAP_SUCCESS; |
|
return( lm->lm_msgtype ); |
|
} |
} |
|
|
static int |
static int |
wait4msg( |
wait4msg( |
LDAP *ld, |
LDAP *ld, |
Line 196 wait4msg(
|
Line 222 wait4msg(
|
|
|
#ifdef LDAP_DEBUG |
#ifdef LDAP_DEBUG |
if ( timeout == NULL ) { |
if ( timeout == NULL ) { |
Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n", |
Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout), msgid %d\n", |
0, 0, 0 ); |
msgid, 0, 0 ); |
} else { |
} else { |
Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n", |
Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec), msgid %d\n", |
(long) timeout->tv_sec, (long) timeout->tv_usec, 0 ); |
(long) timeout->tv_sec, (long) timeout->tv_usec, msgid ); |
} |
} |
#endif /* LDAP_DEBUG */ |
#endif /* LDAP_DEBUG */ |
|
|
Line 215 wait4msg(
|
Line 241 wait4msg(
|
rc = -2; |
rc = -2; |
while ( rc == -2 ) { |
while ( rc == -2 ) { |
#ifdef LDAP_DEBUG |
#ifdef LDAP_DEBUG |
|
Debug( LDAP_DEBUG_TRACE, "wait4msg continue, msgid %d, all %d\n", |
|
msgid, all, 0 ); |
if ( ldap_debug & LDAP_DEBUG_TRACE ) { |
if ( ldap_debug & LDAP_DEBUG_TRACE ) { |
ldap_dump_connection( ld, ld->ld_conns, 1 ); |
ldap_dump_connection( ld, ld->ld_conns, 1 ); |
ldap_dump_requests_and_responses( ld ); |
ldap_dump_requests_and_responses( ld ); |
} |
} |
#endif /* LDAP_DEBUG */ |
#endif /* LDAP_DEBUG */ |
for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) { |
|
if ( ber_sockbuf_ctrl( lc->lconn_sb, |
|
LBER_SB_OPT_DATA_READY, NULL ) ) { |
|
rc = try_read1msg( ld, msgid, all, lc->lconn_sb, |
|
lc, result ); |
|
break; |
|
} |
|
} |
|
|
|
if ( lc == NULL ) { |
if( (*result = chkResponseList(ld, msgid, all)) != NULL ) { |
rc = do_ldap_select( ld, tvp ); |
rc = (*result)->lm_msgtype; |
|
} else { |
|
|
|
for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) { |
|
if ( ber_sockbuf_ctrl( lc->lconn_sb, |
|
LBER_SB_OPT_DATA_READY, NULL ) ) { |
|
rc = try_read1msg( ld, msgid, all, lc->lconn_sb, |
|
lc, result ); |
|
break; |
|
} |
|
} |
|
|
|
if ( lc == NULL ) { |
|
rc = do_ldap_select( ld, tvp ); |
|
|
|
|
#ifdef LDAP_DEBUG |
#ifdef LDAP_DEBUG |
if ( rc == -1 ) { |
if ( rc == -1 ) { |
Debug( LDAP_DEBUG_TRACE, |
Debug( LDAP_DEBUG_TRACE, |
"do_ldap_select returned -1: errno %d\n", |
"do_ldap_select returned -1: errno %d\n", |
errno, 0, 0 ); |
errno, 0, 0 ); |
} |
} |
#endif |
#endif |
|
|
if ( rc == 0 || ( rc == -1 && ( |
if ( rc == 0 || ( rc == -1 && ( |
!LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART) |
!LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART) |
|| errno != EINTR ))) |
|| errno != EINTR ))) |
{ |
{ |
ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : |
ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : |
LDAP_TIMEOUT); |
LDAP_TIMEOUT); |
return( rc ); |
return( rc ); |
} |
} |
|
|
if ( rc == -1 ) { |
if ( rc == -1 ) { |
rc = -2; /* select interrupted: loop */ |
rc = -2; /* select interrupted: loop */ |
} else { |
} else { |
rc = -2; |
rc = -2; |
for ( lc = ld->ld_conns; rc == -2 && lc != NULL; |
for ( lc = ld->ld_conns; rc == -2 && lc != NULL; |
lc = nextlc ) { |
lc = nextlc ) { |
nextlc = lc->lconn_next; |
nextlc = lc->lconn_next; |
if ( lc->lconn_status == |
if ( lc->lconn_status == |
LDAP_CONNST_CONNECTED && |
LDAP_CONNST_CONNECTED && |
ldap_is_read_ready( ld, |
ldap_is_read_ready( ld, |
lc->lconn_sb )) { |
lc->lconn_sb )) { |
rc = try_read1msg( ld, msgid, all, |
rc = try_read1msg( ld, msgid, all, |
lc->lconn_sb, lc, result ); |
lc->lconn_sb, lc, result ); |
} |
} |
} |
} |
} |
} |
|
} |
} |
} |
|
|
if ( rc == -2 && tvp != NULL ) { |
if ( rc == -2 && tvp != NULL ) { |
Line 314 try_read1msg(
|
Line 348 try_read1msg(
|
assert( ld != NULL ); |
assert( ld != NULL ); |
assert( lc != NULL ); |
assert( lc != NULL ); |
|
|
Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_TRACE, "read1msg: msgid %d, all %d\n", msgid, all, 0 ); |
|
|
if ( lc->lconn_ber == NULL ) { |
if ( lc->lconn_ber == NULL ) { |
lc->lconn_ber = ldap_alloc_ber_with_options(ld); |
lc->lconn_ber = ldap_alloc_ber_with_options(ld); |
Line 416 try_read1msg(
|
Line 450 try_read1msg(
|
} else { |
} else { |
/* Note: refs arrary is freed by ldap_chase_v3referrals */ |
/* Note: refs arrary is freed by ldap_chase_v3referrals */ |
refer_cnt = ldap_chase_v3referrals( ld, lr, refs, |
refer_cnt = ldap_chase_v3referrals( ld, lr, refs, |
&lr->lr_res_error, &hadref ); |
1, &lr->lr_res_error, &hadref ); |
if ( refer_cnt > 0 ) { /* sucessfully chased reference */ |
if ( refer_cnt > 0 ) { /* sucessfully chased reference */ |
/* If haven't got end search, set chasing referrals */ |
/* If haven't got end search, set chasing referrals */ |
if( lr->lr_status != LDAP_REQST_COMPLETED) { |
if( lr->lr_status != LDAP_REQST_COMPLETED) { |
Line 455 try_read1msg(
|
Line 489 try_read1msg(
|
* Note: refs arrary is freed by ldap_chase_v3referrals |
* Note: refs arrary is freed by ldap_chase_v3referrals |
*/ |
*/ |
refer_cnt = ldap_chase_v3referrals( ld, lr, refs, |
refer_cnt = ldap_chase_v3referrals( ld, lr, refs, |
&lr->lr_res_error, &hadref ); |
0, &lr->lr_res_error, &hadref ); |
lr->lr_status = LDAP_REQST_COMPLETED; |
lr->lr_status = LDAP_REQST_COMPLETED; |
Debug( LDAP_DEBUG_TRACE, |
Debug( LDAP_DEBUG_TRACE, |
"read1msg: referral chased, mark request completed, id = %d\n", |
"read1msg: referral chased, mark request completed, id = %d\n", |