diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-12-03 21:57:38 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-12-03 21:57:38 +0300 |
commit | 618e3f4887b61c69915f1c641ea47044695d6e7f (patch) | |
tree | c36d6f2bcbc17c8590ad6b2088a6f909bbb7af98 /src/controller.c | |
parent | 426963bff9e01d7d2f48d0e9eb232ccc11b33808 (diff) | |
download | rspamd-618e3f4887b61c69915f1c641ea47044695d6e7f.tar.gz rspamd-618e3f4887b61c69915f1c641ea47044695d6e7f.zip |
* Start new rspamd 0.3.4
* Add ability to manage per-module, per-worker and per-classifier options in XML parser
Diffstat (limited to 'src/controller.c')
-rw-r--r-- | src/controller.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/controller.c b/src/controller.c index 42c034013..617821bf6 100644 --- a/src/controller.c +++ b/src/controller.c @@ -29,6 +29,7 @@ #include "protocol.h" #include "upstream.h" #include "cfg_file.h" +#include "cfg_xml.h" #include "modules.h" #include "tokenizers/tokenizers.h" #include "classifiers/classifiers.h" @@ -67,6 +68,11 @@ struct custom_controller_command { controller_func_t handler; }; +struct rspamd_controller_ctx { + char *password; + guint32 timeout; +}; + static struct controller_command commands[] = { {"password", FALSE, COMMAND_PASSWORD}, {"quit", FALSE, COMMAND_QUIT}, @@ -421,9 +427,9 @@ process_command (struct controller_command *cmd, gchar **cmd_args, struct contro gchar out_buf[BUFSIZ], *arg, *err_str; gint r = 0, days, hours, minutes; time_t uptime; - guint32 size = 0; + guint32 size = 0; struct classifier_config *cl; - gchar *password = g_hash_table_lookup (session->worker->cf->params, "password"); + struct rspamd_controller_ctx *ctx = session->worker->ctx; switch (cmd->type) { case COMMAND_PASSWORD: @@ -436,14 +442,14 @@ process_command (struct controller_command *cmd, gchar **cmd_args, struct contro } return TRUE; } - if (password == NULL) { + if (ctx->password == NULL) { r = rspamd_snprintf (out_buf, sizeof (out_buf), "password command disabled in config, authorized access unallowed" CRLF); if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) { return FALSE; } return TRUE; } - if (strncmp (arg, password, strlen (arg)) == 0) { + if (strncmp (arg, ctx->password, strlen (arg)) == 0) { session->authorized = 1; r = rspamd_snprintf (out_buf, sizeof (out_buf), "password accepted" CRLF); if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) { @@ -1023,6 +1029,9 @@ accept_socket (gint fd, short what, void *arg) struct timeval *io_tv; socklen_t addrlen = sizeof (ss); gint nfd; + struct rspamd_controller_ctx *ctx; + + ctx = worker->ctx; if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) { msg_warn ("accept failed: %s", strerror (errno)); @@ -1044,8 +1053,8 @@ accept_socket (gint fd, short what, void *arg) /* Set up dispatcher */ io_tv = memory_pool_alloc (new_session->session_pool, sizeof (struct timeval)); - io_tv->tv_sec = CONTROLLER_IO_TIMEOUT; - io_tv->tv_usec = 0; + io_tv->tv_sec = ctx->timeout / 1000; + io_tv->tv_usec = ctx->timeout - io_tv->tv_sec * 1000; new_session->s = new_async_session (new_session->session_pool, free_session, new_session); @@ -1055,6 +1064,21 @@ accept_socket (gint fd, short what, void *arg) } } +gpointer +init_controller (void) +{ + struct rspamd_controller_ctx *ctx; + + ctx = g_malloc0 (sizeof (struct rspamd_controller_ctx)); + + ctx->timeout = CONTROLLER_IO_TIMEOUT * 1000; + + register_worker_opt (TYPE_CONTROLLER, "password", xml_handle_string, ctx, G_STRUCT_OFFSET (struct rspamd_controller_ctx, password)); + register_worker_opt (TYPE_CONTROLLER, "timeout", xml_handle_seconds, ctx, G_STRUCT_OFFSET (struct rspamd_controller_ctx, timeout)); + + return ctx; +} + void start_controller (struct rspamd_worker *worker) { |