]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow setting fuzzy flag by symbol not by value
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Jun 2016 13:35:03 +0000 (14:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Jun 2016 13:35:03 +0000 (14:35 +0100)
src/client/rspamc.c
src/plugins/fuzzy_check.c

index 638ccedfe5c2d5c11d5d767bf0f2b0d5e93928f2..68c33472d97753ed0da2439813fd034baf02b68b 100644 (file)
@@ -43,6 +43,7 @@ static gchar *sort = NULL;
 static gchar **http_headers = NULL;
 static gint weight = 0;
 static gint flag = 0;
+static gchar *fuzzy_symbol = NULL;
 static gint max_requests = 8;
 static gdouble timeout = 10.0;
 static gboolean pass_all;
@@ -133,6 +134,8 @@ static GOptionEntry entries[] =
                "Sort output in a specific order (name, weight, time)", NULL},
        { "empty", 'E', 0, G_OPTION_ARG_NONE, &empty_input,
           "Allow empty input instead of reading from stdin", NULL },
+       { "fuzzy-symbol", 'S', 0, G_OPTION_ARG_STRING, &fuzzy_symbol,
+          "Learn the specified fuzzy symbol", NULL },
        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
 };
 
@@ -468,6 +471,9 @@ add_options (GQueue *opts)
                rspamd_printf_gstring (numbuf, "%d", weight);
                ADD_CLIENT_HEADER (opts, "Weight", numbuf->str);
        }
+       if (fuzzy_symbol != NULL) {
+               ADD_CLIENT_HEADER (opts, "Symbol", fuzzy_symbol);
+       }
        if (flag != 0) {
                numbuf = g_string_sized_new (8);
                rspamd_printf_gstring (numbuf, "%d", flag);
index caf894bf3fbaa33c8d5d52478cb20fb1392bca4b..d2b0137f2b4e36b73c681f9168a8ff9e292adc8e 100644 (file)
@@ -2321,7 +2321,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
        return;
 }
 
-static gboolean
+static int
 fuzzy_controller_handler (struct rspamd_http_connection_entry *conn_ent,
        struct rspamd_http_message *msg, struct module_ctx *ctx, gint cmd)
 {
@@ -2337,14 +2337,52 @@ fuzzy_controller_handler (struct rspamd_http_connection_entry *conn_ent,
                        msg_info ("error converting numeric argument %T", arg);
                }
        }
+
        arg = rspamd_http_message_find_header (msg, "Flag");
        if (arg) {
                errno = 0;
+
                if (!rspamd_strtol (arg->begin, arg->len, &flag)) {
                        msg_info ("error converting numeric argument %T", arg);
                        flag = 0;
                }
        }
+       else {
+               flag = 0;
+               arg = rspamd_http_message_find_header (msg, "Symbol");
+
+               /* Search flag by symbol */
+               if (arg) {
+                       struct fuzzy_rule *rule;
+                       GList *cur;
+                       GHashTableIter it;
+                       gpointer k, v;
+                       struct fuzzy_mapping *map;
+
+                       for (cur = fuzzy_module_ctx->fuzzy_rules; cur != NULL && flag == 0;
+                                       cur = g_list_next (cur)) {
+                               rule = cur->data;
+
+                               g_hash_table_iter_init (&it, rule->mappings);
+
+                               while (g_hash_table_iter_next (&it, &k, &v)) {
+                                       map = v;
+
+                                       if (strlen (map->symbol) == arg->len &&
+                                                       rspamd_lc_cmp (map->symbol, arg->begin, arg->len) == 0) {
+                                               flag = map->fuzzy_flag;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (flag == 0) {
+               msg_err ("no flag defined to learn fuzzy");
+               rspamd_controller_send_error (conn_ent, 404, "Unknown or missing flag");
+               return 0;
+       }
 
        fuzzy_process_handler (conn_ent, msg, cmd, value, flag,
                (struct fuzzy_ctx *)ctx);