]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/cache.c
Update dn2domain to use str2dn() not explode_dn()
[openldap] / libraries / libldap / cache.c
index ccfc763092d3973aac0e8100edb35cceeb2ccba9..f071ab6255e02fe9ad97db17f6d3923bddaf5dcf 100644 (file)
@@ -37,6 +37,9 @@ static void           uncache_entry_or_req LDAP_P(( LDAP *ld, LDAP_CONST char *dn, ber_in
 int
 ldap_enable_cache( LDAP *ld, long timeout, ber_len_t maxmem )
 {
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifndef LDAP_NOCACHE
        if ( ld->ld_cache == NULL ) {
                if (( ld->ld_cache = (LDAPCache *)LDAP_MALLOC( sizeof( LDAPCache )))
@@ -62,6 +65,9 @@ ldap_enable_cache( LDAP *ld, long timeout, ber_len_t maxmem )
 void
 ldap_disable_cache( LDAP *ld )
 {
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifndef LDAP_NOCACHE
        if ( ld->ld_cache != NULL ) {
                ld->ld_cache->lc_enabled = 0;
@@ -74,6 +80,9 @@ ldap_disable_cache( LDAP *ld )
 void
 ldap_set_cache_options( LDAP *ld, unsigned long opts )
 {
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifndef LDAP_NOCACHE
        if ( ld->ld_cache != NULL ) {
                ld->ld_cache->lc_options = opts;
@@ -85,6 +94,9 @@ ldap_set_cache_options( LDAP *ld, unsigned long opts )
 void
 ldap_destroy_cache( LDAP *ld )
 {
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifndef LDAP_NOCACHE
        if ( ld->ld_cache != NULL ) {
                ldap_flush_cache( ld );
@@ -102,8 +114,11 @@ ldap_flush_cache( LDAP *ld )
        int             i;
        LDAPMessage     *m, *next;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ENTRY, "ldap_flush_cache\n" ));
+       LDAP_LOG ( CACHE, ENTRY, "ldap_flush_cache\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_flush_cache\n", 0, 0, 0 );
 #endif
@@ -134,11 +149,14 @@ ldap_flush_cache( LDAP *ld )
 void
 ldap_uncache_request( LDAP *ld, int msgid )
 {
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifndef LDAP_NOCACHE
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, 
-               "ldap_uncache_request %d ld_cache %lx\n",
-               msgid, (long) ld->ld_cache ));
+
+       LDAP_LOG ( CACHE, ARGS, "ldap_uncache_request %d ld_cache %lx\n",
+               msgid, (long) ld->ld_cache, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_uncache_request %d ld_cache %lx\n",
            msgid, (long) ld->ld_cache, 0 );
@@ -152,11 +170,15 @@ ldap_uncache_request( LDAP *ld, int msgid )
 void
 ldap_uncache_entry( LDAP *ld, LDAP_CONST char *dn )
 {
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( dn != NULL );
+
 #ifndef LDAP_NOCACHE
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, 
-               "ldap_uncache_entry %s ld_cache %lx\n",
-               dn, (long) ld->ld_cache ));
+
+       LDAP_LOG ( CACHE, ARGS, "ldap_uncache_entry %s ld_cache %lx\n",
+               dn, (long) ld->ld_cache, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_uncache_entry %s ld_cache %lx\n",
            dn, (long) ld->ld_cache, 0 );
@@ -178,9 +200,10 @@ uncache_entry_or_req( LDAP *ld,
        LDAPMessage     *m, *prev, *next;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, 
+
+       LDAP_LOG ( CACHE, ARGS, 
                "uncache_entry_or_req dn %s msgid %ld ld_cache %lx\n",
-               dn, (long) msgid, (long) ld->ld_cache ));
+               dn, (long) msgid, (long) ld->ld_cache );
 #else
        Debug( LDAP_DEBUG_TRACE,
            "ldap_uncache_entry_or_req  dn %s  msgid %ld  ld_cache %lx\n",
@@ -240,8 +263,11 @@ ldap_add_request_to_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request )
        LDAPMessage     *new;
        ber_len_t       len;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ENTRY, "ldap_add_request_to_cache\n" ));
+       LDAP_LOG ( CACHE, ENTRY, "ldap_add_request_to_cache\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_add_request_to_cache\n", 0, 0, 0 );
 #endif
@@ -288,10 +314,15 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
        LDAPMessage     *m, **mp, *req, *new, *prev;
        int             err, keep;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( result != NULL );
+
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ARGS, 
+
+       LDAP_LOG ( CACHE, ARGS, 
                "ldap_add_result_to_cache: id %ld, type %ld\n",
-               (long) result->lm_msgid, (long) result->lm_msgtype ));
+               (long) result->lm_msgid, (long) result->lm_msgtype, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_add_result_to_cache: id %ld, type %ld\n", 
                (long) result->lm_msgid, (long) result->lm_msgtype, 0 );
@@ -300,8 +331,8 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
        if ( ld->ld_cache == NULL ||
            ( ld->ld_cache->lc_enabled == 0 )) {
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
-               "ldap_add_result_to_cache: cache disabled\n" ));
+               LDAP_LOG ( CACHE, DETAIL1, 
+                       "ldap_add_result_to_cache: cache disabled\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "artc: cache disabled\n", 0, 0, 0 );
 #endif
@@ -316,9 +347,9 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
                 * only cache search and compare operations
                 */
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
-               "ldap_add_result_to_cache: "
-               "only caching search & compare operations\n" ));
+               LDAP_LOG ( CACHE, DETAIL1, 
+                       "ldap_add_result_to_cache: only caching search & "
+                       "compare operations\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "artc: only caching search & compare operations\n", 0, 0, 0 );
@@ -347,9 +378,9 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
                        new->lm_chain = NULL;
                        m->lm_chain = new;
 #ifdef NEW_LOGGING
-                       LDAP_LOG (( "cache", LDAP_LEVEL_RESULTS, 
+                       LDAP_LOG ( CACHE, RESULTS, 
                                "ldap_add_result_to_cache: "
-                               "result added to cache request chain\n" ));
+                               "result added to cache request chain\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                            "artc: result added to cache request chain\n",
@@ -389,9 +420,9 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
 
                        if ( !keep ) {
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "cache", LDAP_LEVEL_RESULTS, 
+                               LDAP_LOG ( CACHE, RESULTS, 
                                        "ldap_add_result_to_cache: "
-                                       "not caching result with error\n" ));
+                                       "not caching result with error\n", 0, 0, 0 );
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                    "artc: not caching result with error %d\n",
@@ -407,9 +438,9 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
                                ld->ld_cache->lc_memused += msg_size( req );
                                check_cache_memused( ld->ld_cache );
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "cache", LDAP_LEVEL_RESULTS, 
+                               LDAP_LOG ( CACHE, RESULTS, 
                                        "ldap_add_result_to_cache: "
-                                       "cached result with error\n" ));
+                                       "cached result with error\n", 0, 0, 0 );
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                    "artc: cached result with error %d\n",
@@ -419,9 +450,8 @@ ldap_add_result_to_cache( LDAP *ld, LDAPMessage *result )
                }
        } else {
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "cache", LDAP_LEVEL_RESULTS, 
-                       "ldap_add_result_to_cache: "
-                       "msgid not in request list\n" ));
+               LDAP_LOG ( CACHE, RESULTS, 
+                       "ldap_add_result_to_cache: msgid not in request list\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "artc: msgid not in request list\n",
                    0, 0, 0 );
@@ -447,8 +477,12 @@ ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request )
        int             first, hash;
        time_t  c_time;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( request != NULL );
+
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_ENTRY, "ldap_check_cache\n" ));
+       LDAP_LOG ( CACHE, ENTRY, "ldap_check_cache\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ldap_check_cache\n", 0, 0, 0 );
 #endif
@@ -470,9 +504,9 @@ ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request )
        hash = cache_hash( &reqber );
        for ( m = ld->ld_cache->lc_buckets[ hash ]; m != NULL; m = next ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
+               LDAP_LOG ( CACHE, DETAIL1, 
                        "ldap_check_cache: examining id %ld, type %ld\n",
-                       (long) m->lm_msgid, (long) m->lm_msgtype ));
+                       (long) m->lm_msgid, (long) m->lm_msgtype, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,"cc: examining id %ld,type %ld\n",
                    (long) m->lm_msgid, (long) m->lm_msgtype, 0 );
@@ -486,9 +520,8 @@ ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request )
                                prev->lm_next = next;
                        }
 #ifdef NEW_LOGGING
-                       LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
-                               "ldap_check_cache: expired id %ld\n",
-                               (long) m->lm_msgid ));
+                       LDAP_LOG ( CACHE, DETAIL1, "ldap_check_cache: expired id %ld\n",
+                               (long) m->lm_msgid, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "cc: expired id %d\n",
                            m->lm_msgid, 0, 0 );
@@ -529,9 +562,8 @@ ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request )
                }
                prev = new;
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
-                       "ldap_check_cache: added type %ld\n",
-                       (long) m->lm_msgtype ));
+               LDAP_LOG ( CACHE, DETAIL1, "ldap_check_cache: added type %ld\n",
+                       (long) m->lm_msgtype, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "cc: added type %ld\n",
                    (long) new->lm_msgtype, 0, 0 );
@@ -539,8 +571,8 @@ ldap_check_cache( LDAP *ld, ber_tag_t msgtype, BerElement *request )
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_RESULTS, 
-               "ldap_check_cache: result returned from cache\n" ));
+       LDAP_LOG ( CACHE, RESULTS, 
+               "ldap_check_cache: result returned from cache\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "cc: result returned from cache\n", 0, 0, 0 );
 #endif
@@ -570,9 +602,8 @@ cache_hash( BerElement *ber )
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_RESULTS, 
-               "cache_hash: len is %ld, returning %ld\n",
-                len, len % LDAP_CACHE_BUCKETS ));
+       LDAP_LOG ( CACHE, RESULTS, "cache_hash: len is %ld, returning %ld\n",
+               len, len % LDAP_CACHE_BUCKETS, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "cache_hash: len is %ld, returning %ld\n",
            len, len % LDAP_CACHE_BUCKETS, 0 );
@@ -727,9 +758,9 @@ check_cache_memused( LDAPCache *lc )
        LDAPMessage     *m, *prev, *next;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
+       LDAP_LOG ( CACHE, DETAIL1, 
                "check_cache_memused: %ld bytes in use (%ld max)\n",
-                lc->lc_memused, lc->lc_maxmem ));
+               lc->lc_memused, lc->lc_maxmem, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "check_cache_memused: %ld bytes in use (%ld max)\n",
            lc->lc_memused, lc->lc_maxmem, 0 );
@@ -756,9 +787,8 @@ check_cache_memused( LDAPCache *lc )
                                        }
                                        lc->lc_memused -= msg_size( m );
 #ifdef NEW_LOGGING
-                                       LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
-                                               "check_cache_memused: removed %ld\n",
-                                               m->lm_msgid ));
+                                       LDAP_LOG ( CACHE, DETAIL1, 
+                                               "check_cache_memused: removed %ld\n", m->lm_msgid,0,0 );
 #else
                                        Debug( LDAP_DEBUG_TRACE,
                                            "ccm: removed %d\n",
@@ -774,9 +804,9 @@ check_cache_memused( LDAPCache *lc )
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "cache", LDAP_LEVEL_DETAIL1, 
-               "check_cache_memused: reduced usage to %ld bytes\n",
-               lc->lc_memused ));
+       LDAP_LOG ( CACHE, DETAIL1, 
+               "check_cache_memused: reduced usage to %ld bytes\n", 
+               lc->lc_memused, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "ccm: reduced usage to %ld bytes\n",
            lc->lc_memused, 0, 0 );