diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-19 12:25:14 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-19 12:25:14 +0300 |
commit | 6088008d6c307a553b896eacee60a7ae69fda9dd (patch) | |
tree | 16787da296c228c607723df4f798b50b69636379 | |
parent | 9c455404d443c748b6398076c1746a12a7458bfc (diff) | |
download | rspamd-6088008d6c307a553b896eacee60a7ae69fda9dd.tar.gz rspamd-6088008d6c307a553b896eacee60a7ae69fda9dd.zip |
* With flag -t syntax of modules variables is also inspected
* Set "C" locale on start to avoid some troubles with logging
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | config.h.in | 7 | ||||
-rw-r--r-- | src/cfg_utils.c | 9 | ||||
-rw-r--r-- | src/main.c | 39 | ||||
-rw-r--r-- | src/plugins/regexp.c | 18 |
5 files changed, 55 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 19172f15d..e4b76f3c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,7 @@ CHECK_INCLUDE_FILES(netinet/in.h HAVE_NETINET_IN_H) CHECK_INCLUDE_FILES(arpa/inet.h HAVE_ARPA_INET_H) CHECK_INCLUDE_FILES(netdb.h HAVE_NETDB_H) CHECK_INCLUDE_FILES(syslog.h HAVE_SYSLOG_H) +CHECK_INCLUDE_FILES(locale.h HAVE_LOCALE_H) CHECK_INCLUDE_FILES(libgen.h HAVE_LIBGEN_H) CHECK_INCLUDE_FILES(pwd.h HAVE_PWD_H) CHECK_INCLUDE_FILES(grp.h HAVE_GRP_H) diff --git a/config.h.in b/config.h.in index 97da9c381..982046338 100644 --- a/config.h.in +++ b/config.h.in @@ -39,6 +39,8 @@ #cmakedefine HAVE_LIBGEN_H 1 +#cmakedefine HAVE_LOCALE_H 1 + #cmakedefine HAVE_GRP_H 1 #cmakedefine HAVE_PWD_H 1 @@ -229,6 +231,11 @@ #define HAVE_DIRNAME 1 #endif +#ifdef HAVE_LOCALE_H +#include <locale.h> +#define HAVE_SETLOCALE 1 +#endif + #include <errno.h> #include <signal.h> #include <event.h> diff --git a/src/cfg_utils.c b/src/cfg_utils.c index f95237e59..b81aa4c2d 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -555,12 +555,13 @@ post_load_config (struct config_file *cfg) struct rspamd_regexp* parse_regexp (memory_pool_t *pool, char *line) { - char *begin, *end, *p; + char *begin, *end, *p, *src; struct rspamd_regexp *result; int regexp_flags = 0; enum rspamd_regexp_type type = REGEXP_NONE; GError *err = NULL; + src = line; result = memory_pool_alloc0 (pool, sizeof (struct rspamd_regexp)); /* Skip whitespaces */ while (g_ascii_isspace (*line)) { @@ -594,7 +595,7 @@ parse_regexp (memory_pool_t *pool, char *line) } else { /* We got header name earlier but have not found // expression, so it is invalid regexp */ - msg_warn ("parse_regexp: got no header name (eg. header=) but without corresponding regexp"); + msg_warn ("parse_regexp: got no header name (eg. header=) but without corresponding regexp, %s", src); return NULL; } /* Find end */ @@ -603,7 +604,7 @@ parse_regexp (memory_pool_t *pool, char *line) end ++; } if (end == begin || *end != '/') { - msg_warn ("parse_regexp: no trailing / in regexp"); + msg_warn ("parse_regexp: no trailing / in regexp %s", src); return NULL; } /* Parse flags */ @@ -679,7 +680,7 @@ parse_regexp (memory_pool_t *pool, char *line) *end = '/'; if (result->regexp == NULL || err != NULL) { - msg_warn ("parse_regexp: could not read regexp: %s", err->message); + msg_warn ("parse_regexp: could not read regexp: %s while reading regexp %s", err->message, src); return NULL; } diff --git a/src/main.c b/src/main.c index 16af301dc..56bad7e67 100644 --- a/src/main.c +++ b/src/main.c @@ -383,7 +383,15 @@ main (int argc, char **argv, char **env) else { cfg->log_level = G_LOG_LEVEL_CRITICAL; } - + +#ifdef HAVE_SETLOCALE + /* Set locale setting to C locale to avoid problems in future */ + setlocale (LC_ALL, "C"); + setlocale (LC_CTYPE, "C"); + setlocale (LC_MESSAGES, "C"); + setlocale (LC_TIME, "C"); +#endif + /* First set logger to console logger */ cfg->log_fd = STDERR_FILENO; g_log_set_default_handler (file_log_function, cfg); @@ -406,9 +414,26 @@ main (int argc, char **argv, char **env) fclose (f); + /* Init C modules */ + for (i = 0; i < MODULES_NUM; i ++) { + cur_module = memory_pool_alloc (rspamd->cfg->cfg_pool, sizeof (struct module_ctx)); + if (modules[i].module_init_func(cfg, &cur_module) == 0) { + g_hash_table_insert (cfg->c_modules, (gpointer)modules[i].name, cur_module); + } + } + if (cfg->config_test) { - fprintf (stderr, "syntax OK\n"); - return EXIT_SUCCESS; + /* Init events to test modules */ + event_init (); + res = TRUE; + /* Perform modules configuring */ + for (i = 0; i < MODULES_NUM; i ++) { + if (!modules[i].module_config_func (cfg)) { + res = FALSE; + } + } + fprintf (stderr, "syntax %s\n", res ? "OK" : "BAD"); + return res ? EXIT_SUCCESS : EXIT_FAILURE; } /* Create listen socket */ @@ -450,14 +475,6 @@ main (int argc, char **argv, char **env) exit (-errno); } - /* Init C modules */ - for (i = 0; i < MODULES_NUM; i ++) { - cur_module = memory_pool_alloc (rspamd->cfg->cfg_pool, sizeof (struct module_ctx)); - if (modules[i].module_init_func(cfg, &cur_module) == 0) { - g_hash_table_insert (cfg->c_modules, (gpointer)modules[i].name, cur_module); - } - } - rspamd->pid = getpid(); rspamd->type = TYPE_MAIN; diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 35307359d..00f7cea8e 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -74,20 +74,25 @@ regexp_module_init (struct config_file *cfg, struct module_ctx **ctx) return 0; } -static void +static gboolean read_regexp_expression (memory_pool_t *pool, struct regexp_module_item *chain, char *line) { struct expression *e, *cur; e = parse_expression (regexp_module_ctx->regexp_pool, line); if (e == NULL) { - msg_err ("read_regexp_extension: %s is invalid regexp extension", line); + msg_warn ("read_regexp_expression: %s is invalid regexp expression", line); + return FALSE; } chain->expr = e; cur = e; while (cur) { if (cur->type == EXPR_OPERAND) { cur->content.operand = parse_regexp (pool, cur->content.operand); + if (cur->content.operand == NULL) { + msg_warn ("read_regexp_expression: cannot parse regexp, skip expression %s", line); + return FALSE; + } chain->regexp_number ++; } else { @@ -95,6 +100,8 @@ read_regexp_expression (memory_pool_t *pool, struct regexp_module_item *chain, c } cur = cur->next; } + + return TRUE; } int @@ -104,6 +111,7 @@ regexp_module_config (struct config_file *cfg) struct module_opt *cur; struct regexp_module_item *cur_item; char *value; + int res = TRUE; if ((value = get_module_opt (cfg, "regexp", "metric")) != NULL) { regexp_module_ctx->metric = memory_pool_strdup (regexp_module_ctx->regexp_pool, value); @@ -121,12 +129,14 @@ regexp_module_config (struct config_file *cfg) } cur_item = memory_pool_alloc0 (regexp_module_ctx->regexp_pool, sizeof (struct regexp_module_item)); cur_item->symbol = cur->param; - read_regexp_expression (regexp_module_ctx->regexp_pool, cur_item, cur->value); + if (!read_regexp_expression (regexp_module_ctx->regexp_pool, cur_item, cur->value)) { + res = FALSE; + } regexp_module_ctx->items = g_list_prepend (regexp_module_ctx->items, cur_item); } } - return 0; + return res; } int |