3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
11 * This notice applies to changes, created by or for Novell, Inc.,
12 * to preexisting works for which notices appear elsewhere in this file.
14 * Copyright (C) 1999, 2000 Novell, Inc. All Rights Reserved.
16 * THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
17 * USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
18 * 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
19 * HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
20 * TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS
21 * WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC
22 * LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE
23 * PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
25 * Modification to OpenLDAP source by Novell, Inc.
26 * April 2000 sfs Add code to process V3 referrals and search results
28 * result.c - wait for an ldap result
33 * LDAPResult ::= SEQUENCE {
34 * resultCode ENUMERATED { ... },
36 * errorMessage LDAPString,
37 * referral Referral OPTIONAL
39 * Referral ::= SEQUENCE OF LDAPURL (one or more)
40 * LDAPURL ::= LDAPString (limited to URL chars)
47 #include <ac/stdlib.h>
50 #include <ac/socket.h>
51 #include <ac/string.h>
53 #include <ac/unistd.h>
58 static int ldap_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid ));
59 static int ldap_mark_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid ));
60 static int wait4msg LDAP_P(( LDAP *ld, ber_int_t msgid, int all, struct timeval *timeout,
61 LDAPMessage **result ));
62 static ber_tag_t try_read1msg LDAP_P(( LDAP *ld, ber_int_t msgid,
63 int all, Sockbuf *sb, LDAPConn *lc, LDAPMessage **result ));
64 static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr ));
65 static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ));
69 * ldap_result - wait for an ldap result response to a message from the
70 * ldap server. If msgid is -1, any message will be accepted, otherwise
71 * ldap_result will wait for a response with msgid. If all is 0 the
72 * first message with id msgid will be accepted, otherwise, ldap_result
73 * will wait for all responses with id msgid and then return a pointer to
74 * the entire list of messages. This is only useful for search responses,
75 * which can be of two message types (zero or more entries, followed by an
76 * ldap result). The type of the first message received is returned.
77 * When waiting, any messages that have been abandoned are discarded.
80 * ldap_result( s, msgid, all, timeout, result )
87 struct timeval *timeout,
88 LDAPMessage **result )
90 LDAPMessage *lm, *lastlm, *nextlm;
93 assert( result != NULL );
95 Debug( LDAP_DEBUG_TRACE, "ldap_result\n", 0, 0, 0 );
101 if( result == NULL ) {
102 ld->ld_errno = LDAP_PARAM_ERROR;
107 * First, look through the list of responses we have received on
108 * this association and see if the response we're interested in
109 * is there. If it is, return it. If not, call wait4msg() to
110 * wait until it arrives or timeout occurs.
115 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
116 nextlm = lm->lm_next;
118 if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
119 ldap_mark_abandoned( ld, lm->lm_msgid );
121 if ( lastlm == NULL ) {
122 ld->ld_responses = lm->lm_next;
124 lastlm->lm_next = nextlm;
132 if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
135 if ( all == LDAP_MSG_ONE
136 || (lm->lm_msgtype != LDAP_RES_SEARCH_RESULT
137 && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE /* LDAPv3 */
138 && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY) )
141 for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
142 if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT )
155 return( wait4msg( ld, msgid, all, timeout, result ) );
158 if ( lastlm == NULL ) {
159 ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
160 ? lm->lm_chain : lm->lm_next);
162 lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
163 ? lm->lm_chain : lm->lm_next);
165 if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL )
167 lm->lm_chain->lm_next = lm->lm_next;
173 ld->ld_errno = LDAP_SUCCESS;
174 return( lm->lm_msgtype );
182 struct timeval *timeout,
183 LDAPMessage **result )
186 struct timeval tv, *tvp;
187 time_t start_time = 0;
189 LDAPConn *lc, *nextlc;
191 assert( ld != NULL );
192 assert( result != NULL );
195 if ( timeout == NULL ) {
196 Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n",
199 Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
200 (long) timeout->tv_sec, (long) timeout->tv_usec, 0 );
202 #endif /* LDAP_DEBUG */
204 if ( timeout == NULL ) {
209 start_time = time( NULL );
215 if ( ldap_debug & LDAP_DEBUG_TRACE ) {
216 ldap_dump_connection( ld, ld->ld_conns, 1 );
217 ldap_dump_requests_and_responses( ld );
219 #endif /* LDAP_DEBUG */
220 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
221 if ( ber_sockbuf_ctrl( lc->lconn_sb,
222 LBER_SB_OPT_DATA_READY, NULL ) ) {
223 rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
230 rc = do_ldap_select( ld, tvp );
235 Debug( LDAP_DEBUG_TRACE,
236 "do_ldap_select returned -1: errno %d\n",
241 if ( rc == 0 || ( rc == -1 && (
242 !LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
243 || errno != EINTR )))
245 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
251 rc = -2; /* select interrupted: loop */
254 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
256 nextlc = lc->lconn_next;
257 if ( lc->lconn_status ==
258 LDAP_CONNST_CONNECTED &&
259 ldap_is_read_ready( ld,
261 rc = try_read1msg( ld, msgid, all,
262 lc->lconn_sb, lc, result );
268 if ( rc == -2 && tvp != NULL ) {
269 tmp_time = time( NULL );
270 if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
271 rc = 0; /* timed out */
272 ld->ld_errno = LDAP_TIMEOUT;
276 Debug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
277 (long) tv.tv_sec, 0, 0 );
278 start_time = tmp_time;
293 LDAPMessage **result )
296 LDAPMessage *new, *l, *prev, *tmp;
301 LDAPRequest *lr, *tmplr;
303 int rc, refer_cnt, hadref, simple_request;
306 * v3ref = flag for V3 referral / search reference
307 * 0 = not a ref, 1 = sucessfully chased ref, -1 = pass ref to application
311 assert( ld != NULL );
312 assert( lc != NULL );
314 Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 );
316 if ( lc->lconn_ber == NULL ) {
317 lc->lconn_ber = ldap_alloc_ber_with_options(ld);
319 if( lc->lconn_ber == NULL ) {
325 assert( BER_VALID (ber) );
327 /* get the next message */
329 if ( (tag = ber_get_next( sb, &len, ber ))
330 != LDAP_TAG_MESSAGE ) {
331 if ( tag == LBER_DEFAULT) {
333 Debug( LDAP_DEBUG_CONNS,
334 "ber_get_next failed.\n", 0, 0, 0 );
337 if (errno==EWOULDBLOCK) return -2;
340 if (errno == EAGAIN) return -2;
342 ld->ld_errno = LDAP_SERVER_DOWN;
345 ld->ld_errno = LDAP_LOCAL_ERROR;
350 * We read a complete message.
351 * The connection should no longer need this ber.
353 lc->lconn_ber = NULL;
356 if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
358 ld->ld_errno = LDAP_DECODING_ERROR;
362 /* if it's been abandoned, toss it */
363 if ( ldap_abandoned( ld, id ) ) {
365 Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0);
366 return( -2 ); /* continue looking */
369 if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
370 Debug( LDAP_DEBUG_ANY,
371 "no request for response with msgid %ld (tossing)\n",
374 return( -2 ); /* continue looking */
377 /* the message type */
378 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
379 ld->ld_errno = LDAP_DECODING_ERROR;
384 Debug( LDAP_DEBUG_TRACE, "ldap_read: message type %s msgid %ld, original id %ld\n",
385 ( tag == LDAP_RES_SEARCH_ENTRY ) ? "entry" :
386 ( tag == LDAP_RES_SEARCH_REFERENCE ) ? "reference" : "result",
387 (long) lr->lr_msgid, (long) lr->lr_origid );
391 hadref = simple_request = 0;
392 rc = -2; /* default is to keep looking (no response found) */
393 lr->lr_res_msgtype = tag;
396 * This code figures out if we are going to chase a
397 * referral / search reference, or pass it back to the application
399 v3ref = 0; /* Assume not a V3 search reference or referral */
400 if( (tag != LDAP_RES_SEARCH_ENTRY) && (ld->ld_version > LDAP_VERSION2) ) {
401 BerElement tmpber = *ber; /* struct copy */
404 if( tag == LDAP_RES_SEARCH_REFERENCE) {
405 /* This is a V3 search reference */
406 /* Assume we do not chase the reference, but pass it to application */
408 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
409 (lr->lr_parent != NULL) )
411 /* Get the referral list */
412 if ( ber_scanf( &tmpber, "{v}", &refs ) == LBER_ERROR ) {
413 rc = LDAP_DECODING_ERROR;
415 /* Note: refs arrary is freed by ldap_chase_v3referrals */
416 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
417 &lr->lr_res_error, &hadref );
418 if ( refer_cnt > 0 ) { /* sucessfully chased reference */
419 /* If haven't got end search, set chasing referrals */
420 if( lr->lr_status != LDAP_REQST_COMPLETED) {
421 lr->lr_status = LDAP_REQST_CHASINGREFS;
422 Debug( LDAP_DEBUG_TRACE,
423 "read1msg: search ref chased, mark request chasing refs, id = %d\n",
426 v3ref = 1; /* We sucessfully chased the reference */
431 /* Check for V3 referral */
433 if ( ber_scanf( &tmpber, "{iaa",/*}*/ &lderr,
434 &lr->lr_res_matched, &lr->lr_res_error )
436 /* Check if V3 referral */
437 if( ber_peek_tag( &tmpber, &len) == LDAP_TAG_REFERRAL ) {
438 /* We have a V3 referral, assume we cannot chase it */
440 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
441 || (lr->lr_parent != NULL) )
443 v3ref = -1; /* Assume referral not chased and return it to app */
444 /* Get the referral list */
445 if( ber_scanf( &tmpber, "{v}", &refs) == LBER_ERROR) {
446 rc = LDAP_DECODING_ERROR;
447 lr->lr_status = LDAP_REQST_COMPLETED;
448 Debug( LDAP_DEBUG_TRACE,
449 "read1msg: referral decode error, mark request completed, id = %d\n",
452 /* Chase the referral
453 * Note: refs arrary is freed by ldap_chase_v3referrals
455 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
456 &lr->lr_res_error, &hadref );
457 lr->lr_status = LDAP_REQST_COMPLETED;
458 Debug( LDAP_DEBUG_TRACE,
459 "read1msg: referral chased, mark request completed, id = %d\n",
462 v3ref = 1; /* Referral successfully chased */
471 /* All results that just return a status, i.e. don't return data
472 * go through the following code. This code also chases V2 referrals
473 * and checks if all referrals have been chased.
475 if ( (tag != LDAP_RES_SEARCH_ENTRY) && (v3ref > -1) ) {
476 /* For a v3 search referral/reference, only come here if already chased it */
477 if ( ld->ld_version >= LDAP_VERSION2 &&
478 ( lr->lr_parent != NULL ||
479 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
481 tmpber = *ber; /* struct copy */
483 ; /* V3 search reference or V3 referral sucessfully chased */
485 if ( ber_scanf( &tmpber, "{iaa}", &lderr,
486 &lr->lr_res_matched, &lr->lr_res_error )
488 if ( lderr != LDAP_SUCCESS ) {
489 /* referrals are in error string */
490 refer_cnt = ldap_chase_referrals( ld, lr,
491 &lr->lr_res_error, &hadref );
492 lr->lr_status = LDAP_REQST_COMPLETED;
493 Debug( LDAP_DEBUG_TRACE,
494 "read1msg: V2 referral chased, mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
497 /* save errno, message, and matched string */
498 if ( !hadref || lr->lr_res_error == NULL ) {
499 lr->lr_res_errno = ( lderr ==
500 LDAP_PARTIAL_RESULTS ) ? LDAP_SUCCESS
502 } else if ( ld->ld_errno != LDAP_SUCCESS ) {
503 lr->lr_res_errno = ld->ld_errno;
505 lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
507 Debug( LDAP_DEBUG_TRACE,
508 "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
509 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
510 lr->lr_res_matched ? lr->lr_res_matched : "" );
514 Debug( LDAP_DEBUG_TRACE,
515 "read1msg: %d new referrals\n", refer_cnt, 0, 0 );
517 if ( refer_cnt != 0 ) { /* chasing referrals */
520 if ( refer_cnt < 0 ) {
521 return( -1 ); /* fatal error */
523 lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
525 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
526 /* request without any referrals */
527 simple_request = ( hadref ? 0 : 1 );
529 /* request with referrals or child request */
534 lr->lr_status = LDAP_REQST_COMPLETED; /* declare this request done */
535 Debug( LDAP_DEBUG_TRACE,
536 "read1msg: mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
537 while ( lr->lr_parent != NULL ) {
538 merge_error_info( ld, lr->lr_parent, lr );
541 if ( --lr->lr_outrefcnt > 0 ) {
542 break; /* not completely done yet */
546 /* Check if all requests are finished, lr is now parent */
547 for(tmplr=lr ; tmplr != NULL; tmplr=tmplr->lr_refnext) {
548 if( tmplr->lr_status != LDAP_REQST_COMPLETED) {
553 /* This is the parent request if the request has referrals */
554 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL && tmplr == NULL ) {
556 tag = lr->lr_res_msgtype;
557 Debug( LDAP_DEBUG_ANY, "request %ld done\n",
559 Debug( LDAP_DEBUG_TRACE,
560 "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
561 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
562 lr->lr_res_matched ? lr->lr_res_matched : "" );
563 if ( !simple_request ) {
566 if ( build_result_ber( ld, &ber, lr )
568 rc = -1; /* fatal error */
572 ldap_free_request( ld, lr );
576 ldap_free_connection( ld, lc, 0, 1 );
585 /* make a new ldap message */
586 if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
588 ld->ld_errno = LDAP_NO_MEMORY;
591 new->lm_msgid = (int)id;
592 new->lm_msgtype = tag;
596 if ( ld->ld_cache != NULL ) {
597 ldap_add_result_to_cache( ld, new );
599 #endif /* LDAP_NOCACHE */
601 /* is this the one we're looking for? */
602 if ( msgid == LDAP_RES_ANY || id == msgid ) {
603 if ( all == LDAP_MSG_ONE
604 || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
605 && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
606 && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
608 ld->ld_errno = LDAP_SUCCESS;
610 } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
611 foundit = 1; /* return the chain later */
616 * if not, we must add it to the list of responses. if
617 * the msgid is already there, it must be part of an existing
622 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
623 if ( l->lm_msgid == new->lm_msgid )
628 /* not part of an existing search response */
632 ld->ld_errno = LDAP_SUCCESS;
636 new->lm_next = ld->ld_responses;
637 ld->ld_responses = new;
638 return( -2 ); /* continue looking */
641 Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n",
642 (long) new->lm_msgid, (long) new->lm_msgtype, 0 );
644 /* part of a search response - add to end of list of entries */
645 for ( tmp = l; (tmp->lm_chain != NULL) &&
646 ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
647 (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE));
648 tmp = tmp->lm_chain )
652 /* return the whole chain if that's what we were looking for */
655 ld->ld_responses = l->lm_next;
657 prev->lm_next = l->lm_next;
659 ld->ld_errno = LDAP_SUCCESS;
660 #ifdef LDAP_WORLD_P16
662 * XXX questionable fix; see text for [P16] on
663 * http://www.critical-angle.com/ldapworld/patch/
665 * inclusion of this patch causes searchs to hang on
668 return( l->lm_msgtype );
669 #else /* LDAP_WORLD_P16 */
671 #endif /* !LDAP_WORLD_P16 */
674 return( -2 ); /* continue looking */
679 build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr )
687 ber = ldap_alloc_ber_with_options( ld );
690 ld->ld_errno = LDAP_NO_MEMORY;
694 if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
695 lr->lr_res_msgtype, lr->lr_res_errno,
696 lr->lr_res_matched ? lr->lr_res_matched : "",
697 lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
699 ld->ld_errno = LDAP_ENCODING_ERROR;
701 return( LBER_ERROR );
706 if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
707 ld->ld_errno = LDAP_DECODING_ERROR;
709 return( LBER_ERROR );
712 if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
713 ld->ld_errno = LDAP_DECODING_ERROR;
715 return( LBER_ERROR );
718 tag = ber_peek_tag( ber, &len );
720 if ( tag == LBER_ERROR ) {
721 ld->ld_errno = LDAP_DECODING_ERROR;
723 return( LBER_ERROR );
732 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
735 * Merge error information in "lr" with "parentr" error code and string.
737 if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
738 parentr->lr_res_errno = lr->lr_res_errno;
739 if ( lr->lr_res_error != NULL ) {
740 (void)ldap_append_referral( ld, &parentr->lr_res_error,
743 } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
744 parentr->lr_res_errno == LDAP_SUCCESS ) {
745 parentr->lr_res_errno = lr->lr_res_errno;
746 if ( parentr->lr_res_error != NULL ) {
747 LDAP_FREE( parentr->lr_res_error );
749 parentr->lr_res_error = lr->lr_res_error;
750 lr->lr_res_error = NULL;
751 if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
752 if ( parentr->lr_res_matched != NULL ) {
753 LDAP_FREE( parentr->lr_res_matched );
755 parentr->lr_res_matched = lr->lr_res_matched;
756 lr->lr_res_matched = NULL;
760 Debug( LDAP_DEBUG_TRACE, "merged parent (id %d) error info: ",
761 parentr->lr_msgid, 0, 0 );
762 Debug( LDAP_DEBUG_TRACE, "result errno %d, error <%s>, matched <%s>\n",
763 parentr->lr_res_errno, parentr->lr_res_error ?
764 parentr->lr_res_error : "", parentr->lr_res_matched ?
765 parentr->lr_res_matched : "" );
771 ldap_msgtype( LDAPMessage *lm )
773 assert( lm != NULL );
774 return ( lm != NULL ) ? lm->lm_msgtype : -1;
779 ldap_msgid( LDAPMessage *lm )
781 assert( lm != NULL );
783 return ( lm != NULL ) ? lm->lm_msgid : -1;
788 ldap_msgfree( LDAPMessage *lm )
793 assert( lm != NULL );
795 Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 );
797 for ( ; lm != NULL; lm = next ) {
799 type = lm->lm_msgtype;
800 ber_free( lm->lm_ber, 1 );
801 LDAP_FREE( (char *) lm );
808 * ldap_msgdelete - delete a message. It returns:
809 * 0 if the entire message was deleted
810 * -1 if the message was not found, or only part of it was found
813 ldap_msgdelete( LDAP *ld, int msgid )
815 LDAPMessage *lm, *prev;
817 assert( ld != NULL );
819 Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 );
822 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
823 if ( lm->lm_msgid == msgid )
832 ld->ld_responses = lm->lm_next;
834 prev->lm_next = lm->lm_next;
836 if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY )
844 * return 1 if message msgid is waiting to be abandoned, 0 otherwise
847 ldap_abandoned( LDAP *ld, ber_int_t msgid )
851 if ( ld->ld_abandoned == NULL )
854 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
855 if ( ld->ld_abandoned[i] == msgid )
863 ldap_mark_abandoned( LDAP *ld, ber_int_t msgid )
867 if ( ld->ld_abandoned == NULL )
870 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
871 if ( ld->ld_abandoned[i] == msgid )
874 if ( ld->ld_abandoned[i] == -1 )
877 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
878 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];
885 #ifdef LDAP_CONNECTIONLESS
887 cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber )
894 ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
895 if ( sd != AC_SOCKET_INVALID ) {
896 /* restored from ldap_select1() in result.c version 1.24 */
898 if ( ldap_int_tblsize == 0 )
901 FD_SET( sd, &readfds );
902 rc = select( ldap_int_tblsize, &readfds, 0, 0, timeout );
904 if ( rc == -1 || rc == 0 ) {
905 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
911 /* get the next message */
912 if ( (tag = ber_get_next( ld->ld_sb, &len, ber ))
913 != LDAP_TAG_MESSAGE ) {
914 ld->ld_errno = (tag == LBER_DEFAULT ? LDAP_SERVER_DOWN :
921 #endif /* LDAP_CONNECTIONLESS */