From: Timo Sirainen Date: Tue, 14 Jun 2022 09:25:39 +0000 (+0300) Subject: lib-dict: Add dict_expire_scan() X-Git-Tag: 2.4.0~3960 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4aed677555cf607faafae87c182ab5dc3ff26321;p=thirdparty%2Fdovecot%2Fcore.git lib-dict: Add dict_expire_scan() --- diff --git a/src/lib-dict/dict-private.h b/src/lib-dict/dict-private.h index 727ba631aa..89bd4b7c0b 100644 --- a/src/lib-dict/dict-private.h +++ b/src/lib-dict/dict-private.h @@ -17,6 +17,7 @@ struct dict_vfuncs { struct dict **dict_r, const char **error_r); void (*deinit)(struct dict *dict); void (*wait)(struct dict *dict); + int (*expire_scan)(struct dict *dict, const char **error_r); int (*lookup)(struct dict *dict, const struct dict_op_settings *set, pool_t pool, const char *key, const char *const **values_r, diff --git a/src/lib-dict/dict.c b/src/lib-dict/dict.c index 20ba9e6392..9e8531bdaa 100644 --- a/src/lib-dict/dict.c +++ b/src/lib-dict/dict.c @@ -204,6 +204,14 @@ bool dict_switch_ioloop(struct dict *dict) return ret; } +int dict_expire_scan(struct dict *dict, const char **error_r) +{ + if (dict->v.expire_scan == NULL) + return 0; + else + return dict->v.expire_scan(dict, error_r); +} + static bool dict_key_prefix_is_valid(const char *key, const char *username) { if (str_begins_with(key, DICT_PATH_SHARED)) diff --git a/src/lib-dict/dict.h b/src/lib-dict/dict.h index 4e029fb189..4d56b8748f 100644 --- a/src/lib-dict/dict.h +++ b/src/lib-dict/dict.h @@ -110,6 +110,12 @@ bool dict_have_async_operations(struct dict *dict); be waited on. */ bool dict_switch_ioloop(struct dict *dict) ATTR_NOWARN_UNUSED_RESULT; +/* Scan the dict for expired entries and delete them. Returns 0 if dict does + not support expire scanning (and there is no need to call this function + again), 1 if expire scanning was run successfully, -1 if expire scanning + failed. */ +int dict_expire_scan(struct dict *dict, const char **error_r); + /* Lookup the first value for the key. Set it to NULL if it's not found. Returns 1 if found, 0 if not found and -1 if lookup failed. */ int dict_lookup(struct dict *dict, const struct dict_op_settings *set, pool_t pool,