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)
#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>
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)) {
}
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 */
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 */
*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;
}
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);
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 */
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;
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 {
}
cur = cur->next;
}
+
+ return TRUE;
}
int
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);
}
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