commit 5093c1c: [Project] Allow to convert control command from a string

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Sep 14 16:07:10 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-14 13:23:23 +0100
URL: https://github.com/rspamd/rspamd/commit/5093c1cf295e3e4ff87a5fdb33e1326b3424ae8b

[Project] Allow to convert control command from a string

---
 src/libserver/rspamd_control.c | 44 ++++++++++++++++++++++++++++++++++++++++--
 src/libserver/rspamd_control.h | 11 +++++++++--
 src/libserver/worker_util.c    |  2 +-
 3 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 2ebdbc4d6..4ca3d6585 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -676,8 +676,8 @@ rspamd_control_default_worker_handler (EV_P_ ev_io *w, int revents)
 }
 
 void
-rspamd_control_worker_add_default_handler (struct rspamd_worker *worker,
-		struct ev_loop *ev_base)
+rspamd_control_worker_add_default_cmd_handlers (struct rspamd_worker *worker,
+												struct ev_loop *ev_base)
 {
 	struct rspamd_worker_control_data *cd;
 
@@ -1108,3 +1108,43 @@ rspamd_srv_send_command (struct rspamd_worker *worker,
 			rd->worker->srv_pipe[1], EV_WRITE);
 	ev_io_start (ev_base, &rd->io_ev);
 }
+
+enum rspamd_control_type
+rspamd_control_command_from_string (const gchar *str)
+{
+	enum rspamd_control_type ret = RSPAMD_CONTROL_MAX;
+
+	if (!str) {
+		return ret;
+	}
+
+	if (g_ascii_strcasecmp (str, "hyperscan_loaded") == 0) {
+		ret = RSPAMD_CONTROL_HYPERSCAN_LOADED;
+	}
+	else if (g_ascii_strcasecmp (str, "stat") == 0) {
+		ret = RSPAMD_CONTROL_STAT;
+	}
+	else if (g_ascii_strcasecmp (str, "reload") == 0) {
+		ret = RSPAMD_CONTROL_RELOAD;
+	}
+	else if (g_ascii_strcasecmp (str, "reresolve") == 0) {
+		ret = RSPAMD_CONTROL_RERESOLVE;
+	}
+	else if (g_ascii_strcasecmp (str, "recompile") == 0) {
+		ret = RSPAMD_CONTROL_RECOMPILE;
+	}
+	else if (g_ascii_strcasecmp (str, "log_pipe") == 0) {
+		ret = RSPAMD_CONTROL_LOG_PIPE;
+	}
+	else if (g_ascii_strcasecmp (str, "fuzzy_stat") == 0) {
+		ret = RSPAMD_CONTROL_FUZZY_STAT;
+	}
+	else if (g_ascii_strcasecmp (str, "fuzzy_sync") == 0) {
+		ret = RSPAMD_CONTROL_FUZZY_SYNC;
+	}
+	else if (g_ascii_strcasecmp (str, "monitored_change") == 0) {
+		ret = RSPAMD_CONTROL_MONITORED_CHANGE;
+	}
+
+	return ret;
+}
\ No newline at end of file
diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h
index 87e5e3186..ebb564d7e 100644
--- a/src/libserver/rspamd_control.h
+++ b/src/libserver/rspamd_control.h
@@ -210,8 +210,8 @@ void rspamd_control_process_client_socket (struct rspamd_main *rspamd_main,
 /**
  * Register default handlers for a worker
  */
-void rspamd_control_worker_add_default_handler (struct rspamd_worker *worker,
-												struct ev_loop *ev_base);
+void rspamd_control_worker_add_default_cmd_handlers (struct rspamd_worker *worker,
+													 struct ev_loop *ev_base);
 
 /**
  * Register custom handler for a specific control command for this worker
@@ -240,6 +240,13 @@ void rspamd_srv_send_command (struct rspamd_worker *worker,
 							  rspamd_srv_reply_handler handler,
 							  gpointer ud);
 
+/**
+ * Returns command from a specified string (case insensitive)
+ * @param str
+ * @return
+ */
+enum rspamd_control_type rspamd_control_command_from_string (const gchar *str);
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 56fdd70c1..19c5ac030 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -365,7 +365,7 @@ rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
 	worker->srv->event_loop = event_loop;
 
 	rspamd_worker_init_signals (worker, event_loop);
-	rspamd_control_worker_add_default_handler (worker, event_loop);
+	rspamd_control_worker_add_default_cmd_handlers (worker, event_loop);
 	rspamd_worker_heartbeat_start (worker, event_loop);
 #ifdef WITH_HIREDIS
 	rspamd_redis_pool_config (worker->srv->cfg->redis_pool,


More information about the Commits mailing list