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.
9 ******************************************************************************
10 * This notice applies to changes, created by or for Novell, Inc.,
11 * to preexisting works for which notices appear elsewhere in this file.
13 * Copyright (C) 1999, 2000 Novell, Inc. All Rights Reserved.
15 * THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
16 * USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
17 * 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
18 * HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
19 * TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS
20 * WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC
21 * LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE
22 * PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
23 ******************************************************************************
24 * Modification to OpenLDAP source by Novell, Inc.
25 * April 2000 sfs Add code to process V3 referrals and search results
27 * result.c - wait for an ldap result
32 * LDAPResult ::= SEQUENCE {
33 * resultCode ENUMERATED { ... },
35 * errorMessage LDAPString,
36 * referral Referral OPTIONAL
38 * Referral ::= SEQUENCE OF LDAPURL (one or more)
39 * LDAPURL ::= LDAPString (limited to URL chars)
46 #include <ac/stdlib.h>
49 #include <ac/socket.h>
50 #include <ac/string.h>
52 #include <ac/unistd.h>
57 static int ldap_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid ));
58 static int ldap_mark_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid ));
59 static int wait4msg LDAP_P(( LDAP *ld, ber_int_t msgid, int all, struct timeval *timeout,
60 LDAPMessage **result ));
61 static ber_tag_t try_read1msg LDAP_P(( LDAP *ld, ber_int_t msgid,
62 int all, Sockbuf *sb, LDAPConn *lc, LDAPMessage **result ));
63 static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr ));
64 static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ));
68 * ldap_result - wait for an ldap result response to a message from the
69 * ldap server. If msgid is -1, any message will be accepted, otherwise
70 * ldap_result will wait for a response with msgid. If all is 0 the
71 * first message with id msgid will be accepted, otherwise, ldap_result
72 * will wait for all responses with id msgid and then return a pointer to
73 * the entire list of messages. This is only useful for search responses,
74 * which can be of two message types (zero or more entries, followed by an
75 * ldap result). The type of the first message received is returned.
76 * When waiting, any messages that have been abandoned are discarded.
79 * ldap_result( s, msgid, all, timeout, result )
86 struct timeval *timeout,
87 LDAPMessage **result )
89 LDAPMessage *lm, *lastlm, *nextlm;
92 assert( result != NULL );
94 Debug( LDAP_DEBUG_TRACE, "ldap_result\n", 0, 0, 0 );
100 if( result == NULL ) {
101 ld->ld_errno = LDAP_PARAM_ERROR;
106 * First, look through the list of responses we have received on
107 * this association and see if the response we're interested in
108 * is there. If it is, return it. If not, call wait4msg() to
109 * wait until it arrives or timeout occurs.
114 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
115 nextlm = lm->lm_next;
117 if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
118 ldap_mark_abandoned( ld, lm->lm_msgid );
120 if ( lastlm == NULL ) {
121 ld->ld_responses = lm->lm_next;
123 lastlm->lm_next = nextlm;
131 if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
134 if ( all == LDAP_MSG_ONE
135 || (lm->lm_msgtype != LDAP_RES_SEARCH_RESULT
136 && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE /* LDAPv3 */
137 && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY) )
140 for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
141 if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT )
154 return( wait4msg( ld, msgid, all, timeout, result ) );
157 if ( lastlm == NULL ) {
158 ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
159 ? lm->lm_chain : lm->lm_next);
161 lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
162 ? lm->lm_chain : lm->lm_next);
164 if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL )
166 lm->lm_chain->lm_next = lm->lm_next;
172 ld->ld_errno = LDAP_SUCCESS;
173 return( lm->lm_msgtype );
181 struct timeval *timeout,
182 LDAPMessage **result )
185 struct timeval tv, *tvp;
186 time_t start_time = 0;
188 LDAPConn *lc, *nextlc;
190 assert( ld != NULL );
191 assert( result != NULL );
194 if ( timeout == NULL ) {
195 Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n",
198 Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
199 (long) timeout->tv_sec, (long) timeout->tv_usec, 0 );
201 #endif /* LDAP_DEBUG */
203 if ( timeout == NULL ) {
208 start_time = time( NULL );
214 if ( ldap_debug & LDAP_DEBUG_TRACE ) {
215 ldap_dump_connection( ld, ld->ld_conns, 1 );
216 ldap_dump_requests_and_responses( ld );
218 #endif /* LDAP_DEBUG */
219 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
220 if ( ber_pvt_sb_data_ready(lc->lconn_sb) ) {
221 rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
228 rc = do_ldap_select( ld, tvp );
233 Debug( LDAP_DEBUG_TRACE,
234 "do_ldap_select returned -1: errno %d\n",
239 if ( rc == 0 || ( rc == -1 && (
240 !LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
241 || errno != EINTR )))
243 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
249 rc = -2; /* select interrupted: loop */
252 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
254 nextlc = lc->lconn_next;
255 if ( lc->lconn_status ==
256 LDAP_CONNST_CONNECTED &&
257 ldap_is_read_ready( ld,
259 rc = try_read1msg( ld, msgid, all,
260 lc->lconn_sb, lc, result );
266 if ( rc == -2 && tvp != NULL ) {
267 tmp_time = time( NULL );
268 if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
269 rc = 0; /* timed out */
270 ld->ld_errno = LDAP_TIMEOUT;
274 Debug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
275 (long) tv.tv_sec, 0, 0 );
276 start_time = tmp_time;
291 LDAPMessage **result )
294 LDAPMessage *new, *l, *prev, *tmp;
299 LDAPRequest *lr, *tmplr;
301 int rc, refer_cnt, hadref, simple_request;
304 * v3ref = flag for V3 referral / search reference
305 * 0 = not a ref, 1 = sucessfully chased ref, -1 = pass ref to application
309 assert( ld != NULL );
310 assert( lc != NULL );
312 Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 );
314 if ( lc->lconn_ber == NULL ) {
315 lc->lconn_ber = ldap_alloc_ber_with_options(ld);
317 if( lc->lconn_ber == NULL ) {
323 assert( BER_VALID (ber) );
325 /* get the next message */
327 if ( (tag = ber_get_next( sb, &len, ber ))
328 != LDAP_TAG_MESSAGE ) {
329 if ( tag == LBER_DEFAULT) {
331 Debug( LDAP_DEBUG_CONNS,
332 "ber_get_next failed.\n", 0, 0, 0 );
335 if (errno==EWOULDBLOCK) return -2;
338 if (errno == EAGAIN) return -2;
340 ld->ld_errno = LDAP_SERVER_DOWN;
343 ld->ld_errno = LDAP_LOCAL_ERROR;
348 * We read a complete message.
349 * The connection should no longer need this ber.
351 lc->lconn_ber = NULL;
354 if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
356 ld->ld_errno = LDAP_DECODING_ERROR;
360 /* if it's been abandoned, toss it */
361 if ( ldap_abandoned( ld, id ) ) {
363 Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0);
364 return( -2 ); /* continue looking */
367 if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
368 Debug( LDAP_DEBUG_ANY,
369 "no request for response with msgid %ld (tossing)\n",
372 return( -2 ); /* continue looking */
375 /* the message type */
376 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
377 ld->ld_errno = LDAP_DECODING_ERROR;
382 Debug( LDAP_DEBUG_TRACE, "ldap_read: message type %s msgid %ld, original id %ld\n",
383 ( tag == LDAP_RES_SEARCH_ENTRY ) ? "entry" :
384 ( tag == LDAP_RES_SEARCH_REFERENCE ) ? "reference" : "result",
385 (long) lr->lr_msgid, (long) lr->lr_origid );
389 hadref = simple_request = 0;
390 rc = -2; /* default is to keep looking (no response found) */
391 lr->lr_res_msgtype = tag;
394 * This code figures out if we are going to chase a
395 * referral / search reference, or pass it back to the application
397 v3ref = 0; /* Assume not a V3 search reference or referral */
398 if( (tag != LDAP_RES_SEARCH_ENTRY) && (ld->ld_version > LDAP_VERSION2) ) {
399 BerElement tmpber = *ber; /* struct copy */
402 if( tag == LDAP_RES_SEARCH_REFERENCE) {
403 /* This is a V3 search reference */
404 /* Assume we do not chase the reference, but pass it to application */
406 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
407 (lr->lr_parent != NULL) )
409 /* Get the referral list */
410 if ( ber_scanf( &tmpber, "{v}", &refs ) == LBER_ERROR ) {
411 rc = LDAP_DECODING_ERROR;
413 /* Note: refs arrary is freed by ldap_chase_v3referrals */
414 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
415 &lr->lr_res_error, &hadref );
416 if ( refer_cnt > 0 ) { /* sucessfully chased reference */
417 /* If haven't got end search, set chasing referrals */
418 if( lr->lr_status != LDAP_REQST_COMPLETED) {
419 lr->lr_status = LDAP_REQST_CHASINGREFS;
420 Debug( LDAP_DEBUG_TRACE,
421 "read1msg: search ref chased, mark request chasing refs, id = %d\n",
424 v3ref = 1; /* We sucessfully chased the reference */
429 /* Check for V3 referral */
431 if ( ber_scanf( &tmpber, "{iaa",/*}*/ &lderr,
432 &lr->lr_res_matched, &lr->lr_res_error )
434 /* Check if V3 referral */
435 if( ber_peek_tag( &tmpber, &len) == LDAP_TAG_REFERRAL ) {
436 /* We have a V3 referral, assume we cannot chase it */
438 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
439 || (lr->lr_parent != NULL) )
441 v3ref = -1; /* Assume referral not chased and return it to app */
442 /* Get the referral list */
443 if( ber_scanf( &tmpber, "v", &refs) == LBER_ERROR) {
444 rc = LDAP_DECODING_ERROR;
445 lr->lr_status = LDAP_REQST_COMPLETED;
446 Debug( LDAP_DEBUG_TRACE,
447 "read1msg: referral decode error, mark request completed, id = %d\n",
450 /* Chase the referral
451 * Note: refs arrary is freed by ldap_chase_v3referrals
453 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
454 &lr->lr_res_error, &hadref );
455 lr->lr_status = LDAP_REQST_COMPLETED;
456 Debug( LDAP_DEBUG_TRACE,
457 "read1msg: referral chased, mark request completed, id = %d\n",
460 v3ref = 1; /* Referral successfully chased */
469 /* All results that just return a status, i.e. don't return data
470 * go through the following code. This code also chases V2 referrals
471 * and checks if all referrals have been chased.
473 if ( (tag != LDAP_RES_SEARCH_ENTRY) && (v3ref > -1) ) {
474 /* For a v3 search referral/reference, only come here if already chased it */
475 if ( ld->ld_version >= LDAP_VERSION2 &&
476 ( lr->lr_parent != NULL ||
477 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
479 tmpber = *ber; /* struct copy */
481 ; /* V3 search reference or V3 referral sucessfully chased */
483 if ( ber_scanf( &tmpber, "{iaa}", &lderr,
484 &lr->lr_res_matched, &lr->lr_res_error )
486 if ( lderr != LDAP_SUCCESS ) {
487 /* referrals are in error string */
488 refer_cnt = ldap_chase_referrals( ld, lr,
489 &lr->lr_res_error, &hadref );
490 lr->lr_status = LDAP_REQST_COMPLETED;
491 Debug( LDAP_DEBUG_TRACE,
492 "read1msg: V2 referral chased, mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
495 /* save errno, message, and matched string */
496 if ( !hadref || lr->lr_res_error == NULL ) {
497 lr->lr_res_errno = ( lderr ==
498 LDAP_PARTIAL_RESULTS ) ? LDAP_SUCCESS
500 } else if ( ld->ld_errno != LDAP_SUCCESS ) {
501 lr->lr_res_errno = ld->ld_errno;
503 lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
505 Debug( LDAP_DEBUG_TRACE,
506 "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
507 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
508 lr->lr_res_matched ? lr->lr_res_matched : "" );
512 Debug( LDAP_DEBUG_TRACE,
513 "read1msg: %d new referrals\n", refer_cnt, 0, 0 );
515 if ( refer_cnt != 0 ) { /* chasing referrals */
518 if ( refer_cnt < 0 ) {
519 return( -1 ); /* fatal error */
521 lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
523 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
524 /* request without any referrals */
525 simple_request = ( hadref ? 0 : 1 );
527 /* request with referrals or child request */
532 lr->lr_status = LDAP_REQST_COMPLETED; /* declare this request done */
533 Debug( LDAP_DEBUG_TRACE,
534 "read1msg: mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
535 while ( lr->lr_parent != NULL ) {
536 merge_error_info( ld, lr->lr_parent, lr );
539 if ( --lr->lr_outrefcnt > 0 ) {
540 break; /* not completely done yet */
544 /* Check if all requests are finished, lr is now parent */
545 for(tmplr=lr ; tmplr != NULL; tmplr=tmplr->lr_refnext) {
546 if( tmplr->lr_status != LDAP_REQST_COMPLETED) {
551 /* This is the parent request if the request has referrals */
552 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL && tmplr == NULL ) {
554 tag = lr->lr_res_msgtype;
555 Debug( LDAP_DEBUG_ANY, "request %ld done\n",
557 Debug( LDAP_DEBUG_TRACE,
558 "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
559 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
560 lr->lr_res_matched ? lr->lr_res_matched : "" );
561 if ( !simple_request ) {
564 if ( build_result_ber( ld, &ber, lr )
566 rc = -1; /* fatal error */
570 ldap_free_request( ld, lr );
574 ldap_free_connection( ld, lc, 0, 1 );
583 /* make a new ldap message */
584 if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
586 ld->ld_errno = LDAP_NO_MEMORY;
589 new->lm_msgid = (int)id;
590 new->lm_msgtype = tag;
594 if ( ld->ld_cache != NULL ) {
595 ldap_add_result_to_cache( ld, new );
597 #endif /* LDAP_NOCACHE */
599 /* is this the one we're looking for? */
600 if ( msgid == LDAP_RES_ANY || id == msgid ) {
601 if ( all == LDAP_MSG_ONE
602 || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
603 && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
604 && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
606 ld->ld_errno = LDAP_SUCCESS;
608 } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
609 foundit = 1; /* return the chain later */
614 * if not, we must add it to the list of responses. if
615 * the msgid is already there, it must be part of an existing
620 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
621 if ( l->lm_msgid == new->lm_msgid )
626 /* not part of an existing search response */
630 ld->ld_errno = LDAP_SUCCESS;
634 new->lm_next = ld->ld_responses;
635 ld->ld_responses = new;
636 return( -2 ); /* continue looking */
639 Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n",
640 (long) new->lm_msgid, (long) new->lm_msgtype, 0 );
642 /* part of a search response - add to end of list of entries */
643 for ( tmp = l; (tmp->lm_chain != NULL) &&
644 ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
645 (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE));
646 tmp = tmp->lm_chain )
650 /* return the whole chain if that's what we were looking for */
653 ld->ld_responses = l->lm_next;
655 prev->lm_next = l->lm_next;
657 ld->ld_errno = LDAP_SUCCESS;
658 #ifdef LDAP_WORLD_P16
660 * XXX questionable fix; see text for [P16] on
661 * http://www.critical-angle.com/ldapworld/patch/
663 * inclusion of this patch causes searchs to hang on
666 return( l->lm_msgtype );
667 #else /* LDAP_WORLD_P16 */
669 #endif /* !LDAP_WORLD_P16 */
672 return( -2 ); /* continue looking */
677 build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr )
685 ber = ldap_alloc_ber_with_options( ld );
688 ld->ld_errno = LDAP_NO_MEMORY;
692 if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
693 lr->lr_res_msgtype, lr->lr_res_errno,
694 lr->lr_res_matched ? lr->lr_res_matched : "",
695 lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
697 ld->ld_errno = LDAP_ENCODING_ERROR;
699 return( LBER_ERROR );
704 if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
705 ld->ld_errno = LDAP_DECODING_ERROR;
707 return( LBER_ERROR );
710 if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
711 ld->ld_errno = LDAP_DECODING_ERROR;
713 return( LBER_ERROR );
716 tag = ber_peek_tag( ber, &len );
718 if ( tag == LBER_ERROR ) {
719 ld->ld_errno = LDAP_DECODING_ERROR;
721 return( LBER_ERROR );
730 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
733 * Merge error information in "lr" with "parentr" error code and string.
735 if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
736 parentr->lr_res_errno = lr->lr_res_errno;
737 if ( lr->lr_res_error != NULL ) {
738 (void)ldap_append_referral( ld, &parentr->lr_res_error,
741 } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
742 parentr->lr_res_errno == LDAP_SUCCESS ) {
743 parentr->lr_res_errno = lr->lr_res_errno;
744 if ( parentr->lr_res_error != NULL ) {
745 LDAP_FREE( parentr->lr_res_error );
747 parentr->lr_res_error = lr->lr_res_error;
748 lr->lr_res_error = NULL;
749 if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
750 if ( parentr->lr_res_matched != NULL ) {
751 LDAP_FREE( parentr->lr_res_matched );
753 parentr->lr_res_matched = lr->lr_res_matched;
754 lr->lr_res_matched = NULL;
758 Debug( LDAP_DEBUG_TRACE, "merged parent (id %d) error info: ",
759 parentr->lr_msgid, 0, 0 );
760 Debug( LDAP_DEBUG_TRACE, "result errno %d, error <%s>, matched <%s>\n",
761 parentr->lr_res_errno, parentr->lr_res_error ?
762 parentr->lr_res_error : "", parentr->lr_res_matched ?
763 parentr->lr_res_matched : "" );
769 ldap_msgtype( LDAPMessage *lm )
771 assert( lm != NULL );
772 return ( lm != NULL ) ? lm->lm_msgtype : -1;
777 ldap_msgid( LDAPMessage *lm )
779 assert( lm != NULL );
781 return ( lm != NULL ) ? lm->lm_msgid : -1;
786 ldap_msgfree( LDAPMessage *lm )
791 assert( lm != NULL );
793 Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 );
795 for ( ; lm != NULL; lm = next ) {
797 type = lm->lm_msgtype;
798 ber_free( lm->lm_ber, 1 );
799 LDAP_FREE( (char *) lm );
806 * ldap_msgdelete - delete a message. It returns:
807 * 0 if the entire message was deleted
808 * -1 if the message was not found, or only part of it was found
811 ldap_msgdelete( LDAP *ld, int msgid )
813 LDAPMessage *lm, *prev;
815 assert( ld != NULL );
817 Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 );
820 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
821 if ( lm->lm_msgid == msgid )
830 ld->ld_responses = lm->lm_next;
832 prev->lm_next = lm->lm_next;
834 if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY )
842 * return 1 if message msgid is waiting to be abandoned, 0 otherwise
845 ldap_abandoned( LDAP *ld, ber_int_t msgid )
849 if ( ld->ld_abandoned == NULL )
852 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
853 if ( ld->ld_abandoned[i] == msgid )
861 ldap_mark_abandoned( LDAP *ld, ber_int_t msgid )
865 if ( ld->ld_abandoned == NULL )
868 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
869 if ( ld->ld_abandoned[i] == msgid )
872 if ( ld->ld_abandoned[i] == -1 )
875 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
876 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];
883 #ifdef LDAP_CONNECTIONLESS
885 cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber )
891 if ( ! ber_pvt_sb_data_ready(&ld->ld_sb) ) {
892 /* restored from ldap_select1() in result.c version 1.24 */
894 if ( ldap_int_tblsize == 0 )
897 FD_SET( ber_pvt_sb_get_desc(&ld->ld_sb), &readfds );
898 rc = select( ldap_int_tblsize, &readfds, 0, 0, timeout );
900 if ( rc == -1 || rc == 0 ) {
901 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
907 /* get the next message */
908 if ( (tag = ber_get_next( &ld->ld_sb, &len, ber ))
909 != LDAP_TAG_MESSAGE ) {
910 ld->ld_errno = (tag == LBER_DEFAULT ? LDAP_SERVER_DOWN :
917 #endif /* LDAP_CONNECTIONLESS */