commit 8a9cf09: [Minor] Add flags support to rspamc

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Jul 16 15:28:08 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-16 15:40:27 +0100
URL: https://github.com/rspamd/rspamd/commit/8a9cf09b55619b7c46f1d6e3cc742cf10973bd60

[Minor] Add flags support to rspamc

---
 src/client/rspamc.c      | 22 ++++++++++++++++++++--
 src/libserver/protocol.c |  1 +
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index d08a7f620..5b3f874ef 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -79,6 +79,10 @@ static gint retcode = EXIT_SUCCESS;
     g_queue_push_tail ((o), nh); \
 } while (0)
 
+#define ADD_CLIENT_FLAG(str, n) do { \
+   g_string_append ((str), (n)); \
+} while (0)
+
 static gboolean rspamc_password_callback (const gchar *option_name,
 		const gchar *value,
 		gpointer data,
@@ -553,6 +557,7 @@ add_options (GQueue *opts)
 {
 	GString *numbuf;
 	gchar **hdr, **rcpt;
+	GString *flagbuf = g_string_new (NULL);
 
 	if (ip != NULL) {
 		rspamd_inet_addr_t *addr = NULL;
@@ -634,7 +639,7 @@ add_options (GQueue *opts)
 	}
 
 	if (pass_all) {
-		ADD_CLIENT_HEADER (opts, "Pass", "all");
+		ADD_CLIENT_FLAG (flagbuf, "pass_all");
 	}
 
 	if (classifier) {
@@ -664,7 +669,7 @@ add_options (GQueue *opts)
 	}
 
 	if (profile) {
-		ADD_CLIENT_HEADER (opts, "Profile", "true");
+		ADD_CLIENT_FLAG (flagbuf, "profile");
 	}
 
 	if (skip_images) {
@@ -693,6 +698,19 @@ add_options (GQueue *opts)
 
 		hdr ++;
 	}
+
+	if (flagbuf->len > 0) {
+		goffset last = flagbuf->len - 1;
+
+		if (flagbuf->str[last] == ',') {
+			flagbuf->str[last] = '\0';
+			flagbuf->len --;
+		}
+
+		ADD_CLIENT_HEADER (opts, "Flags", flagbuf->str);
+	}
+
+	g_string_free (flagbuf, TRUE);
 }
 
 static void
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 602878d9b..30ab766ce 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -365,6 +365,7 @@ rspamd_protocol_handle_flag (struct rspamd_task *task, const gchar *str,
 	CHECK_TASK_FLAG("skip", RSPAMD_TASK_FLAG_NO_LOG);
 	CHECK_TASK_FLAG("no_stat", RSPAMD_TASK_FLAG_NO_STAT);
 	CHECK_TASK_FLAG("ssl", RSPAMD_TASK_FLAG_SSL);
+	CHECK_TASK_FLAG("profile", RSPAMD_TASK_FLAG_PROFILE);
 
 	CHECK_PROTOCOL_FLAG("milter", RSPAMD_TASK_PROTOCOL_FLAG_MILTER);
 	CHECK_PROTOCOL_FLAG("zstd", RSPAMD_TASK_PROTOCOL_FLAG_COMPRESSED);


More information about the Commits mailing list