Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-dict/dict-db.c @ 9575:0a00dcc4f0ea HEAD
lib-storage: Allow shared namespace prefix to use %variable modifiers.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 26 May 2010 17:07:51 +0100 |
parents | 00cd9aacd03c |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
9361
diff
changeset
|
1 /* Copyright (c) 2006-2010 Dovecot authors, see the included COPYING file */ |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
2 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
4 #include "dict-private.h" |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
5 |
4517
e661182eab75
Berkeley DB dict support is now enabled only when using --with-db configure option.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4516
diff
changeset
|
6 #ifdef BUILD_DB |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
7 #include <stdlib.h> |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
8 #include <db.h> |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
9 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
10 struct db_dict { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
11 struct dict dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
12 enum dict_data_type value_type; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
13 pool_t pool; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
14 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
15 DB_ENV *db_env; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
16 DB *pdb; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
17 DB *sdb; |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
18 DB_TXN *tid; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
19 }; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
20 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
21 struct db_dict_iterate_context { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
22 struct dict_iterate_context ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
23 pool_t pool; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
24 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
25 DBC *cursor; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
26 char *path; |
4520 | 27 unsigned int path_len; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
28 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
29 DBT pkey, pdata; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
30 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
31 int (*iterate_next)(struct db_dict_iterate_context *ctx, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
32 const char **key_r, const char **value_r); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
33 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
34 enum dict_iterate_flags flags; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
35 }; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
36 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
37 struct db_dict_transaction_context { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
38 struct dict_transaction_context ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
39 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
40 DB_TXN *tid; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
41 }; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
42 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
43 static void db_dict_deinit(struct dict *_dict); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
44 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
4520
diff
changeset
|
45 static int associate_key(DB *pdb ATTR_UNUSED, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
4520
diff
changeset
|
46 const DBT *pkey ATTR_UNUSED, |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
47 const DBT *pdata, DBT *skey) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
48 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
49 memset(skey, 0, sizeof(*skey)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
50 skey->data = pdata->data; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
51 skey->size = pdata->size; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
52 return 0; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
53 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
54 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
4520
diff
changeset
|
55 static int uint32_t_compare(DB *db ATTR_UNUSED, |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
56 const DBT *keya, const DBT *keyb) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
57 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
58 const uint32_t *ua = keya->data, *ub = keyb->data; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
59 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
60 return *ua > *ub ? 1 : |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
61 (*ua < *ub ? -1 : 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
62 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
63 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
64 static int db_dict_open(struct db_dict *dict, const char *uri, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
65 const char *username) |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
66 { |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
67 const char *dir; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
68 int ret; |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
69 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
70 dict->db_env->set_errfile(dict->db_env, stderr); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
71 dict->db_env->set_errpfx(dict->db_env, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
72 p_strdup_printf(dict->pool, "db_env(%s)", username)); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
73 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
74 dir = strrchr(uri, '/'); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
75 if (dir != NULL) |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
76 dir = t_strdup_until(uri, dir); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
77 else |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
78 dir = "."; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
79 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
80 ret = dict->db_env->open(dict->db_env, dir, DB_CREATE | |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
81 DB_INIT_MPOOL | DB_INIT_TXN, 0); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
82 if (ret != 0) { |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
83 i_error("db_env.open(%s) failed: %s\n", dir, db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
84 return -1; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
85 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
86 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
87 ret = dict->db_env->txn_begin(dict->db_env, NULL, &dict->tid, 0); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
88 if (ret != 0) { |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
89 i_error("db_env.txn_begin() failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
90 return -1; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
91 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
92 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
93 /* create both primary and secondary databases */ |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
94 ret = db_create(&dict->pdb, dict->db_env, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
95 if (ret != 0) { |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
96 i_error("db_create(primary) failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
97 return -1; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
98 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
99 dict->pdb->set_errfile(dict->pdb, stderr); |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
100 dict->pdb->set_errpfx(dict->pdb, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
101 p_strdup_printf(dict->pool, "db(primary, %s)", username)); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
102 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
103 ret = db_create(&dict->sdb, dict->db_env, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
104 if (ret != 0) { |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
105 i_error("db_create(secondary) failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
106 return -1; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
107 } |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
108 dict->sdb->set_errfile(dict->sdb, stderr); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
109 dict->sdb->set_errpfx(dict->sdb, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
110 p_strdup_printf(dict->pool, "db(secondary, %s)", username)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
111 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
112 if ((ret = dict->pdb->open(dict->pdb, dict->tid, uri, NULL, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
113 DB_BTREE, DB_CREATE, 0)) != 0) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
114 i_error("pdb.open() failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
115 return -1; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
116 } |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
117 if (dict->sdb->set_flags(dict->sdb, DB_DUP) != 0) |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
118 return -1; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
119 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
120 /* by default keys are compared as strings. if we store uint32_t, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
121 we need a customized compare function */ |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
122 if (dict->value_type == DICT_DATA_TYPE_UINT32) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
123 if (dict->sdb->set_bt_compare(dict->sdb, uint32_t_compare) != 0) |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
124 return -1; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
125 } |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
126 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
127 if ((ret = dict->sdb->open(dict->sdb, dict->tid, NULL, NULL, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
128 DB_BTREE, DB_CREATE, 0)) != 0) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
129 i_error("sdb.open() failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
130 return -1; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
131 } |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
132 if ((ret = dict->pdb->associate(dict->pdb, dict->tid, dict->sdb, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
133 associate_key, DB_CREATE)) != 0) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
134 i_error("pdb.associate() failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
135 return -1; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
136 } |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
137 return 0; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
138 } |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
139 |
9174
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
9050
diff
changeset
|
140 static struct dict * |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
9050
diff
changeset
|
141 db_dict_init(struct dict *driver, const char *uri, |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
9050
diff
changeset
|
142 enum dict_data_type value_type, |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
9050
diff
changeset
|
143 const char *username, const char *base_dir ATTR_UNUSED) |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
144 { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
145 struct db_dict *dict; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
146 pool_t pool; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
147 int ret, major, minor, patch; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
148 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
149 (void)db_version(&major, &minor, &patch); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
150 if (major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
151 i_error("Berkeley DB version mismatch: " |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
152 "Compiled against %d.%d.%d headers, " |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
153 "run-time linked against %d.%d.%d library", |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
154 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
155 major, minor, patch); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
156 return NULL; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
157 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
158 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
159 pool = pool_alloconly_create("db dict", 1024); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
160 dict = p_new(pool, struct db_dict, 1); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
161 dict->pool = pool; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
162 dict->dict = *driver; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
163 dict->value_type = value_type; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
164 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
165 /* prepare the environment */ |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
166 ret = db_env_create(&dict->db_env, 0); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
167 if (ret != 0) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
168 i_error("db_env_create() failed: %s\n", db_strerror(ret)); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
169 pool_unref(&pool); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
170 return NULL; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
171 } |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
172 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
173 if (db_dict_open(dict, uri, username) < 0) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
174 i_error("db(%s) open failed", uri); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
175 db_dict_deinit(&dict->dict); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
176 return NULL; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
177 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
178 return &dict->dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
179 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
180 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
181 static void db_dict_deinit(struct dict *_dict) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
182 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
183 struct db_dict *dict = (struct db_dict *)_dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
184 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
185 if (dict->tid != NULL) |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
186 (void)dict->tid->commit(dict->tid, 0); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
187 if (dict->pdb != NULL) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
188 dict->pdb->close(dict->pdb, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
189 if (dict->sdb != NULL) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
190 dict->sdb->close(dict->sdb, 0); |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
191 dict->db_env->close(dict->db_env, 0); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
192 pool_unref(&dict->pool); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
193 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
194 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
195 static int db_dict_iterate_set(struct db_dict_iterate_context *ctx, int ret, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
196 const char **key_r, const char **value_r) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
197 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
198 struct db_dict *dict = (struct db_dict *)ctx->ctx.dict; |
8059
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
199 uint32_t value; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
200 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
201 if (ret == DB_NOTFOUND) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
202 return 0; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
203 else if (ret != 0) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
204 return -1; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
205 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
206 p_clear(ctx->pool); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
207 *key_r = p_strndup(ctx->pool, ctx->pkey.data, ctx->pkey.size); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
208 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
209 switch (dict->value_type) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
210 case DICT_DATA_TYPE_UINT32: |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
211 i_assert(ctx->pdata.size == sizeof(uint32_t)); |
8059
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
212 |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
213 /* data may not be aligned, so use memcpy() */ |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
214 memcpy(&value, ctx->pdata.data, sizeof(value)); |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
215 *value_r = p_strdup(ctx->pool, dec2str(value)); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
216 break; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
217 case DICT_DATA_TYPE_STRING: |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
218 *value_r = p_strndup(ctx->pool, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
219 ctx->pdata.data, ctx->pdata.size); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
220 break; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
221 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
222 return 1; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
223 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
224 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
225 static int db_dict_lookup(struct dict *_dict, pool_t pool, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
226 const char *key, const char **value_r) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
227 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
228 struct db_dict *dict = (struct db_dict *)_dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
229 DBT pkey, pdata; |
8059
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
230 uint32_t value; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
231 int ret; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
232 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
233 memset(&pkey, 0, sizeof(DBT)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
234 memset(&pdata, 0, sizeof(DBT)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
235 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
236 pkey.data = (char *)key; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
237 pkey.size = strlen(key); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
238 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
239 ret = dict->pdb->get(dict->pdb, NULL, &pkey, &pdata, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
240 if (ret == DB_NOTFOUND) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
241 return 0; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
242 else if (ret != 0) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
243 return -1; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
244 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
245 switch (dict->value_type) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
246 case DICT_DATA_TYPE_UINT32: |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
247 i_assert(pdata.size == sizeof(uint32_t)); |
8059
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
248 |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
249 /* data may not be aligned, so use memcpy() */ |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
250 memcpy(&value, pdata.data, sizeof(value)); |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
251 *value_r = p_strdup(pool, dec2str(value)); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
252 break; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
253 case DICT_DATA_TYPE_STRING: |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
254 *value_r = p_strndup(pool, pdata.data, pdata.size); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
255 break; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
256 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
257 return 1; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
258 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
259 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
260 static int db_dict_iterate_next(struct db_dict_iterate_context *ctx, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
261 const char **key_r, const char **value_r) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
262 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
263 DBT pkey, pdata, skey; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
264 int ret; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
265 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
266 memset(&pkey, 0, sizeof(pkey)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
267 memset(&pdata, 0, sizeof(pdata)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
268 memset(&skey, 0, sizeof(skey)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
269 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
270 if ((ctx->flags & DICT_ITERATE_FLAG_SORT_BY_VALUE) != 0) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
271 while ((ret = ctx->cursor->c_pget(ctx->cursor, &skey, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
272 &ctx->pkey, &ctx->pdata, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
273 DB_NEXT)) == 0) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
274 /* make sure the path matches */ |
4520 | 275 if (ctx->path == NULL) |
276 break; | |
277 if (ctx->path_len <= ctx->pkey.size && | |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
278 strncmp(ctx->path, ctx->pkey.data, |
4520 | 279 ctx->path_len) == 0) |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
280 break; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
281 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
282 } else { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
283 ret = ctx->cursor->c_get(ctx->cursor, &ctx->pkey, &ctx->pdata, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
284 DB_NEXT); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
285 if (ctx->path != NULL && ret == 0 && |
4520 | 286 (ctx->path_len > ctx->pkey.size || |
287 strncmp(ctx->path, ctx->pkey.data, ctx->path_len) != 0)) { | |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
288 /* there are no more matches */ |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
289 return 0; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
290 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
291 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
292 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
293 return db_dict_iterate_set(ctx, ret, key_r, value_r); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
294 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
295 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
296 static int db_dict_iterate_first(struct db_dict_iterate_context *ctx, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
297 const char **key_r, const char **value_r) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
298 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
299 struct db_dict *dict = (struct db_dict *)ctx->ctx.dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
300 int ret; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
301 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
302 ctx->iterate_next = db_dict_iterate_next; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
303 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
304 if ((ctx->flags & DICT_ITERATE_FLAG_SORT_BY_VALUE) != 0) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
305 /* iterating through secondary database returns values sorted */ |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
306 ret = dict->sdb->cursor(dict->sdb, NULL, &ctx->cursor, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
307 } else { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
308 ret = dict->pdb->cursor(dict->pdb, NULL, &ctx->cursor, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
309 if (ret == 0 && ctx->path != NULL) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
310 ctx->pkey.data = ctx->path; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
311 ctx->pkey.size = strlen(ctx->path); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
312 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
313 ret = ctx->cursor->c_get(ctx->cursor, &ctx->pkey, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
314 &ctx->pdata, DB_SET_RANGE); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
315 if (ret == 0 && strncmp(ctx->path, ctx->pkey.data, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
316 ctx->pkey.size) != 0) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
317 return 0; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
318 return db_dict_iterate_set(ctx, ret, key_r, value_r); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
319 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
320 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
321 return db_dict_iterate_next(ctx, key_r, value_r); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
322 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
323 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
324 static struct dict_iterate_context * |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
325 db_dict_iterate_init(struct dict *_dict, const char *path, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
326 enum dict_iterate_flags flags) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
327 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
328 struct db_dict_iterate_context *ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
329 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
330 ctx = i_new(struct db_dict_iterate_context, 1); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
331 ctx->pool = pool_alloconly_create("db iter", 1024); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
332 ctx->cursor = NULL; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
333 ctx->ctx.dict = _dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
334 ctx->flags = flags; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
335 ctx->path = i_strdup_empty(path); |
4520 | 336 ctx->path_len = ctx->path == NULL ? 0 : strlen(ctx->path); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
337 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
338 ctx->iterate_next = db_dict_iterate_first; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
339 return &ctx->ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
340 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
341 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
342 static int db_dict_iterate(struct dict_iterate_context *_ctx, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
343 const char **key_r, const char **value_r) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
344 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
345 struct db_dict_iterate_context *ctx = |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
346 (struct db_dict_iterate_context *)_ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
347 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
348 return ctx->iterate_next(ctx, key_r, value_r); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
349 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
350 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
351 static void db_dict_iterate_deinit(struct dict_iterate_context *_ctx) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
352 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
353 struct db_dict_iterate_context *ctx = |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
354 (struct db_dict_iterate_context *)_ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
355 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
356 ctx->cursor->c_close(ctx->cursor); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
357 pool_unref(&ctx->pool); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
358 i_free(ctx->path); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
359 i_free(ctx); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
360 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
361 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
362 static struct dict_transaction_context * |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
363 db_dict_transaction_init(struct dict *_dict) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
364 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
365 struct db_dict *dict = (struct db_dict *)_dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
366 struct db_dict_transaction_context *ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
367 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
368 ctx = i_new(struct db_dict_transaction_context, 1); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
369 ctx->ctx.dict = _dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
370 dict->db_env->txn_begin(dict->db_env, NULL, &ctx->tid, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
371 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
372 return &ctx->ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
373 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
374 |
9361
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
375 static int |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
376 db_dict_transaction_commit(struct dict_transaction_context *_ctx, |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
377 bool async ATTR_UNUSED, |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
378 dict_transaction_commit_callback_t *callback, |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
379 void *context) |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
380 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
381 struct db_dict_transaction_context *ctx = |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
382 (struct db_dict_transaction_context *)_ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
383 int ret; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
384 |
9361
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
385 ret = ctx->tid->commit(ctx->tid, 0) < 0 ? -1 : 1; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
386 i_free(ctx); |
9361
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
387 |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
388 if (callback != NULL) |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
389 callback(ret, context); |
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
390 return ret; |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
391 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
392 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
393 static void db_dict_transaction_rollback(struct dict_transaction_context *_ctx) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
394 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
395 struct db_dict_transaction_context *ctx = |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
396 (struct db_dict_transaction_context *)_ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
397 |
9050
c09602d2820c
Berkeley DB dict: Transactions should be aborted with abort(), not discard().
Timo Sirainen <tss@iki.fi>
parents:
8660
diff
changeset
|
398 ctx->tid->abort(ctx->tid); |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
399 i_free(ctx); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
400 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
401 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
402 static void db_dict_set(struct dict_transaction_context *_ctx, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
403 const char *key, const char *value) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
404 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
405 struct db_dict_transaction_context *ctx = |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
406 (struct db_dict_transaction_context *)_ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
407 struct db_dict *dict = (struct db_dict *)_ctx->dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
408 DBT dkey, ddata; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
409 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
410 memset(&dkey, 0, sizeof(dkey)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
411 memset(&ddata, 0, sizeof(ddata)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
412 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
413 dkey.data = (char *)key; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
414 dkey.size = strlen(key); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
415 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
416 if (dict->value_type == DICT_DATA_TYPE_UINT32) { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
417 uint32_t ivalue = (uint32_t)strtoul(value, NULL, 10); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
418 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
419 ddata.data = &ivalue; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
420 ddata.size = sizeof(ivalue); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
421 } else { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
422 ddata.data = (char *)value; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
423 ddata.size = strlen(value); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
424 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
425 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
426 dict->pdb->put(dict->pdb, ctx->tid, &dkey, &ddata, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
427 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
428 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
429 static void db_dict_unset(struct dict_transaction_context *_ctx, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
430 const char *key) |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
431 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
432 struct db_dict_transaction_context *ctx = |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
433 (struct db_dict_transaction_context *)_ctx; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
434 struct db_dict *dict = (struct db_dict *)_ctx->dict; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
435 DBT dkey; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
436 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
437 memset(&dkey, 0, sizeof(dkey)); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
438 dkey.data = (char *)key; |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
439 dkey.size = strlen(key); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
440 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
441 dict->pdb->del(dict->pdb, ctx->tid, &dkey, 0); |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
442 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
443 |
7501
c6e9fd175bdf
Added ATTR_UNUSED to function parameters that won't be implemented for v1.1.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
444 static void |
c6e9fd175bdf
Added ATTR_UNUSED to function parameters that won't be implemented for v1.1.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
445 db_dict_atomic_inc(struct dict_transaction_context *_ctx ATTR_UNUSED, |
c6e9fd175bdf
Added ATTR_UNUSED to function parameters that won't be implemented for v1.1.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
446 const char *key ATTR_UNUSED, long long diff ATTR_UNUSED) |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
447 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
448 /* FIXME */ |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
449 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
450 |
4517
e661182eab75
Berkeley DB dict support is now enabled only when using --with-db configure option.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4516
diff
changeset
|
451 struct dict dict_driver_db = { |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
452 MEMBER(name) "db", |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
453 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
454 db_dict_init, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
455 db_dict_deinit, |
9361
a1b92a251bb9
dict: Added support for async commits. Changed dict_atomic_inc() behavior.
Timo Sirainen <tss@iki.fi>
parents:
9174
diff
changeset
|
456 NULL, |
4516
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
457 db_dict_lookup, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
458 db_dict_iterate_init, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
459 db_dict_iterate, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
460 db_dict_iterate_deinit, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
461 db_dict_transaction_init, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
462 db_dict_transaction_commit, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
463 db_dict_transaction_rollback, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
464 db_dict_set, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
465 db_dict_unset, |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
466 db_dict_atomic_inc |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
467 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
468 }; |
4517
e661182eab75
Berkeley DB dict support is now enabled only when using --with-db configure option.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4516
diff
changeset
|
469 #endif |