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/counter.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/counter.c')
-rw-r--r-- | src/expr/counter.c | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/src/expr/counter.c b/src/expr/counter.c index 62bd143..665fa14 100644 --- a/src/expr/counter.c +++ b/src/expr/counter.c @@ -128,38 +128,21 @@ nft_rule_expr_counter_parse(struct nft_rule_expr *e, struct nlattr *attr) } static int -nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, char *xml) +nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) { #ifdef XML_PARSING struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data; - mxml_node_t *tree = NULL; mxml_node_t *node = NULL; char *endptr; uint64_t tmp; - tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK); - if (tree == NULL) - return -1; - - if (mxmlElementGetAttr(tree, "type") == NULL) { - mxmlDelete(tree); - return -1; - } - - if (strcmp("counter", mxmlElementGetAttr(tree, "type")) != 0) { - mxmlDelete(tree); - return -1; - } - /* get and set <pkts>. Is not mandatory*/ node = mxmlFindElement(tree, tree, "pkts", NULL, NULL, MXML_DESCEND_FIRST); if (node != NULL) { tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp == UINT64_MAX || tmp < 0 || *endptr ) { - mxmlDelete(tree); + if (tmp == UINT64_MAX || tmp < 0 || *endptr ) return -1; - } ctr->pkts = tmp; e->flags |= (1 << NFT_EXPR_CTR_PACKETS); @@ -170,16 +153,13 @@ nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, char *xml) MXML_DESCEND); if (node != NULL) { tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp == UINT64_MAX || tmp < 0 || *endptr) { - mxmlDelete(tree); + if (tmp == UINT64_MAX || tmp < 0 || *endptr) return -1; - } ctr->bytes = tmp; e->flags |= (1 << NFT_EXPR_CTR_BYTES); } - mxmlDelete(tree); return 0; #else errno = EOPNOTSUPP; |