- 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;
+ }
+ }