diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-07-14 11:31:09 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-07-14 11:31:09 +0400 |
commit | 3dec59f3f4fba7e9649226b8b1d53b0c21cd3322 (patch) | |
tree | e9a416f24bb7161e86af0ec6be45fb80ddd63794 /src/controller.c | |
parent | 6e877394d741fd99a2ed2246f802cd5655f061b5 (diff) | |
download | rspamd-3dec59f3f4fba7e9649226b8b1d53b0c21cd3322.tar.gz rspamd-3dec59f3f4fba7e9649226b8b1d53b0c21cd3322.zip |
* Remove completion logic from controller: it is hardly used but breaks new commands logic
Diffstat (limited to 'src/controller.c')
-rw-r--r-- | src/controller.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/controller.c b/src/controller.c index ce33c53a2..a59bc3d32 100644 --- a/src/controller.c +++ b/src/controller.c @@ -94,10 +94,9 @@ static struct controller_command commands[] = { static GList *custom_commands = NULL; -static GCompletion *comp; static time_t start_time; -static gchar greetingbuf[1024]; +static gchar greetingbuf[1024]; static sig_atomic_t wanna_die = 0; extern rspamd_hash_t *counters; @@ -147,14 +146,6 @@ sigusr_handler (gint fd, short what, void *arg) return; } -static gchar * -completion_func (gpointer elem) -{ - struct controller_command *cmd = (struct controller_command *)elem; - - return cmd->command; -} - static void free_session (void *ud) { @@ -812,16 +803,33 @@ process_custom_command (gchar *line, gchar **cmd_args, struct controller_session return FALSE; } +static struct controller_command * +process_normal_command (const gchar *line) +{ + gint i; + struct controller_command *c; + + for (i = 0; i < G_N_ELEMENTS (commands); i ++) { + c = &commands[i]; + if (g_ascii_strcasecmp (line, c->command) == 0) { + return c; + } + } + + return NULL; +} + static gboolean controller_read_socket (f_str_t * in, void *arg) { struct controller_session *session = (struct controller_session *)arg; struct classifier_ctx *cls_ctx; gint len, i, r; - gchar *s, **params, *cmd, out_buf[128]; + gchar *s, **params, *cmd, out_buf[128]; + struct controller_command *command; struct worker_task *task; struct mime_text_part *part; - GList *comp_list, *cur = NULL; + GList *cur = NULL; GTree *tokens = NULL; GError *err = NULL; f_str_t c; @@ -836,14 +844,14 @@ controller_read_socket (f_str_t * in, void *arg) len = g_strv_length (params); if (len > 0) { cmd = g_strstrip (params[0]); - comp_list = g_completion_complete (comp, cmd, NULL); - switch (g_list_length (comp_list)) { - case 1: - if (! process_command ((struct controller_command *)comp_list->data, ¶ms[1], session)) { + + command = process_normal_command (cmd); + if (command != NULL) { + if (! process_command (command, ¶ms[1], session)) { return FALSE; } - break; - case 0: + } + else { if (!process_custom_command (cmd, ¶ms[1], session)) { msg_debug ("'%s'", cmd); i = rspamd_snprintf (out_buf, sizeof (out_buf), "Unknown command" CRLF); @@ -851,14 +859,6 @@ controller_read_socket (f_str_t * in, void *arg) return FALSE; } } - break; - default: - msg_debug ("'%s'", cmd); - i = rspamd_snprintf (out_buf, sizeof (out_buf), "Ambigious command" CRLF); - if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) { - return FALSE; - } - break; } } if (session->state == STATE_COMMAND) { @@ -1196,8 +1196,6 @@ void start_controller (struct rspamd_worker *worker) { struct sigaction signals; - gint i; - GList *comp_list = NULL; gchar *hostbuf; gsize hostmax; @@ -1220,13 +1218,6 @@ start_controller (struct rspamd_worker *worker) msg_info ("cannot start statfile synchronization, statfiles would not be synchronized"); } - /* Init command completion */ - for (i = 0; i < G_N_ELEMENTS (commands); i++) { - comp_list = g_list_prepend (comp_list, &commands[i]); - } - comp = g_completion_new (completion_func); - g_completion_add_items (comp, comp_list); - g_completion_set_compare (comp, g_ascii_strncasecmp); /* Fill hostname buf */ hostmax = sysconf (_SC_HOST_NAME_MAX) + 1; hostbuf = alloca (hostmax); |