diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2013-07-25 18:46:35 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-25 20:03:21 +0200 |
commit | e13819c5f5b6138c4c7e01156d0fd9f58b11702d (patch) | |
tree | c4bbc0256f537099a8233915597419843359793b /src/expr/log.c | |
parent | 3ebc57b84c227fcfc55545af85e246ab4cad2041 (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/log.c')
-rw-r--r-- | src/expr/log.c | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/src/expr/log.c b/src/expr/log.c index 1ffd1d9..9ff2d32 100644 --- a/src/expr/log.c +++ b/src/expr/log.c @@ -157,56 +157,36 @@ static int nft_rule_expr_log_xml_parse(struct nft_rule_expr *e, mxml_node_t *tre #ifdef XML_PARSING struct nft_expr_log *log = nft_expr_data(e); mxml_node_t *node = NULL; - uint64_t tmp; - char *endptr; node = mxmlFindElement(tree, tree, "prefix", NULL, NULL, MXML_DESCEND_FIRST); - if (node == NULL) - goto err; + if (node == NULL) { + errno = EINVAL; + return -1; + } log->prefix = strdup(node->child->value.opaque); e->flags |= (1 << NFT_EXPR_LOG_PREFIX); - node = mxmlFindElement(tree, tree, "group", NULL, NULL, MXML_DESCEND); - if (node == NULL) - goto err; - - tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT32_MAX || tmp < 0 || *endptr) - goto err; + if (nft_mxml_num_parse(tree, "group", MXML_DESCEND_FIRST, BASE_DEC, + &log->group, NFT_TYPE_U32) != 0) + return -1; - log->group = tmp; e->flags |= (1 << NFT_EXPR_LOG_GROUP); - node = mxmlFindElement(tree, tree, "snaplen", NULL, NULL, - MXML_DESCEND); - if (node == NULL) - goto err; - - tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT32_MAX || tmp < 0 || *endptr) - goto err; + if (nft_mxml_num_parse(tree, "snaplen", MXML_DESCEND_FIRST, BASE_DEC, + &log->snaplen, NFT_TYPE_U32) != 0) + return -1; - log->snaplen = tmp; e->flags |= (1 << NFT_EXPR_LOG_SNAPLEN); - node = mxmlFindElement(tree, tree, "qthreshold", NULL, NULL, - MXML_DESCEND); - if (node == NULL) - goto err; - - tmp = strtoull(node->child->value.opaque, &endptr, 10); - if (tmp > UINT32_MAX || tmp < 0 || *endptr) - goto err; + if (nft_mxml_num_parse(tree, "qthreshold", MXML_DESCEND_FIRST, + BASE_DEC, &log->qthreshold, NFT_TYPE_U32) != 0) + return -1; - log->qthreshold = tmp; e->flags |= (1 << NFT_EXPR_LOG_QTHRESHOLD); return 0; -err: - errno = EINVAL; - return -1; #else errno = EOPNOTSUPP; return -1; |