diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-04 14:50:22 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-04 16:47:38 +0200 |
commit | d844fa06e43bc80487acfe5647cef4d4994c95fd (patch) | |
tree | 2dd70dc1b8889da6f566e467eeebdd13feafeabb /src/mxml.c | |
parent | 0dbe80fee352545f51bdc4fd71621223e8b62306 (diff) |
src: consolidate XML parsing of expressions via nft_mxml_expr_parse
Move common code for XML parsing of expressions to the new
nft_mxml_expr_parse function.
This patch reduces the XML parsing code in 300 LOC.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/mxml.c')
-rw-r--r-- | src/mxml.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/mxml.c b/src/mxml.c new file mode 100644 index 0000000..76fb05f --- /dev/null +++ b/src/mxml.c @@ -0,0 +1,55 @@ +/* + * (C) 2012-2013 by Pablo Neira Ayuso <pablo@netfilter.org> + * (C) 2013 by Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This code has been sponsored by Sophos Astaro <http://www.sophos.com> + */ +#include "internal.h" +#include "expr_ops.h" + +#include <linux/netfilter/nf_tables.h> +#include <libnftables/rule.h> +#include <libnftables/expr.h> + +struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node) +{ + mxml_node_t *tree; + struct nft_rule_expr *e; + const char *expr_name; + char *xml_text; + int ret; + + expr_name = mxmlElementGetAttr(node, "type"); + if (expr_name == NULL) + goto err; + + e = nft_rule_expr_alloc(expr_name); + if (e == NULL) + goto err; + + xml_text = mxmlSaveAllocString(node, MXML_NO_CALLBACK); + if (xml_text == NULL) + goto err_expr; + + tree = mxmlLoadString(NULL, xml_text, MXML_OPAQUE_CALLBACK); + free(xml_text); + + if (tree == NULL) + goto err_expr; + + ret = e->ops->xml_parse(e, tree); + mxmlDelete(tree); + + return ret < 0 ? NULL : e; +err_expr: + nft_rule_expr_free(e); +err: + mxmlDelete(tree); + errno = EINVAL; + return NULL; +} |