diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2013-07-25 18:46:35 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-25 20:03:21 +0200 |
commit | e13819c5f5b6138c4c7e01156d0fd9f58b11702d (patch) | |
tree | c4bbc0256f537099a8233915597419843359793b /src/mxml.c | |
parent | 3ebc57b84c227fcfc55545af85e246ab4cad2041 (diff) |
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 <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 | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -11,6 +11,8 @@ */ #include "internal.h" #include "expr_ops.h" +#include <stdint.h> +#include <limits.h> #include <linux/netfilter/nf_tables.h> #include <libnftables/rule.h> @@ -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 |