diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-04 14:50:22 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-04 16:47:38 +0200 |
commit | d844fa06e43bc80487acfe5647cef4d4994c95fd (patch) | |
tree | 2dd70dc1b8889da6f566e467eeebdd13feafeabb /src/expr/cmp.c | |
parent | 0dbe80fee352545f51bdc4fd71621223e8b62306 (diff) |
src: consolidate XML parsing of expressions via nft_mxml_expr_parse
Move common code for XML parsing of expressions to the new
nft_mxml_expr_parse function.
This patch reduces the XML parsing code in 300 LOC.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expr/cmp.c')
-rw-r--r-- | src/expr/cmp.c | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/src/expr/cmp.c b/src/expr/cmp.c index f92b3b6..ca8dd82 100644 --- a/src/expr/cmp.c +++ b/src/expr/cmp.c @@ -168,45 +168,26 @@ static char *expr_cmp_str[] = { [NFT_CMP_GTE] = "gte", }; -static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, char *xml) +static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) { #ifdef XML_PARSING struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data; - mxml_node_t *tree = NULL; mxml_node_t *node = NULL; mxml_node_t *save = NULL; union nft_data_reg data_regtmp; uint64_t tmp; char *endptr; - tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK); - if (tree == NULL) - return -1; - - if (mxmlElementGetAttr(tree, "type") == NULL) { - mxmlDelete(tree); - return -1; - } - - if (strcmp("cmp", mxmlElementGetAttr(tree, "type")) != 0) { - mxmlDelete(tree); - return -1; - } - /* Get and set <sreg>. Is not mandatory */ node = mxmlFindElement(tree, tree, "sreg", NULL, NULL, MXML_DESCEND_FIRST); if (node != NULL) { tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT8_MAX || tmp < 0 || *endptr) { - mxmlDelete(tree); + if (tmp > UINT8_MAX || tmp < 0 || *endptr) return -1; - } - if (tmp > NFT_REG_MAX) { - mxmlDelete(tree); + if (tmp > NFT_REG_MAX) return -1; - } cmp->sreg = (uint8_t)tmp; e->flags |= (1 << NFT_EXPR_CMP_SREG); @@ -229,7 +210,6 @@ static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, char *xml) cmp->op = NFT_CMP_GTE; } else { /* If <op> is present, a valid value is mandatory */ - mxmlDelete(tree); return -1; } e->flags |= (1 << NFT_EXPR_CMP_OP); @@ -245,7 +225,6 @@ static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, char *xml) if (nft_data_reg_xml_parse(&data_regtmp, mxmlSaveAllocString(node, MXML_NO_CALLBACK)) < 0) { - mxmlDelete(tree); return -1; } @@ -256,7 +235,6 @@ static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, char *xml) e->flags |= (1 << NFT_EXPR_CMP_DATA); } - mxmlDelete(tree); return 0; #else errno = EOPNOTSUPP; |