From 210adc4063a7557b3bc0ffd69bd992c0bec4bacc Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Mon, 16 Sep 2013 20:24:51 +0200 Subject: src: xml: refactor XML parsing code This patch refactors nft_*_xml_parse to provide a new intermediate function nft_mxml_parse_* which will allow us to navigate an entire XML tree containing a ruleset without xml2text2xml conversions. While at it, I added a helper to build the XML tree and validate the top node name. Signed-off-by: Arturo Borrero Gonzalez --- src/mxml.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/mxml.c') diff --git a/src/mxml.c b/src/mxml.c index 6b7ca68..82156b7 100644 --- a/src/mxml.c +++ b/src/mxml.c @@ -15,11 +15,30 @@ #include #include +#include +#include #include #include #include #ifdef XML_PARSING +mxml_node_t *nft_mxml_build_tree(const char *xml, const char *treename) +{ + mxml_node_t *tree; + + tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK); + if (tree == NULL) + goto err; + + if (strcmp(tree->value.opaque, treename) == 0) + return tree; + + mxmlDelete(tree); +err: + errno = EINVAL; + return NULL; +} + struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node) { mxml_node_t *tree; -- cgit v1.2.3