]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Add helpers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Jul 2018 17:39:11 +0000 (18:39 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Jul 2018 17:39:11 +0000 (18:39 +0100)
src/libmime/filter.c
src/libmime/filter.h

index f9901da7c791e8bbf020a9a130a0951bad03bad6..8677ef8a1c98739147618cb252b7a8041309b4d2 100644 (file)
@@ -419,3 +419,36 @@ rspamd_check_action_metric (struct rspamd_task *task, struct rspamd_metric_resul
 
        return METRIC_ACTION_NOACTION;
 }
+
+struct rspamd_symbol_result*
+rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym)
+{
+       struct rspamd_symbol_result *res = NULL;
+       khiter_t k;
+
+
+       if (task->result) {
+               k = kh_get (rspamd_symbols_hash, task->result->symbols, sym);
+
+               if (k != kh_end (task->result->symbols)) {
+                       res = &kh_value (task->result->symbols, k);
+               }
+       }
+
+       return res;
+}
+
+void
+rspamd_task_symbol_result_foreach (struct rspamd_task *task,
+                                                                               GHFunc func,
+                                                                               gpointer ud)
+{
+       const gchar *kk;
+       struct rspamd_symbol_result res;
+
+       if (func && task->result) {
+               kh_foreach (task->result->symbols, kk, res, {
+                       func ((gpointer)kk, (gpointer)&res, ud);
+               });
+       }
+}
\ No newline at end of file
index 4f75cc19295ef8e8cbe6b8540254cbcbbf5233f9..de8cb57b8a156ab2621b9f305a6a9d72fc0166be 100644 (file)
@@ -104,6 +104,25 @@ struct rspamd_symbol_result* rspamd_task_insert_result_full (struct rspamd_task
 gboolean rspamd_task_add_result_option (struct rspamd_task *task,
                struct rspamd_symbol_result *s, const gchar *opt);
 
+/**
+ * Finds symbol result
+ * @param task
+ * @param sym
+ * @return
+ */
+struct rspamd_symbol_result* rspamd_task_find_symbol_result (
+               struct rspamd_task *task, const char *sym);
+
+/**
+ * Compatibility function to iterate on symbols hash
+ * @param task
+ * @param func
+ * @param ud
+ */
+void rspamd_task_symbol_result_foreach (struct rspamd_task *task,
+                                                                               GHFunc func,
+                                                                               gpointer ud);
+
 /**
  * Default consolidation function for metric, it get all symbols and multiply symbol
  * weight by some factor that is specified in config. Default factor is 1.