]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Adopt code for the new options
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 5 Dec 2016 13:23:54 +0000 (13:23 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 5 Dec 2016 13:23:54 +0000 (13:23 +0000)
src/libmime/filter.c
src/libstat/classifiers/bayes.c
src/lua/lua_config.c
src/lua/lua_task.c
src/plugins/dkim_check.c
src/plugins/spf.c
src/plugins/surbl.c

index 686e30ad7af671e7e4f9ca9ee3f140584215f27a..c9f40ea1db6c8274785bac0f36ed2462c52c8ab9 100644 (file)
@@ -80,7 +80,6 @@ insert_metric_result (struct rspamd_task *task,
 {
        struct metric_result *metric_res;
        struct symbol *s = NULL;
-       char *opt_cpy;
        gdouble w, *gr_score = NULL;
        struct rspamd_symbol_def *sdef;
        struct rspamd_symbols_group *gr = NULL;
index 07fe6cc8672af4087aad9d398dbd754e8d5ed789..98b3fd6ca9f3e31d75a5adff6dfbdefc879e9327 100644 (file)
@@ -181,13 +181,12 @@ bayes_classify (struct rspamd_classifier * ctx,
                struct rspamd_task *task)
 {
        double final_prob, h, s, *pprob;
-       char *sumbuf;
+       gchar sumbuf[32];
        struct rspamd_statfile *st = NULL;
        struct bayes_task_closure cl;
        rspamd_token_t *tok;
        guint i;
        gint id;
-       GList *cur;
 
        g_assert (ctx != NULL);
        g_assert (tokens != NULL);
@@ -262,9 +261,6 @@ bayes_classify (struct rspamd_classifier * ctx,
        rspamd_mempool_set_variable (task->task_pool, "bayes_prob", pprob, NULL);
 
        if (cl.processed_tokens > 0 && fabs (final_prob - 0.5) > 0.05) {
-
-               sumbuf = rspamd_mempool_alloc (task->task_pool, 32);
-
                /* Now we can have exactly one HAM and exactly one SPAM statfiles per classifier */
                for (i = 0; i < ctx->statfiles_ids->len; i++) {
                        id = g_array_index (ctx->statfiles_ids, gint, i);
@@ -287,14 +283,14 @@ bayes_classify (struct rspamd_classifier * ctx,
                 * Bayes p is from 0.5 to 1.0, but confidence is from 0 to 1, so
                 * we need to rescale it to display correctly
                 */
-               rspamd_snprintf (sumbuf, 32, "%.2f%%", (final_prob - 0.5) * 200.);
+               rspamd_snprintf (sumbuf, sizeof (sumbuf), "%.2f%%",
+                               (final_prob - 0.5) * 200.);
                final_prob = rspamd_normalize_probability (final_prob, 0.5);
                g_assert (st != NULL);
-               cur = g_list_prepend (NULL, sumbuf);
                rspamd_task_insert_result (task,
                                st->stcf->symbol,
                                final_prob,
-                               cur);
+                               sumbuf);
        }
 
        return TRUE;
index 7c2b8460962541171ca83ce45023ded421525a32..48bb36e6d1f3fffb1183e8fe18d1c8ac747bfee7 100644 (file)
@@ -808,6 +808,7 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
        gint level = lua_gettop (cd->L), nresults, err_idx;
        lua_State *L = cd->L;
        GString *tb;
+       struct symbol *s;
 
        lua_pushcfunction (L, &rspamd_lua_traceback);
        err_idx = lua_gettop (L);
@@ -837,7 +838,6 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
                if (nresults >= 1) {
                        /* Function returned boolean, so maybe we need to insert result? */
                        gint res = 0;
-                       GList *opts = NULL;
                        gint i;
                        gdouble flag = 1.0;
 
@@ -860,17 +860,18 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
                                        flag = res;
                                }
 
-                               for (i = lua_gettop (L); i >= level + first_opt; i--) {
-                                       if (lua_type (L, i) == LUA_TSTRING) {
-                                               const char *opt = lua_tostring (L, i);
+                               s = rspamd_task_insert_result (task, cd->symbol, flag, NULL);
 
-                                               opts = g_list_prepend (opts,
-                                                               rspamd_mempool_strdup (task->task_pool,
-                                                                               opt));
+                               if (s) {
+                                       for (i = lua_gettop (L); i >= level + first_opt; i--) {
+                                               if (lua_type (L, i) == LUA_TSTRING) {
+                                                       const char *opt = lua_tostring (L, i);
+
+                                                       rspamd_task_add_result_option (task, s, opt);
+                                               }
                                        }
                                }
 
-                               rspamd_task_insert_result (task, cd->symbol, flag, opts);
                        }
 
                        lua_pop (L, nresults);
index 8f28bb97bf5b719a013a5814946828f2f32d1d75..7693fe48e5ec0906322fe9d925663578a7dc8dfd 100644 (file)
@@ -1018,7 +1018,7 @@ lua_task_insert_result (lua_State * L)
        struct rspamd_task *task = lua_check_task (L, 1);
        const gchar *symbol_name, *param;
        double flag;
-       GList *params = NULL;
+       struct symbol *s;
        gint i, top;
 
        if (task != NULL) {
@@ -1026,35 +1026,30 @@ lua_task_insert_result (lua_State * L)
                        rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2));
                flag = luaL_checknumber (L, 3);
                top = lua_gettop (L);
+               s = rspamd_task_insert_result (task, symbol_name, flag, NULL);
+
                /* Get additional options */
-               for (i = 4; i <= top; i++) {
-                       if (lua_type (L, i) == LUA_TSTRING) {
-                               param = luaL_checkstring (L, i);
-                               params =
-                                               g_list_prepend (params,
-                                                               rspamd_mempool_strdup (task->task_pool, param));
-                       }
-                       else if (lua_type (L, i) == LUA_TTABLE) {
-                               lua_pushvalue (L, i);
-                               lua_pushnil (L);
+               if (s) {
+                       for (i = 4; i <= top; i++) {
+                               if (lua_type (L, i) == LUA_TSTRING) {
+                                       param = luaL_checkstring (L, i);
+                                       rspamd_task_add_result_option (task, s, param);
+                               }
+                               else if (lua_type (L, i) == LUA_TTABLE) {
+                                       lua_pushvalue (L, i);
+                                       lua_pushnil (L);
+
+                                       while (lua_next (L, -2)) {
+                                               param = lua_tostring (L, -1);
+                                               rspamd_task_add_result_option (task, s, param);
+                                               lua_pop (L, 1);
+                                       }
 
-                               while (lua_next (L, -2)) {
-                                       param = lua_tostring (L, -1);
-                                       params = g_list_prepend (params,
-                                                                       rspamd_mempool_strdup (task->task_pool,
-                                                                                       param));
                                        lua_pop (L, 1);
                                }
-
-                               lua_pop (L, 1);
                        }
                }
 
-               if (params) {
-                       params = g_list_reverse (params);
-               }
-
-               rspamd_task_insert_result (task, symbol_name, flag, params);
        }
        else {
                return luaL_error (L, "invalid arguments");
index 71214b2bc7ba184754948045b62a24036a229e57..5d30cdcb37a46f15eb13d6e346ddd76b681e056c 100644 (file)
@@ -616,8 +616,8 @@ dkim_module_check (struct dkim_check_result *res)
        if (all_done) {
                DL_FOREACH (first, cur) {
                        const gchar *symbol = NULL;
-                       GList *messages = NULL;
                        int symbol_weight = 1;
+
                        if (cur->ctx == NULL) {
                                continue;
                        }
@@ -635,14 +635,12 @@ dkim_module_check (struct dkim_check_result *res)
                        else if (cur->res == DKIM_TRYAGAIN) {
                                symbol = dkim_module_ctx->symbol_tempfail;
                        }
+
                        if (symbol != NULL) {
-                               messages = g_list_prepend (messages,
-                                               rspamd_mempool_strdup (cur->task->task_pool,
-                                               rspamd_dkim_get_domain (cur->ctx)));
                                rspamd_task_insert_result (cur->task,
                                                symbol,
                                                symbol_weight,
-                                               messages);
+                                               rspamd_dkim_get_domain (cur->ctx));
                        }
                }
                rspamd_session_watcher_pop (res->task->s, res->w);
index 98ca09c371ced95df70782ca3a5aec4708274e31..d7b76e003e4813ab22fb8a2151d8e4887e85a774 100644 (file)
@@ -347,7 +347,6 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
        gchar *spf_result;
        guint af, mask, bmask, addrlen;
        const gchar *spf_message, *spf_symbol;
-       GList *opts = NULL;
 
        if (task->from_addr == NULL) {
                return FALSE;
@@ -406,7 +405,6 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
        if (res) {
                spf_result = rspamd_mempool_alloc (task->task_pool,
                                strlen (addr->spf_string) + 2);
-               opts = g_list_prepend (opts, spf_result);
 
                switch (addr->mech) {
                case SPF_FAIL:
@@ -464,7 +462,7 @@ spf_check_element (struct spf_resolved *rec, struct spf_addr *addr,
                rspamd_task_insert_result (task,
                                spf_symbol,
                                1,
-                               opts);
+                               spf_result);
                ucl_object_insert_key (task->messages,
                                ucl_object_fromstring (spf_message), "spf", 0,
                                false);
@@ -575,15 +573,12 @@ spf_symbol_callback (struct rspamd_task *task, void *unused)
                        w = rspamd_session_get_watcher (task->s);
 
                        if (!rspamd_spf_resolve (task, spf_plugin_callback, w)) {
-                               GList *opts = NULL;
-
-                               opts = g_list_prepend (opts, "(SPF): spf DNS fail");
                                msg_info_task ("cannot make spf request for [%s]",
                                                task->message_id);
                                rspamd_task_insert_result (task,
                                                spf_module_ctx->symbol_dnsfail,
                                                1,
-                                               opts);
+                                               "(SPF): spf DNS fail");
                        }
                        else {
                                rspamd_session_watcher_push (task->s);
index 6dea0b939a6506eee863b3b21b5f16660a35ecb6..32c002d963c151f63788dfb7ba03c3cd409d5ca0 100644 (file)
@@ -1137,9 +1137,7 @@ process_dns_results (struct rspamd_task *task,
                                        task->message_id,
                                        url, suffix->suffix,
                                        bit->bit);
-                       rspamd_task_insert_result (task, bit->symbol, 1,
-                               g_list_prepend (NULL,
-                               rspamd_mempool_strdup (task->task_pool, url)));
+                       rspamd_task_insert_result (task, bit->symbol, 1, url);
                        got_result = TRUE;
                }
        }
@@ -1158,9 +1156,7 @@ process_dns_results (struct rspamd_task *task,
                                                task->message_id,
                                                url, suffix->suffix,
                                                bit->bit);
-                               rspamd_task_insert_result (task, bit->symbol, 1,
-                                       g_list_prepend (NULL,
-                                       rspamd_mempool_strdup (task->task_pool, url)));
+                               rspamd_task_insert_result (task, bit->symbol, 1, url);
                        }
                }
        }
@@ -1170,9 +1166,7 @@ process_dns_results (struct rspamd_task *task,
                        msg_info_task ("<%s> domain [%s] is in surbl %s",
                                        task->message_id,
                                        url, suffix->suffix);
-                       rspamd_task_insert_result (task, suffix->symbol, 1,
-                                       g_list_prepend (NULL,
-                                                       rspamd_mempool_strdup (task->task_pool, url)));
+                       rspamd_task_insert_result (task, suffix->symbol, 1, url);
                }
                else {
                        ina.s_addr = addr;
@@ -1456,7 +1450,7 @@ surbl_tree_url_callback (gpointer key, gpointer value, void *data)
                                        rspamd_task_insert_result (param->task,
                                                        surbl_module_ctx->redirector_symbol,
                                                        1,
-                                                       g_list_prepend (NULL, found_tld));
+                                                       found_tld);
                                }
 
                                register_redirector_call (url,