From e13819c5f5b6138c4c7e01156d0fd9f58b11702d Mon Sep 17 00:00:00 2001 From: Arturo Borrero Date: Thu, 25 Jul 2013 18:46:35 +0200 Subject: src: xml: consolidate common XML code via nft_mxml_num_parse This patch moves common XML parsing code to nft_mxml_num_parse(). To handle this, the nft_strtoi() helper fuction is included. I've changed some MXML_DESCEND[_FIRST] flags to avoid match a nested node under some circumstances, ie, matching two nodes with the same name that are descendant. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/mxml.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/mxml.c') diff --git a/src/mxml.c b/src/mxml.c index 07f29ac..8cb1f6c 100644 --- a/src/mxml.c +++ b/src/mxml.c @@ -11,6 +11,8 @@ */ #include "internal.h" #include "expr_ops.h" +#include +#include #include #include @@ -58,7 +60,6 @@ err: int nft_mxml_reg_parse(mxml_node_t *tree, const char *reg_name, uint32_t flags) { mxml_node_t *node; - char *endptr; uint64_t val; node = mxmlFindElement(tree, tree, reg_name, NULL, NULL, flags); @@ -67,8 +68,11 @@ int nft_mxml_reg_parse(mxml_node_t *tree, const char *reg_name, uint32_t flags) goto err; } - val = strtoull(node->child->value.opaque, &endptr, 10); - if (val > NFT_REG_MAX || val < 0 || *endptr) { + if (nft_strtoi(node->child->value.opaque, BASE_DEC, &val, + NFT_TYPE_U64) != 0) + goto err; + + if (val > NFT_REG_MAX) { errno = ERANGE; goto err; } @@ -130,4 +134,20 @@ int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, err: return -1; } + +int +nft_mxml_num_parse(mxml_node_t *tree, const char *node_name, + uint32_t mxml_flags, int base, void *number, + enum nft_type type) +{ + mxml_node_t *node = NULL; + + node = mxmlFindElement(tree, tree, node_name, NULL, NULL, mxml_flags); + if (node == NULL || node->child == NULL) { + errno = EINVAL; + return -1; + } + + return nft_strtoi(node->child->value.opaque, base, number, type); +} #endif -- cgit v1.2.3