summaryrefslogtreecommitdiffstats
path: root/src/expr/data_reg.c
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2013-07-25 18:46:35 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-07-25 20:03:21 +0200
commite13819c5f5b6138c4c7e01156d0fd9f58b11702d (patch)
treec4bbc0256f537099a8233915597419843359793b /src/expr/data_reg.c
parent3ebc57b84c227fcfc55545af85e246ab4cad2041 (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/expr/data_reg.c')
-rw-r--r--src/expr/data_reg.c27
1 files changed, 4 insertions, 23 deletions
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index 260ae59..b290b96 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -134,9 +134,6 @@ static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, char *xml)
mxml_node_t *tree = NULL;
mxml_node_t *node = NULL;
int i;
- int64_t tmp;
- uint64_t utmp;
- char *endptr;
char node_name[6];
tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK);
@@ -172,38 +169,22 @@ static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, char *xml)
return -1;
}
- /* Get <len> */
- node = mxmlFindElement(tree, tree, "len", NULL, NULL, MXML_DESCEND);
- if (node == NULL) {
+ if (nft_mxml_num_parse(tree, "len", MXML_DESCEND, BASE_DEC, &reg->len,
+ NFT_TYPE_U8) != 0) {
mxmlDelete(tree);
return -1;
}
- tmp = strtoll(node->child->value.opaque, &endptr, 10);
- if (tmp > INT64_MAX || tmp < 0 || *endptr) {
- mxmlDelete(tree);
- return -1;
- }
-
- reg->len = tmp;
-
/* Get and set <dataN> */
for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) {
sprintf(node_name, "data%d", i);
- node = mxmlFindElement(tree, tree, node_name, NULL,
- NULL, MXML_DESCEND);
- if (node == NULL) {
+ if (nft_mxml_num_parse(tree, node_name, MXML_DESCEND, BASE_HEX,
+ &reg->val[i], NFT_TYPE_U32) != 0) {
mxmlDelete(tree);
return -1;
}
- utmp = strtoull(node->child->value.opaque, &endptr, 16);
- if (utmp == UINT64_MAX || utmp < 0 || *endptr) {
- mxmlDelete(tree);
- return -1;
- }
- reg->val[i] = utmp;
}
mxmlDelete(tree);