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. This is only useful for search responses, which can be
78 * of two message types (zero or more entries, followed by an
79 * ldap result). The type of the first message received is returned.
80 * When waiting, any messages that have been abandoned are discarded.
83 * ldap_result( s, msgid, all, timeout, result )
90 struct timeval *timeout,
91 LDAPMessage **result )
96 assert( result != NULL );
98 Debug( LDAP_DEBUG_TRACE, "ldap_result msgid %d\n", msgid, 0, 0 );
104 if( result == NULL ) {
105 ld->ld_errno = LDAP_PARAM_ERROR;
109 lm = chkResponseList(ld, msgid, all);
112 return( wait4msg( ld, msgid, all, timeout, result ) );
116 ld->ld_errno = LDAP_SUCCESS;
117 return( lm->lm_msgtype );
121 chkResponseList( LDAP *ld,
125 LDAPMessage *lm, *lastlm, *nextlm;
127 * Look through the list of responses we have received on
128 * this association and see if the response we're interested in
129 * is there. If it is, return it. If not, call wait4msg() to
130 * wait until it arrives or timeout occurs.
134 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
135 nextlm = lm->lm_next;
137 if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
138 ldap_mark_abandoned( ld, lm->lm_msgid );
140 if ( lastlm == NULL ) {
141 ld->ld_responses = lm->lm_next;
143 lastlm->lm_next = nextlm;
151 if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
154 if ( all == LDAP_MSG_ONE
155 || (lm->lm_msgtype != LDAP_RES_SEARCH_RESULT
156 && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE /* LDAPv3 */
157 && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY
158 && lm->lm_msgtype != LDAP_RES_EXTENDED_PARTIAL) )
161 for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
162 if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT )
175 if ( lastlm == NULL ) {
176 ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
177 ? lm->lm_chain : lm->lm_next);
179 lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
180 ? lm->lm_chain : lm->lm_next);
182 if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL )
184 lm->lm_chain->lm_next = lm->lm_next;
196 struct timeval *timeout,
197 LDAPMessage **result )
200 struct timeval tv, *tvp;
201 time_t start_time = 0;
203 LDAPConn *lc, *nextlc;
205 assert( ld != NULL );
206 assert( result != NULL );
209 if ( timeout == NULL ) {
210 Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout), msgid %d\n",
213 Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec), msgid %d\n",
214 (long) timeout->tv_sec, (long) timeout->tv_usec, msgid );
216 #endif /* LDAP_DEBUG */
218 if ( timeout == NULL ) {
223 start_time = time( NULL );
229 if ( ldap_debug & LDAP_DEBUG_TRACE ) {
230 ldap_dump_connection( ld, ld->ld_conns, 1 );
231 ldap_dump_requests_and_responses( ld );
233 #endif /* LDAP_DEBUG */
234 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
235 if ( ber_sockbuf_ctrl( lc->lconn_sb,
236 LBER_SB_OPT_DATA_READY, NULL ) ) {
237 if( (*result = chkResponseList(ld, msgid, all)) == NULL ) {
238 rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
241 rc = (*result)->lm_msgtype;
248 rc = do_ldap_select( ld, tvp );
253 Debug( LDAP_DEBUG_TRACE,
254 "do_ldap_select returned -1: errno %d\n",
259 if ( rc == 0 || ( rc == -1 && (
260 !LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
261 || errno != EINTR )))
263 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
269 rc = -2; /* select interrupted: loop */
272 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
274 nextlc = lc->lconn_next;
275 if ( lc->lconn_status ==
276 LDAP_CONNST_CONNECTED &&
277 ldap_is_read_ready( ld,
279 rc = try_read1msg( ld, msgid, all,
280 lc->lconn_sb, lc, result );
286 if ( rc == -2 && tvp != NULL ) {
287 tmp_time = time( NULL );
288 if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
289 rc = 0; /* timed out */
290 ld->ld_errno = LDAP_TIMEOUT;
294 Debug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
295 (long) tv.tv_sec, 0, 0 );
296 start_time = tmp_time;
311 LDAPMessage **result )
314 LDAPMessage *new, *l, *prev, *tmp;
319 LDAPRequest *lr, *tmplr;
321 int rc, refer_cnt, hadref, simple_request;
324 * v3ref = flag for V3 referral / search reference
325 * 0 = not a ref, 1 = sucessfully chased ref, -1 = pass ref to application
329 assert( ld != NULL );
330 assert( lc != NULL );
332 Debug( LDAP_DEBUG_TRACE, "read1msg: msgid %d, all %d\n", msgid, all, 0 );
334 if ( lc->lconn_ber == NULL ) {
335 lc->lconn_ber = ldap_alloc_ber_with_options(ld);
337 if( lc->lconn_ber == NULL ) {
343 assert( BER_VALID (ber) );
345 /* get the next message */
347 if ( (tag = ber_get_next( sb, &len, ber ))
348 != LDAP_TAG_MESSAGE ) {
349 if ( tag == LBER_DEFAULT) {
351 Debug( LDAP_DEBUG_CONNS,
352 "ber_get_next failed.\n", 0, 0, 0 );
355 if (errno==EWOULDBLOCK) return -2;
358 if (errno == EAGAIN) return -2;
360 ld->ld_errno = LDAP_SERVER_DOWN;
363 ld->ld_errno = LDAP_LOCAL_ERROR;
368 * We read a complete message.
369 * The connection should no longer need this ber.
371 lc->lconn_ber = NULL;
374 if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
376 ld->ld_errno = LDAP_DECODING_ERROR;
380 /* if it's been abandoned, toss it */
381 if ( ldap_abandoned( ld, id ) ) {
383 Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0);
384 return( -2 ); /* continue looking */
387 if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
388 Debug( LDAP_DEBUG_ANY,
389 "no request for response with msgid %ld (tossing)\n",
392 return( -2 ); /* continue looking */
395 /* the message type */
396 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
397 ld->ld_errno = LDAP_DECODING_ERROR;
402 Debug( LDAP_DEBUG_TRACE, "ldap_read: message type %s msgid %ld, original id %ld\n",
403 ldap_int_msgtype2str( tag ),
404 (long) lr->lr_msgid, (long) lr->lr_origid );
408 hadref = simple_request = 0;
409 rc = -2; /* default is to keep looking (no response found) */
410 lr->lr_res_msgtype = tag;
413 * This code figures out if we are going to chase a
414 * referral / search reference, or pass it back to the application
416 v3ref = 0; /* Assume not a V3 search reference or referral */
417 if( (tag != LDAP_RES_SEARCH_ENTRY) && (ld->ld_version > LDAP_VERSION2) ) {
418 BerElement tmpber = *ber; /* struct copy */
421 if( tag == LDAP_RES_SEARCH_REFERENCE) {
422 /* This is a V3 search reference */
423 /* Assume we do not chase the reference, but pass it to application */
425 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
426 (lr->lr_parent != NULL) )
428 /* Get the referral list */
429 if ( ber_scanf( &tmpber, "{v}", &refs ) == LBER_ERROR ) {
430 rc = LDAP_DECODING_ERROR;
432 /* Note: refs arrary is freed by ldap_chase_v3referrals */
433 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
434 1, &lr->lr_res_error, &hadref );
435 if ( refer_cnt > 0 ) { /* sucessfully chased reference */
436 /* If haven't got end search, set chasing referrals */
437 if( lr->lr_status != LDAP_REQST_COMPLETED) {
438 lr->lr_status = LDAP_REQST_CHASINGREFS;
439 Debug( LDAP_DEBUG_TRACE,
440 "read1msg: search ref chased, mark request chasing refs, id = %d\n",
443 v3ref = 1; /* We sucessfully chased the reference */
448 /* Check for V3 referral */
450 if ( ber_scanf( &tmpber, "{iaa",/*}*/ &lderr,
451 &lr->lr_res_matched, &lr->lr_res_error )
453 /* Check if V3 referral */
454 if( ber_peek_tag( &tmpber, &len) == LDAP_TAG_REFERRAL ) {
455 /* We have a V3 referral, assume we cannot chase it */
457 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
458 || (lr->lr_parent != NULL) )
460 v3ref = -1; /* Assume referral not chased and return it to app */
461 /* Get the referral list */
462 if( ber_scanf( &tmpber, "{v}", &refs) == LBER_ERROR) {
463 rc = LDAP_DECODING_ERROR;
464 lr->lr_status = LDAP_REQST_COMPLETED;
465 Debug( LDAP_DEBUG_TRACE,
466 "read1msg: referral decode error, mark request completed, id = %d\n",
469 /* Chase the referral
470 * Note: refs arrary is freed by ldap_chase_v3referrals
472 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
473 0, &lr->lr_res_error, &hadref );
474 lr->lr_status = LDAP_REQST_COMPLETED;
475 Debug( LDAP_DEBUG_TRACE,
476 "read1msg: referral chased, mark request completed, id = %d\n",
479 v3ref = 1; /* Referral successfully chased */
485 if( lr->lr_res_matched != NULL ) {
486 LDAP_FREE( lr->lr_res_matched );
487 lr->lr_res_matched = NULL;
489 if( lr->lr_res_error != NULL ) {
490 LDAP_FREE( lr->lr_res_error );
491 lr->lr_res_error = NULL;
497 /* All results that just return a status, i.e. don't return data
498 * go through the following code. This code also chases V2 referrals
499 * and checks if all referrals have been chased.
501 if ( (tag != LDAP_RES_SEARCH_ENTRY) && (v3ref > -1) ) {
502 /* For a v3 search referral/reference, only come here if already chased it */
503 if ( ld->ld_version >= LDAP_VERSION2 &&
504 ( lr->lr_parent != NULL ||
505 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
507 tmpber = *ber; /* struct copy */
509 ; /* V3 search reference or V3 referral sucessfully chased */
511 if ( ber_scanf( &tmpber, "{iaa}", &lderr,
512 &lr->lr_res_matched, &lr->lr_res_error )
514 if ( lderr != LDAP_SUCCESS ) {
515 /* referrals are in error string */
516 refer_cnt = ldap_chase_referrals( ld, lr,
517 &lr->lr_res_error, &hadref );
518 lr->lr_status = LDAP_REQST_COMPLETED;
519 Debug( LDAP_DEBUG_TRACE,
520 "read1msg: V2 referral chased, mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
523 /* save errno, message, and matched string */
524 if ( !hadref || lr->lr_res_error == NULL ) {
525 lr->lr_res_errno = ( lderr ==
526 LDAP_PARTIAL_RESULTS ) ? LDAP_SUCCESS
528 } else if ( ld->ld_errno != LDAP_SUCCESS ) {
529 lr->lr_res_errno = ld->ld_errno;
531 lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
533 Debug( LDAP_DEBUG_TRACE,
534 "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
535 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
536 lr->lr_res_matched ? lr->lr_res_matched : "" );
540 Debug( LDAP_DEBUG_TRACE,
541 "read1msg: %d new referrals\n", refer_cnt, 0, 0 );
543 if ( refer_cnt != 0 ) { /* chasing referrals */
546 if ( refer_cnt < 0 ) {
547 return( -1 ); /* fatal error */
549 lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
551 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
552 /* request without any referrals */
553 simple_request = ( hadref ? 0 : 1 );
555 /* request with referrals or child request */
560 lr->lr_status = LDAP_REQST_COMPLETED; /* declare this request done */
561 Debug( LDAP_DEBUG_TRACE,
562 "read1msg: mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
563 while ( lr->lr_parent != NULL ) {
564 merge_error_info( ld, lr->lr_parent, lr );
567 if ( --lr->lr_outrefcnt > 0 ) {
568 break; /* not completely done yet */
572 /* Check if all requests are finished, lr is now parent */
573 for(tmplr=lr ; tmplr != NULL; tmplr=tmplr->lr_refnext) {
574 if( tmplr->lr_status != LDAP_REQST_COMPLETED) {
579 /* This is the parent request if the request has referrals */
580 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL && tmplr == NULL ) {
582 tag = lr->lr_res_msgtype;
583 Debug( LDAP_DEBUG_ANY, "request %ld done\n",
585 Debug( LDAP_DEBUG_TRACE,
586 "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
587 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
588 lr->lr_res_matched ? lr->lr_res_matched : "" );
589 if ( !simple_request ) {
592 if ( build_result_ber( ld, &ber, lr )
594 rc = -1; /* fatal error */
598 ldap_free_request( ld, lr );
602 ldap_free_connection( ld, lc, 0, 1 );
611 /* make a new ldap message */
612 if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
614 ld->ld_errno = LDAP_NO_MEMORY;
617 new->lm_msgid = (int)id;
618 new->lm_msgtype = tag;
622 if ( ld->ld_cache != NULL ) {
623 ldap_add_result_to_cache( ld, new );
625 #endif /* LDAP_NOCACHE */
627 /* is this the one we're looking for? */
628 if ( msgid == LDAP_RES_ANY || id == msgid ) {
629 if ( all == LDAP_MSG_ONE
630 || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
631 && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
632 && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
634 ld->ld_errno = LDAP_SUCCESS;
636 } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
637 foundit = 1; /* return the chain later */
642 * if not, we must add it to the list of responses. if
643 * the msgid is already there, it must be part of an existing
648 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
649 if ( l->lm_msgid == new->lm_msgid )
654 /* not part of an existing search response */
658 ld->ld_errno = LDAP_SUCCESS;
662 new->lm_next = ld->ld_responses;
663 ld->ld_responses = new;
664 return( -2 ); /* continue looking */
667 Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n",
668 (long) new->lm_msgid, (long) new->lm_msgtype, 0 );
670 /* part of a search response - add to end of list of entries */
671 for ( tmp = l; (tmp->lm_chain != NULL) &&
672 ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
673 (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
674 (tmp->lm_chain->lm_msgtype == LDAP_RES_EXTENDED_PARTIAL ));
675 tmp = tmp->lm_chain )
679 /* return the whole chain if that's what we were looking for */
682 ld->ld_responses = l->lm_next;
684 prev->lm_next = l->lm_next;
686 ld->ld_errno = LDAP_SUCCESS;
687 #ifdef LDAP_WORLD_P16
689 * XXX questionable fix; see text for [P16] on
690 * http://www.critical-angle.com/ldapworld/patch/
692 * inclusion of this patch causes searchs to hang on
695 return( l->lm_msgtype );
696 #else /* LDAP_WORLD_P16 */
698 #endif /* !LDAP_WORLD_P16 */
701 return( -2 ); /* continue looking */
706 build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr )
714 ber = ldap_alloc_ber_with_options( ld );
717 ld->ld_errno = LDAP_NO_MEMORY;
721 if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
722 lr->lr_res_msgtype, lr->lr_res_errno,
723 lr->lr_res_matched ? lr->lr_res_matched : "",
724 lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
726 ld->ld_errno = LDAP_ENCODING_ERROR;
728 return( LBER_ERROR );
733 if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
734 ld->ld_errno = LDAP_DECODING_ERROR;
736 return( LBER_ERROR );
739 if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
740 ld->ld_errno = LDAP_DECODING_ERROR;
742 return( LBER_ERROR );
745 tag = ber_peek_tag( ber, &len );
747 if ( tag == LBER_ERROR ) {
748 ld->ld_errno = LDAP_DECODING_ERROR;
750 return( LBER_ERROR );
759 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
762 * Merge error information in "lr" with "parentr" error code and string.
764 if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
765 parentr->lr_res_errno = lr->lr_res_errno;
766 if ( lr->lr_res_error != NULL ) {
767 (void)ldap_append_referral( ld, &parentr->lr_res_error,
770 } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
771 parentr->lr_res_errno == LDAP_SUCCESS ) {
772 parentr->lr_res_errno = lr->lr_res_errno;
773 if ( parentr->lr_res_error != NULL ) {
774 LDAP_FREE( parentr->lr_res_error );
776 parentr->lr_res_error = lr->lr_res_error;
777 lr->lr_res_error = NULL;
778 if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
779 if ( parentr->lr_res_matched != NULL ) {
780 LDAP_FREE( parentr->lr_res_matched );
782 parentr->lr_res_matched = lr->lr_res_matched;
783 lr->lr_res_matched = NULL;
787 Debug( LDAP_DEBUG_TRACE, "merged parent (id %d) error info: ",
788 parentr->lr_msgid, 0, 0 );
789 Debug( LDAP_DEBUG_TRACE, "result errno %d, error <%s>, matched <%s>\n",
790 parentr->lr_res_errno, parentr->lr_res_error ?
791 parentr->lr_res_error : "", parentr->lr_res_matched ?
792 parentr->lr_res_matched : "" );
798 ldap_msgtype( LDAPMessage *lm )
800 assert( lm != NULL );
801 return ( lm != NULL ) ? lm->lm_msgtype : -1;
806 ldap_msgid( LDAPMessage *lm )
808 assert( lm != NULL );
810 return ( lm != NULL ) ? lm->lm_msgid : -1;
814 char * ldap_int_msgtype2str( ber_tag_t tag )
817 case LDAP_RES_ADD: return "add";
818 case LDAP_RES_BIND: return "bind";
819 case LDAP_RES_COMPARE: return "compare";
820 case LDAP_RES_DELETE: return "delete";
821 case LDAP_RES_EXTENDED: return "extended-result";
822 case LDAP_RES_EXTENDED_PARTIAL: return "extended-partial";
823 case LDAP_RES_MODIFY: return "modify";
824 case LDAP_RES_RENAME: return "rename";
825 case LDAP_RES_SEARCH_ENTRY: return "search-entry";
826 case LDAP_RES_SEARCH_REFERENCE: return "search-reference";
827 case LDAP_RES_SEARCH_RESULT: return "search-result";
833 ldap_msgfree( LDAPMessage *lm )
838 Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 );
840 for ( ; lm != NULL; lm = next ) {
842 type = lm->lm_msgtype;
843 ber_free( lm->lm_ber, 1 );
844 LDAP_FREE( (char *) lm );
851 * ldap_msgdelete - delete a message. It returns:
852 * 0 if the entire message was deleted
853 * -1 if the message was not found, or only part of it was found
856 ldap_msgdelete( LDAP *ld, int msgid )
858 LDAPMessage *lm, *prev;
860 assert( ld != NULL );
862 Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 );
865 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
866 if ( lm->lm_msgid == msgid )
875 ld->ld_responses = lm->lm_next;
877 prev->lm_next = lm->lm_next;
879 if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY )
887 * return 1 if message msgid is waiting to be abandoned, 0 otherwise
890 ldap_abandoned( LDAP *ld, ber_int_t msgid )
894 if ( ld->ld_abandoned == NULL )
897 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
898 if ( ld->ld_abandoned[i] == msgid )
906 ldap_mark_abandoned( LDAP *ld, ber_int_t msgid )
910 if ( ld->ld_abandoned == NULL )
913 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
914 if ( ld->ld_abandoned[i] == msgid )
917 if ( ld->ld_abandoned[i] == -1 )
920 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
921 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];