~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/auth/auth-cache.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2004-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2004-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "auth-common.h"
4
4
#include "lib-signals.h"
12
12
#include <time.h>
13
13
 
14
14
struct auth_cache {
15
 
        struct hash_table *hash;
 
15
        HASH_TABLE(char *, struct auth_cache_node *) hash;
16
16
        struct auth_cache_node *head, *tail;
17
17
 
18
 
        size_t size_left;
 
18
        size_t max_size, size_left;
19
19
        unsigned int ttl_secs, neg_ttl_secs;
20
20
 
21
21
        unsigned int hit_count, miss_count;
178
178
static void
179
179
auth_cache_node_destroy(struct auth_cache *cache, struct auth_cache_node *node)
180
180
{
 
181
        char *key = node->data;
 
182
 
181
183
        auth_cache_node_unlink(cache, node);
182
184
 
183
185
        cache->size_left += node->alloc_size;
184
 
        hash_table_remove(cache->hash, node->data);
 
186
        hash_table_remove(cache->hash, key);
185
187
        i_free(node);
186
188
}
187
189
 
197
199
{
198
200
        struct auth_cache *cache = context;
199
201
        unsigned int total_count;
 
202
        size_t cache_used;
200
203
 
201
204
        total_count = cache->hit_count + cache->miss_count;
202
205
        i_info("Authentication cache hits %u/%u (%u%%)",
204
207
               total_count == 0 ? 100 : (cache->hit_count * 100 / total_count));
205
208
 
206
209
        i_info("Authentication cache inserts: "
207
 
               "positive: %u %lluB, negative: %u %lluB",
 
210
               "positive: %u entries %llu bytes, "
 
211
               "negative: %u entries %llu bytes",
208
212
               cache->pos_entries, cache->pos_size,
209
213
               cache->neg_entries, cache->neg_size);
210
214
 
 
215
        cache_used = cache->max_size - cache->size_left;
 
216
        i_info("Authentication cache current size: "
 
217
               "%"PRIuSIZE_T" bytes used of %"PRIuSIZE_T" bytes (%u%%)",
 
218
               cache_used, cache->max_size,
 
219
               (unsigned int)(cache_used * 100ULL / cache->max_size));
 
220
 
211
221
        /* reset counters */
212
222
        cache->hit_count = cache->miss_count = 0;
213
223
        cache->pos_entries = cache->neg_entries = 0;
221
231
        struct auth_cache *cache;
222
232
 
223
233
        cache = i_new(struct auth_cache, 1);
224
 
        cache->hash = hash_table_create(default_pool, default_pool, 0, str_hash,
225
 
                                        (hash_cmp_callback_t *)strcmp);
 
234
        hash_table_create(&cache->hash, default_pool, 0, str_hash, strcmp);
 
235
        cache->max_size = max_size;
226
236
        cache->size_left = max_size;
227
237
        cache->ttl_secs = ttl_secs;
228
238
        cache->neg_ttl_secs = neg_ttl_secs;
386
396
{
387
397
        struct auth_cache_node *node;
388
398
        size_t data_size, alloc_size, key_len, value_len = strlen(value);
389
 
        char *current_username;
 
399
        char *hash_key, *current_username;
390
400
 
391
401
        if (*value == '\0' && cache->neg_ttl_secs == 0) {
392
402
                /* we're not caching negative entries */
430
440
        auth_cache_node_link_head(cache, node);
431
441
 
432
442
        cache->size_left -= alloc_size;
433
 
        hash_table_insert(cache->hash, node->data, node);
 
443
        hash_key = node->data;
 
444
        hash_table_insert(cache->hash, hash_key, node);
434
445
 
435
446
        if (*value != '\0') {
436
447
                cache->pos_entries++;