aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-17 11:27:01 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-17 11:27:01 +0000
commite2b8e747ed8f4b84b0530e8b328e3ba49d4c07d4 (patch)
tree8b836956e3ff61d248a30361e2096cb39eae11a5 /src/libutil
parent7c433350c5ee177af72cfa5011bd8db00a495f56 (diff)
downloadrspamd-e2b8e747ed8f4b84b0530e8b328e3ba49d4c07d4.tar.gz
rspamd-e2b8e747ed8f4b84b0530e8b328e3ba49d4c07d4.zip
Add skeleton for the new expressions.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/CMakeLists.txt1
-rw-r--r--src/libutil/expression.c49
-rw-r--r--src/libutil/expression.h77
3 files changed, 127 insertions, 0 deletions
diff --git a/src/libutil/CMakeLists.txt b/src/libutil/CMakeLists.txt
index 3e8fd87a7..3ef5b1d07 100644
--- a/src/libutil/CMakeLists.txt
+++ b/src/libutil/CMakeLists.txt
@@ -4,6 +4,7 @@ SET(LIBRSPAMDUTILSRC
${CMAKE_CURRENT_SOURCE_DIR}/aio_event.c
${CMAKE_CURRENT_SOURCE_DIR}/bloom.c
${CMAKE_CURRENT_SOURCE_DIR}/diff.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/expression.c
${CMAKE_CURRENT_SOURCE_DIR}/fstring.c
${CMAKE_CURRENT_SOURCE_DIR}/fuzzy.c
${CMAKE_CURRENT_SOURCE_DIR}/hash.c
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
new file mode 100644
index 000000000..21d94b7db
--- /dev/null
+++ b/src/libutil/expression.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, Vsevolod Stakhov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <expression.h>
+#include "config.h"
+
+gboolean
+rspamd_parse_expression (const gchar *line, gsize len,
+ struct rspamd_atom_subr *subr, gpointer subr_data,
+ rspamd_mempool_t *pool, GError **err,
+ struct rspamd_expression **target)
+{
+ g_assert (line != NULL);
+ g_assert (subr != NULL && subr->parse != NULL);
+
+ if (len == 0) {
+ len = strlen (line);
+ }
+ return FALSE;
+}
+
+gint
+rspamd_process_expression (struct rspamd_expression *expr, gpointer data)
+{
+ g_assert (expr != NULL);
+
+ return 0;
+}
diff --git a/src/libutil/expression.h b/src/libutil/expression.h
new file mode 100644
index 000000000..a99343e69
--- /dev/null
+++ b/src/libutil/expression.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2015, Vsevolod Stakhov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_LIBUTIL_EXPRESSION_H_
+#define SRC_LIBUTIL_EXPRESSION_H_
+
+#include "config.h"
+#include "mem_pool.h"
+
+typedef struct rspamd_expression_atom_s {
+ /* Opaque userdata */
+ gpointer data;
+ /* String representation of atom */
+ const gchar *str;
+ /* Relative priority */
+ gint priority;
+} rspamd_expression_atom_t;
+
+struct rspamd_atom_subr {
+ /* Parses atom from string and returns atom structure */
+ rspamd_expression_atom_t * (*parse)(const gchar *line, gsize len,
+ rspamd_mempool_t *pool, gpointer ud, GError **err);
+ /* Process atom via the opaque pointer (e.g. struct rspamd_task *) */
+ gint (*process) (gpointer input, rspamd_expression_atom_t *atom);
+ /* Calculates the relative priority of the expression */
+ gint (*priority) (rspamd_expression_atom_t *atom);
+};
+
+/* Opaque structure */
+struct rspamd_expression;
+
+/**
+ * Parse symbolic expression and create the expression using the specified subroutines for atoms processing
+ * @param line line to parse
+ * @param len length of the line (if 0 then line should be NULL terminated)
+ * @param subr subroutines for atoms parsing
+ * @param subr_data opaque dat pointer
+ * @param pool pool to use for memory allocations
+ * @param err error pointer
+ * @param target the target expression
+ * @return TRUE if an expression have been parsed
+ */
+gboolean rspamd_parse_expression (const gchar *line, gsize len,
+ struct rspamd_atom_subr *subr, gpointer subr_data,
+ rspamd_mempool_t *pool, GError **err,
+ struct rspamd_expression **target);
+
+/**
+ * Process the expression and return its value using atom 'process' functions with the specified data pointer
+ * @param expr expression to process
+ * @param data opaque data pointer for all the atoms
+ * @return the value of expression
+ */
+gint rspamd_process_expression (struct rspamd_expression *expr, gpointer data);
+
+#endif /* SRC_LIBUTIL_EXPRESSION_H_ */