]> source.dussan.org Git - rspamd.git/commitdiff
* Add ability to add custom messages to rspamd output
authorcebka@lenovo-laptop <cebka@lenovo-laptop>
Wed, 17 Feb 2010 15:57:05 +0000 (18:57 +0300)
committercebka@lenovo-laptop <cebka@lenovo-laptop>
Wed, 17 Feb 2010 15:57:05 +0000 (18:57 +0300)
* Add messages from spf checks

src/main.h
src/plugins/fuzzy_check.c
src/plugins/spf.c
src/protocol.c
src/spf.c
src/worker.c

index a7cab8676b6ee765c3fc28015aa69c8d6253916b..cffb215d5a4e9021213585f3a2b5e0db102291b0 100644 (file)
@@ -199,6 +199,7 @@ struct worker_task {
        GList *urls;                                                                                            /**< list of parsed urls                                                        */
        GHashTable *results;                                                                            /**< hash table of metric_result indexed by 
                                                                                                                                 *    metric's name                                                                     */
+       GList *messages;                                                                                        /**< list of messages that would be reported            */
        GHashTable *re_cache;                                                                           /**< cache for matched or not matched regexps           */
        struct config_file *cfg;                                                                        /**< pointer to config object                                           */
        struct save_point save;                                                                         /**< save point for delayed processing                          */
index 987a2cb40c6d37c483717ad1f180496615e01b10..40b1aaa79de88d3a9c6374381e3267899b475ddf 100644 (file)
@@ -490,7 +490,7 @@ fuzzy_controller_handler (char **args, struct controller_session *session, int c
 {
        char                           *arg, out_buf[BUFSIZ], *err_str;
        uint32_t                        size;
-       int                             r, value, *sargs;
+       int                             r, value = 1, *sargs;
 
        /* Process size */
        arg = args[0];
@@ -510,11 +510,7 @@ fuzzy_controller_handler (char **args, struct controller_session *session, int c
        }
        /* Process value */
        arg = args[1];
-       if (!arg || *arg == '\0') {
-               msg_info ("empty value, assume it 1");
-               value = 1;
-       }
-       else {
+       if (arg && *arg != '\0') {
                value = strtol (arg, &err_str, 10);
        }
 
index ae762f12af273d0b6285ebe5bc855819aeadccac..57a6f4407134e1a8424b80c2d24230f1121c102e 100644 (file)
@@ -155,13 +155,16 @@ spf_plugin_callback (struct spf_record *record, struct worker_task *task)
                     switch (addr->mech) {
                         case SPF_FAIL:
                             insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_fail, 1, g_list_prepend (NULL, addr->spf_string));
+                                                       task->messages = g_list_prepend (task->messages, "(SPF): spf fail");
                             break;
                         case SPF_SOFT_FAIL:
                         case SPF_NEUTRAL:
                             insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_softfail, 1, g_list_prepend (NULL, addr->spf_string));
+                                                       task->messages = g_list_prepend (task->messages, "(SPF): spf softfail");
                             break;
                         default:
                             insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_allow, 1, g_list_prepend (NULL, addr->spf_string));
+                                                       task->messages = g_list_prepend (task->messages, "(SPF): spf allow");
                             break;
                     }
                     /* Stop parsing */
index 134820cabd3b7a810286dcb86581f2f01a1dbf0a..e076408078e71348c30a300a528049cd3acf7e1b 100644 (file)
@@ -547,6 +547,7 @@ show_metric_symbols (struct metric_result *metric_res, struct metric_callback_da
        }
 }
 
+
 static void
 show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data)
 {
@@ -652,6 +653,22 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                (long int)task->msg->len, calculate_check_time (&task->ts, task->cfg->clock_res));
 }
 
+static void
+show_messages (struct worker_task *task)
+{
+       int                             r = 0;
+       char                            outbuf[OUTBUFSIZ];
+       GList                          *cur;
+       
+       cur = task->messages;
+       while (cur) {
+               r += snprintf (outbuf + r, sizeof (outbuf) - r, "Message: %s" CRLF, (char *)cur->data);
+               cur = g_list_next (cur);
+       }
+
+       rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, FALSE);
+}
+
 static int
 write_check_reply (struct worker_task *task)
 {
@@ -694,6 +711,8 @@ write_check_reply (struct worker_task *task)
 
                /* Write result for each metric separately */
                g_hash_table_foreach (task->results, show_metric_result, &cd);
+               /* Messages */
+               show_messages (task);
                /* URL stat */
                show_url_header (task);
        }
@@ -748,7 +767,8 @@ write_process_reply (struct worker_task *task)
 
                /* Write result for each metric separately */
                g_hash_table_foreach (task->results, show_metric_result, &cd);
-               /* URL stat */
+               /* Messages */
+               show_messages (task);
        }
        write_hashes_to_log (task, logbuf, cd.log_offset, cd.log_size);
        msg_info ("%s", logbuf);
index d9f64310d9842c3f45108c2b17e29b58c290854a..50ad3176e9a8085972222bba61786663d6699ae9 100644 (file)
--- a/src/spf.c
+++ b/src/spf.c
@@ -887,6 +887,12 @@ parse_spf_record (struct worker_task *task, struct spf_record *rec)
                                        begin += sizeof (SPF_INCLUDE) - 1;
                                        res = parse_spf_include (task, begin, rec, new);
                                }
+                               else if (strncmp (begin, SPF_IP6, sizeof (SPF_IP4) - 1) == 0) {
+                                       begin += sizeof (SPF_IP6) - 1;
+                                       msg_info ("ignoring ip6 spf command as IPv6 is not supported: %s", begin);
+                                       new = NULL;
+                                       res = TRUE;
+                               }
                                else {
                                        msg_info ("bad spf command: %s", begin);
                                }
index 92c80bc32b7f6a933d82398da346f5db58f6437f..0f1be10471fb94eacb44d8b578fee564ea5f6b50 100644 (file)
@@ -214,6 +214,9 @@ free_task (struct worker_task *task, gboolean is_soft)
                if (task->urls) {
                        g_list_free (task->urls);
                }
+               if (task->messages) {
+                       g_list_free (task->messages);
+               }
                memory_pool_delete (task->task_pool);
                if (task->dispatcher) {
                        if (is_soft) {