diff options
author | Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> | 2013-09-13 14:45:21 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-09-16 12:47:57 +0200 |
commit | 2f5a7c560ab5e20111f6196181a603e1bd3f8791 (patch) | |
tree | fd31f5583e86184e878bf80faab03355cd6667ec /src/mxml.c | |
parent | f4befc129827632209779c71d804f6139ac03541 (diff) |
src: xml: avoid unecessary tree to text to tree conversions
This patch avoid several tree to text to tree conversions in the XML
parsing helpers.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/mxml.c')
-rw-r--r-- | src/mxml.c | 59 |
1 files changed, 4 insertions, 55 deletions
@@ -86,68 +86,17 @@ int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, union nft_data_reg *data_reg, uint16_t flags) { mxml_node_t *node; - const char *type; - char *tmpstr = NULL; - int ret; node = mxmlFindElement(tree, tree, node_name, NULL, NULL, MXML_DESCEND_FIRST); if (node == NULL || node->child == NULL) { - if (flags & NFT_XML_OPT) - return 0; - - errno = EINVAL; - goto err; - } - - tmpstr = mxmlSaveAllocString(node, MXML_NO_CALLBACK); - if (tmpstr == NULL) { - errno = ENOMEM; - goto err; - } - - ret = nft_data_reg_xml_parse(data_reg, tmpstr); - xfree(tmpstr); - - if (ret < 0) { - if (flags & NFT_XML_OPT) - return 0; - - errno = EINVAL; - goto err; - } - - node = mxmlFindElement(node, node, "data_reg", NULL, NULL, - MXML_DESCEND); - if (node == NULL || node->child == NULL) { - if (flags & NFT_XML_OPT) - return 0; - - errno = EINVAL; - goto err; - } - - type = mxmlElementGetAttr(node, "type"); - if (type == NULL) { - if (flags & NFT_XML_OPT) - return DATA_NONE; - - errno = EINVAL; - goto err; - } + if (!(flags & NFT_XML_OPT)) + errno = EINVAL; - if (strcmp(type, "value") == 0) - return DATA_VALUE; - else if (strcmp(type, "verdict") == 0) - return DATA_VERDICT; - else if (strcmp(type, "chain") == 0) - return DATA_CHAIN; - else if (flags & NFT_XML_OPT) return DATA_NONE; + } - errno = EINVAL; -err: - return -1; + return nft_data_reg_xml_parse(data_reg, node); } int |