X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fresult.c;h=a47e0577e97b557058ea13bbcf557a01f6b94564;hb=9e0958d5bc342e2f35f6ee8aaa6cf179b2d55085;hp=5f9ff57cecf54c7826d90b7a5d2ab29882daaead;hpb=2cb228a9cebd2ee13b4a5e318ebb8bc295d75745;p=openldap diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index 5f9ff57cec..a47e0577e9 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -1,3 +1,4 @@ +/* $OpenLDAP$ */ /* * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file @@ -36,13 +37,13 @@ #include "ldap-int.h" -static int ldap_abandoned LDAP_P(( LDAP *ld, int msgid )); -static int ldap_mark_abandoned LDAP_P(( LDAP *ld, int msgid )); -static int wait4msg LDAP_P(( LDAP *ld, int msgid, int all, struct timeval *timeout, +static int ldap_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid )); +static int ldap_mark_abandoned LDAP_P(( LDAP *ld, ber_int_t msgid )); +static int wait4msg LDAP_P(( LDAP *ld, ber_int_t msgid, int all, struct timeval *timeout, LDAPMessage **result )); -static int try_read1msg LDAP_P(( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc, - LDAPMessage **result )); -static unsigned long build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr )); +static ber_tag_t try_read1msg LDAP_P(( LDAP *ld, ber_int_t msgid, + int all, Sockbuf *sb, LDAPConn *lc, LDAPMessage **result )); +static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr )); static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )); @@ -61,7 +62,11 @@ static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPReques * ldap_result( s, msgid, all, timeout, result ) */ int -ldap_result( LDAP *ld, int msgid, int all, struct timeval *timeout, +ldap_result( + LDAP *ld, + int msgid, + int all, + struct timeval *timeout, LDAPMessage **result ) { LDAPMessage *lm, *lastlm, *nextlm; @@ -87,15 +92,15 @@ ldap_result( LDAP *ld, int msgid, int all, struct timeval *timeout, * wait until it arrives or timeout occurs. */ - *result = NULLMSG; - lastlm = NULLMSG; - for ( lm = ld->ld_responses; lm != NULLMSG; lm = nextlm ) { + *result = NULL; + lastlm = NULL; + for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) { nextlm = lm->lm_next; if ( ldap_abandoned( ld, lm->lm_msgid ) ) { ldap_mark_abandoned( ld, lm->lm_msgid ); - if ( lastlm == NULLMSG ) { + if ( lastlm == NULL ) { ld->ld_responses = lm->lm_next; } else { lastlm->lm_next = nextlm; @@ -115,34 +120,33 @@ ldap_result( LDAP *ld, int msgid, int all, struct timeval *timeout, && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY) ) break; - for ( tmp = lm; tmp != NULLMSG; tmp = tmp->lm_chain ) { + for ( tmp = lm; tmp != NULL; tmp = tmp->lm_chain ) { if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT ) break; } - if ( tmp == NULLMSG ) { - return( wait4msg( ld, msgid, all, timeout, - result ) ); + if ( tmp == NULL ) { + lm = NULL; } break; } lastlm = lm; } - if ( lm == NULLMSG ) { + if ( lm == NULL ) { return( wait4msg( ld, msgid, all, timeout, result ) ); } - if ( lastlm == NULLMSG ) { - ld->ld_responses = (all == 0 && lm->lm_chain != NULLMSG + if ( lastlm == NULL ) { + ld->ld_responses = (all == 0 && lm->lm_chain != NULL ? lm->lm_chain : lm->lm_next); } else { - lastlm->lm_next = (all == 0 && lm->lm_chain != NULLMSG + lastlm->lm_next = (all == 0 && lm->lm_chain != NULL ? lm->lm_chain : lm->lm_next); } if ( all == 0 ) - lm->lm_chain = NULLMSG; - lm->lm_next = NULLMSG; + lm->lm_chain = NULL; + lm->lm_next = NULL; *result = lm; ld->ld_errno = LDAP_SUCCESS; @@ -150,7 +154,11 @@ ldap_result( LDAP *ld, int msgid, int all, struct timeval *timeout, } static int -wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout, +wait4msg( + LDAP *ld, + ber_int_t msgid, + int all, + struct timeval *timeout, LDAPMessage **result ) { int rc; @@ -253,26 +261,32 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout, } -static int -try_read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, - LDAPConn *lc, LDAPMessage **result ) +static ber_tag_t +try_read1msg( + LDAP *ld, + ber_int_t msgid, + int all, + Sockbuf *sb, + LDAPConn *lc, + LDAPMessage **result ) { BerElement *ber; LDAPMessage *new, *l, *prev, *tmp; - long id; - unsigned long tag, len; + ber_int_t id; + ber_tag_t tag; + ber_len_t len; int foundit = 0; LDAPRequest *lr; BerElement tmpber; int rc, refer_cnt, hadref, simple_request; - unsigned long lderr; + ber_int_t lderr; assert( ld != NULL ); assert( lc != NULL ); Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 ); - if ( lc->lconn_ber == NULLBER ) { + if ( lc->lconn_ber == NULL ) { lc->lconn_ber = ldap_alloc_ber_with_options(ld); if( lc->lconn_ber == NULL ) { @@ -309,7 +323,7 @@ try_read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, * We read a complete message. * The connection should no longer need this ber. */ - lc->lconn_ber = NULLBER; + lc->lconn_ber = NULL; /* message id */ if ( ber_get_int( ber, &id ) == LBER_ERROR ) { @@ -319,7 +333,7 @@ try_read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, } /* if it's been abandoned, toss it */ - if ( ldap_abandoned( ld, (int)id ) ) { + if ( ldap_abandoned( ld, id ) ) { ber_free( ber, 1 ); return( -2 ); /* continue looking */ } @@ -327,7 +341,7 @@ try_read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) { Debug( LDAP_DEBUG_ANY, "no request for response with msgid %ld (tossing)\n", - id, 0, 0 ); + (long) id, 0, 0 ); ber_free( ber, 1 ); return( -2 ); /* continue looking */ } @@ -339,10 +353,10 @@ try_read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, return( -1 ); } - Debug( LDAP_DEBUG_TRACE, "ldap_read: %s msgid %ld, original id %d\n", + Debug( LDAP_DEBUG_TRACE, "ldap_read: %s msgid %ld, original id %ld\n", ( tag == LDAP_RES_SEARCH_ENTRY ) ? "entry" : ( tag == LDAP_RES_SEARCH_REFERENCE ) ? "reference" : "result", - id, lr->lr_origid ); + (long) id, (long) lr->lr_origid ); id = lr->lr_origid; refer_cnt = 0; @@ -415,7 +429,7 @@ Debug( LDAP_DEBUG_TRACE, id = lr->lr_msgid; tag = lr->lr_res_msgtype; Debug( LDAP_DEBUG_ANY, "request %ld done\n", - id, 0, 0 ); + (long) id, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "res_errno: %d, res_error: <%s>, res_matched: <%s>\n", lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "", @@ -477,15 +491,15 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); * search response. */ - prev = NULLMSG; - for ( l = ld->ld_responses; l != NULLMSG; l = l->lm_next ) { + prev = NULL; + for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) { if ( l->lm_msgid == new->lm_msgid ) break; prev = l; } /* not part of an existing search response */ - if ( l == NULLMSG ) { + if ( l == NULL ) { if ( foundit ) { *result = new; ld->ld_errno = LDAP_SUCCESS; @@ -497,11 +511,11 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); return( -2 ); /* continue looking */ } - Debug( LDAP_DEBUG_TRACE, "adding response id %d type %d:\n", - new->lm_msgid, new->lm_msgtype, 0 ); + Debug( LDAP_DEBUG_TRACE, "adding response id %ld type %ld:\n", + (long) new->lm_msgid, (long) new->lm_msgtype, 0 ); /* part of a search response - add to end of list of entries */ - for ( tmp = l; tmp->lm_chain != NULLMSG && + for ( tmp = l; tmp->lm_chain != NULL && tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY; tmp = tmp->lm_chain ) ; /* NULL */ @@ -509,7 +523,7 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); /* return the whole chain if that's what we were looking for */ if ( foundit ) { - if ( prev == NULLMSG ) + if ( prev == NULL ) ld->ld_responses = l->lm_next; else prev->lm_next = l->lm_next; @@ -533,11 +547,12 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); } -static unsigned long +static ber_tag_t build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr ) { - unsigned long len, tag; - long along; + ber_len_t len; + ber_int_t tag; + ber_int_t along; BerElement *ber; *bp = NULL; @@ -549,7 +564,7 @@ build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr ) } if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid, - (unsigned long) lr->lr_res_msgtype, lr->lr_res_errno, + lr->lr_res_msgtype, lr->lr_res_errno, lr->lr_res_matched ? lr->lr_res_matched : "", lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) { @@ -651,7 +666,7 @@ ldap_msgfree( LDAPMessage *lm ) Debug( LDAP_DEBUG_TRACE, "ldap_msgfree\n", 0, 0, 0 ); - for ( ; lm != NULLMSG; lm = next ) { + for ( ; lm != NULL; lm = next ) { next = lm->lm_chain; type = lm->lm_msgtype; ber_free( lm->lm_ber, 1 ); @@ -675,17 +690,17 @@ ldap_msgdelete( LDAP *ld, int msgid ) Debug( LDAP_DEBUG_TRACE, "ldap_msgdelete\n", 0, 0, 0 ); - prev = NULLMSG; - for ( lm = ld->ld_responses; lm != NULLMSG; lm = lm->lm_next ) { + prev = NULL; + for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) { if ( lm->lm_msgid == msgid ) break; prev = lm; } - if ( lm == NULLMSG ) + if ( lm == NULL ) return( -1 ); - if ( prev == NULLMSG ) + if ( prev == NULL ) ld->ld_responses = lm->lm_next; else prev->lm_next = lm->lm_next; @@ -701,7 +716,7 @@ ldap_msgdelete( LDAP *ld, int msgid ) * return 1 if message msgid is waiting to be abandoned, 0 otherwise */ static int -ldap_abandoned( LDAP *ld, int msgid ) +ldap_abandoned( LDAP *ld, ber_int_t msgid ) { int i; @@ -717,7 +732,7 @@ ldap_abandoned( LDAP *ld, int msgid ) static int -ldap_mark_abandoned( LDAP *ld, int msgid ) +ldap_mark_abandoned( LDAP *ld, ber_int_t msgid ) { int i; @@ -743,11 +758,19 @@ ldap_mark_abandoned( LDAP *ld, int msgid ) int cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber ) { - int rc; - unsigned long tag, len; + int rc; + ber_tag_t tag; + ber_len_t len; if ( ! ber_pvt_sb_data_ready(&ld->ld_sb) ) { - rc = ldap_select1( ld, timeout ); + /* restored from ldap_select1() in result.c version 1.24 */ + fd_set readfds; + if ( ldap_int_tblsize == 0 ) + ldap_int_ip_init(); + FD_ZERO( &readfds ); + FD_SET( ber_pvt_sb_get_desc(&ld->ld_sb), &readfds ); + rc = select( ldap_int_tblsize, &readfds, 0, 0, timeout ); + if ( rc == -1 || rc == 0 ) { ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN : LDAP_TIMEOUT); @@ -763,6 +786,6 @@ cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber ) return( -1 ); } - return( tag ); + return( 0 ); } #endif /* LDAP_CONNECTIONLESS */