diff options
Diffstat (limited to 'src/cfg_utils.c')
-rw-r--r-- | src/cfg_utils.c | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c index b81aa4c2d..1eeb518ed 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -549,143 +549,6 @@ post_load_config (struct config_file *cfg) fill_cfg_params (cfg); } -/* - * Rspamd regexp utility functions - */ -struct rspamd_regexp* -parse_regexp (memory_pool_t *pool, char *line) -{ - 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)) { - line ++; - } - if (line == '\0') { - msg_warn ("parse_regexp: got empty regexp"); - return NULL; - } - /* First try to find header name */ - begin = strchr (line, '='); - if (begin != NULL) { - *begin = '\0'; - result->header = memory_pool_strdup (pool, line); - result->type = REGEXP_HEADER; - *begin = '='; - line = begin; - } - /* Find begin of regexp */ - while (*line != '/') { - line ++; - } - if (*line != '\0') { - begin = line + 1; - } - else if (result->header == NULL) { - /* Assume that line without // is just a header name */ - result->header = memory_pool_strdup (pool, line); - result->type = REGEXP_HEADER; - return result; - } - 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, %s", src); - return NULL; - } - /* Find end */ - end = begin; - while (*end && (*end != '/' || *(end - 1) == '\\')) { - end ++; - } - if (end == begin || *end != '/') { - msg_warn ("parse_regexp: no trailing / in regexp %s", src); - return NULL; - } - /* Parse flags */ - p = end + 1; - while (p != NULL) { - switch (*p) { - case 'i': - regexp_flags |= G_REGEX_CASELESS; - p ++; - break; - case 'm': - regexp_flags |= G_REGEX_MULTILINE; - p ++; - break; - case 's': - regexp_flags |= G_REGEX_DOTALL; - p ++; - break; - case 'x': - regexp_flags |= G_REGEX_EXTENDED; - p ++; - break; - case 'u': - regexp_flags |= G_REGEX_UNGREEDY; - p ++; - break; - case 'o': - regexp_flags |= G_REGEX_OPTIMIZE; - p ++; - break; - /* Type flags */ - case 'H': - if (result->type == REGEXP_NONE) { - result->type = REGEXP_HEADER; - } - p ++; - break; - case 'M': - if (result->type == REGEXP_NONE) { - result->type = REGEXP_MESSAGE; - } - p ++; - break; - case 'P': - if (result->type == REGEXP_NONE) { - result->type = REGEXP_MIME; - } - p ++; - break; - case 'U': - if (result->type == REGEXP_NONE) { - result->type = REGEXP_URL; - } - p ++; - break; - case 'X': - if (result->type == REGEXP_NONE || result->type == REGEXP_HEADER) { - result->type = REGEXP_RAW_HEADER; - } - p ++; - break; - /* Stop flags parsing */ - default: - p = NULL; - break; - } - } - - *end = '\0'; - result->regexp = g_regex_new (begin, regexp_flags, 0, &err); - result->regexp_text = memory_pool_strdup (pool, begin); - memory_pool_add_destructor (pool, (pool_destruct_func)g_regex_unref, (void *)result->regexp); - *end = '/'; - - if (result->regexp == NULL || err != NULL) { - msg_warn ("parse_regexp: could not read regexp: %s while reading regexp %s", err->message, src); - return NULL; - } - - return result; -} void parse_err (const char *fmt, ...) |