aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-12 17:58:09 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-12 17:58:09 +0300
commit9a0362647374be48a29887d0571b8a665877be6b (patch)
treed2d5de53776d3b1b1faec6cd2254dccf31b81024 /src
parent2003dce62438e513e614056540c22f4f755ec88b (diff)
downloadrspamd-9a0362647374be48a29887d0571b8a665877be6b.tar.gz
rspamd-9a0362647374be48a29887d0571b8a665877be6b.zip
* Some fixes to regexp module
* Add documentation for rspamd regexp module
Diffstat (limited to 'src')
-rw-r--r--src/cfg_utils.c25
-rw-r--r--src/plugins/regexp.c7
-rw-r--r--src/util.c5
3 files changed, 26 insertions, 11 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index 7efb9390d..3d2ce611c 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -562,6 +562,13 @@ parse_regexp (memory_pool_t *pool, char *line)
GError *err = NULL;
result = memory_pool_alloc0 (pool, sizeof (struct rspamd_regexp));
+ /* Skip whitespaces */
+ while (g_ascii_isspace (*line)) {
+ line ++;
+ }
+ if (line == '\0') {
+ return NULL;
+ }
/* First try to find header name */
begin = strchr (line, '=');
if (begin != NULL) {
@@ -626,26 +633,26 @@ parse_regexp (memory_pool_t *pool, char *line)
break;
/* Type flags */
case 'H':
- if (type != REGEXP_NONE) {
- type = REGEXP_HEADER;
+ if (result->type == REGEXP_NONE) {
+ result->type = REGEXP_HEADER;
}
p ++;
break;
case 'M':
- if (type != REGEXP_NONE) {
- type = REGEXP_MESSAGE;
+ if (result->type == REGEXP_NONE) {
+ result->type = REGEXP_MESSAGE;
}
p ++;
break;
case 'P':
- if (type != REGEXP_NONE) {
- type = REGEXP_MIME;
+ if (result->type == REGEXP_NONE) {
+ result->type = REGEXP_MIME;
}
p ++;
break;
case 'U':
- if (type != REGEXP_NONE) {
- type = REGEXP_URL;
+ if (result->type == REGEXP_NONE) {
+ result->type = REGEXP_URL;
}
p ++;
break;
@@ -656,8 +663,6 @@ parse_regexp (memory_pool_t *pool, char *line)
}
}
- result = memory_pool_alloc (pool, sizeof (struct rspamd_regexp));
- result->type = type;
*end = '\0';
result->regexp = g_regex_new (begin, regexp_flags, 0, &err);
result->regexp_text = memory_pool_strdup (pool, begin);
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index a2079bffa..06da6932f 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -68,6 +68,8 @@ regexp_module_init (struct config_file *cfg, struct module_ctx **ctx)
regexp_module_ctx->url_filter = NULL;
regexp_module_ctx->regexp_pool = memory_pool_new (1024);
regexp_module_ctx->items = NULL;
+
+ *ctx = (struct module_ctx *)regexp_module_ctx;
return 0;
}
@@ -141,6 +143,11 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task)
GList *cur;
struct uri *url;
+ if (re == NULL) {
+ msg_info ("process_regexp: invalid regexp passed");
+ return 0;
+ }
+
switch (re->type) {
case REGEXP_NONE:
return 0;
diff --git a/src/util.c b/src/util.c
index cbe6d9821..a60bafea6 100644
--- a/src/util.c
+++ b/src/util.c
@@ -737,7 +737,10 @@ parse_expression (memory_pool_t *pool, char *line)
/* Copy operand */
str = memory_pool_alloc (pool, p - c + 1);
g_strlcpy (str, c, (p - c + 1));
- insert_expression (pool, &expr, EXPR_OPERAND, 0, str);
+ g_strstrip (str);
+ if (strlen (str) != 0) {
+ insert_expression (pool, &expr, EXPR_OPERAND, 0, str);
+ }
}
if (*p == ')') {
if (stack == NULL) {