From: Vsevolod Stakhov Date: Wed, 25 Apr 2018 12:37:07 +0000 (+0100) Subject: [Minor] Implement traverse functor in maps X-Git-Tag: 1.7.4~38 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fcd60ee107f7529e50bb6eab4e92cd5de41b6bd0;p=rspamd.git [Minor] Implement traverse functor in maps --- diff --git a/src/libutil/map.c b/src/libutil/map.c index 931e9b90e..0a27365eb 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -2222,3 +2222,13 @@ err: return NULL; } + +rspamd_map_traverse_function +rspamd_map_get_traverse_function (struct rspamd_map *map) +{ + if (map) { + return map->traverse_function; + } + + return NULL; +} \ No newline at end of file diff --git a/src/libutil/map.h b/src/libutil/map.h index 171c0c55f..75c8788ca 100644 --- a/src/libutil/map.h +++ b/src/libutil/map.h @@ -23,6 +23,11 @@ typedef gchar * (*map_cb_t)(gchar *chunk, gint len, struct map_cb_data *data, gboolean final); typedef void (*map_fin_cb_t)(struct map_cb_data *data); +typedef gboolean (*rspamd_map_traverse_cb)(gconstpointer key, + gconstpointer value, gsize hits, gpointer ud); +typedef void (*rspamd_map_traverse_function)(rspamd_map_traverse_cb cb, + gpointer cbdata, gboolean reset_hits); + /** * Common map object */ @@ -77,4 +82,11 @@ void rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base, */ void rspamd_map_remove_all (struct rspamd_config *cfg); +/** + * Get traverse function for specific map + * @param map + * @return + */ +rspamd_map_traverse_function rspamd_map_get_traverse_function (struct rspamd_map *map); + #endif diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h index 1de6fb942..fb1e609bd 100644 --- a/src/libutil/map_private.h +++ b/src/libutil/map_private.h @@ -114,18 +114,19 @@ struct rspamd_map { gchar *name; guint32 id; gboolean scheduled_check; + rspamd_map_dtor dtor; + gpointer dtor_data; + rspamd_map_traverse_function traverse_function; /* Should we check HTTP or just load cached data */ - gboolean active_http; struct timeval tv; gdouble poll_timeout; time_t next_check; + gboolean active_http; /* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */ gint *locked; /* Shared cache data */ struct rspamd_map_cachepoint *cache; gchar tag[MEMPOOL_UID_LEN]; - rspamd_map_dtor dtor; - gpointer dtor_data; }; enum rspamd_map_http_stage {