]> source.dussan.org Git - rspamd.git/commitdiff
* With flag -t syntax of modules variables is also inspected
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 19 Mar 2009 09:25:14 +0000 (12:25 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 19 Mar 2009 09:25:14 +0000 (12:25 +0300)
* Set "C" locale on start to avoid some troubles with logging

CMakeLists.txt
config.h.in
src/cfg_utils.c
src/main.c
src/plugins/regexp.c

index 19172f15dece7a97d34f9ab28eddb42d57b42613..e4b76f3c764086c1f1575a531d866c15c0c41c70 100644 (file)
@@ -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)
index 97da9c381cf87b0b9d12f91dbf3084bc9ee13564..98204633892c9b15990e7e132d2f95d78df4c0ce 100644 (file)
@@ -39,6 +39,8 @@
 
 #cmakedefine HAVE_LIBGEN_H       1
 
+#cmakedefine HAVE_LOCALE_H       1
+
 #cmakedefine HAVE_GRP_H          1
 #cmakedefine HAVE_PWD_H          1
 
 #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>
index f95237e5910e14216e573b662edd904a264a296f..b81aa4c2d812328cd172f181703222a6cb616409 100644 (file)
@@ -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;
        }
 
index 16af301dcc066b29d5541e665186517c556e0c6a..56bad7e67cdb683db3af7d88a3ccd234f2e2b95a 100644 (file)
@@ -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;
        
index 35307359dcf22e237e83f5f36bdf3b890ba1a457..00f7cea8ef2a36fa9d3a8b630698749fea8a6337 100644 (file)
@@ -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