dict.c revision 31257b47d47510ceb093a6b218810a1a5b830c55
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic ARRAY_DEFINE(dict_drivers, struct dict *);
e54512a5189192fe72d1e2c53927c98c5ac920b4Timo Sirainenstatic struct dict *dict_driver_lookup(const char *name)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (dict_driver_lookup(driver->name) != NULL) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen i_fatal("dict_driver_register(%s): Already registered",
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenvoid dict_driver_unregister(struct dict *driver)
8fb1e3e2349c9940732b5bb77a2a4053b8f72a4fTimo Sirainen idx = array_foreach_idx(&dict_drivers, dicts);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct dict *dict_init(const char *uri, enum dict_data_type value_type,
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen const char *p, *name;
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen i_error("Dictionary URI is missing ':': %s", uri);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen dict->v.init(dict, p+1, value_type, username, base_dir);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return dict->v.wait == NULL ? 1 : dict->v.wait(dict);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainenstatic bool dict_key_prefix_is_valid(const char *key)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return strncmp(key, DICT_PATH_SHARED, strlen(DICT_PATH_SHARED)) == 0 ||
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen strncmp(key, DICT_PATH_PRIVATE, strlen(DICT_PATH_PRIVATE)) == 0;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenint dict_lookup(struct dict *dict, pool_t pool, const char *key,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen const char **value_r)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen return dict->v.lookup(dict, pool, key, value_r);
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainendict_iterate_init(struct dict *dict, const char *path,
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen return dict_iterate_init_multiple(dict, paths, flags);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainendict_iterate_init_multiple(struct dict *dict, const char *const *paths,
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainen unsigned int i;
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen return dict->v.iterate_init(dict, paths, flags);
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainenbool dict_iterate(struct dict_iterate_context *ctx,
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch return ctx->dict->v.iterate(ctx, key_r, value_r);
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainenint dict_iterate_deinit(struct dict_iterate_context **_ctx)
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainenstruct dict_transaction_context *dict_transaction_begin(struct dict *dict)
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint dict_transaction_commit(struct dict_transaction_context **_ctx)
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen return ctx->dict->v.transaction_commit(ctx, FALSE, NULL, NULL);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenvoid dict_transaction_commit_async(struct dict_transaction_context **_ctx,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen ctx->dict->v.transaction_commit(ctx, TRUE, callback, context);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenvoid dict_transaction_rollback(struct dict_transaction_context **_ctx)
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenvoid dict_set(struct dict_transaction_context *ctx,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid dict_unset(struct dict_transaction_context *ctx,
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo Sirainen const char *key)
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainenvoid dict_atomic_inc(struct dict_transaction_context *ctx,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenconst char *dict_escape_string(const char *str)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen const char *p;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* see if we need to escape it */
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen if (*p == '\0')
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen for (; *p != '\0'; p++) {
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen switch (*p) {
e217d6fce33746e198ecc21bff0bc658664c9ef4Timo Sirainenconst char *dict_unescape_string(const char *str)
70612e07102b75a8511aa7f9de60771176b18de0Timo Sirainen const char *p;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen /* see if we need to unescape it */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (*p == '\\')
469a6cf705835ade57dcb59979b6e054207ae5d7Timo Sirainen if (*p == '\0')
5f44975ec6c5755dd74bcd4c47a123a7242ecab3Timo Sirainen /* unescape */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ret = t_str_new((size_t) (p - str) + strlen(p) + 1);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen for (; *p != '\0'; p++) {
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen if (*p != '\\')
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen if (*++p == '|')
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen else if (*p == '\0')