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 LDAP_RES_ANY (-1), any message will be
71 * accepted. If msgid is LDAP_RES_UNSOLICITED (0), any unsolicited
72 * message is accepted. Otherwise ldap_result will wait for a response
73 * with msgid. If all is LDAP_MSG_ONE (0) the first message with id
74 * msgid will be accepted, otherwise, ldap_result will wait for all
75 * responses with id msgid and then return a pointer to the entire list
76 * of messages. This is only useful for search responses, which can be
77 * of two message types (zero or more entries, followed by an
78 * ldap result). The type of the first message received is returned.
79 * When waiting, any messages that have been abandoned are discarded.
82 * ldap_result( s, msgid, all, timeout, result )
89 struct timeval *timeout,
90 LDAPMessage **result )
92 LDAPMessage *lm, *lastlm, *nextlm;
95 assert( result != NULL );
97 Debug( LDAP_DEBUG_TRACE, "ldap_result\n", 0, 0, 0 );
103 if( result == NULL ) {
104 ld->ld_errno = LDAP_PARAM_ERROR;
109 * First, look through the list of responses we have received on
110 * this association and see if the response we're interested in
111 * is there. If it is, return it. If not, call wait4msg() to
112 * wait until it arrives or timeout occurs.
117 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
118 nextlm = lm->lm_next;
120 if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
121 ldap_mark_abandoned( ld, lm->lm_msgid );
123 if ( lastlm == NULL ) {
124 ld->ld_responses = lm->lm_next;
126 lastlm->lm_next = nextlm;
134 if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
137 if ( all == LDAP_MSG_ONE
138 || (lm->lm_msgtype != LDAP_RES_SEARCH_RESULT
139 && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE /* LDAPv3 */
140 && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY
141 && lm->lm_msgtype != LDAP_RES_EXTENDED_PARTIAL) )
144 for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
145 if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT )
158 return( wait4msg( ld, msgid, all, timeout, result ) );
161 if ( lastlm == NULL ) {
162 ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
163 ? lm->lm_chain : lm->lm_next);
165 lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
166 ? lm->lm_chain : lm->lm_next);
168 if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL )
170 lm->lm_chain->lm_next = lm->lm_next;
176 ld->ld_errno = LDAP_SUCCESS;
177 return( lm->lm_msgtype );
185 struct timeval *timeout,
186 LDAPMessage **result )
189 struct timeval tv, *tvp;
190 time_t start_time = 0;
192 LDAPConn *lc, *nextlc;
194 assert( ld != NULL );
195 assert( result != NULL );
198 if ( timeout == NULL ) {
199 Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout)\n",
202 Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
203 (long) timeout->tv_sec, (long) timeout->tv_usec, 0 );
205 #endif /* LDAP_DEBUG */
207 if ( timeout == NULL ) {
212 start_time = time( NULL );
218 if ( ldap_debug & LDAP_DEBUG_TRACE ) {
219 ldap_dump_connection( ld, ld->ld_conns, 1 );
220 ldap_dump_requests_and_responses( ld );
222 #endif /* LDAP_DEBUG */
223 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
224 if ( ber_sockbuf_ctrl( lc->lconn_sb,
225 LBER_SB_OPT_DATA_READY, NULL ) ) {
226 rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
233 rc = do_ldap_select( ld, tvp );
238 Debug( LDAP_DEBUG_TRACE,
239 "do_ldap_select returned -1: errno %d\n",
244 if ( rc == 0 || ( rc == -1 && (
245 !LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
246 || errno != EINTR )))
248 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
254 rc = -2; /* select interrupted: loop */
257 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
259 nextlc = lc->lconn_next;
260 if ( lc->lconn_status ==
261 LDAP_CONNST_CONNECTED &&
262 ldap_is_read_ready( ld,
264 rc = try_read1msg( ld, msgid, all,
265 lc->lconn_sb, lc, result );
271 if ( rc == -2 && tvp != NULL ) {
272 tmp_time = time( NULL );
273 if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
274 rc = 0; /* timed out */
275 ld->ld_errno = LDAP_TIMEOUT;
279 Debug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
280 (long) tv.tv_sec, 0, 0 );
281 start_time = tmp_time;
296 LDAPMessage **result )
299 LDAPMessage *new, *l, *prev, *tmp;
304 LDAPRequest *lr, *tmplr;
306 int rc, refer_cnt, hadref, simple_request;
309 * v3ref = flag for V3 referral / search reference
310 * 0 = not a ref, 1 = sucessfully chased ref, -1 = pass ref to application
314 assert( ld != NULL );
315 assert( lc != NULL );
317 Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 );
319 if ( lc->lconn_ber == NULL ) {
320 lc->lconn_ber = ldap_alloc_ber_with_options(ld);
322 if( lc->lconn_ber == NULL ) {
328 assert( BER_VALID (ber) );
330 /* get the next message */
332 if ( (tag = ber_get_next( sb, &len, ber ))
333 != LDAP_TAG_MESSAGE ) {
334 if ( tag == LBER_DEFAULT) {
336 Debug( LDAP_DEBUG_CONNS,
337 "ber_get_next failed.\n", 0, 0, 0 );
340 if (errno==EWOULDBLOCK) return -2;
343 if (errno == EAGAIN) return -2;
345 ld->ld_errno = LDAP_SERVER_DOWN;
348 ld->ld_errno = LDAP_LOCAL_ERROR;
353 * We read a complete message.
354 * The connection should no longer need this ber.
356 lc->lconn_ber = NULL;
359 if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
361 ld->ld_errno = LDAP_DECODING_ERROR;
365 /* if it's been abandoned, toss it */
366 if ( ldap_abandoned( ld, id ) ) {
368 Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0);
369 return( -2 ); /* continue looking */
372 if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
373 Debug( LDAP_DEBUG_ANY,
374 "no request for response with msgid %ld (tossing)\n",
377 return( -2 ); /* continue looking */
380 /* the message type */
381 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
382 ld->ld_errno = LDAP_DECODING_ERROR;
387 Debug( LDAP_DEBUG_TRACE, "ldap_read: message type %s msgid %ld, original id %ld\n",
388 ldap_int_msgtype2str( tag ),
389 (long) lr->lr_msgid, (long) lr->lr_origid );
393 hadref = simple_request = 0;
394 rc = -2; /* default is to keep looking (no response found) */
395 lr->lr_res_msgtype = tag;
398 * This code figures out if we are going to chase a
399 * referral / search reference, or pass it back to the application
401 v3ref = 0; /* Assume not a V3 search reference or referral */
402 if( (tag != LDAP_RES_SEARCH_ENTRY) && (ld->ld_version > LDAP_VERSION2) ) {
403 BerElement tmpber = *ber; /* struct copy */
406 if( tag == LDAP_RES_SEARCH_REFERENCE) {
407 /* This is a V3 search reference */
408 /* Assume we do not chase the reference, but pass it to application */
410 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
411 (lr->lr_parent != NULL) )
413 /* Get the referral list */
414 if ( ber_scanf( &tmpber, "{v}", &refs ) == LBER_ERROR ) {
415 rc = LDAP_DECODING_ERROR;
417 /* Note: refs arrary is freed by ldap_chase_v3referrals */
418 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
419 &lr->lr_res_error, &hadref );
420 if ( refer_cnt > 0 ) { /* sucessfully chased reference */
421 /* If haven't got end search, set chasing referrals */
422 if( lr->lr_status != LDAP_REQST_COMPLETED) {
423 lr->lr_status = LDAP_REQST_CHASINGREFS;
424 Debug( LDAP_DEBUG_TRACE,
425 "read1msg: search ref chased, mark request chasing refs, id = %d\n",
428 v3ref = 1; /* We sucessfully chased the reference */
433 /* Check for V3 referral */
435 if ( ber_scanf( &tmpber, "{iaa",/*}*/ &lderr,
436 &lr->lr_res_matched, &lr->lr_res_error )
438 /* Check if V3 referral */
439 if( ber_peek_tag( &tmpber, &len) == LDAP_TAG_REFERRAL ) {
440 /* We have a V3 referral, assume we cannot chase it */
442 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
443 || (lr->lr_parent != NULL) )
445 v3ref = -1; /* Assume referral not chased and return it to app */
446 /* Get the referral list */
447 if( ber_scanf( &tmpber, "{v}", &refs) == LBER_ERROR) {
448 rc = LDAP_DECODING_ERROR;
449 lr->lr_status = LDAP_REQST_COMPLETED;
450 Debug( LDAP_DEBUG_TRACE,
451 "read1msg: referral decode error, mark request completed, id = %d\n",
454 /* Chase the referral
455 * Note: refs arrary is freed by ldap_chase_v3referrals
457 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
458 &lr->lr_res_error, &hadref );
459 lr->lr_status = LDAP_REQST_COMPLETED;
460 Debug( LDAP_DEBUG_TRACE,
461 "read1msg: referral chased, mark request completed, id = %d\n",
464 v3ref = 1; /* Referral successfully chased */
470 if( lr->lr_res_matched != NULL ) {
471 LDAP_FREE( lr->lr_res_matched );
472 lr->lr_res_matched = NULL;
474 if( lr->lr_res_error != NULL ) {
475 LDAP_FREE( lr->lr_res_error );
476 lr->lr_res_error = NULL;
482 /* All results that just return a status, i.e. don't return data
483 * go through the following code. This code also chases V2 referrals
484 * and checks if all referrals have been chased.
486 if ( (tag != LDAP_RES_SEARCH_ENTRY) && (v3ref > -1) ) {
487 /* For a v3 search referral/reference, only come here if already chased it */
488 if ( ld->ld_version >= LDAP_VERSION2 &&
489 ( lr->lr_parent != NULL ||
490 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
492 tmpber = *ber; /* struct copy */
494 ; /* V3 search reference or V3 referral sucessfully chased */
496 if ( ber_scanf( &tmpber, "{iaa}", &lderr,
497 &lr->lr_res_matched, &lr->lr_res_error )
499 if ( lderr != LDAP_SUCCESS ) {
500 /* referrals are in error string */
501 refer_cnt = ldap_chase_referrals( ld, lr,
502 &lr->lr_res_error, &hadref );
503 lr->lr_status = LDAP_REQST_COMPLETED;
504 Debug( LDAP_DEBUG_TRACE,
505 "read1msg: V2 referral chased, mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
508 /* save errno, message, and matched string */
509 if ( !hadref || lr->lr_res_error == NULL ) {
510 lr->lr_res_errno = ( lderr ==
511 LDAP_PARTIAL_RESULTS ) ? LDAP_SUCCESS
513 } else if ( ld->ld_errno != LDAP_SUCCESS ) {
514 lr->lr_res_errno = ld->ld_errno;
516 lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
518 Debug( LDAP_DEBUG_TRACE,
519 "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
520 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
521 lr->lr_res_matched ? lr->lr_res_matched : "" );
525 Debug( LDAP_DEBUG_TRACE,
526 "read1msg: %d new referrals\n", refer_cnt, 0, 0 );
528 if ( refer_cnt != 0 ) { /* chasing referrals */
531 if ( refer_cnt < 0 ) {
532 return( -1 ); /* fatal error */
534 lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
536 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
537 /* request without any referrals */
538 simple_request = ( hadref ? 0 : 1 );
540 /* request with referrals or child request */
545 lr->lr_status = LDAP_REQST_COMPLETED; /* declare this request done */
546 Debug( LDAP_DEBUG_TRACE,
547 "read1msg: mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
548 while ( lr->lr_parent != NULL ) {
549 merge_error_info( ld, lr->lr_parent, lr );
552 if ( --lr->lr_outrefcnt > 0 ) {
553 break; /* not completely done yet */
557 /* Check if all requests are finished, lr is now parent */
558 for(tmplr=lr ; tmplr != NULL; tmplr=tmplr->lr_refnext) {
559 if( tmplr->lr_status != LDAP_REQST_COMPLETED) {
564 /* This is the parent request if the request has referrals */
565 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL && tmplr == NULL ) {
567 tag = lr->lr_res_msgtype;
568 Debug( LDAP_DEBUG_ANY, "request %ld done\n",
570 Debug( LDAP_DEBUG_TRACE,
571 "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
572 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
573 lr->lr_res_matched ? lr->lr_res_matched : "" );
574 if ( !simple_request ) {
577 if ( build_result_ber( ld, &ber, lr )
579 rc = -1; /* fatal error */
583 ldap_free_request( ld, lr );
587 ldap_free_connection( ld, lc, 0, 1 );
596 /* make a new ldap message */
597 if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
599 ld->ld_errno = LDAP_NO_MEMORY;
602 new->lm_msgid = (int)id;
603 new->lm_msgtype = tag;
607 if ( ld->ld_cache != NULL ) {
608 ldap_add_result_to_cache( ld, new );
610 #endif /* LDAP_NOCACHE */
612 /* is this the one we're looking for? */
613 if ( msgid == LDAP_RES_ANY || id == msgid ) {
614 if ( all == LDAP_MSG_ONE
615 || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
616 && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
617 && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
619 ld->ld_errno = LDAP_SUCCESS;
621 } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
622 foundit = 1; /* return the chain later */
627 * if not, we must add it to the list of responses. if
628 * the msgid is already there, it must be part of an existing
633 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
634 if ( l->lm_msgid == new->lm_msgid )
639 /* not part of an existing search response */
643 ld->ld_errno = LDAP_SUCCESS;
647 new->lm_next = ld->ld_responses;
648 ld->ld_responses = new;
649 return( -2 ); /* continue looking */
652 Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n",
653 (long) new->lm_msgid, (long) new->lm_msgtype, 0 );
655 /* part of a search response - add to end of list of entries */
656 for ( tmp = l; (tmp->lm_chain != NULL) &&
657 ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
658 (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
659 (tmp->lm_chain->lm_msgtype == LDAP_RES_EXTENDED_PARTIAL ));
660 tmp = tmp->lm_chain )
664 /* return the whole chain if that's what we were looking for */
667 ld->ld_responses = l->lm_next;
669 prev->lm_next = l->lm_next;
671 ld->ld_errno = LDAP_SUCCESS;
672 #ifdef LDAP_WORLD_P16
674 * XXX questionable fix; see text for [P16] on
675 * http://www.critical-angle.com/ldapworld/patch/
677 * inclusion of this patch causes searchs to hang on
680 return( l->lm_msgtype );
681 #else /* LDAP_WORLD_P16 */
683 #endif /* !LDAP_WORLD_P16 */
686 return( -2 ); /* continue looking */
691 build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr )
699 ber = ldap_alloc_ber_with_options( ld );
702 ld->ld_errno = LDAP_NO_MEMORY;
706 if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
707 lr->lr_res_msgtype, lr->lr_res_errno,
708 lr->lr_res_matched ? lr->lr_res_matched : "",
709 lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
711 ld->ld_errno = LDAP_ENCODING_ERROR;
713 return( LBER_ERROR );
718 if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
719 ld->ld_errno = LDAP_DECODING_ERROR;
721 return( LBER_ERROR );
724 if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
725 ld->ld_errno = LDAP_DECODING_ERROR;
727 return( LBER_ERROR );
730 tag = ber_peek_tag( ber, &len );
732 if ( tag == LBER_ERROR ) {
733 ld->ld_errno = LDAP_DECODING_ERROR;
735 return( LBER_ERROR );
744 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
747 * Merge error information in "lr" with "parentr" error code and string.
749 if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
750 parentr->lr_res_errno = lr->lr_res_errno;
751 if ( lr->lr_res_error != NULL ) {
752 (void)ldap_append_referral( ld, &parentr->lr_res_error,
755 } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
756 parentr->lr_res_errno == LDAP_SUCCESS ) {
757 parentr->lr_res_errno = lr->lr_res_errno;
758 if ( parentr->lr_res_error != NULL ) {
759 LDAP_FREE( parentr->lr_res_error );
761 parentr->lr_res_error = lr->lr_res_error;
762 lr->lr_res_error = NULL;
763 if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
764 if ( parentr->lr_res_matched != NULL ) {
765 LDAP_FREE( parentr->lr_res_matched );
767 parentr->lr_res_matched = lr->lr_res_matched;
768 lr->lr_res_matched = NULL;
772 Debug( LDAP_DEBUG_TRACE, "merged parent (id %d) error info: ",
773 parentr->lr_msgid, 0, 0 );
774 Debug( LDAP_DEBUG_TRACE, "result errno %d, error <%s>, matched <%s>\n",
775 parentr->lr_res_errno, parentr->lr_res_error ?
776 parentr->lr_res_error : "", parentr->lr_res_matched ?
777 parentr->lr_res_matched : "" );
783 ldap_msgtype( LDAPMessage *lm )
785 assert( lm != NULL );
786 return ( lm != NULL ) ? lm->lm_msgtype : -1;
791 ldap_msgid( LDAPMessage *lm )
793 assert( lm != NULL );
795 return ( lm != NULL ) ? lm->lm_msgid : -1;
799 char * ldap_int_msgtype2str( ber_tag_t tag )
802 case LDAP_RES_ADD: return "add";
803 case LDAP_RES_BIND: return "bind";
804 case LDAP_RES_COMPARE: return "compare";
805 case LDAP_RES_DELETE: return "delete";
806 case LDAP_RES_EXTENDED: return "extended-result";
807 case LDAP_RES_EXTENDED_PARTIAL: return "extended-partial";
808 case LDAP_RES_MODIFY: return "modify";
809 case LDAP_RES_RENAME: return "rename";
810 case LDAP_RES_SEARCH_ENTRY: return "search-entry";
811 case LDAP_RES_SEARCH_REFERENCE: return "search-reference";
812 case LDAP_RES_SEARCH_RESULT: return "search-result";
818 ldap_msgfree( LDAPMessage *lm )
823 Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 );
825 for ( ; lm != NULL; lm = next ) {
827 type = lm->lm_msgtype;
828 ber_free( lm->lm_ber, 1 );
829 LDAP_FREE( (char *) lm );
836 * ldap_msgdelete - delete a message. It returns:
837 * 0 if the entire message was deleted
838 * -1 if the message was not found, or only part of it was found
841 ldap_msgdelete( LDAP *ld, int msgid )
843 LDAPMessage *lm, *prev;
845 assert( ld != NULL );
847 Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 );
850 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
851 if ( lm->lm_msgid == msgid )
860 ld->ld_responses = lm->lm_next;
862 prev->lm_next = lm->lm_next;
864 if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY )
872 * return 1 if message msgid is waiting to be abandoned, 0 otherwise
875 ldap_abandoned( LDAP *ld, ber_int_t msgid )
879 if ( ld->ld_abandoned == NULL )
882 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
883 if ( ld->ld_abandoned[i] == msgid )
891 ldap_mark_abandoned( LDAP *ld, ber_int_t msgid )
895 if ( ld->ld_abandoned == NULL )
898 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
899 if ( ld->ld_abandoned[i] == msgid )
902 if ( ld->ld_abandoned[i] == -1 )
905 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
906 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];