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/expr/exthdr.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/expr/exthdr.c') diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c index 51e784e..769b53c 100644 --- a/src/expr/exthdr.c +++ b/src/expr/exthdr.c @@ -199,8 +199,6 @@ nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) #ifdef XML_PARSING struct nft_expr_exthdr *exthdr = nft_expr_data(e); mxml_node_t *node = NULL; - uint64_t tmp; - char *endptr; int32_t reg; int type; @@ -225,28 +223,17 @@ nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) e->flags |= (1 << NFT_EXPR_EXTHDR_TYPE); /* Get and set */ - node = mxmlFindElement(tree, tree, "offset", NULL, NULL, - MXML_DESCEND); - if (node == NULL) - return -1; - - tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT_MAX || tmp < 0 || *endptr) + if (nft_mxml_num_parse(tree, "offset", MXML_DESCEND_FIRST, BASE_DEC, + &exthdr->offset, NFT_TYPE_U32) != 0) return -1; - exthdr->offset = tmp; e->flags |= (1 << NFT_EXPR_EXTHDR_OFFSET); /* Get and set */ - node = mxmlFindElement(tree, tree, "len", NULL, NULL, MXML_DESCEND); - if (node == NULL) - return -1; - - tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT_MAX || tmp < 0 || *endptr) + if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + &exthdr->len, NFT_TYPE_U32) != 0) return -1; - exthdr->len = tmp; e->flags |= (1 << NFT_EXPR_EXTHDR_LEN); return 0; -- cgit v1.2.3