From: Vsevolod Stakhov Date: Sat, 12 Nov 2016 13:24:31 +0000 (+0000) Subject: [Feature] Add fuzzy_delhash command to rspamc client X-Git-Tag: 1.4.0~83 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2c256794ff455b4e39868fc860afec24b4326f6a;p=rspamd.git [Feature] Add fuzzy_delhash command to rspamc client --- diff --git a/src/client/rspamc.c b/src/client/rspamc.c index eda1d2f9e..33d49345a 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -168,6 +168,7 @@ enum rspamc_command_type { RSPAMC_COMMAND_LEARN_HAM, RSPAMC_COMMAND_FUZZY_ADD, RSPAMC_COMMAND_FUZZY_DEL, + RSPAMC_COMMAND_FUZZY_DELHASH, RSPAMC_COMMAND_STAT, RSPAMC_COMMAND_STAT_RESET, RSPAMC_COMMAND_COUNTERS, @@ -221,7 +222,7 @@ struct rspamc_command { .name = "fuzzy_add", .path = "fuzzyadd", .description = - "add message to fuzzy storage (check -f and -w options for this command)", + "add hashes from a message to the fuzzy storage (check -f and -w options for this command)", .is_controller = TRUE, .is_privileged = TRUE, .need_input = TRUE, @@ -232,12 +233,23 @@ struct rspamc_command { .name = "fuzzy_del", .path = "fuzzydel", .description = - "delete message from fuzzy storage (check -f option for this command)", + "delete hashes from a message from the fuzzy storage (check -f option for this command)", .is_controller = TRUE, .is_privileged = TRUE, .need_input = TRUE, .command_output_func = NULL }, + { + .cmd = RSPAMC_COMMAND_FUZZY_DELHASH, + .name = "fuzzy_delhash", + .path = "fuzzydelhash", + .description = + "delete a hash from fuzzy storage (check -f option for this command)", + .is_controller = TRUE, + .is_privileged = TRUE, + .need_input = FALSE, + .command_output_func = NULL + }, { .cmd = RSPAMC_COMMAND_STAT, .name = "stat", @@ -385,6 +397,9 @@ check_rspamc_command (const gchar *cmd) else if (g_ascii_strcasecmp (cmd, "FUZZY_DEL") == 0) { ct = RSPAMC_COMMAND_FUZZY_DEL; } + else if (g_ascii_strcasecmp (cmd, "FUZZY_DELHASH") == 0) { + ct = RSPAMC_COMMAND_FUZZY_DELHASH; + } else if (g_ascii_strcasecmp (cmd, "STAT") == 0) { ct = RSPAMC_COMMAND_STAT; } @@ -1640,31 +1655,40 @@ main (gint argc, gchar **argv, gchar **env) } else { for (i = start_argc; i < argc; i++) { - if (stat (argv[i], &st) == -1) { - fprintf (stderr, "cannot stat file %s\n", argv[i]); - exit (EXIT_FAILURE); - } - if (S_ISDIR (st.st_mode)) { - /* Directories are processed with a separate limit */ - rspamc_process_dir (ev_base, cmd, argv[i], kwattrs); - cur_req = 0; + if (cmd->cmd == RSPAMC_COMMAND_FUZZY_DELHASH) { + ADD_CLIENT_HEADER (kwattrs, "Hash", argv[i]); } else { - in = fopen (argv[i], "r"); - if (in == NULL) { - fprintf (stderr, "cannot open file %s\n", argv[i]); + if (stat (argv[i], &st) == -1) { + fprintf (stderr, "cannot stat file %s\n", argv[i]); exit (EXIT_FAILURE); } - rspamc_process_input (ev_base, cmd, in, argv[i], kwattrs); - cur_req++; - fclose (in); - } - if (cur_req >= max_requests) { - cur_req = 0; - /* Wait for completion */ - event_base_loop (ev_base, 0); + if (S_ISDIR (st.st_mode)) { + /* Directories are processed with a separate limit */ + rspamc_process_dir (ev_base, cmd, argv[i], kwattrs); + cur_req = 0; + } + else { + in = fopen (argv[i], "r"); + if (in == NULL) { + fprintf (stderr, "cannot open file %s\n", argv[i]); + exit (EXIT_FAILURE); + } + rspamc_process_input (ev_base, cmd, in, argv[i], kwattrs); + cur_req++; + fclose (in); + } + if (cur_req >= max_requests) { + cur_req = 0; + /* Wait for completion */ + event_base_loop (ev_base, 0); + } } } + + if (cmd->cmd == RSPAMC_COMMAND_FUZZY_DELHASH) { + rspamc_process_input (ev_base, cmd, NULL, "hashes", kwattrs); + } } event_base_loop (ev_base, 0);