summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-30 19:52:08 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-30 19:52:08 +0400
commit579c4aa001d5434803972711b8c2689454fc4038 (patch)
tree9d99a7bca4c8ddaada6c9bb8318b9fc4063f8a9d /src
parentf579fed1dee306a5cf58360589d29ae1514d25b4 (diff)
downloadrspamd-579c4aa001d5434803972711b8c2689454fc4038.tar.gz
rspamd-579c4aa001d5434803972711b8c2689454fc4038.zip
* Try to fix expression parser to support ',' inside regexp arguments of functions
Diffstat (limited to 'src')
-rw-r--r--src/expressions.c79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/expressions.c b/src/expressions.c
index 3fff36fbd..c3e8d2532 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -238,6 +238,7 @@ parse_expression (memory_pool_t *pool, char *line)
struct expression_argument *arg;
GQueue *function_stack;
char *p, *c, *str, op;
+ gboolean in_regexp = FALSE;
enum {
SKIP_SPACES,
@@ -386,44 +387,52 @@ parse_expression (memory_pool_t *pool, char *line)
break;
case READ_FUNCTION_ARGUMENT:
- /* Append argument to list */
- if (*p == ',' || *p == ')') {
- arg = memory_pool_alloc (pool, sizeof (struct expression_argument));
- if (*(p - 1) != ')') {
- /* Not a function argument */
- str = memory_pool_alloc (pool, p - c + 1);
- g_strlcpy (str, c, (p - c + 1));
- g_strstrip (str);
- arg->type = EXPRESSION_ARGUMENT_NORMAL;
- arg->data = str;
- func->args = g_list_prepend (func->args, arg);
- }
- else {
- arg->type = EXPRESSION_ARGUMENT_FUNCTION;
- arg->data = old;
- func->args = g_list_prepend (func->args, arg);
- }
- /* Pop function */
- if (*p == ')') {
- /* Last function in chain, goto skipping spaces state */
- old = func;
- func = g_queue_pop_tail (function_stack);
- if (g_queue_get_length (function_stack) == 0) {
- state = SKIP_SPACES;
+ if (*p == '/' && !in_regexp) {
+ in_regexp = TRUE;
+ }
+ if (!in_regexp) {
+ /* Append argument to list */
+ if (*p == ',' || *p == ')') {
+ arg = memory_pool_alloc (pool, sizeof (struct expression_argument));
+ if (*(p - 1) != ')') {
+ /* Not a function argument */
+ str = memory_pool_alloc (pool, p - c + 1);
+ g_strlcpy (str, c, (p - c + 1));
+ g_strstrip (str);
+ arg->type = EXPRESSION_ARGUMENT_NORMAL;
+ arg->data = str;
+ func->args = g_list_prepend (func->args, arg);
}
+ else {
+ arg->type = EXPRESSION_ARGUMENT_FUNCTION;
+ arg->data = old;
+ func->args = g_list_prepend (func->args, arg);
+ }
+ /* Pop function */
+ if (*p == ')') {
+ /* Last function in chain, goto skipping spaces state */
+ old = func;
+ func = g_queue_pop_tail (function_stack);
+ if (g_queue_get_length (function_stack) == 0) {
+ state = SKIP_SPACES;
+ }
+ }
+ c = p + 1;
+ }
+ if (*p == '(') {
+ /* Push current function to stack */
+ g_queue_push_tail (function_stack, func);
+ func = memory_pool_alloc (pool, sizeof (struct expression_function));
+ func->name = memory_pool_alloc (pool, p - c + 1);
+ func->args = NULL;
+ g_strlcpy (func->name, c, (p - c + 1));
+ g_strstrip (func->name);
+ state = READ_FUNCTION_ARGUMENT;
+ c = p + 1;
}
- c = p + 1;
}
- if (*p == '(') {
- /* Push current function to stack */
- g_queue_push_tail (function_stack, func);
- func = memory_pool_alloc (pool, sizeof (struct expression_function));
- func->name = memory_pool_alloc (pool, p - c + 1);
- func->args = NULL;
- g_strlcpy (func->name, c, (p - c + 1));
- g_strstrip (func->name);
- state = READ_FUNCTION_ARGUMENT;
- c = p + 1;
+ else if (*p == '/' && *(p - 1) != '\\') {
+ in_regexp = FALSE;
}
p ++;
break;