diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-01-21 21:08:16 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-01-21 21:08:16 +0000 |
commit | 8fb3dc2ad50d23b2bec5dcf1ddeb17c50b8b3b67 (patch) | |
tree | 4d103cf93aa97bf74291996e0e18d9086a7d37cc /src/client | |
parent | d4af7a5a931dcc10ff6847548f8a234dc7a53a24 (diff) | |
download | rspamd-8fb3dc2ad50d23b2bec5dcf1ddeb17c50b8b3b67.tar.gz rspamd-8fb3dc2ad50d23b2bec5dcf1ddeb17c50b8b3b67.zip |
[Minor] Use raw more intentionally in a client
--raw flag now means raw **input**, and there is a special flag to emit
reply in ucl. Previously, `--raw` and `--ucl` had the same meaning which
was stupid. Now `--raw` is an input flag whilst `--ucl` is an output flag
as intended.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/rspamc.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 3760c62e0..0a49c1c04 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -57,6 +57,7 @@ static gboolean json = FALSE; static gboolean compact = FALSE; static gboolean headers = FALSE; static gboolean raw = FALSE; +static gboolean ucl_reply = FALSE; static gboolean extended_urls = FALSE; static gboolean mime_output = FALSE; static gboolean empty_input = FALSE; @@ -130,9 +131,9 @@ static GOptionEntry entries[] = { "compact", '\0', 0, G_OPTION_ARG_NONE, &compact, "Output compact json reply", NULL}, { "headers", 0, 0, G_OPTION_ARG_NONE, &headers, "Output HTTP headers", NULL }, - { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "Output raw reply from rspamd", + { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "Input is a raw file, not an email file", NULL }, - { "ucl", 0, 0, G_OPTION_ARG_NONE, &raw, "Output ucl reply from rspamd", + { "ucl", 0, 0, G_OPTION_ARG_NONE, &ucl_reply, "Output ucl reply from rspamd", NULL }, { "max-requests", 'n', 0, G_OPTION_ARG_INT, &max_requests, "Maximum count of parallel requests to rspamd", NULL }, @@ -406,7 +407,7 @@ read_cmd_line (gint *argc, gchar ***argv) } if (json || compact) { - raw = TRUE; + ucl_reply = TRUE; } /* Argc and argv are shifted after this function */ g_option_context_free (context); @@ -635,6 +636,10 @@ add_options (GQueue *opts) ADD_CLIENT_FLAG (flagbuf, "pass_all"); } + if (raw) { + ADD_CLIENT_HEADER (opts, "Raw", "yes"); + } + if (classifier) { ADD_CLIENT_HEADER (opts, "Classifier", classifier); } @@ -1404,7 +1409,7 @@ rspamc_mime_output (FILE *out, ucl_object_t *result, GString *input, } } - if (json || raw || compact) { + if (json || ucl_reply || compact) { /* We also append json data as a specific header */ if (json) { json_header = ucl_object_emit (result, @@ -1482,7 +1487,7 @@ rspamc_client_execute_cmd (struct rspamc_command *cmd, ucl_object_t *result, rspamc_mime_output (out, result, input, time, err); } else if (result) { - if (raw || cmd->command_output_func == NULL) { + if (ucl_reply || cmd->command_output_func == NULL) { if (json) { ucl_out = ucl_object_emit (result, compact ? UCL_EMIT_JSON_COMPACT : UCL_EMIT_JSON); @@ -1571,7 +1576,7 @@ rspamc_client_cb (struct rspamd_client_connection *conn, if (headers && msg != NULL) { rspamc_output_headers (out, msg); } - if (raw || cmd->command_output_func == NULL) { + if (ucl_reply || cmd->command_output_func == NULL) { if (cmd->need_input) { ucl_object_insert_key (result, ucl_object_fromstring (cbdata->filename), @@ -1611,15 +1616,15 @@ rspamc_client_cb (struct rspamd_client_connection *conn, rspamd_fprintf (out, "%s\n", err->message); if (json && msg != NULL) { - const gchar *raw; + const gchar *raw_body; gsize rawlen; - raw = rspamd_http_message_get_body (msg, &rawlen); + raw_body = rspamd_http_message_get_body (msg, &rawlen); - if (raw) { + if (raw_body) { /* We can also output the resulting json */ rspamd_fprintf (out, "%*s\n", (gint)(rawlen - bodylen), - raw); + raw_body); } } } |