]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Allow to disable/enable composite symbols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Feb 2019 15:12:47 +0000 (15:12 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Feb 2019 15:12:47 +0000 (15:12 +0000)
src/libserver/cfg_rcl.c
src/libserver/composites.c
src/libserver/rspamd_symcache.c
src/libserver/rspamd_symcache.h

index 59656392d93013ac7bde44499509de2bd791b282..f2a49212cbac96ed3ed3a0844f01b909489c2367 100644 (file)
@@ -1402,7 +1402,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool,
 
        if (new) {
                rspamd_symcache_add_symbol (cfg->cache, composite_name, 0,
-                               NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1);
+                               NULL, composite, SYMBOL_TYPE_COMPOSITE, -1);
        }
 
        return TRUE;
index f46f8276de2de78d16ee6162314699447dc369d4..b1bb2f694731604f62552e27bb5899af01f239a0 100644 (file)
@@ -559,9 +559,10 @@ composites_metric_callback (struct rspamd_metric_result *metric_res,
                        NBYTES (g_hash_table_size (task->cfg->composite_symbols) * 2));
 
        /* Process hash table */
-       g_hash_table_foreach (task->cfg->composite_symbols,
-               composites_foreach_callback,
-               cd);
+       rspamd_symcache_composites_foreach (task,
+                       task->cfg->cache,
+                       composites_foreach_callback,
+                       cd);
 
        /* Remove symbols that are in composites */
        g_hash_table_foreach (cd->symbols_to_remove, composites_remove_symbols, cd);
index e3db8d6efbf572bdce3f31e8e4c76c54e6121f77..a41d1b9cdd7d0c8154210d99201facdc165f1528 100644 (file)
@@ -23,6 +23,7 @@
 #include "unix-std.h"
 #include "contrib/t1ha/t1ha.h"
 #include "libserver/worker_util.h"
+#include "khash.h"
 #include <math.h>
 
 #if defined(__STDC_VERSION__) &&  __STDC_VERSION__ >= 201112L
@@ -81,51 +82,6 @@ struct symcache_order {
        ref_entry_t ref;
 };
 
-struct rspamd_symcache {
-       /* Hash table for fast access */
-       GHashTable *items_by_symbol;
-       GPtrArray *items_by_id;
-       struct symcache_order *items_by_order;
-       GPtrArray *filters;
-       GPtrArray *prefilters;
-       GPtrArray *postfilters;
-       GPtrArray *composites;
-       GPtrArray *idempotent;
-       GPtrArray *virtual;
-       GPtrArray *squeezed;
-       GList *delayed_deps;
-       GList *delayed_conditions;
-       rspamd_mempool_t *static_pool;
-       guint64 cksum;
-       gdouble total_weight;
-       guint used_items;
-       guint stats_symbols_count;
-       guint64 total_hits;
-       guint id;
-       struct rspamd_config *cfg;
-       gdouble reload_time;
-       gint peak_cb;
-};
-
-struct item_stat {
-       struct rspamd_counter_data time_counter;
-       gdouble avg_time;
-       gdouble weight;
-       guint hits;
-       guint64 total_hits;
-       struct rspamd_counter_data frequency_counter;
-       gdouble avg_frequency;
-       gdouble stddev_frequency;
-};
-
-struct rspamd_symcache_dynamic_item {
-       guint16 start_msec; /* Relative to task time */
-       unsigned started:1;
-       unsigned finished:1;
-       /* unsigned pad:14; */
-       guint32 async_events;
-};
-
 struct rspamd_symcache_item {
        /* This block is likely shared */
        struct item_stat *st;
@@ -165,6 +121,53 @@ struct rspamd_symcache_item {
        GPtrArray *rdeps;
 };
 
+struct item_stat {
+       struct rspamd_counter_data time_counter;
+       gdouble avg_time;
+       gdouble weight;
+       guint hits;
+       guint64 total_hits;
+       struct rspamd_counter_data frequency_counter;
+       gdouble avg_frequency;
+       gdouble stddev_frequency;
+};
+
+struct rspamd_symcache {
+       /* Hash table for fast access */
+       GHashTable *items_by_symbol;
+       GPtrArray *items_by_id;
+       struct symcache_order *items_by_order;
+       GPtrArray *filters;
+       GPtrArray *prefilters;
+       GPtrArray *postfilters;
+       GPtrArray *composites;
+       GPtrArray *idempotent;
+       GPtrArray *virtual;
+       GPtrArray *squeezed;
+       GList *delayed_deps;
+       GList *delayed_conditions;
+       rspamd_mempool_t *static_pool;
+       guint64 cksum;
+       gdouble total_weight;
+       guint used_items;
+       guint stats_symbols_count;
+       guint64 total_hits;
+       guint id;
+       struct rspamd_config *cfg;
+       gdouble reload_time;
+       gint peak_cb;
+};
+
+struct rspamd_symcache_dynamic_item {
+       guint16 start_msec; /* Relative to task time */
+       unsigned started:1;
+       unsigned finished:1;
+       /* unsigned pad:14; */
+       guint32 async_events;
+};
+
+
+
 struct cache_dependency {
        struct rspamd_symcache_item *item;
        gchar *sym;
@@ -2841,4 +2844,25 @@ rspamd_symcache_get_symbol_flags (struct rspamd_symcache *cache,
        }
 
        return 0;
+}
+
+void
+rspamd_symcache_composites_foreach (struct rspamd_task *task,
+                                                                                struct rspamd_symcache *cache,
+                                                                                GHFunc func,
+                                                                                gpointer fd)
+{
+       guint i;
+       struct rspamd_symcache_item *item;
+       struct rspamd_symcache_dynamic_item *dyn_item;
+
+       PTR_ARRAY_FOREACH (cache->composites, i, item) {
+               dyn_item = rspamd_symcache_get_dynamic (task->checkpoint, item);
+
+               if (!CHECK_START_BIT (task->checkpoint, dyn_item)) {
+                       SET_START_BIT (task->checkpoint, dyn_item);
+                       func (item->symbol, item->specific.normal.user_data, fd);
+                       SET_FINISH_BIT (task->checkpoint, dyn_item);
+               }
+       }
 }
\ No newline at end of file
index 965895221b7a9541e41e0df1a43b923664ae68d9..69eac1f01fe3298db23b6e35ed2b2865542abf25 100644 (file)
@@ -402,4 +402,16 @@ gboolean rspamd_symcache_item_async_dec_check_full (struct rspamd_task *task,
 void rspamd_symcache_disable_all_symbols (struct rspamd_task *task,
                                                                                  struct rspamd_symcache *cache,
                                                                                  guint skip_mask);
+
+/**
+ * Iterates over the list of the enabled composites calling specified function
+ * @param task
+ * @param cache
+ * @param func
+ * @param fd
+ */
+void rspamd_symcache_composites_foreach (struct rspamd_task *task,
+                                                                                struct rspamd_symcache *cache,
+                                                                                GHFunc func,
+                                                                                gpointer fd);
 #endif