summaryrefslogtreecommitdiffstats
path: root/src/cfg_utils.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-03-25 19:19:47 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-03-25 19:19:47 +0300
commit2f2642851746b0985f67e8dde58e2458eae07cca (patch)
treec379cf43cf7a26be6e70111e8e79815258a1c0ee /src/cfg_utils.c
parent9e16e433e1386b3613ea5667b12ee14c3ef0588c (diff)
downloadrspamd-2f2642851746b0985f67e8dde58e2458eae07cca.tar.gz
rspamd-2f2642851746b0985f67e8dde58e2458eae07cca.zip
* Initial add of xml parser for rspamd configuration
Diffstat (limited to 'src/cfg_utils.c')
-rw-r--r--src/cfg_utils.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index 023d97315..534d44eae 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -24,13 +24,13 @@
#include "config.h"
-#include <math.h>
#include "cfg_file.h"
#include "main.h"
#include "filter.h"
#include "settings.h"
#include "classifiers/classifiers.h"
+#include "cfg_xml.h"
#ifdef WITH_LUA
#include "lua/lua_common.h"
#endif
@@ -760,6 +760,55 @@ parse_normalizer (struct config_file *cfg, struct statfile *st, const char *line
return FALSE;
}
+static GMarkupParser xml_parser = {
+ .start_element = rspamd_xml_start_element,
+ .end_element = rspamd_xml_end_element,
+ .passthrough = NULL,
+ .text = rspamd_xml_text,
+ .error = rspamd_xml_error,
+};
+
+gboolean
+read_xml_config (struct config_file *cfg, const char *filename)
+{
+ struct stat st;
+ int fd;
+ gchar *data;
+ gboolean res;
+ GMarkupParseContext *ctx;
+ GError *err = NULL;
+
+ struct rspamd_xml_userdata ud;
+
+ if (stat (filename, &st) == -1) {
+ msg_err ("cannot stat %s: %s", filename, strerror (errno));
+ return FALSE;
+ }
+ if ((fd = open (filename, O_RDONLY)) == -1) {
+ msg_err ("cannot open %s: %s", filename, strerror (errno));
+ return FALSE;
+
+ }
+ /* Now mmap this file to simplify reading process */
+ if ((data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+ msg_err ("cannot mmap %s: %s", filename, strerror (errno));
+ close (fd);
+ return FALSE;
+ }
+ close (fd);
+
+ /* Prepare xml parser */
+ ud.cfg = cfg;
+ ud.state = XML_READ_START;
+
+ ctx = g_markup_parse_context_new (&xml_parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &ud, NULL);
+ res = g_markup_parse_context_parse (ctx, data, st.st_size, &err);
+
+ munmap (data, st.st_size);
+
+ return res;
+}
+
/*
* vi:ts=4
*/