-static TCBDB *greylist_db_get(const greylist_config_t *config,
- const char *path, bool cleanup,
+static inline bool greylist_db_need_cleanup(const greylist_config_t *config, TCBDB *db)
+{
+ int len = 0;
+ time_t now = time(NULL);
+ const time_t *last_cleanup = tcbdbget3(db, static_cleanup.str, static_cleanup.len, &len);
+ if (last_cleanup == NULL) {
+ debug("No last cleanup time");
+ } else {
+ debug("Last cleanup time %u, (ie %us ago)",
+ (uint32_t)*last_cleanup, (uint32_t)(now - *last_cleanup));
+ }
+ return last_cleanup == NULL
+ || len != sizeof(*last_cleanup)
+ || (now - *last_cleanup) >= config->cleanup_period;
+}
+
+static TCBDB **greylist_db_get(const greylist_config_t *config, const char *path,