ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
#endif
/* Find the next result... */
- for ( lm = r; lm != NULL; lm = lm->lm_chain ) {
- /* skip over entries and references */
- if( lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY &&
- lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE &&
- lm->lm_msgtype != LDAP_RES_INTERMEDIATE )
- {
- break;
+ if ( r->lm_chain == NULL ) {
+ if ((r->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
+ (r->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
+ (r->lm_msgtype == LDAP_RES_INTERMEDIATE)) {
+ lm = NULL;
+ } else {
+ lm = r;
+ }
+ } else {
+ if ((r->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_SEARCH_ENTRY) ||
+ (r->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_SEARCH_REFERENCE) ||
+ (r->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_INTERMEDIATE)) {
+ lm = NULL;
+ } else {
+ lm = r->lm_chain_tail->lm_chain;
}
}
}
/* Find the next result... */
- for ( lm = lm->lm_chain; lm != NULL; lm = lm->lm_chain ) {
- /* skip over entries and references */
- if( lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY &&
- lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE &&
- lm->lm_msgtype != LDAP_RES_INTERMEDIATE )
- {
- /* more results to return */
- errcode = LDAP_MORE_RESULTS_TO_RETURN;
- break;
+ lm = lm->lm_chain;
+ if ( lm ) {
+ if ( lm->lm_chain == NULL ) {
+ if ((lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY) &&
+ (lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) &&
+ (lm->lm_msgtype != LDAP_RES_INTERMEDIATE)) {
+ /* more results to return */
+ errcode = LDAP_MORE_RESULTS_TO_RETURN;
+ }
+ } else {
+ if ((lm->lm_chain_tail->lm_chain->lm_msgtype
+ != LDAP_RES_SEARCH_ENTRY) &&
+ (lm->lm_chain_tail->lm_chain->lm_msgtype
+ != LDAP_RES_SEARCH_REFERENCE) &&
+ (lm->lm_chain_tail->lm_chain->lm_msgtype
+ != LDAP_RES_INTERMEDIATE)) {
+ errcode = LDAP_MORE_RESULTS_TO_RETURN;
+ }
}
}
}
break;
}
- for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
- if ( tmp->lm_msgtype != LDAP_RES_SEARCH_ENTRY
- && tmp->lm_msgtype != LDAP_RES_SEARCH_REFERENCE
- && tmp->lm_msgtype != LDAP_RES_INTERMEDIATE )
- {
- break;
+ if ( lm->lm_chain == NULL ) {
+ if ((lm->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
+ (lm->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
+ (lm->lm_msgtype == LDAP_RES_INTERMEDIATE)) {
+ tmp = NULL;
+ } else {
+ tmp = lm;
+ }
+ } else {
+ if ((lm->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_SEARCH_ENTRY) ||
+ (lm->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_SEARCH_REFERENCE) ||
+ (lm->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_INTERMEDIATE)) {
+ tmp = NULL;
+ } else {
+ tmp = lm->lm_chain_tail->lm_chain;
}
}
LDAPMessage **result )
{
BerElement *ber;
- LDAPMessage *new, *l, *prev, *tmp;
+ LDAPMessage *new, *l, *prev, *tmp, *chain_head;
ber_int_t id;
ber_tag_t tag;
ber_len_t len;
firstmsg = 0;
new->lm_next = ld->ld_responses;
ld->ld_responses = new;
+ new->lm_chain_tail = new;
+ chain_head = new;
} else {
tmp->lm_chain = new;
+ chain_head->lm_chain_tail = tmp;
}
tmp = new;
/* "ok" means there's more to parse */
* first response off the head of the chain.
*/
tmp->lm_chain = new;
+ chain_head->lm_chain_tail = tmp;
*result = chkResponseList( ld, msgid, all );
ld->ld_errno = LDAP_SUCCESS;
return( (*result)->lm_msgtype );
new->lm_next = ld->ld_responses;
ld->ld_responses = new;
+ new->lm_chain_tail = new;
goto exit;
}
(long) new->lm_msgid, (long) new->lm_msgtype, 0 );
/* part of a search response - add to end of list of entries */
- for ( tmp = l; (tmp->lm_chain != NULL) &&
- ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
- (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
- (tmp->lm_chain->lm_msgtype == LDAP_RES_INTERMEDIATE ));
- tmp = tmp->lm_chain )
- ; /* NULL */
- tmp->lm_chain = new;
+ if (l->lm_chain == NULL) {
+ if ((l->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
+ (l->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
+ (l->lm_msgtype == LDAP_RES_INTERMEDIATE)) {
+ /* do not advance lm_chain_tail in this case */
+ l->lm_chain = new;
+ } else {
+ /*FIXME: ldap_msgfree( l );*/
+ l = new;
+ l->lm_chain_tail = new;
+ }
+ } else {
+ if ((l->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_SEARCH_ENTRY) ||
+ (l->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_SEARCH_REFERENCE) ||
+ (l->lm_chain_tail->lm_chain->lm_msgtype
+ == LDAP_RES_INTERMEDIATE)) {
+ l->lm_chain_tail->lm_chain->lm_chain = new;
+ l->lm_chain_tail = l->lm_chain_tail->lm_chain;
+ } else {
+ /*FIXME: ldap_msgfree( l->lm_chain_tail->lm_chain );*/
+ l->lm_chain_tail->lm_chain = new;
+ }
+ }
/* return the whole chain if that's what we were looking for */
if ( foundit ) {