commit 3e22813: [Minor] Document `gtube_patterns`

Vsevolod Stakhov vsevolod at rspamd.com
Thu Nov 9 14:07:06 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-11-09 13:45:36 +0000
URL: https://github.com/rspamd/rspamd/commit/3e228133bb945d5c1a3a381365b3c3a3d552098b (refs/pull/4691/head)

[Minor] Document `gtube_patterns`

---
 src/libserver/cfg_rcl.cxx | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/libserver/cfg_rcl.cxx b/src/libserver/cfg_rcl.cxx
index fbfcbcd34..b43014a1c 100644
--- a/src/libserver/cfg_rcl.cxx
+++ b/src/libserver/cfg_rcl.cxx
@@ -31,6 +31,7 @@
 
 #include <string>
 #include <filesystem>
+#include <algorithm>// for std::transform
 #include <memory>
 #include "contrib/ankerl/unordered_dense.h"
 #include "fmt/core.h"
@@ -349,15 +350,21 @@ rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
 
 	const auto *gtube_patterns = ucl_object_lookup(obj, "gtube_patterns");
 	if (gtube_patterns != nullptr && ucl_object_type(gtube_patterns) == UCL_STRING) {
-		const auto *gtube_st = ucl_object_tostring(gtube_patterns);
+		auto gtube_st = std::string{ucl_object_tostring(gtube_patterns)};
+		std::transform(gtube_st.begin(), gtube_st.end(), gtube_st.begin(), [](const auto c) -> int {
+			if (c <= 'Z' && c >= 'A')
+				return c - ('Z' - 'z');
+			return c;
+		});
+
 
-		if (g_ascii_strcasecmp(gtube_st, "all") == 0) {
+		if (gtube_st == "all") {
 			cfg->gtube_patterns_policy = RSPAMD_GTUBE_ALL;
 		}
-		else if (g_ascii_strcasecmp(gtube_st, "reject") == 0) {
+		else if (gtube_st == "reject") {
 			cfg->gtube_patterns_policy = RSPAMD_GTUBE_REJECT;
 		}
-		else if (g_ascii_strcasecmp(gtube_st, "disable") == 0) {
+		else if (gtube_st == "disabled" || gtube_st == "disable") {
 			cfg->gtube_patterns_policy = RSPAMD_GTUBE_DISABLED;
 		}
 		else {
@@ -365,7 +372,7 @@ rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
 						CFG_RCL_ERROR,
 						EINVAL,
 						"invalid GTUBE patterns policy: %s",
-						gtube_st);
+						gtube_st.c_str());
 			return FALSE;
 		}
 	}
@@ -2183,6 +2190,16 @@ rspamd_rcl_config_init(struct rspamd_config *cfg, GHashTable *skip_sections)
 									   0,
 									   "Events backend to use: kqueue, epoll, select, poll or auto (default: auto)");
 
+		rspamd_rcl_add_doc_by_path(cfg,
+								   "options",
+								   "Swtich mode of gtube patterns: disable, reject, all",
+								   "gtube_patterns",
+								   UCL_STRING,
+								   nullptr,
+								   0,
+								   "reject",
+								   0);
+
 		/* Neighbours configuration */
 		rspamd_rcl_add_section_doc(&top, sub, "neighbours", "name",
 								   rspamd_rcl_neighbours_handler,


More information about the Commits mailing list