From: Vsevolod Stakhov Date: Mon, 27 Jun 2016 13:35:03 +0000 (+0100) Subject: [Feature] Allow setting fuzzy flag by symbol not by value X-Git-Tag: 1.3.0~241 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1af1d6ec7bf52eef7955474f8f51bc6351fa5980;p=rspamd.git [Feature] Allow setting fuzzy flag by symbol not by value --- diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 638ccedfe..68c33472d 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -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); diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index caf894bf3..d2b0137f2 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -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);