diff options
author | Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> | 2013-09-16 20:24:51 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-09-16 22:42:43 +0200 |
commit | 210adc4063a7557b3bc0ffd69bd992c0bec4bacc (patch) | |
tree | 784228ac8183c4f4da0f696954040e214dfa760b /src/table.c | |
parent | 2f5a7c560ab5e20111f6196181a603e1bd3f8791 (diff) |
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 <arturo.borrero.glez@gmail.com>
Diffstat (limited to 'src/table.c')
-rw-r--r-- | src/table.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/table.c b/src/table.c index 0b51d15..c8fff1e 100644 --- a/src/table.c +++ b/src/table.c @@ -218,24 +218,16 @@ int nft_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_table *t) } EXPORT_SYMBOL(nft_table_nlmsg_parse); -static int nft_table_xml_parse(struct nft_table *t, const char *xml) -{ #ifdef XML_PARSING - mxml_node_t *tree; +int nft_mxml_table_parse(mxml_node_t *tree, struct nft_table *t) +{ const char *name; int family; - tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK); - if (tree == NULL) - return -1; - - if (strcmp(tree->value.opaque, "table") != 0) - goto err; - name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, NFT_XML_MAND); if (name == NULL) - goto err; + return -1; if (t->name) xfree(t->name); @@ -246,7 +238,7 @@ static int nft_table_xml_parse(struct nft_table *t, const char *xml) family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST, NFT_XML_MAND); if (family < 0) - goto err; + return -1; t->family = family; t->flags |= (1 << NFT_TABLE_ATTR_FAMILY); @@ -254,15 +246,25 @@ static int nft_table_xml_parse(struct nft_table *t, const char *xml) if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND, BASE_DEC, &t->table_flags, NFT_TYPE_U32, NFT_XML_MAND) != 0) - goto err; + return -1; t->flags |= (1 << NFT_TABLE_ATTR_FLAGS); - mxmlDelete(tree); return 0; -err: +} +#endif + +static int nft_table_xml_parse(struct nft_table *t, const char *xml) +{ +#ifdef XML_PARSING + int ret; + mxml_node_t *tree = nft_mxml_build_tree(xml, "table"); + if (tree == NULL) + return -1; + + ret = nft_mxml_table_parse(tree, t); mxmlDelete(tree); - return -1; + return ret; #else errno = EOPNOTSUPP; return -1; |