dict.c revision 31257b47d47510ceb093a6b218810a1a5b830c55
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic ARRAY_DEFINE(dict_drivers, struct dict *);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct dict *dict_driver_lookup(const char *name)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (dict_driver_lookup(driver->name) != NULL) {
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainen i_fatal("dict_driver_register(%s): Already registered",
bbce20cb4e5739e9a06058cf8ee1f38a7f6884f6Timo Sirainenvoid dict_driver_unregister(struct dict *driver)
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen idx = array_foreach_idx(&dict_drivers, dicts);
6a4bfb2b0bb9f53fb1d4e705bf3948ef4d1ecccbTimo Sirainenstruct dict *dict_init(const char *uri, enum dict_data_type value_type,
6a4bfb2b0bb9f53fb1d4e705bf3948ef4d1ecccbTimo Sirainen const char *p, *name;
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen i_error("Dictionary URI is missing ':': %s", uri);
1f4f81ba81bb9fa8abe2d94f344373c230066d67Timo Sirainen dict->v.init(dict, p+1, value_type, username, base_dir);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return dict->v.wait == NULL ? 1 : dict->v.wait(dict);
1f4f81ba81bb9fa8abe2d94f344373c230066d67Timo Sirainenstatic bool dict_key_prefix_is_valid(const char *key)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return strncmp(key, DICT_PATH_SHARED, strlen(DICT_PATH_SHARED)) == 0 ||
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen strncmp(key, DICT_PATH_PRIVATE, strlen(DICT_PATH_PRIVATE)) == 0;
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainenint dict_lookup(struct dict *dict, pool_t pool, const char *key,
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen const char **value_r)
0d658231054332c3f4c04aab0422af649de89a8cTimo Sirainen return dict->v.lookup(dict, pool, key, value_r);
89334d8c6915db0fc8630470b7f3cd5ee9aa29aaTimo Sirainendict_iterate_init(struct dict *dict, const char *path,
89334d8c6915db0fc8630470b7f3cd5ee9aa29aaTimo Sirainen return dict_iterate_init_multiple(dict, paths, flags);
dcf4c70f8358db12859c3ab5b81b3abaac4109a3Timo Sirainendict_iterate_init_multiple(struct dict *dict, const char *const *paths,
dcf4c70f8358db12859c3ab5b81b3abaac4109a3Timo Sirainen unsigned int i;
23c502c6ef08d83e8ed68f90ed75138e14a3a246Timo Sirainen return dict->v.iterate_init(dict, paths, flags);
dcf4c70f8358db12859c3ab5b81b3abaac4109a3Timo Sirainenbool dict_iterate(struct dict_iterate_context *ctx,
9df8c9225140d9d1df5ddf4c6c9da61662ae6c44Timo Sirainen return ctx->dict->v.iterate(ctx, key_r, value_r);
95a284736b8b11319a3f575ba249ba2eb7dbac1bTimo Sirainenint dict_iterate_deinit(struct dict_iterate_context **_ctx)
8eeafcb306872435f3171e6acf5a9937aec3a175Timo Sirainenstruct dict_transaction_context *dict_transaction_begin(struct dict *dict)
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainenint dict_transaction_commit(struct dict_transaction_context **_ctx)
faee566824fe3567c8beacf097f9dcfc0d3761b7Timo Sirainen return ctx->dict->v.transaction_commit(ctx, FALSE, NULL, NULL);
f537e7efaec891d6b3320ca94331d09ca8c4a4dbTimo Sirainenvoid dict_transaction_commit_async(struct dict_transaction_context **_ctx,
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainen ctx->dict->v.transaction_commit(ctx, TRUE, callback, context);
fc7b17677ac1a5fa3f7fe13d5ef7dcfea8d9b4a1Timo Sirainenvoid dict_transaction_rollback(struct dict_transaction_context **_ctx)
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenvoid dict_set(struct dict_transaction_context *ctx,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenvoid dict_unset(struct dict_transaction_context *ctx,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen const char *key)
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenvoid dict_atomic_inc(struct dict_transaction_context *ctx,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenconst char *dict_escape_string(const char *str)
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen const char *p;
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen /* see if we need to escape it */
c21c33a8c98972c45349066fc76ac9e2c05013c1Timo Sirainen if (*p == '\0')
dcf4c70f8358db12859c3ab5b81b3abaac4109a3Timo Sirainen for (; *p != '\0'; p++) {
dcf4c70f8358db12859c3ab5b81b3abaac4109a3Timo Sirainen switch (*p) {
dcf4c70f8358db12859c3ab5b81b3abaac4109a3Timo Sirainenconst char *dict_unescape_string(const char *str)
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen const char *p;
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen /* see if we need to unescape it */
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen if (*p == '\\')
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen if (*p == '\0')
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen /* unescape */
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen ret = t_str_new((size_t) (p - str) + strlen(p) + 1);
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen for (; *p != '\0'; p++) {
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen if (*p != '\\')
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen if (*++p == '|')
1cf72a848805fcf014b01c9d3665b6a157846a21Timo Sirainen else if (*p == '\0')