Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-dict/dict-db.c @ 8607:04816f18bf18 HEAD
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 09 Jan 2009 13:14:04 -0500 |
parents | b9faf4db2a9f |
children | d8a56ea9f408 |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8059
diff
changeset
|
1 /* Copyright (c) 2006-2009 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 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
140 static struct dict *db_dict_init(struct dict *driver, const char *uri, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
141 enum dict_data_type value_type, |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
142 const char *username) |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
143 { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
144 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
|
145 pool_t pool; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
146 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
|
147 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
148 (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
|
149 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
|
150 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
|
151 "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
|
152 "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
|
153 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
|
154 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
|
155 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
|
156 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
158 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
|
159 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
|
160 dict->pool = pool; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
161 dict->dict = *driver; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
162 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
|
163 |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
164 /* prepare the environment */ |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
165 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
|
166 if (ret != 0) { |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
167 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
|
168 pool_unref(&pool); |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
169 return NULL; |
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
170 } |
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 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
|
173 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
|
174 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
|
175 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
|
176 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
178 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
181 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
183 |
8607
04816f18bf18
Berkeley DB fixes and cleanups. Don't leak memory/bdb resources.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
184 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
|
185 (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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 dict->db_env->close(dict->db_env, 0); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
191 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
|
192 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
195 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
|
196 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
198 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
|
199 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
201 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
|
202 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
|
203 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
|
204 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
206 *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
|
207 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
209 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
|
210 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
|
211 |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
212 /* 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
|
213 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
|
214 *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
|
215 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
|
216 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
|
217 *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
|
218 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
|
219 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
|
220 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
222 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
225 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
|
226 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
228 DBT pkey, pdata; |
8059
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
229 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
|
230 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
|
231 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
233 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
|
234 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
236 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
|
237 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
245 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
|
246 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
|
247 |
25ff4c990c23
dict-db: Don't assume bdb returns aligned memory addresses.
Timo Sirainen <tss@iki.fi>
parents:
7501
diff
changeset
|
248 /* 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
|
249 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
|
250 *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
|
251 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
|
252 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
|
253 *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
|
254 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
|
255 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
257 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
260 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
|
261 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
263 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
|
264 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
266 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
|
267 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
|
268 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
270 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
|
271 &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
|
272 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
|
273 /* make sure the path matches */ |
4520 | 274 if (ctx->path == NULL) |
275 break; | |
276 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
|
277 strncmp(ctx->path, ctx->pkey.data, |
4520 | 278 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
|
279 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
|
280 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 } 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
|
282 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
|
283 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
|
284 if (ctx->path != NULL && ret == 0 && |
4520 | 285 (ctx->path_len > ctx->pkey.size || |
286 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
|
287 /* 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
|
288 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
|
289 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
293 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
296 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
|
297 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
299 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
|
300 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
302 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
304 /* 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
|
305 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
|
306 } 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
313 &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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
321 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
324 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
|
325 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
|
326 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
328 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 ctx->path = i_strdup_empty(path); |
4520 | 335 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
|
336 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
338 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
|
339 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
342 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
|
343 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
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 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
348 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
351 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
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 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 ctx->cursor->c_close(ctx->cursor); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
362 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
|
363 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
365 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
|
366 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
368 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
|
369 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
|
370 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
372 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 static int db_dict_transaction_commit(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
|
375 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
376 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
|
377 (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
|
378 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
|
379 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 ret = ctx->tid->commit(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
|
381 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
|
382 return ret == 0 ? 0 : -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
|
383 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
385 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
|
386 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
387 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
|
388 (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
|
389 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
390 ctx->tid->discard(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
|
391 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
|
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 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
395 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
|
396 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
398 (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
|
399 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
|
400 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
|
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 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
|
403 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
|
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 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
|
406 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
|
407 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
409 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
|
410 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
412 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
|
413 } 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
|
414 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
|
415 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
|
416 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
419 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
422 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
|
423 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
425 (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
|
426 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
|
427 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
|
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 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
|
430 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
|
431 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
|
432 |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 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
|
434 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 |
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
|
436 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
|
437 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
|
438 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
|
439 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 /* 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
|
441 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 |
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
|
443 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
|
444 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
|
445 { |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. Added dict_unset(). Added Berkeley DB support. Most of the code written by Tianyan Liu.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
446 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
|
447 db_dict_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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 } |
aa2f73a4df26
Dictionary changes: Added support for defining value's type. Key is still always a string. Added support for sorting the iteration replies. 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 }; |
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
|
460 #endif |