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.
133 Debug( LDAP_DEBUG_TRACE, "chkResponseList for msgid %d, all %d\n",
136 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
137 nextlm = lm->lm_next;
139 if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
140 Debug( LDAP_DEBUG_TRACE, "chkResponseList msg abandoned, msgid %d\n",
142 ldap_mark_abandoned( ld, lm->lm_msgid );
144 if ( lastlm == NULL ) {
145 /* Remove first entry in list */
146 ld->ld_responses = lm->lm_next;
148 lastlm->lm_next = nextlm;
156 if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
159 if ( all == LDAP_MSG_ONE
160 || (lm->lm_msgtype != LDAP_RES_SEARCH_RESULT
161 && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE /* LDAPv3 */
162 && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY
163 && lm->lm_msgtype != LDAP_RES_EXTENDED_PARTIAL) )
166 for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) {
167 if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT )
180 /* Found an entry, remove it from the list */
181 if ( lastlm == NULL ) {
182 ld->ld_responses = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
183 ? lm->lm_chain : lm->lm_next);
185 lastlm->lm_next = (all == LDAP_MSG_ONE && lm->lm_chain != NULL
186 ? lm->lm_chain : lm->lm_next);
188 if ( all == LDAP_MSG_ONE && lm->lm_chain != NULL )
190 lm->lm_chain->lm_next = lm->lm_next;
198 Debug( LDAP_DEBUG_TRACE, "chkResponseList returns NULL\n", 0, 0, 0);
200 Debug( LDAP_DEBUG_TRACE, "chkResponseList returns msgid %d, type %lu\n",
201 lm->lm_msgid, (unsigned long) lm->lm_msgtype, 0);
211 struct timeval *timeout,
212 LDAPMessage **result )
215 struct timeval tv, *tvp;
216 time_t start_time = 0;
218 LDAPConn *lc, *nextlc;
220 assert( ld != NULL );
221 assert( result != NULL );
224 if ( timeout == NULL ) {
225 Debug( LDAP_DEBUG_TRACE, "wait4msg (infinite timeout), msgid %d\n",
228 Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec), msgid %d\n",
229 (long) timeout->tv_sec, (long) timeout->tv_usec, msgid );
231 #endif /* LDAP_DEBUG */
233 if ( timeout == NULL ) {
238 start_time = time( NULL );
244 Debug( LDAP_DEBUG_TRACE, "wait4msg continue, msgid %d, all %d\n",
246 if ( ldap_debug & LDAP_DEBUG_TRACE ) {
247 ldap_dump_connection( ld, ld->ld_conns, 1 );
248 ldap_dump_requests_and_responses( ld );
250 #endif /* LDAP_DEBUG */
252 if( (*result = chkResponseList(ld, msgid, all)) != NULL ) {
253 rc = (*result)->lm_msgtype;
256 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
257 if ( ber_sockbuf_ctrl( lc->lconn_sb,
258 LBER_SB_OPT_DATA_READY, NULL ) ) {
259 rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
266 rc = do_ldap_select( ld, tvp );
271 Debug( LDAP_DEBUG_TRACE,
272 "do_ldap_select returned -1: errno %d\n",
277 if ( rc == 0 || ( rc == -1 && (
278 !LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
279 || errno != EINTR )))
281 ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
287 rc = -2; /* select interrupted: loop */
290 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
292 nextlc = lc->lconn_next;
293 if ( lc->lconn_status ==
294 LDAP_CONNST_CONNECTED &&
295 ldap_is_read_ready( ld,
297 rc = try_read1msg( ld, msgid, all,
298 lc->lconn_sb, lc, result );
305 if ( rc == -2 && tvp != NULL ) {
306 tmp_time = time( NULL );
307 if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
308 rc = 0; /* timed out */
309 ld->ld_errno = LDAP_TIMEOUT;
313 Debug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
314 (long) tv.tv_sec, 0, 0 );
315 start_time = tmp_time;
330 LDAPMessage **result )
333 LDAPMessage *new, *l, *prev, *tmp;
338 LDAPRequest *lr, *tmplr;
340 int rc, refer_cnt, hadref, simple_request;
343 * v3ref = flag for V3 referral / search reference
344 * 0 = not a ref, 1 = sucessfully chased ref, -1 = pass ref to application
348 assert( ld != NULL );
349 assert( lc != NULL );
351 Debug( LDAP_DEBUG_TRACE, "read1msg: msgid %d, all %d\n", msgid, all, 0 );
353 if ( lc->lconn_ber == NULL ) {
354 lc->lconn_ber = ldap_alloc_ber_with_options(ld);
356 if( lc->lconn_ber == NULL ) {
362 assert( BER_VALID (ber) );
364 /* get the next message */
366 if ( (tag = ber_get_next( sb, &len, ber ))
367 != LDAP_TAG_MESSAGE ) {
368 if ( tag == LBER_DEFAULT) {
370 Debug( LDAP_DEBUG_CONNS,
371 "ber_get_next failed.\n", 0, 0, 0 );
374 if (errno==EWOULDBLOCK) return -2;
377 if (errno == EAGAIN) return -2;
379 ld->ld_errno = LDAP_SERVER_DOWN;
382 ld->ld_errno = LDAP_LOCAL_ERROR;
387 * We read a complete message.
388 * The connection should no longer need this ber.
390 lc->lconn_ber = NULL;
393 if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
395 ld->ld_errno = LDAP_DECODING_ERROR;
399 /* if it's been abandoned, toss it */
400 if ( ldap_abandoned( ld, id ) ) {
402 Debug( LDAP_DEBUG_ANY, "abandoned\n", 0, 0, 0);
403 return( -2 ); /* continue looking */
406 if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
407 Debug( LDAP_DEBUG_ANY,
408 "no request for response with msgid %ld (tossing)\n",
411 return( -2 ); /* continue looking */
414 /* the message type */
415 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
416 ld->ld_errno = LDAP_DECODING_ERROR;
421 Debug( LDAP_DEBUG_TRACE, "ldap_read: message type %s msgid %ld, original id %ld\n",
422 ldap_int_msgtype2str( tag ),
423 (long) lr->lr_msgid, (long) lr->lr_origid );
427 hadref = simple_request = 0;
428 rc = -2; /* default is to keep looking (no response found) */
429 lr->lr_res_msgtype = tag;
432 * This code figures out if we are going to chase a
433 * referral / search reference, or pass it back to the application
435 v3ref = 0; /* Assume not a V3 search reference or referral */
436 if( (tag != LDAP_RES_SEARCH_ENTRY) && (ld->ld_version > LDAP_VERSION2) ) {
437 BerElement tmpber = *ber; /* struct copy */
440 if( tag == LDAP_RES_SEARCH_REFERENCE) {
441 /* This is a V3 search reference */
442 /* Assume we do not chase the reference, but pass it to application */
444 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ||
445 (lr->lr_parent != NULL) )
447 /* Get the referral list */
448 if ( ber_scanf( &tmpber, "{v}", &refs ) == LBER_ERROR ) {
449 rc = LDAP_DECODING_ERROR;
451 /* Note: refs arrary is freed by ldap_chase_v3referrals */
452 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
453 1, &lr->lr_res_error, &hadref );
454 if ( refer_cnt > 0 ) { /* sucessfully chased reference */
455 /* If haven't got end search, set chasing referrals */
456 if( lr->lr_status != LDAP_REQST_COMPLETED) {
457 lr->lr_status = LDAP_REQST_CHASINGREFS;
458 Debug( LDAP_DEBUG_TRACE,
459 "read1msg: search ref chased, mark request chasing refs, id = %d\n",
462 v3ref = 1; /* We sucessfully chased the reference */
467 /* Check for V3 referral */
469 if ( ber_scanf( &tmpber, "{iaa",/*}*/ &lderr,
470 &lr->lr_res_matched, &lr->lr_res_error )
472 /* Check if V3 referral */
473 if( ber_peek_tag( &tmpber, &len) == LDAP_TAG_REFERRAL ) {
474 /* We have a V3 referral, assume we cannot chase it */
476 if( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
477 || (lr->lr_parent != NULL) )
479 v3ref = -1; /* Assume referral not chased and return it to app */
480 /* Get the referral list */
481 if( ber_scanf( &tmpber, "{v}", &refs) == LBER_ERROR) {
482 rc = LDAP_DECODING_ERROR;
483 lr->lr_status = LDAP_REQST_COMPLETED;
484 Debug( LDAP_DEBUG_TRACE,
485 "read1msg: referral decode error, mark request completed, id = %d\n",
488 /* Chase the referral
489 * Note: refs arrary is freed by ldap_chase_v3referrals
491 refer_cnt = ldap_chase_v3referrals( ld, lr, refs,
492 0, &lr->lr_res_error, &hadref );
493 lr->lr_status = LDAP_REQST_COMPLETED;
494 Debug( LDAP_DEBUG_TRACE,
495 "read1msg: referral chased, mark request completed, id = %d\n",
498 v3ref = 1; /* Referral successfully chased */
504 if( lr->lr_res_matched != NULL ) {
505 LDAP_FREE( lr->lr_res_matched );
506 lr->lr_res_matched = NULL;
508 if( lr->lr_res_error != NULL ) {
509 LDAP_FREE( lr->lr_res_error );
510 lr->lr_res_error = NULL;
516 /* All results that just return a status, i.e. don't return data
517 * go through the following code. This code also chases V2 referrals
518 * and checks if all referrals have been chased.
520 if ( (tag != LDAP_RES_SEARCH_ENTRY) && (v3ref > -1) ) {
521 /* For a v3 search referral/reference, only come here if already chased it */
522 if ( ld->ld_version >= LDAP_VERSION2 &&
523 ( lr->lr_parent != NULL ||
524 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
526 tmpber = *ber; /* struct copy */
528 ; /* V3 search reference or V3 referral sucessfully chased */
530 if ( ber_scanf( &tmpber, "{iaa}", &lderr,
531 &lr->lr_res_matched, &lr->lr_res_error )
533 if ( lderr != LDAP_SUCCESS ) {
534 /* referrals are in error string */
535 refer_cnt = ldap_chase_referrals( ld, lr,
536 &lr->lr_res_error, &hadref );
537 lr->lr_status = LDAP_REQST_COMPLETED;
538 Debug( LDAP_DEBUG_TRACE,
539 "read1msg: V2 referral chased, mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
542 /* save errno, message, and matched string */
543 if ( !hadref || lr->lr_res_error == NULL ) {
544 lr->lr_res_errno = ( lderr ==
545 LDAP_PARTIAL_RESULTS ) ? LDAP_SUCCESS
547 } else if ( ld->ld_errno != LDAP_SUCCESS ) {
548 lr->lr_res_errno = ld->ld_errno;
550 lr->lr_res_errno = LDAP_PARTIAL_RESULTS;
552 Debug( LDAP_DEBUG_TRACE,
553 "new result: res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
554 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
555 lr->lr_res_matched ? lr->lr_res_matched : "" );
559 Debug( LDAP_DEBUG_TRACE,
560 "read1msg: %d new referrals\n", refer_cnt, 0, 0 );
562 if ( refer_cnt != 0 ) { /* chasing referrals */
565 if ( refer_cnt < 0 ) {
566 return( -1 ); /* fatal error */
568 lr->lr_res_errno = LDAP_SUCCESS; /* sucessfully chased referral */
570 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
571 /* request without any referrals */
572 simple_request = ( hadref ? 0 : 1 );
574 /* request with referrals or child request */
579 lr->lr_status = LDAP_REQST_COMPLETED; /* declare this request done */
580 Debug( LDAP_DEBUG_TRACE,
581 "read1msg: mark request completed, id = %d\n", lr->lr_msgid, 0, 0);
582 while ( lr->lr_parent != NULL ) {
583 merge_error_info( ld, lr->lr_parent, lr );
586 if ( --lr->lr_outrefcnt > 0 ) {
587 break; /* not completely done yet */
591 /* Check if all requests are finished, lr is now parent */
592 for(tmplr=lr ; tmplr != NULL; tmplr=tmplr->lr_refnext) {
593 if( tmplr->lr_status != LDAP_REQST_COMPLETED) {
598 /* This is the parent request if the request has referrals */
599 if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL && tmplr == NULL ) {
601 tag = lr->lr_res_msgtype;
602 Debug( LDAP_DEBUG_ANY, "request %ld done\n",
604 Debug( LDAP_DEBUG_TRACE,
605 "res_errno: %d, res_error: <%s>, res_matched: <%s>\n",
606 lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
607 lr->lr_res_matched ? lr->lr_res_matched : "" );
608 if ( !simple_request ) {
611 if ( build_result_ber( ld, &ber, lr )
613 rc = -1; /* fatal error */
617 ldap_free_request( ld, lr );
621 ldap_free_connection( ld, lc, 0, 1 );
630 /* make a new ldap message */
631 if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
633 ld->ld_errno = LDAP_NO_MEMORY;
636 new->lm_msgid = (int)id;
637 new->lm_msgtype = tag;
641 if ( ld->ld_cache != NULL ) {
642 ldap_add_result_to_cache( ld, new );
644 #endif /* LDAP_NOCACHE */
646 /* is this the one we're looking for? */
647 if ( msgid == LDAP_RES_ANY || id == msgid ) {
648 if ( all == LDAP_MSG_ONE
649 || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
650 && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
651 && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
653 ld->ld_errno = LDAP_SUCCESS;
655 } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
656 foundit = 1; /* return the chain later */
661 * if not, we must add it to the list of responses. if
662 * the msgid is already there, it must be part of an existing
667 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
668 if ( l->lm_msgid == new->lm_msgid )
673 /* not part of an existing search response */
677 ld->ld_errno = LDAP_SUCCESS;
681 new->lm_next = ld->ld_responses;
682 ld->ld_responses = new;
683 return( -2 ); /* continue looking */
686 Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n",
687 (long) new->lm_msgid, (long) new->lm_msgtype, 0 );
689 /* part of a search response - add to end of list of entries */
690 for ( tmp = l; (tmp->lm_chain != NULL) &&
691 ((tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY) ||
692 (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) ||
693 (tmp->lm_chain->lm_msgtype == LDAP_RES_EXTENDED_PARTIAL ));
694 tmp = tmp->lm_chain )
698 /* return the whole chain if that's what we were looking for */
701 ld->ld_responses = l->lm_next;
703 prev->lm_next = l->lm_next;
705 ld->ld_errno = LDAP_SUCCESS;
706 #ifdef LDAP_WORLD_P16
708 * XXX questionable fix; see text for [P16] on
709 * http://www.critical-angle.com/ldapworld/patch/
711 * inclusion of this patch causes searchs to hang on
714 return( l->lm_msgtype );
715 #else /* LDAP_WORLD_P16 */
717 #endif /* !LDAP_WORLD_P16 */
720 return( -2 ); /* continue looking */
725 build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr )
733 ber = ldap_alloc_ber_with_options( ld );
736 ld->ld_errno = LDAP_NO_MEMORY;
740 if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
741 lr->lr_res_msgtype, lr->lr_res_errno,
742 lr->lr_res_matched ? lr->lr_res_matched : "",
743 lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
745 ld->ld_errno = LDAP_ENCODING_ERROR;
747 return( LBER_ERROR );
752 if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
753 ld->ld_errno = LDAP_DECODING_ERROR;
755 return( LBER_ERROR );
758 if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
759 ld->ld_errno = LDAP_DECODING_ERROR;
761 return( LBER_ERROR );
764 tag = ber_peek_tag( ber, &len );
766 if ( tag == LBER_ERROR ) {
767 ld->ld_errno = LDAP_DECODING_ERROR;
769 return( LBER_ERROR );
778 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
781 * Merge error information in "lr" with "parentr" error code and string.
783 if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
784 parentr->lr_res_errno = lr->lr_res_errno;
785 if ( lr->lr_res_error != NULL ) {
786 (void)ldap_append_referral( ld, &parentr->lr_res_error,
789 } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
790 parentr->lr_res_errno == LDAP_SUCCESS ) {
791 parentr->lr_res_errno = lr->lr_res_errno;
792 if ( parentr->lr_res_error != NULL ) {
793 LDAP_FREE( parentr->lr_res_error );
795 parentr->lr_res_error = lr->lr_res_error;
796 lr->lr_res_error = NULL;
797 if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
798 if ( parentr->lr_res_matched != NULL ) {
799 LDAP_FREE( parentr->lr_res_matched );
801 parentr->lr_res_matched = lr->lr_res_matched;
802 lr->lr_res_matched = NULL;
806 Debug( LDAP_DEBUG_TRACE, "merged parent (id %d) error info: ",
807 parentr->lr_msgid, 0, 0 );
808 Debug( LDAP_DEBUG_TRACE, "result errno %d, error <%s>, matched <%s>\n",
809 parentr->lr_res_errno, parentr->lr_res_error ?
810 parentr->lr_res_error : "", parentr->lr_res_matched ?
811 parentr->lr_res_matched : "" );
817 ldap_msgtype( LDAPMessage *lm )
819 assert( lm != NULL );
820 return ( lm != NULL ) ? lm->lm_msgtype : -1;
825 ldap_msgid( LDAPMessage *lm )
827 assert( lm != NULL );
829 return ( lm != NULL ) ? lm->lm_msgid : -1;
833 char * ldap_int_msgtype2str( ber_tag_t tag )
836 case LDAP_RES_ADD: return "add";
837 case LDAP_RES_BIND: return "bind";
838 case LDAP_RES_COMPARE: return "compare";
839 case LDAP_RES_DELETE: return "delete";
840 case LDAP_RES_EXTENDED: return "extended-result";
841 case LDAP_RES_EXTENDED_PARTIAL: return "extended-partial";
842 case LDAP_RES_MODIFY: return "modify";
843 case LDAP_RES_RENAME: return "rename";
844 case LDAP_RES_SEARCH_ENTRY: return "search-entry";
845 case LDAP_RES_SEARCH_REFERENCE: return "search-reference";
846 case LDAP_RES_SEARCH_RESULT: return "search-result";
852 ldap_msgfree( LDAPMessage *lm )
857 Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 );
859 for ( ; lm != NULL; lm = next ) {
861 type = lm->lm_msgtype;
862 ber_free( lm->lm_ber, 1 );
863 LDAP_FREE( (char *) lm );
870 * ldap_msgdelete - delete a message. It returns:
871 * 0 if the entire message was deleted
872 * -1 if the message was not found, or only part of it was found
875 ldap_msgdelete( LDAP *ld, int msgid )
877 LDAPMessage *lm, *prev;
879 assert( ld != NULL );
881 Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 );
884 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
885 if ( lm->lm_msgid == msgid )
894 ld->ld_responses = lm->lm_next;
896 prev->lm_next = lm->lm_next;
898 if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY )
906 * return 1 if message msgid is waiting to be abandoned, 0 otherwise
909 ldap_abandoned( LDAP *ld, ber_int_t msgid )
913 if ( ld->ld_abandoned == NULL )
916 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
917 if ( ld->ld_abandoned[i] == msgid )
925 ldap_mark_abandoned( LDAP *ld, ber_int_t msgid )
929 if ( ld->ld_abandoned == NULL )
932 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
933 if ( ld->ld_abandoned[i] == msgid )
936 if ( ld->ld_abandoned[i] == -1 )
939 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
940 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];