X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fresult.c;h=8b03df7697467b60834a69e9bf494f154526892f;hb=c8e37af0ca8302c276e8c6af84eca4f926171261;hp=8fa906c57a280009dbc24fbcaf18ecd8cc3491b9;hpb=fde9d8702e2ec5537153713cdd2749e585fd5816;p=openldap diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index 8fa906c57a..8b03df7697 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -36,13 +36,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 +61,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 +91,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 +119,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 +153,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 +260,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 +322,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 +332,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 */ } @@ -477,15 +490,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; @@ -501,7 +514,7 @@ lr->lr_res_matched ? lr->lr_res_matched : "" ); new->lm_msgid, 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 +522,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,25 +546,29 @@ 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; - ber = *bp = ldap_alloc_ber_with_options( ld ); + *bp = NULL; + ber = ldap_alloc_ber_with_options( ld ); if( ber == NULL ) { + ld->ld_errno = LDAP_NO_MEMORY; return LBER_ERROR; } 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 ) { ld->ld_errno = LDAP_ENCODING_ERROR; + ber_free(ber, 1); return( LBER_ERROR ); } @@ -559,11 +576,13 @@ build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr ) if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; + ber_free(ber, 1); return( LBER_ERROR ); } if ( ber_get_int( ber, &along ) == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; + ber_free(ber, 1); return( LBER_ERROR ); } @@ -571,9 +590,11 @@ build_result_ber( LDAP *ld, BerElement **bp, LDAPRequest *lr ) if ( tag == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; + ber_free(ber, 1); return( LBER_ERROR ); } + *bp = ber; return tag; } @@ -644,7 +665,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 ); @@ -668,17 +689,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; @@ -694,7 +715,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; @@ -710,7 +731,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; @@ -736,8 +757,9 @@ 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 ); @@ -756,6 +778,6 @@ cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber ) return( -1 ); } - return( tag ); + return( 0 ); } #endif /* LDAP_CONNECTIONLESS */