]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Implement traverse functor in maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 25 Apr 2018 12:37:07 +0000 (13:37 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 25 Apr 2018 12:37:07 +0000 (13:37 +0100)
src/libutil/map.c
src/libutil/map.h
src/libutil/map_private.h

index 931e9b90ee06c786ca93bc3981ed95de5b8e3f25..0a27365eb1290633b0676a2aa03c94b28e28c350 100644 (file)
@@ -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
index 171c0c55fc60766fdd5d853f6cb2f8ca7aacdc0f..75c8788cad6d194f52eee1255380ebc3d866d0a3 100644 (file)
@@ -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
index 1de6fb942e82da495760842dfdee948086450bd3..fb1e609bd2344886308d1ca4b848bf3728922e49 100644 (file)
@@ -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 {