src/statfile.c)
SET(UTILSSRC utils/url_extracter.c)
+SET(EXPRSRC utils/expression_parser.c)
SET(UTILSDEPENDS src/mem_pool.c
src/hash.c
src/url.c
+ src/fuzzy.c
+ src/expressions.c
+ src/message.c
src/util.c)
LIST(LENGTH PLUGINSSRC RSPAMD_MODULES_NUM)
TARGET_LINK_LIBRARIES(utils/url-extracter ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(utils/url-extracter ${GMIME2_LIBRARIES})
+ADD_EXECUTABLE(utils/expression-parser ${UTILSDEPENDS} ${CONTRIBSRC} ${EXPRSRC})
+SET_TARGET_PROPERTIES(utils/expression-parser PROPERTIES LINKER_LANGUAGE C)
+TARGET_LINK_LIBRARIES(utils/expression-parser m)
+IF(LIBUTIL_LIBRARY)
+ TARGET_LINK_LIBRARIES(utils/expression-parser util)
+ENDIF(LIBUTIL_LIBRARY)
+TARGET_LINK_LIBRARIES(utils/expression-parser ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(utils/expression-parser ${GMIME2_LIBRARIES})
+
INSTALL(PROGRAMS rspamd-${RSPAMD_VERSION} DESTINATION bin RENAME rspamd)
INSTALL(PROGRAMS rspamc.pl DESTINATION bin RENAME rspamc)
IF(ENABLE_PERL MATCHES "ON")
case READ_REGEXP_FLAGS:
if (!is_regexp_flag (*p) || *(p + 1) == '\0') {
if (c != p) {
- if (is_regexp_flag (*p) && *(p + 1) == '\0') {
+ if ((is_regexp_flag (*p) || *p == '/') && *(p + 1) == '\0') {
p ++;
}
str = memory_pool_alloc (pool, p - c + 2);
msg_debug ("optimize_regexp_expression: found '!' operator, inversing result");
res = !res;
it = it->next;
- *e = it;
+ *e = it->next;
continue;
}
else if (it->content.operation == '&' && res == FALSE) {
msg_debug ("optimize_regexp_expression: found '&' and previous expression is false");
- *e = it;
+ *e = it->next;
ret = TRUE;
}
else if (it->content.operation == '|' && res == TRUE) {
msg_debug ("optimize_regexp_expression: found '|' and previous expression is true");
- *e = it;
+ *e = it->next;
ret = TRUE;
}
break;
gsize cur, op1, op2;
struct expression *it = expr;
struct rspamd_regexp *re;
- gboolean try_optimize = TRUE;
stack = g_queue_new ();
/* Find corresponding symbol */
cur = process_regexp ((struct rspamd_regexp *)it->content.operand, task);
msg_debug ("process_regexp_expression: regexp %s found", cur ? "is" : "is not");
- if (try_optimize) {
- try_optimize = optimize_regexp_expression (&it, stack, cur);
- } else {
- g_queue_push_head (stack, GSIZE_TO_POINTER (cur));
- }
+ g_queue_push_head (stack, GSIZE_TO_POINTER (cur));
} else if (it->type == EXPR_FUNCTION) {
cur = (gsize)call_expression_function ((struct expression_function *)it->content.operand, task);
msg_debug ("process_regexp_expression: function %s returned %s", ((struct expression_function *)it->content.operand)->name,
cur ? "true" : "false");
- if (try_optimize) {
- try_optimize = optimize_regexp_expression (&it, stack, cur);
- } else {
- g_queue_push_head (stack, GSIZE_TO_POINTER (cur));
- }
+ g_queue_push_head (stack, GSIZE_TO_POINTER (cur));
} else if (it->type == EXPR_REGEXP) {
/* Compile regexp if it is not parsed */
if (it->content.operand == NULL) {
g_queue_free (stack);
return FALSE;
}
- try_optimize = TRUE;
switch (it->content.operation) {
case '!':
op1 = GPOINTER_TO_SIZE (g_queue_pop_head (stack));
--- /dev/null
+#include "../src/config.h"
+#include "../src/main.h"
+#include "../src/cfg_file.h"
+#include "../src/expressions.h"
+
+int
+main (int argc, char **argv)
+{
+ memory_pool_t *pool;
+ struct expression *cur;
+ char *line, *outstr;
+ int r, s;
+ char buf[BUFSIZ];
+
+ pool = memory_pool_new (memory_pool_get_size ());
+
+ line = fgets (buf, sizeof (buf), stdin);
+ while (line) {
+ s = strlen (line);
+ if (buf[s - 1] == '\n') {
+ buf[s - 1] = '\0';
+ }
+ if (buf[s - 2] == '\r') {
+ buf[s - 2] = '\0';
+ }
+
+ r = 0;
+ cur = parse_expression (pool, line);
+ s = strlen (line) * 4;
+ outstr = memory_pool_alloc (pool, s);
+ while (cur) {
+ if (cur->type == EXPR_REGEXP) {
+ r += snprintf (outstr + r, s - r, "OP:%s ", (char *)cur->content.operand);
+ } else if (cur->type == EXPR_STR) {
+ r += snprintf (outstr + r, s - r, "S:%s ", (char *)cur->content.operand);
+
+ } else if (cur->type == EXPR_FUNCTION) {
+ r += snprintf (outstr + r, s - r, "F:%s ", ((struct expression_function *)cur->content.operand)->name);
+ }
+ else {
+ r += snprintf (outstr + r, s - r, "O:%c ", cur->content.operation);
+ }
+ cur = cur->next;
+ }
+ printf ("Parsed expression: '%s' -> '%s'\n", line, outstr);
+ line = fgets (buf, sizeof (buf), stdin);
+ }
+
+ memory_pool_delete (pool);
+}