Lines Matching refs:ld
52 static void uncache_entry_or_req( LDAP *ld, char *dn, int msgid );
65 ldap_enable_cache( LDAP *ld, time_t timeout, ssize_t maxmem )
68 LOCK_LDAP(ld);
70 if ( ld->ld_cache == NULLLDCACHE ) {
71 if (( ld->ld_cache = (LDAPCache *)malloc( sizeof( LDAPCache )))
73 ld->ld_errno = LDAP_NO_MEMORY;
75 UNLOCK_LDAP(ld);
79 (void) memset( ld->ld_cache, 0, sizeof( LDAPCache ));
80 ld->ld_cache->lc_memused = sizeof( LDAPCache );
83 ld->ld_cache->lc_timeout = timeout;
84 ld->ld_cache->lc_maxmem = maxmem;
85 check_cache_memused( ld->ld_cache );
86 ld->ld_cache->lc_enabled = 1;
88 UNLOCK_LDAP(ld);
95 ldap_disable_cache( LDAP *ld )
98 LOCK_LDAP(ld);
100 if ( ld->ld_cache != NULLLDCACHE ) {
101 ld->ld_cache->lc_enabled = 0;
104 UNLOCK_LDAP(ld);
111 ldap_set_cache_options( LDAP *ld, unsigned int opts )
114 LOCK_LDAP(ld);
116 if ( ld->ld_cache != NULLLDCACHE ) {
117 ld->ld_cache->lc_options = opts;
120 UNLOCK_LDAP(ld);
126 ldap_destroy_cache( LDAP *ld )
129 LOCK_LDAP(ld);
131 if ( ld->ld_cache != NULLLDCACHE ) {
132 ldap_flush_cache( ld );
133 free( (char *)ld->ld_cache );
134 ld->ld_cache = NULLLDCACHE;
137 UNLOCK_LDAP(ld);
143 ldap_flush_cache( LDAP *ld )
149 LOCK_LDAP(ld);
153 if ( ld->ld_cache != NULLLDCACHE ) {
155 for ( m = ld->ld_cache->lc_requests; m != NULLMSG; m = next ) {
159 ld->ld_cache->lc_requests = NULLMSG;
163 for ( m = ld->ld_cache->lc_buckets[ i ];
168 ld->ld_cache->lc_buckets[ i ] = NULLMSG;
170 ld->ld_cache->lc_memused = sizeof( LDAPCache );
173 UNLOCK_LDAP(ld);
179 ldap_uncache_request( LDAP *ld, int msgid )
182 LOCK_LDAP(ld);
185 msgid, ld->ld_cache, 0 );
187 uncache_entry_or_req( ld, NULL, msgid );
189 UNLOCK_LDAP(ld);
195 ldap_uncache_entry( LDAP *ld, char *dn )
198 LOCK_LDAP(ld);
201 dn, ld->ld_cache, 0 );
203 uncache_entry_or_req( ld, dn, 0 );
205 UNLOCK_LDAP(ld);
211 uncache_entry_or_req( LDAP *ld,
220 dn, msgid, ld->ld_cache );
222 if ( ld->ld_cache == NULLLDCACHE ) {
228 for ( m = ld->ld_cache->lc_requests; m != NULLMSG; m = next ) {
233 ld->ld_cache->lc_requests = next;
237 ld->ld_cache->lc_memused -= msg_size( m );
247 for ( m = ld->ld_cache->lc_buckets[ i ]; m != NULLMSG;
253 ld->ld_cache->lc_buckets[ i ] = next;
257 ld->ld_cache->lc_memused -= msg_size( m );
268 add_request_to_cache( LDAP *ld, unsigned int msgtype, BerElement *request )
275 ld->ld_errno = LDAP_SUCCESS;
276 if ( ld->ld_cache == NULLLDCACHE ||
277 ( ld->ld_cache->lc_enabled == 0 )) {
283 if (( new->lm_ber = alloc_ber_with_options( ld )) == NULLBER ) {
292 ld->ld_errno = LDAP_NO_MEMORY;
298 new->lm_msgid = ld->ld_msgid;
300 new->lm_next = ld->ld_cache->lc_requests;
301 ld->ld_cache->lc_requests = new;
303 ld->ld_errno = LDAP_NO_MEMORY;
309 add_result_to_cache( LDAP *ld, LDAPMessage *result )
317 if ( ld->ld_cache == NULLLDCACHE ||
318 ( ld->ld_cache->lc_enabled == 0 )) {
341 for ( m = ld->ld_cache->lc_requests; m != NULL; m = m->lm_next ) {
366 err = ldap_result2error( ld, result, 0 );
375 if ( ld->ld_cache->lc_options == 0 ) {
379 } else if (( ld->ld_cache->lc_options &
385 ld->ld_cache->lc_requests = req->lm_next;
396 mp = &ld->ld_cache->lc_buckets[
401 ld->ld_cache->lc_memused += msg_size( req );
402 check_cache_memused( ld->ld_cache );
423 check_cache( LDAP *ld, unsigned int msgtype, BerElement *request )
432 if ( ld->ld_cache == NULLLDCACHE ||
433 ( ld->ld_cache->lc_enabled == 0 )) {
440 validtime = time( NULL ) - ld->ld_cache->lc_timeout;
444 for ( m = ld->ld_cache->lc_buckets[ hash ]; m != NULLMSG; m = next ) {
451 ld->ld_cache->lc_buckets[ hash ] = next;
457 ld->ld_cache->lc_memused -= msg_size( m );
478 LOCK_RESPONSE(ld);
483 UNLOCK_RESPONSE(ld);
488 new->lm_msgid = ld->ld_msgid;
491 new->lm_next = ld->ld_responses;
492 ld->ld_responses = new;
504 UNLOCK_RESPONSE(ld);
527 Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 107, "cache_hash: len is %1$ld, returning %2$ld\n"),
675 Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 108, "check_cache_memused: %1$ld bytes in use (%2$ld max)\n"),
710 Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 110, "ccm: reduced usage to %ld bytes\n"),