X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fcache.c;h=43feaadbd4930105b9a7761bcc852405f11276f1;hb=f3880e56334b477054b3a0049aa4fbb69632a1ca;hp=d70ebd306ebe8ef1ffd395a698d425eb5b58480a;hpb=1bcec8bf6a17a65396b2c947faed846d20428db9;p=openldap diff --git a/libraries/libldap/cache.c b/libraries/libldap/cache.c index d70ebd306e..43feaadbd4 100644 --- a/libraries/libldap/cache.c +++ b/libraries/libldap/cache.c @@ -12,7 +12,8 @@ #include "portable.h" #include -#include + +#include #include #include @@ -26,19 +27,19 @@ static int cache_hash LDAP_P(( BerElement *ber )); static LDAPMessage *msg_dup LDAP_P(( LDAPMessage *msg )); static int request_cmp LDAP_P(( BerElement *req1, BerElement *req2 )); static int chain_contains_dn LDAP_P(( LDAPMessage *msg, LDAP_CONST char *dn )); -static long msg_size LDAP_P(( LDAPMessage *msg )); +static ber_len_t msg_size LDAP_P(( LDAPMessage *msg )); static void check_cache_memused LDAP_P(( LDAPCache *lc )); -static void uncache_entry_or_req LDAP_P(( LDAP *ld, LDAP_CONST char *dn, int msgid )); +static void uncache_entry_or_req LDAP_P(( LDAP *ld, LDAP_CONST char *dn, ber_int_t msgid )); #endif int -ldap_enable_cache( LDAP *ld, long timeout, long maxmem ) +ldap_enable_cache( LDAP *ld, long timeout, ber_len_t maxmem ) { #ifndef LDAP_NOCACHE - if ( ld->ld_cache == NULLLDCACHE ) { + if ( ld->ld_cache == NULL ) { if (( ld->ld_cache = (LDAPCache *)LDAP_MALLOC( sizeof( LDAPCache ))) - == NULLLDCACHE ) { + == NULL ) { ld->ld_errno = LDAP_NO_MEMORY; return( -1 ); } @@ -61,7 +62,7 @@ void ldap_disable_cache( LDAP *ld ) { #ifndef LDAP_NOCACHE - if ( ld->ld_cache != NULLLDCACHE ) { + if ( ld->ld_cache != NULL ) { ld->ld_cache->lc_enabled = 0; } #endif @@ -73,7 +74,7 @@ void ldap_set_cache_options( LDAP *ld, unsigned long opts ) { #ifndef LDAP_NOCACHE - if ( ld->ld_cache != NULLLDCACHE ) { + if ( ld->ld_cache != NULL ) { ld->ld_cache->lc_options = opts; } #endif @@ -84,10 +85,10 @@ void ldap_destroy_cache( LDAP *ld ) { #ifndef LDAP_NOCACHE - if ( ld->ld_cache != NULLLDCACHE ) { + if ( ld->ld_cache != NULL ) { ldap_flush_cache( ld ); LDAP_FREE( (char *)ld->ld_cache ); - ld->ld_cache = NULLLDCACHE; + ld->ld_cache = NULL; } #endif } @@ -102,22 +103,22 @@ ldap_flush_cache( LDAP *ld ) Debug( LDAP_DEBUG_TRACE, "ldap_flush_cache\n", 0, 0, 0 ); - if ( ld->ld_cache != NULLLDCACHE ) { + if ( ld->ld_cache != NULL ) { /* delete all requests in the queue */ - for ( m = ld->ld_cache->lc_requests; m != NULLMSG; m = next ) { + for ( m = ld->ld_cache->lc_requests; m != NULL; m = next ) { next = m->lm_next; ldap_msgfree( m ); } - ld->ld_cache->lc_requests = NULLMSG; + ld->ld_cache->lc_requests = NULL; /* delete all messages in the cache */ for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) { for ( m = ld->ld_cache->lc_buckets[ i ]; - m != NULLMSG; m = next ) { + m != NULL; m = next ) { next = m->lm_next; ldap_msgfree( m ); } - ld->ld_cache->lc_buckets[ i ] = NULLMSG; + ld->ld_cache->lc_buckets[ i ] = NULL; } ld->ld_cache->lc_memused = sizeof( LDAPCache ); } @@ -154,26 +155,26 @@ ldap_uncache_entry( LDAP *ld, LDAP_CONST char *dn ) static void uncache_entry_or_req( LDAP *ld, const char *dn, /* if non-NULL, uncache entry */ - int msgid ) /* request to uncache (if dn == NULL) */ + ber_int_t msgid ) /* request to uncache (if dn == NULL) */ { int i; LDAPMessage *m, *prev, *next; Debug( LDAP_DEBUG_TRACE, - "ldap_uncache_entry_or_req dn %s msgid %d ld_cache %lx\n", - dn, msgid, (long) ld->ld_cache ); + "ldap_uncache_entry_or_req dn %s msgid %ld ld_cache %lx\n", + dn, (long) msgid, (long) ld->ld_cache ); - if ( ld->ld_cache == NULLLDCACHE ) { + if ( ld->ld_cache == NULL ) { return; } /* first check the request queue */ - prev = NULLMSG; - for ( m = ld->ld_cache->lc_requests; m != NULLMSG; m = next ) { + prev = NULL; + for ( m = ld->ld_cache->lc_requests; m != NULL; m = next ) { next = m->lm_next; if (( dn != NULL && chain_contains_dn( m, dn )) || ( dn == NULL && m->lm_msgid == msgid )) { - if ( prev == NULLMSG ) { + if ( prev == NULL ) { ld->ld_cache->lc_requests = next; } else { prev->lm_next = next; @@ -187,13 +188,13 @@ uncache_entry_or_req( LDAP *ld, /* now check the rest of the cache */ for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) { - prev = NULLMSG; - for ( m = ld->ld_cache->lc_buckets[ i ]; m != NULLMSG; + prev = NULL; + for ( m = ld->ld_cache->lc_buckets[ i ]; m != NULL; m = next ) { next = m->lm_next; if (( dn != NULL && chain_contains_dn( m, dn )) || ( dn == NULL && m->lm_msgid == msgid )) { - if ( prev == NULLMSG ) { + if ( prev == NULL ) { ld->ld_cache->lc_buckets[ i ] = next; } else { prev->lm_next = next; @@ -210,23 +211,23 @@ uncache_entry_or_req( LDAP *ld, #endif void -ldap_add_request_to_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) +ldap_add_request_to_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request ) { #ifndef LDAP_NOCACHE LDAPMessage *new; - long len; + ber_len_t len; Debug( LDAP_DEBUG_TRACE, "ldap_add_request_to_cache\n", 0, 0, 0 ); ld->ld_errno = LDAP_SUCCESS; - if ( ld->ld_cache == NULLLDCACHE || + if ( ld->ld_cache == NULL || ( ld->ld_cache->lc_enabled == 0 )) { return; } if (( new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) )) != NULL ) { - if (( new->lm_ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) { + if (( new->lm_ber = ldap_alloc_ber_with_options( ld )) == NULL ) { LDAP_FREE( (char *)new ); return; } @@ -260,10 +261,10 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result ) LDAPMessage *m, **mp, *req, *new, *prev; int err, keep; - Debug( LDAP_DEBUG_TRACE, "ldap_add_result_to_cache: id %d, type %d\n", - result->lm_msgid, result->lm_msgtype, 0 ); + Debug( LDAP_DEBUG_TRACE, "ldap_add_result_to_cache: id %ld, type %ld\n", + (long) result->lm_msgid, (long) result->lm_msgtype, 0 ); - if ( ld->ld_cache == NULLLDCACHE || + if ( ld->ld_cache == NULL || ( ld->ld_cache->lc_enabled == 0 )) { Debug( LDAP_DEBUG_TRACE, "artc: cache disabled\n", 0, 0, 0 ); return; @@ -286,7 +287,7 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result ) * result to it. if this result completes the results for the * request, add the request/result chain to the cache proper. */ - prev = NULLMSG; + prev = NULL; for ( m = ld->ld_cache->lc_requests; m != NULL; m = m->lm_next ) { if ( m->lm_msgid == result->lm_msgid ) { break; @@ -294,12 +295,12 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result ) prev = m; } - if ( m != NULLMSG ) { /* found request; add to end of chain */ + if ( m != NULL ) { /* found request; add to end of chain */ req = m; - for ( ; m->lm_chain != NULLMSG; m = m->lm_chain ) + for ( ; m->lm_chain != NULL; m = m->lm_chain ) ; - if (( new = msg_dup( result )) != NULLMSG ) { - new->lm_chain = NULLMSG; + if (( new = msg_dup( result )) != NULL ) { + new->lm_chain = NULL; m->lm_chain = new; Debug( LDAP_DEBUG_TRACE, "artc: result added to cache request chain\n", @@ -330,7 +331,7 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result ) keep = 1; } - if ( prev == NULLMSG ) { + if ( prev == NULL ) { ld->ld_cache->lc_requests = req->lm_next; } else { prev->lm_next = req->lm_next; @@ -370,7 +371,7 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result ) * will find them. */ int -ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) +ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request ) { #ifndef LDAP_NOCACHE LDAPMessage *m, *new, *prev, *next; @@ -380,7 +381,7 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) Debug( LDAP_DEBUG_TRACE, "ldap_check_cache\n", 0, 0, 0 ); - if ( ld->ld_cache == NULLLDCACHE || + if ( ld->ld_cache == NULL || ( ld->ld_cache->lc_enabled == 0 )) { return( -1 ); } @@ -390,11 +391,11 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) c_time = time( NULL ); - prev = NULLMSG; + prev = NULL; hash = cache_hash( &reqber ); - for ( m = ld->ld_cache->lc_buckets[ hash ]; m != NULLMSG; m = next ) { - Debug( LDAP_DEBUG_TRACE,"cc: examining id %d,type %d\n", - m->lm_msgid, m->lm_msgtype, 0 ); + for ( m = ld->ld_cache->lc_buckets[ hash ]; m != NULL; m = next ) { + Debug( LDAP_DEBUG_TRACE,"cc: examining id %ld,type %ld\n", + (long) m->lm_msgid, (long) m->lm_msgtype, 0 ); if ( difftime(c_time, m->lm_time) > ld->ld_cache->lc_timeout ) { /* delete expired message */ next = m->lm_next; @@ -417,7 +418,7 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) } } - if ( m == NULLMSG ) { + if ( m == NULL ) { return( -1 ); } @@ -425,13 +426,13 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) * add duplicates of responses to incoming queue */ first = 1; - for ( m = m->lm_chain; m != NULLMSG; m = m->lm_chain ) { - if (( new = msg_dup( m )) == NULLMSG ) { + for ( m = m->lm_chain; m != NULL; m = m->lm_chain ) { + if (( new = msg_dup( m )) == NULL ) { return( -1 ); } new->lm_msgid = ld->ld_msgid; - new->lm_chain = NULLMSG; + new->lm_chain = NULL; if ( first ) { new->lm_next = ld->ld_responses; ld->ld_responses = new; @@ -440,8 +441,8 @@ ldap_check_cache( LDAP *ld, unsigned long msgtype, BerElement *request ) prev->lm_chain = new; } prev = new; - Debug( LDAP_DEBUG_TRACE, "cc: added type %d\n", - new->lm_msgtype, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "cc: added type %ld\n", + (long) new->lm_msgtype, 0, 0 ); } Debug( LDAP_DEBUG_TRACE, "cc: result returned from cache\n", 0, 0, 0 ); @@ -457,7 +458,7 @@ static int cache_hash( BerElement *ber ) { BerElement bercpy; - unsigned long len; + ber_len_t len; /* * just take the length of the packet and mod with # of buckets @@ -480,20 +481,20 @@ static LDAPMessage * msg_dup( LDAPMessage *msg ) { LDAPMessage *new; - long len; + ber_len_t len; if (( new = (LDAPMessage *)LDAP_MALLOC( sizeof(LDAPMessage))) != NULL ) { *new = *msg; /* struct copy */ - if (( new->lm_ber = ber_dup( msg->lm_ber )) == NULLBER ) { + if (( new->lm_ber = ber_dup( msg->lm_ber )) == NULL ) { LDAP_FREE( (char *)new ); - return( NULLMSG ); + return( NULL ); } len = msg->lm_ber->ber_end - msg->lm_ber->ber_buf; if (( new->lm_ber->ber_buf = (char *) ber_memalloc( (size_t)len )) == NULL ) { ber_free( new->lm_ber, 0 ); LDAP_FREE( (char *)new ); - return( NULLMSG ); + return( NULL ); } SAFEMEMCPY( new->lm_ber->ber_buf, msg->lm_ber->ber_buf, (size_t)len ); @@ -509,7 +510,7 @@ msg_dup( LDAPMessage *msg ) static int request_cmp( BerElement *req1, BerElement *req2 ) { - unsigned long len; + ber_len_t len; BerElement r1, r2; r1 = *req1; /* struct copies */ @@ -531,7 +532,7 @@ request_cmp( BerElement *req1, BerElement *req2 ) * check remaining length and bytes if necessary */ if (( len = r1.ber_end - r1.ber_ptr ) != - (unsigned long) (r2.ber_end - r2.ber_ptr) ) + (ber_len_t) (r2.ber_end - r2.ber_ptr) ) { return( -1 ); /* different lengths */ } @@ -544,7 +545,7 @@ chain_contains_dn( LDAPMessage *msg, const char *dn ) { LDAPMessage *m; BerElement ber; - long msgid; + ber_int_t msgid; char *s; int rc; @@ -553,7 +554,7 @@ chain_contains_dn( LDAPMessage *msg, const char *dn ) * first check the base or dn of the request */ ber = *msg->lm_ber; /* struct copy */ - if ( ber_scanf( &ber, "{i{a", &msgid, &s ) != LBER_ERROR ) { + if ( ber_scanf( &ber, "{i{a" /*}}*/, &msgid, &s ) != LBER_ERROR ) { rc = ( strcasecmp( dn, s ) == 0 ) ? 1 : 0; LDAP_FREE( s ); if ( rc != 0 ) { @@ -569,12 +570,12 @@ chain_contains_dn( LDAPMessage *msg, const char *dn ) * now check the dn of each search result */ rc = 0; - for ( m = msg->lm_chain; m != NULLMSG && rc == 0 ; m = m->lm_chain ) { + for ( m = msg->lm_chain; m != NULL && rc == 0 ; m = m->lm_chain ) { if ( m->lm_msgtype != LDAP_RES_SEARCH_ENTRY ) { continue; } ber = *m->lm_ber; /* struct copy */ - if ( ber_scanf( &ber, "{a", &s ) != LBER_ERROR ) { + if ( ber_scanf( &ber, "{a" /*}*/, &s ) != LBER_ERROR ) { rc = ( strcasecmp( dn, s ) == 0 ) ? 1 : 0; LDAP_FREE( s ); } @@ -584,14 +585,14 @@ chain_contains_dn( LDAPMessage *msg, const char *dn ) } -static long +static ber_len_t msg_size( LDAPMessage *msg ) { LDAPMessage *m; - long size; + ber_len_t size; size = 0; - for ( m = msg; m != NULLMSG; m = m->lm_chain ) { + for ( m = msg; m != NULL; m = m->lm_chain ) { size += ( sizeof( LDAPMessage ) + m->lm_ber->ber_end - m->lm_ber->ber_buf ); } @@ -633,12 +634,12 @@ check_cache_memused( LDAPCache *lc ) while ( lc->lc_memused > lc->lc_maxmem * SIZE_FACTOR ) { c_time = time( NULL ); for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) { - prev = NULLMSG; - for ( m = lc->lc_buckets[ i ]; m != NULLMSG; + prev = NULL; + for ( m = lc->lc_buckets[ i ]; m != NULL; m = next ) { next = m->lm_next; if ( difftime(c_time, m->lm_time) > remove_threshold) { - if ( prev == NULLMSG ) { + if ( prev == NULL ) { lc->lc_buckets[ i ] = next; } else { prev->lm_next = next;