]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Use watchers for spf plugin
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Jul 2016 13:54:10 +0000 (14:54 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Jul 2016 14:09:39 +0000 (15:09 +0100)
src/libserver/spf.c
src/libserver/spf.h
src/plugins/spf.c

index 7fae5052315a28837a123e9781ade226cfc49478..aa777f85c9cdf42304dacf96f299a81bb12b928b 100644 (file)
@@ -60,6 +60,7 @@ struct spf_record {
        gchar *local_part;
        struct rspamd_task *task;
        spf_cb_t callback;
+       gpointer cbdata;
        gboolean done;
 };
 
@@ -356,7 +357,7 @@ rspamd_spf_maybe_return (struct spf_record *rec)
 
        if (rec->requests_inflight == 0 && !rec->done) {
                flat = rspamd_spf_record_flatten (rec);
-               rec->callback (flat, rec->task);
+               rec->callback (flat, rec->task, rec->cbdata);
                REF_RELEASE (flat);
                rec->done = TRUE;
        }
@@ -1821,7 +1822,8 @@ rspamd_spf_get_domain (struct rspamd_task *task)
 }
 
 gboolean
-resolve_spf (struct rspamd_task *task, spf_cb_t callback)
+rspamd_spf_resolve (struct rspamd_task *task, spf_cb_t callback,
+               gpointer cbdata)
 {
        struct spf_record *rec;
        struct rspamd_spf_cred *cred;
@@ -1839,6 +1841,7 @@ resolve_spf (struct rspamd_task *task, spf_cb_t callback)
        rec = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct spf_record));
        rec->task = task;
        rec->callback = callback;
+       rec->cbdata = cbdata;
 
        rec->resolved = g_ptr_array_sized_new (8);
 
index 01850a39208522a0a15be80750886ed7d227037c..001d3775a998789ea03df35378fca2933a9dbeb2 100644 (file)
@@ -8,7 +8,8 @@
 struct rspamd_task;
 struct spf_resolved;
 
-typedef void (*spf_cb_t)(struct spf_resolved *record, struct rspamd_task *task);
+typedef void (*spf_cb_t)(struct spf_resolved *record,
+               struct rspamd_task *task, gpointer cbdata);
 
 typedef enum spf_mech_e {
        SPF_FAIL,
@@ -66,7 +67,8 @@ struct spf_resolved {
 /*
  * Resolve spf record for specified task and call a callback after resolution fails/succeed
  */
-gboolean resolve_spf (struct rspamd_task *task, spf_cb_t callback);
+gboolean rspamd_spf_resolve (struct rspamd_task *task, spf_cb_t callback,
+               gpointer cbdata);
 
 /*
  * Get a domain for spf for specified task
index 5dbc535e48bddb1339cfebf60106773984110d6d..5a12d3c7c84bffd548fcc28de3255eabf860e839 100644 (file)
@@ -68,18 +68,6 @@ module_t spf_module = {
        RSPAMD_MODULE_VER
 };
 
-static GQuark
-spf_plugin_quark (void)
-{
-       return g_quark_from_static_string ("spf-plugin");
-}
-
-static void
-spf_plugin_fin (gpointer ud)
-{
-
-}
-
 gint
 spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 {
@@ -373,9 +361,11 @@ spf_check_list (struct spf_resolved *rec, struct rspamd_task *task)
 }
 
 static void
-spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task)
+spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task,
+               gpointer ud)
 {
        struct spf_resolved *l;
+       struct rspamd_async_watcher *w = ud;
 
        if (record && record->elts->len > 0 && record->domain) {
 
@@ -394,7 +384,7 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task)
                spf_record_unref (l);
        }
 
-       rspamd_session_remove_event (task->s, spf_plugin_fin, NULL);
+       rspamd_session_watcher_pop (task->s, w);
 }
 
 
@@ -403,6 +393,7 @@ spf_symbol_callback (struct rspamd_task *task, void *unused)
 {
        const gchar *domain;
        struct spf_resolved *l;
+       struct rspamd_async_watcher *w;
 
        if (radix_find_compressed_addr (spf_module_ctx->whitelist_ip,
                        task->from_addr) != RADIX_NO_VALUE) {
@@ -424,13 +415,13 @@ spf_symbol_callback (struct rspamd_task *task, void *unused)
                        spf_record_unref (l);
                }
                else {
-                       if (!resolve_spf (task, spf_plugin_callback)) {
+                       w = rspamd_session_get_watcher (task->s);
+                       if (!rspamd_spf_resolve (task, spf_plugin_callback, w)) {
                                msg_info_task ("cannot make spf request for [%s]",
                                                task->message_id);
                        }
                        else {
-                               rspamd_session_add_event (task->s, spf_plugin_fin, NULL,
-                                               spf_plugin_quark ());
+                               rspamd_session_watcher_push (task->s);
                        }
                }
        }