From: Vsevolod Stakhov Date: Sun, 22 Sep 2019 08:54:24 +0000 (+0100) Subject: [Minor] Add string/enum conversion methods X-Git-Tag: 2.0~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=de0d6076198efa2c4bf7d5cf0d11b23f0664d0c5;p=rspamd.git [Minor] Add string/enum conversion methods --- diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 3d1b8ef7c..503825184 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -1165,6 +1165,52 @@ rspamd_control_command_from_string (const gchar *str) else if (g_ascii_strcasecmp (str, "monitored_change") == 0) { ret = RSPAMD_CONTROL_MONITORED_CHANGE; } + else if (g_ascii_strcasecmp (str, "child_change") == 0) { + ret = RSPAMD_CONTROL_CHILD_CHANGE; + } return ret; -} \ No newline at end of file +} + +const gchar * +rspamd_control_command_to_string (enum rspamd_control_type cmd) +{ + const gchar *reply = "unknown"; + + switch (cmd) { + case RSPAMD_CONTROL_STAT: + reply = "stat"; + break; + case RSPAMD_CONTROL_RELOAD: + reply = "reload"; + break; + case RSPAMD_CONTROL_RERESOLVE: + reply = "reresolve"; + break; + case RSPAMD_CONTROL_RECOMPILE: + reply = "recompile"; + break; + case RSPAMD_CONTROL_HYPERSCAN_LOADED: + reply = "hyperscan_loaded"; + break; + case RSPAMD_CONTROL_LOG_PIPE: + reply = "log_pipe"; + break; + case RSPAMD_CONTROL_FUZZY_STAT: + reply = "fuzzy_stat"; + break; + case RSPAMD_CONTROL_FUZZY_SYNC: + reply = "fuzzy_sync"; + break; + case RSPAMD_CONTROL_MONITORED_CHANGE: + reply = "monitored_change"; + break; + case RSPAMD_CONTROL_CHILD_CHANGE: + reply = "child_change"; + break; + default: + break; + } + + return reply; +} diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h index 6c092ca74..d1ce88f31 100644 --- a/src/libserver/rspamd_control.h +++ b/src/libserver/rspamd_control.h @@ -267,6 +267,13 @@ void rspamd_control_broadcast_srv_cmd (struct rspamd_main *rspamd_main, */ enum rspamd_control_type rspamd_control_command_from_string (const gchar *str); +/** + * Returns command name from it's type + * @param cmd + * @return + */ +const gchar *rspamd_control_command_to_string (enum rspamd_control_type cmd); + #ifdef __cplusplus } #endif