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 ));
66 static LDAPMessage * chkResponseList LDAP_P(( LDAP *ld, int msgid, int all));
70 * ldap_result - wait for an ldap result response to a message from the
71 * ldap server. If msgid is LDAP_RES_ANY (-1), any message will be
72 * accepted. If msgid is LDAP_RES_UNSOLICITED (0), any unsolicited
73 * message is accepted. Otherwise ldap_result will wait for a response
74 * with msgid. If all is LDAP_MSG_ONE (0) the first message with id
75 * msgid will be accepted, otherwise, ldap_result will wait for all
76 * responses with id msgid and then return a pointer to the entire list
77 * of messages. In general, this is only useful for search responses,
78 * which can be of three message types (zero or more entries, zero or
79 * search references, followed by an ldap result). An extension to
80 * LDAPv3 allows partial extended responses to be returned in response
81 * to any request. The type of the first message received is returned.
82 * When waiting, any messages that have been abandoned are discarded.
85 * ldap_result( s, msgid, all, timeout, result )
92 struct timeval *timeout,
93 LDAPMessage **result )
98 assert( result != NULL );
100 Debug( LDAP_DEBUG_TRACE, "ldap_result msgid %d\n", msgid, 0, 0 );
106 if( result == NULL ) {
107 ld->ld_errno = LDAP_PARAM_ERROR;
111 lm = chkResponseList(ld, msgid, all);
114 return( wait4msg( ld, msgid, all, timeout, result ) );
118 ld->ld_errno = LDAP_SUCCESS;
119 return( lm->lm_msgtype );
128 LDAPMessage *lm, *lastlm, *nextlm;
130 * Look through the list of responses we have received on
131 * this association and see if the response we're interested in
132 * is there. If it is, return it. If not, call wait4msg() to
133 * wait until it arrives or timeout occurs.
136 Debug( LDAP_DEBUG_TRACE,
137 "ldap_chkResponseList for msgid=%d, all=%d\n",
140 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
141 nextlm = lm->lm_next;
143 if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
144 Debug( LDAP_DEBUG_TRACE,
145 "ldap_chkResponseList msg abandoned, msgid %d\n",
147 ldap_mark_abandoned( ld, lm->lm_msgid );
149 if ( lastlm == NULL ) {
150 /* Remove first entry in list */
151 ld->ld_responses = lm->lm_next;
153 lastlm->lm_next = nextlm;
161 if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
164 if ( all == LDAP_MSG_ONE || msgid == LDAP_RES_UNSOLICITED ) {
168 for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
169 if ( tmp->lm_msgtype != LDAP_RES_SEARCH_ENTRY
170 && tmp->lm_msgtype != LDAP_RES_SEARCH_REFERENCE
171 && tmp->lm_msgtype != LDAP_RES_EXTENDED_PARTIAL )
187 /* Found an entry, remove it from the list */
188 if ( lastlm == NULL ) {
189 ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
190 ? lm->lm_chain : lm->lm_next);
192 lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
193 ? lm->lm_chain : lm->lm_next);
195 if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL ) {
196 lm->lm_chain->lm_next = lm->lm_next;
204 Debug( LDAP_DEBUG_TRACE,
205 "ldap_chkResponseList returns NULL\n", 0, 0, 0);
207 Debug( LDAP_DEBUG_TRACE,
208 "ldap_chkResponseList returns msgid %d, type 0x%02lu\n",
209 lm->lm_msgid, (unsigned long) lm->lm_msgtype, 0);
220 struct timeval *timeout,
221 LDAPMessage **result )
224 struct timeval tv, *tvp;
225 time_t start_time = 0;
227 LDAPConn *lc, *nextlc;
229 assert( ld != NULL );
230 assert( result != NULL );
233 if ( timeout == NULL ) {
234 Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout), msgid %d\n",
237 Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec), msgid %d\n",
238 (long) timeout->tv_sec, (long) timeout->tv_usec, msgid );
240 #endif /* LDAP_DEBUG */
242 if ( timeout == NULL ) {
247 start_time = time( NULL );
253 Debug( LDAP_DEBUG_TRACE, "wait4msg continue, msgid %d, all %d\n",
255 if ( ldap_debug & LDAP_DEBUG_TRACE ) {
256 ldap_dump_connection( ld, ld->ld_conns, 1 );
257 ldap_dump_requests_and_responses( ld );
259 #endif /* LDAP_DEBUG */
261 if( (*result = chkResponseList(ld, msgid, all)) != NULL ) {
262 rc = (*result)->lm_msgtype;
265 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
266 if ( ber_sockbuf_ctrl( lc->lconn_sb,
267 LBER_SB_OPT_DATA_READY, NULL ) ) {
268 rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
275 rc = ldap_int_select( ld, tvp );
280 Debug( LDAP_DEBUG_TRACE,
281 "ldap_int_select returned -1: errno %d\n",
286 if ( rc == 0 || ( rc == -1 && (
287 !LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
288 || errno != EINTR )))
290 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
296 rc = -2; /* select interrupted: loop */
299 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
301 nextlc = lc->lconn_next;
302 if ( lc->lconn_status ==
303 LDAP_CONNST_CONNECTED &&
304 ldap_is_read_ready( ld,
306 rc = try_read1msg( ld, msgid, all,
307 lc->lconn_sb, lc, result );
314 if ( rc == -2 && tvp != NULL ) {
315 tmp_time = time( NULL );
316 if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
317 rc = 0; /* timed out */
318 ld->ld_errno = LDAP_TIMEOUT;
322 Debug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
323 (long) tv.tv_sec, 0, 0 );
324 start_time = tmp_time;
339 LDAPMessage **result )
342 LDAPMessage *new, *l, *prev, *tmp;
347 LDAPRequest *lr, *tmplr;
349 int rc, refer_cnt, hadref, simple_request;
352 * v3ref = flag for V3 referral / search reference
353 * 0 = not a ref, 1 = sucessfully chased ref, -1 = pass ref to application
357 assert( ld != NULL );
358 assert( lc != NULL );
360 Debug( LDAP_DEBUG_TRACE, "read1msg: msgid %d, all %d\n", msgid, all, 0 );
362 if ( lc->lconn_ber == NULL ) {
363 lc->lconn_ber = ldap_alloc_ber_with_options(ld);
365 if( lc->lconn_ber == NULL ) {
371 assert( LBER_VALID (ber) );
373 /* get the next message */
375 #ifdef LDAP_CONNECTIONLESS
376 if ( LDAP_IS_UDP(ld) ) {
377 struct sockaddr from;
378 ber_int_sb_read(sb, &from, sizeof(struct sockaddr));
381 if ( (tag = ber_get_next( sb, &len, ber ))
382 != LDAP_TAG_MESSAGE ) {
383 if ( tag == LBER_DEFAULT) {
385 Debug( LDAP_DEBUG_CONNS,
386 "ber_get_next failed.\n", 0, 0, 0 );
389 if (errno==EWOULDBLOCK) return -2;
392 if (errno == EAGAIN) return -2;
394 ld->ld_errno = LDAP_SERVER_DOWN;
397 ld->ld_errno = LDAP_LOCAL_ERROR;
402 * We read a complete message.
403 * The connection should no longer need this ber.
405 lc->lconn_ber = NULL;
408 if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
410 ld->ld_errno = LDAP_DECODING_ERROR;
414 /* if it's been abandoned, toss it */
415 if ( ldap_abandoned( ld, id ) ) {
417 Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0);
418 return( -2 ); /* continue looking */
421 if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
422 Debug( LDAP_DEBUG_ANY,
423 "no request for response with msgid %ld (tossing)\n",
426 return( -2 ); /* continue looking */
428 #ifdef LDAP_CONNECTIONLESS
429 if (LDAP_IS_UDP(ld) && ld->ld_options.ldo_version == LDAP_VERSION2) {
431 ber_scanf(ber, "a{", &blank);
436 /* the message type */
437 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
438 ld->ld_errno = LDAP_DECODING_ERROR;
443 Debug( LDAP_DEBUG_TRACE,
444 "ldap_read: message type %s msgid %ld, original id %ld\n",
445 ldap_int_msgtype2str( tag ),
446 (long) lr->lr_msgid, (long) lr->lr_origid );
450 hadref = simple_request = 0;
451 rc = -2; /* default is to keep looking (no response found) */
452 lr->lr_res_msgtype = tag;
455 * This code figures out if we are going to chase a
456 * referral / search reference, or pass it back to the application
458 v3ref = 0; /* Assume not a V3 search reference or referral */
459 if( (tag != LDAP_RES_SEARCH_ENTRY) && (ld->ld_version > LDAP_VERSION2) ) {
460 BerElement tmpber = *ber; /* struct copy */
463 if( tag == LDAP_RES_SEARCH_REFERENCE) {
464 /* This is a V3 search reference */
465 /* Assume we do not chase the reference, but pass it to application */
467 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
468 (lr->lr_parent != NULL) )
470 /* Get the referral list */
471 if ( ber_scanf( &tmpber, "{v}", &refs ) == LBER_ERROR ) {
472 rc = LDAP_DECODING_ERROR;
474 /* Note: refs arrary is freed by ldap_chase_v3referrals */
475 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
476 1, &lr->lr_res_error, &hadref );
477 if ( refer_cnt > 0 ) { /* sucessfully chased reference */
478 /* If haven't got end search, set chasing referrals */
479 if( lr->lr_status != LDAP_REQST_COMPLETED) {
480 lr->lr_status = LDAP_REQST_CHASINGREFS;
481 Debug( LDAP_DEBUG_TRACE,
482 "read1msg: search ref chased, mark request chasing refs, id = %d\n",
485 v3ref = 1; /* We sucessfully chased the reference */
490 /* Check for V3 referral */
492 if ( ber_scanf( &tmpber, "{iaa",/*}*/ &lderr,
493 &lr->lr_res_matched, &lr->lr_res_error )
495 /* Check if V3 referral */
496 if( ber_peek_tag( &tmpber, &len) == LDAP_TAG_REFERRAL ) {
497 /* We have a V3 referral, assume we cannot chase it */
499 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
500 || (lr->lr_parent != NULL) )
502 v3ref = -1; /* Assume referral not chased and return it to app */
503 /* Get the referral list */
504 if( ber_scanf( &tmpber, "{v}", &refs) == LBER_ERROR) {
505 rc = LDAP_DECODING_ERROR;
506 lr->lr_status = LDAP_REQST_COMPLETED;
507 Debug( LDAP_DEBUG_TRACE,
508 "read1msg: referral decode error, mark request completed, id = %d\n",
511 /* Chase the referral
512 * Note: refs arrary is freed by ldap_chase_v3referrals
514 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
515 0, &lr->lr_res_error, &hadref );
516 lr->lr_status = LDAP_REQST_COMPLETED;
517 Debug( LDAP_DEBUG_TRACE,
518 "read1msg: referral chased, mark request completed, id = %d\n",
521 v3ref = 1; /* Referral successfully chased */
527 if( lr->lr_res_matched != NULL ) {
528 LDAP_FREE( lr->lr_res_matched );
529 lr->lr_res_matched = NULL;
531 if( lr->lr_res_error != NULL ) {
532 LDAP_FREE( lr->lr_res_error );
533 lr->lr_res_error = NULL;
539 /* All results that just return a status, i.e. don't return data
540 * go through the following code. This code also chases V2 referrals
541 * and checks if all referrals have been chased.
543 if ( (tag != LDAP_RES_SEARCH_ENTRY) && (v3ref > -1) ) {
544 /* For a v3 search referral/reference, only come here if already chased it */
545 if ( ld->ld_version >= LDAP_VERSION2 &&
546 ( lr->lr_parent != NULL ||
547 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
549 tmpber = *ber; /* struct copy */
551 ; /* V3 search reference or V3 referral sucessfully chased */
552 } else if ( ber_scanf( &tmpber, "{iaa}", &lderr,
553 &lr->lr_res_matched, &lr->lr_res_error )
555 if ( lderr != LDAP_SUCCESS ) {
556 /* referrals are in error string */
557 refer_cnt = ldap_chase_referrals( ld, lr,
558 &lr->lr_res_error, -1, &hadref );
559 lr->lr_status = LDAP_REQST_COMPLETED;
560 Debug( LDAP_DEBUG_TRACE,
561 "read1msg: V2 referral chased, mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
564 /* save errno, message, and matched string */
565 if ( !hadref || lr->lr_res_error == NULL ) {
566 lr->lr_res_errno = ( lderr ==
567 LDAP_PARTIAL_RESULTS ) ? LDAP_SUCCESS
569 } else if ( ld->ld_errno != LDAP_SUCCESS ) {
570 lr->lr_res_errno = ld->ld_errno;
572 lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
574 Debug( LDAP_DEBUG_TRACE,
575 "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
576 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
577 lr->lr_res_matched ? lr->lr_res_matched : "" );
581 Debug( LDAP_DEBUG_TRACE,
582 "read1msg: %d new referrals\n", refer_cnt, 0, 0 );
584 if ( refer_cnt != 0 ) { /* chasing referrals */
587 if ( refer_cnt < 0 ) {
588 return( -1 ); /* fatal error */
590 lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
592 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
593 /* request without any referrals */
594 simple_request = ( hadref ? 0 : 1 );
596 /* request with referrals or child request */
601 lr->lr_status = LDAP_REQST_COMPLETED; /* declare this request done */
602 Debug( LDAP_DEBUG_TRACE,
603 "read1msg: mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
604 while ( lr->lr_parent != NULL ) {
605 merge_error_info( ld, lr->lr_parent, lr );
608 if ( --lr->lr_outrefcnt > 0 ) {
609 break; /* not completely done yet */
613 /* Check if all requests are finished, lr is now parent */
615 if (tmplr->lr_status == LDAP_REQST_COMPLETED) {
616 for(tmplr=lr->lr_child; tmplr != NULL; tmplr=tmplr->lr_refnext) {
617 if( tmplr->lr_status != LDAP_REQST_COMPLETED) {
623 /* This is the parent request if the request has referrals */
624 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL && tmplr == NULL ) {
626 tag = lr->lr_res_msgtype;
627 Debug( LDAP_DEBUG_ANY, "request %ld done\n",
629 Debug( LDAP_DEBUG_TRACE,
630 "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
631 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
632 lr->lr_res_matched ? lr->lr_res_matched : "" );
633 if ( !simple_request ) {
636 if ( build_result_ber( ld, &ber, lr )
638 rc = -1; /* fatal error */
642 ldap_free_request( ld, lr );
646 ldap_free_connection( ld, lc, 0, 1 );
655 /* make a new ldap message */
656 if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
658 ld->ld_errno = LDAP_NO_MEMORY;
661 new->lm_msgid = (int)id;
662 new->lm_msgtype = tag;
666 if ( ld->ld_cache != NULL ) {
667 ldap_add_result_to_cache( ld, new );
669 #endif /* LDAP_NOCACHE */
671 /* is this the one we're looking for? */
672 if ( msgid == LDAP_RES_ANY || id == msgid ) {
673 if ( all == LDAP_MSG_ONE
674 || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
675 && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
676 && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
678 ld->ld_errno = LDAP_SUCCESS;
680 } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
681 foundit = 1; /* return the chain later */
686 * if not, we must add it to the list of responses. if
687 * the msgid is already there, it must be part of an existing
692 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
693 if ( l->lm_msgid == new->lm_msgid )
698 /* not part of an existing search response */
702 ld->ld_errno = LDAP_SUCCESS;
706 new->lm_next = ld->ld_responses;
707 ld->ld_responses = new;
708 return( -2 ); /* continue looking */
711 Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n",
712 (long) new->lm_msgid, (long) new->lm_msgtype, 0 );
714 /* part of a search response - add to end of list of entries */
715 for ( tmp = l; (tmp->lm_chain != NULL) &&
716 ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
717 (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
718 (tmp->lm_chain->lm_msgtype == LDAP_RES_EXTENDED_PARTIAL ));
719 tmp = tmp->lm_chain )
723 /* return the whole chain if that's what we were looking for */
726 ld->ld_responses = l->lm_next;
728 prev->lm_next = l->lm_next;
730 ld->ld_errno = LDAP_SUCCESS;
731 #ifdef LDAP_WORLD_P16
733 * XXX questionable fix; see text for [P16] on
734 * http://www.critical-angle.com/ldapworld/patch/
736 * inclusion of this patch causes searchs to hang on
739 return( l->lm_msgtype );
740 #else /* LDAP_WORLD_P16 */
742 #endif /* !LDAP_WORLD_P16 */
745 return( -2 ); /* continue looking */
750 build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr )
758 ber = ldap_alloc_ber_with_options( ld );
761 ld->ld_errno = LDAP_NO_MEMORY;
765 if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
766 lr->lr_res_msgtype, lr->lr_res_errno,
767 lr->lr_res_matched ? lr->lr_res_matched : "",
768 lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
770 ld->ld_errno = LDAP_ENCODING_ERROR;
772 return( LBER_ERROR );
777 if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
778 ld->ld_errno = LDAP_DECODING_ERROR;
780 return( LBER_ERROR );
783 if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
784 ld->ld_errno = LDAP_DECODING_ERROR;
786 return( LBER_ERROR );
789 tag = ber_peek_tag( ber, &len );
791 if ( tag == LBER_ERROR ) {
792 ld->ld_errno = LDAP_DECODING_ERROR;
794 return( LBER_ERROR );
803 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
806 * Merge error information in "lr" with "parentr" error code and string.
808 if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
809 parentr->lr_res_errno = lr->lr_res_errno;
810 if ( lr->lr_res_error != NULL ) {
811 (void)ldap_append_referral( ld, &parentr->lr_res_error,
814 } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
815 parentr->lr_res_errno == LDAP_SUCCESS ) {
816 parentr->lr_res_errno = lr->lr_res_errno;
817 if ( parentr->lr_res_error != NULL ) {
818 LDAP_FREE( parentr->lr_res_error );
820 parentr->lr_res_error = lr->lr_res_error;
821 lr->lr_res_error = NULL;
822 if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
823 if ( parentr->lr_res_matched != NULL ) {
824 LDAP_FREE( parentr->lr_res_matched );
826 parentr->lr_res_matched = lr->lr_res_matched;
827 lr->lr_res_matched = NULL;
831 Debug( LDAP_DEBUG_TRACE, "merged parent (id %d) error info: ",
832 parentr->lr_msgid, 0, 0 );
833 Debug( LDAP_DEBUG_TRACE, "result errno %d, error <%s>, matched <%s>\n",
834 parentr->lr_res_errno, parentr->lr_res_error ?
835 parentr->lr_res_error : "", parentr->lr_res_matched ?
836 parentr->lr_res_matched : "" );
842 ldap_msgtype( LDAPMessage *lm )
844 assert( lm != NULL );
845 return ( lm != NULL ) ? lm->lm_msgtype : -1;
850 ldap_msgid( LDAPMessage *lm )
852 assert( lm != NULL );
854 return ( lm != NULL ) ? lm->lm_msgid : -1;
858 char * ldap_int_msgtype2str( ber_tag_t tag )
861 case LDAP_RES_ADD: return "add";
862 case LDAP_RES_BIND: return "bind";
863 case LDAP_RES_COMPARE: return "compare";
864 case LDAP_RES_DELETE: return "delete";
865 case LDAP_RES_EXTENDED: return "extended-result";
866 case LDAP_RES_EXTENDED_PARTIAL: return "extended-partial";
867 case LDAP_RES_MODIFY: return "modify";
868 case LDAP_RES_RENAME: return "rename";
869 case LDAP_RES_SEARCH_ENTRY: return "search-entry";
870 case LDAP_RES_SEARCH_REFERENCE: return "search-reference";
871 case LDAP_RES_SEARCH_RESULT: return "search-result";
877 ldap_msgfree( LDAPMessage *lm )
882 Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 );
884 for ( ; lm != NULL; lm = next ) {
886 type = lm->lm_msgtype;
887 ber_free( lm->lm_ber, 1 );
888 LDAP_FREE( (char *) lm );
895 * ldap_msgdelete - delete a message. It returns:
896 * 0 if the entire message was deleted
897 * -1 if the message was not found, or only part of it was found
900 ldap_msgdelete( LDAP *ld, int msgid )
902 LDAPMessage *lm, *prev;
904 assert( ld != NULL );
906 Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 );
909 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
910 if ( lm->lm_msgid == msgid )
919 ld->ld_responses = lm->lm_next;
921 prev->lm_next = lm->lm_next;
923 if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY )
931 * return 1 if message msgid is waiting to be abandoned, 0 otherwise
934 ldap_abandoned( LDAP *ld, ber_int_t msgid )
938 if ( ld->ld_abandoned == NULL )
941 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
942 if ( ld->ld_abandoned[i] == msgid )
950 ldap_mark_abandoned( LDAP *ld, ber_int_t msgid )
954 if ( ld->ld_abandoned == NULL )
957 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
958 if ( ld->ld_abandoned[i] == msgid )
961 if ( ld->ld_abandoned[i] == -1 )
964 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
965 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];