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/ct.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/expr/ct.c') diff --git a/src/expr/ct.c b/src/expr/ct.c index f399219..a0323e1 100644 --- a/src/expr/ct.c +++ b/src/expr/ct.c @@ -183,10 +183,9 @@ static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree #ifdef XML_PARSING struct nft_expr_ct *ct = nft_expr_data(e); mxml_node_t *node = NULL; - uint64_t tmp; int32_t reg; - char *endptr; int key; + uint8_t dir; reg = nft_mxml_reg_parse(tree, "dreg", MXML_DESCEND_FIRST); if (reg < 0) @@ -206,18 +205,14 @@ static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree ct->key = key; e->flags |= (1 << NFT_EXPR_CT_KEY); - node = mxmlFindElement(tree, tree, "dir", NULL, NULL, MXML_DESCEND); - if (node == NULL) - goto err; - - tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT8_MAX || tmp < 0 || *endptr) + if (nft_mxml_num_parse(tree, "dir", MXML_DESCEND_FIRST, BASE_DEC, &dir, + NFT_TYPE_U8) != 0) goto err; - if (tmp != IP_CT_DIR_ORIGINAL && tmp != IP_CT_DIR_REPLY) + if (dir != IP_CT_DIR_ORIGINAL && dir != IP_CT_DIR_REPLY) goto err; - ct->dir = tmp; + ct->dir = dir; e->flags |= (1 << NFT_EXPR_CT_DIR); return 0; -- cgit v1.2.3