blob: da5fde0f52a65b7c71f6343215840145c427bd6b [file] [log] [blame]
Willy Tarreau51041c72007-09-09 21:56:53 +02001#ifndef SESSION_HASH_H
2#define SESSION_HASH_H
3
4/*
5 * HashTable functions.
6 *
7 * Copyright 2007 Arnaud Cornet
8 *
9 * This file is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License, version 2.1 as published by the Free Software Foundation.
12 *
13 */
14
15#include <common/appsession.h>
16
17#ifndef TABLESHIFT
18#define TABLESHIFT 11
19#endif
20#define TABLESIZE (1UL << TABLESHIFT)
21#define TABLEMASK (TABLESIZE - 1)
22
23/*
24 * quick and dirty AppSession hash table, using sessid as key
25 */
26
27struct appsession_hash
28{
29 struct list *table;
30 void (*destroy)(appsess *);
31};
32
33unsigned int appsession_hash_f(char *);
34int appsession_hash_init(struct appsession_hash *hash,
35 void(*destroy)(appsess*));
36void appsession_hash_insert(struct appsession_hash *hash,
37 struct appsessions *session);
38struct appsessions *appsession_hash_lookup(struct appsession_hash *hash,
39 char *key);
40void appsession_hash_remove(struct appsession_hash *hash,
41 struct appsessions *session);
42
43void appsession_hash_destroy(struct appsession_hash *hash);
44#if defined(DEBUG_HASH)
45void appsession_hash_dump(struct appsession_hash *hash);
46#endif
47
48/*
49 * Iterates <item> through a hashtable of items of type "typeof(*item)"
50 * A pointer to the appsession_hash is passed in <hash>. The hash table
51 * internaly uses <list_head> member of the struct. A temporary variable <back>
52 * of same type as <item> is needed so that <item> may safely be deleted if
53 * needed. <idx> is a variable containing <item>'s current bucket index in the
54 * hash table.
55 * Example: as_hash_for_each_entry_safe(idx, item, tmp, &hash, hash_list)
56 * { ... }
57 */
58#define as_hash_for_each_entry_safe(idx, item, back, hash, member) \
59 for (idx = 0; idx < TABLESIZE; idx++) \
60 list_for_each_entry_safe(item, back, &((hash)->table[idx]), member)
61
62#endif /* SESSION_HASH_H */