From 0d993808484537046f93dd938a07e2e2c2e9ac87 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 19 Oct 2015 17:16:21 +0100 Subject: [PATCH] Add ability to specify custom headers for rspamc client --- doc/rspamc.1.md | 3 +++ src/client/rspamc.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/doc/rspamc.1.md b/doc/rspamc.1.md index f4d089bc1..99bfea376 100644 --- a/doc/rspamc.1.md +++ b/doc/rspamc.1.md @@ -111,6 +111,9 @@ requires input. \--mime : Output the full mime message instead of scanning results only +\--header=*header* +: Add custom HTTP header for a request. You may specify header in format `name=value` or just `name` for an empty header. This option can be repeated multiple times. + \--commands : List available commands diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 9be97cba0..7c0e76d5c 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -48,6 +48,7 @@ static gchar *hostname = "localhost"; static gchar *classifier = "bayes"; static gchar *local_addr = NULL; static gchar *execute = NULL; +static gchar **http_headers = NULL; static gint weight = 0; static gint flag = 0; static gint max_requests = 8; @@ -118,6 +119,8 @@ static GOptionEntry entries[] = "Execute the specified command and pass output to it", NULL }, { "mime", 'e', 0, G_OPTION_ARG_NONE, &mime_output, "Write mime body of message with headers instead of just a scan's result", NULL }, + {"header", 0, 0, G_OPTION_ARG_STRING_ARRAY, &http_headers, + "Add custom HTTP header to query (can be repeated)", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; @@ -389,6 +392,7 @@ static void add_options (GHashTable *opts) { GString *numbuf; + gchar **hdr; if (ip != NULL) { g_hash_table_insert (opts, "Ip", ip); @@ -430,6 +434,25 @@ add_options (GHashTable *opts) if (extended_urls) { g_hash_table_insert (opts, "URL-Format", "extended"); } + + hdr = http_headers; + + while (*hdr != NULL) { + gchar **kv = g_strsplit_set (*hdr, ":=", 2); + + if (kv == NULL || kv[1] == NULL) { + g_hash_table_insert (opts, *hdr, ""); + + if (kv) { + g_strfreev (kv); + } + } + else { + g_hash_table_insert (opts, kv[0], kv[1]); + } + + hdr ++; + } } static void -- 2.39.5