~ubuntu-branches/ubuntu/trusty/dovecot/trusty-updates

« back to all changes in this revision

Viewing changes to src/lib/hash.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (1.15.3) (96.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140108093549-814nkqdcxfbvgktg
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef HASH_H
2
2
#define HASH_H
3
3
 
 
4
struct hash_table;
 
5
 
 
6
#ifdef __GNUC__
 
7
#  define HASH_VALUE_CAST(table) (typeof((table)._value))
 
8
#else
 
9
#  define HASH_VALUE_CAST(table)
 
10
#endif
 
11
 
4
12
/* Returns hash code. */
5
13
typedef unsigned int hash_callback_t(const void *p);
6
14
/* Returns 0 if the pointers are equal. */
7
15
typedef int hash_cmp_callback_t(const void *p1, const void *p2);
8
16
 
9
17
/* Create a new hash table. If initial_size is 0, the default value is used.
10
 
   If hash_cb or key_compare_cb is NULL, direct hashing/comparing is used.
11
 
 
12
18
   table_pool is used to allocate/free large hash tables, node_pool is used
13
19
   for smaller allocations and can also be alloconly pool. The pools must not
14
20
   be free'd before hash_table_destroy() is called. */
15
 
struct hash_table *
16
 
hash_table_create(pool_t table_pool, pool_t node_pool, unsigned int initial_size,
17
 
                  hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb);
 
21
void hash_table_create(struct hash_table **table_r, pool_t node_pool,
 
22
                       unsigned int initial_size,
 
23
                       hash_callback_t *hash_cb,
 
24
                       hash_cmp_callback_t *key_compare_cb);
 
25
#if defined (__GNUC__) && !defined(__cplusplus)
 
26
#  define hash_table_create(table, pool, size, hash_cb, key_cmp_cb) \
 
27
        ({(void)COMPILE_ERROR_IF_TRUE( \
 
28
                sizeof((*table)._key) != sizeof(void *) || \
 
29
                sizeof((*table)._value) != sizeof(void *)); \
 
30
        (void)COMPILE_ERROR_IF_TRUE( \
 
31
                !__builtin_types_compatible_p(typeof(&key_cmp_cb), \
 
32
                        int (*)(typeof((*table)._key), typeof((*table)._key))) && \
 
33
                !__builtin_types_compatible_p(typeof(&key_cmp_cb), \
 
34
                        int (*)(typeof((*table)._const_key), typeof((*table)._const_key)))); \
 
35
        (void)COMPILE_ERROR_IF_TRUE( \
 
36
                !__builtin_types_compatible_p(typeof(&hash_cb), \
 
37
                        unsigned int (*)(typeof((*table)._key))) && \
 
38
                !__builtin_types_compatible_p(typeof(&hash_cb), \
 
39
                        unsigned int (*)(typeof((*table)._const_key)))); \
 
40
        hash_table_create(&(*table)._table, pool, size, \
 
41
                (hash_callback_t *)hash_cb, \
 
42
                (hash_cmp_callback_t *)key_cmp_cb);})
 
43
#else
 
44
#  define hash_table_create(table, pool, size, hash_cb, key_cmp_cb) \
 
45
        hash_table_create(&(*table)._table, pool, size, \
 
46
                (hash_callback_t *)hash_cb, \
 
47
                (hash_cmp_callback_t *)key_cmp_cb)
 
48
#endif
 
49
 
 
50
/* Create hash table where comparisons are done directly with the pointers. */
 
51
void hash_table_create_direct(struct hash_table **table_r, pool_t node_pool,
 
52
                              unsigned int initial_size);
 
53
#if defined (__GNUC__) && !defined(__cplusplus)
 
54
#  define hash_table_create_direct(table, pool, size) \
 
55
        ({(void)COMPILE_ERROR_IF_TRUE( \
 
56
                sizeof((*table)._key) != sizeof(void *) || \
 
57
                sizeof((*table)._value) != sizeof(void *)); \
 
58
        hash_table_create_direct(&(*table)._table, pool, size);})
 
59
#else
 
60
#  define hash_table_create_direct(table, pool, size) \
 
61
        hash_table_create_direct(&(*table)._table, pool, size)
 
62
#endif
 
63
 
 
64
#define hash_table_is_created(table) \
 
65
        ((table)._table != NULL)
 
66
 
18
67
void hash_table_destroy(struct hash_table **table);
 
68
#define hash_table_destroy(table) \
 
69
        hash_table_destroy(&(*table)._table)
19
70
/* Remove all nodes from hash table. If free_collisions is TRUE, the
20
 
   memory allocated from node_pool is freed, or discarded with
21
 
   alloconly pools. */
 
71
   memory allocated from node_pool is freed, or discarded with alloconly pools.
 
72
   WARNING: If you p_clear() the node_pool, the free_collisions must be TRUE. */
22
73
void hash_table_clear(struct hash_table *table, bool free_collisions);
 
74
#define hash_table_clear(table, free_collisions) \
 
75
        hash_table_clear((table)._table, free_collisions)
23
76
 
24
77
void *hash_table_lookup(const struct hash_table *table, const void *key) ATTR_PURE;
 
78
#define hash_table_lookup(table, key) \
 
79
        HASH_VALUE_CAST(table)hash_table_lookup((table)._table, \
 
80
                (const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._key, (table)._const_key, key)))
 
81
 
25
82
bool hash_table_lookup_full(const struct hash_table *table,
26
83
                            const void *lookup_key,
27
 
                            void **orig_key, void **value);
 
84
                            void **orig_key_r, void **value_r);
 
85
#ifndef __cplusplus
 
86
#  define hash_table_lookup_full(table, lookup_key, orig_key_r, value_r) \
 
87
        hash_table_lookup_full((table)._table, \
 
88
                (void *)((const char *)(lookup_key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, lookup_key)), \
 
89
                (void *)((orig_key_r) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._keyp, orig_key_r) + \
 
90
                        COMPILE_ERROR_IF_TRUE(sizeof(*orig_key_r) != sizeof(void *))), \
 
91
                (void *)((value_r) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._valuep, value_r) + \
 
92
                        COMPILE_ERROR_IF_TRUE(sizeof(*value_r) != sizeof(void *))))
 
93
#else
 
94
/* C++ requires (void **) casting, but that's not possible with strict
 
95
   aliasing, so .. we'll just disable the type checks */
 
96
#  define hash_table_lookup_full(table, lookup_key, orig_key_r, value_r) \
 
97
        hash_table_lookup_full((table)._table, lookup_key, orig_key_r, value_r)
 
98
#endif
28
99
 
29
100
/* Insert/update node in hash table. The difference is that hash_table_insert()
30
101
   replaces the key in table to given one, while hash_table_update() doesnt. */
31
102
void hash_table_insert(struct hash_table *table, void *key, void *value);
32
103
void hash_table_update(struct hash_table *table, void *key, void *value);
 
104
#define hash_table_insert(table, key, value) \
 
105
        hash_table_insert((table)._table, \
 
106
                (void *)((char*)(key) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._key, key)), \
 
107
                (void *)((char*)(value) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._value, value)))
 
108
#define hash_table_update(table, key, value) \
 
109
        hash_table_update((table)._table, \
 
110
                (void *)((char *)(key) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._key, key)), \
 
111
                (void *)((char *)(value) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._value, value)))
33
112
 
34
113
void hash_table_remove(struct hash_table *table, const void *key);
 
114
#define hash_table_remove(table, key) \
 
115
        hash_table_remove((table)._table, \
 
116
                (const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, key)))
35
117
unsigned int hash_table_count(const struct hash_table *table) ATTR_PURE;
 
118
#define hash_table_count(table) \
 
119
        hash_table_count((table)._table)
36
120
 
37
121
/* Iterates through all nodes in hash table. You may safely call hash_table_*()
38
122
   functions while iterating, but if you add any new nodes, they may or may
39
123
   not be called for in this iteration. */
40
124
struct hash_iterate_context *hash_table_iterate_init(struct hash_table *table);
 
125
#define hash_table_iterate_init(table) \
 
126
        hash_table_iterate_init((table)._table)
41
127
bool hash_table_iterate(struct hash_iterate_context *ctx,
42
128
                        void **key_r, void **value_r);
 
129
#ifndef __cplusplus
 
130
#  define hash_table_iterate(ctx, table, key_r, value_r) \
 
131
        hash_table_iterate(ctx, \
 
132
                (void *)((key_r) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._keyp, key_r) + \
 
133
                        COMPILE_ERROR_IF_TRUE(sizeof(*key_r) != sizeof(void *)) + \
 
134
                        COMPILE_ERROR_IF_TRUE(sizeof(*value_r) != sizeof(void *))), \
 
135
                (void *)((value_r) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._valuep, value_r)))
 
136
#else
 
137
/* C++ requires (void **) casting, but that's not possible with strict
 
138
   aliasing, so .. we'll just disable the type checks */
 
139
#  define hash_table_iterate(ctx, table, key_r, value_r) \
 
140
        hash_table_iterate(ctx, key_r, value_r)
 
141
#endif
 
142
 
43
143
void hash_table_iterate_deinit(struct hash_iterate_context **ctx);
44
144
 
45
145
/* Hash table isn't resized, and removed nodes aren't removed from
46
146
   the list while hash table is freezed. Supports nesting. */
47
147
void hash_table_freeze(struct hash_table *table);
48
148
void hash_table_thaw(struct hash_table *table);
 
149
#define hash_table_freeze(table) \
 
150
        hash_table_freeze((table)._table)
 
151
#define hash_table_thaw(table) \
 
152
        hash_table_thaw((table)._table)
49
153
 
50
154
/* Copy all nodes from one hash table to another */
51
155
void hash_table_copy(struct hash_table *dest, struct hash_table *src);
 
156
#define hash_table_copy(table1, table2) \
 
157
        hash_table_copy((table1)._table, (table2)._table)
52
158
 
53
159
/* hash function for strings */
54
 
unsigned int str_hash(const void *p) ATTR_PURE;
55
 
unsigned int strcase_hash(const void *p) ATTR_PURE;
 
160
unsigned int str_hash(const char *p) ATTR_PURE;
 
161
unsigned int strcase_hash(const char *p) ATTR_PURE;
56
162
/* a generic hash for a given memory block */
57
163
unsigned int mem_hash(const void *p, unsigned int size) ATTR_PURE;
58
164