/src/dovecot/src/lib-dict/dict-transaction-memory.c
Line | Count | Source |
1 | | /* Copyright (c) Dovecot authors, see top-level COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "array.h" |
5 | | #include "dict-transaction-memory.h" |
6 | | |
7 | | void dict_transaction_memory_init(struct dict_transaction_memory_context *ctx, |
8 | | struct dict *dict, pool_t pool) |
9 | 0 | { |
10 | 0 | ctx->ctx.dict = dict; |
11 | 0 | ctx->pool = pool; |
12 | 0 | p_array_init(&ctx->changes, pool, 32); |
13 | 0 | } |
14 | | |
15 | | void dict_transaction_memory_rollback(struct dict_transaction_context *_ctx) |
16 | 0 | { |
17 | 0 | struct dict_transaction_memory_context *ctx = |
18 | 0 | (struct dict_transaction_memory_context *)_ctx; |
19 | |
|
20 | 0 | pool_unref(&ctx->pool); |
21 | 0 | } |
22 | | |
23 | | void dict_transaction_memory_set(struct dict_transaction_context *_ctx, |
24 | | const char *key, const char *value) |
25 | 0 | { |
26 | 0 | struct dict_transaction_memory_context *ctx = |
27 | 0 | (struct dict_transaction_memory_context *)_ctx; |
28 | 0 | struct dict_transaction_memory_change *change; |
29 | |
|
30 | 0 | change = array_append_space(&ctx->changes); |
31 | 0 | change->type = DICT_CHANGE_TYPE_SET; |
32 | 0 | change->key = p_strdup(ctx->pool, key); |
33 | 0 | change->value.str = p_strdup(ctx->pool, value); |
34 | 0 | } |
35 | | |
36 | | void dict_transaction_memory_unset(struct dict_transaction_context *_ctx, |
37 | | const char *key) |
38 | 0 | { |
39 | 0 | struct dict_transaction_memory_context *ctx = |
40 | 0 | (struct dict_transaction_memory_context *)_ctx; |
41 | 0 | struct dict_transaction_memory_change *change; |
42 | |
|
43 | 0 | change = array_append_space(&ctx->changes); |
44 | 0 | change->type = DICT_CHANGE_TYPE_UNSET; |
45 | 0 | change->key = p_strdup(ctx->pool, key); |
46 | 0 | } |
47 | | |
48 | | void dict_transaction_memory_atomic_inc(struct dict_transaction_context *_ctx, |
49 | | const char *key, long long diff) |
50 | 0 | { |
51 | 0 | struct dict_transaction_memory_context *ctx = |
52 | 0 | (struct dict_transaction_memory_context *)_ctx; |
53 | 0 | struct dict_transaction_memory_change *change; |
54 | |
|
55 | 0 | change = array_append_space(&ctx->changes); |
56 | 0 | change->type = DICT_CHANGE_TYPE_INC; |
57 | 0 | change->key = p_strdup(ctx->pool, key); |
58 | 0 | change->value.diff = diff; |
59 | 0 | } |