From 1a0abb3036452852757d13fe394c6c72dff877bd Mon Sep 17 00:00:00 2001 From: Ana Rey Date: Wed, 9 Apr 2014 11:16:19 +0200 Subject: xml, json: Delete a cmpdata label in xml and json file It delete the cmpdata label in the structure of json and xml file. Example of xmlfile: The old structure of xml file: [...] 1 eq 4 0x0100a8c0 The new structure of json file: [...] 1 eq 4 0x0100a8c0 [...] To generate the new testfiles, It use the option -u of nft-parsing-test script. Signed-off-by: Ana Rey Signed-off-by: Pablo Neira Ayuso --- src/expr/cmp.c | 10 ++-------- src/jansson.c | 9 +++------ src/mxml.c | 11 +++-------- 3 files changed, 8 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/expr/cmp.c b/src/expr/cmp.c index 63250f3..2c334ab 100644 --- a/src/expr/cmp.c +++ b/src/expr/cmp.c @@ -258,7 +258,7 @@ nft_rule_expr_cmp_snprintf_json(char *buf, size_t size, struct nft_expr_cmp *cmp { int len = size, offset = 0, ret; - ret = snprintf(buf, len, "\"sreg\":%u,\"op\":\"%s\",\"cmpdata\":{", + ret = snprintf(buf, len, "\"sreg\":%u,\"op\":\"%s\",", cmp->sreg, expr_cmp_str[cmp->op]); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -266,9 +266,6 @@ nft_rule_expr_cmp_snprintf_json(char *buf, size_t size, struct nft_expr_cmp *cmp NFT_OUTPUT_JSON, 0, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = snprintf(buf+offset, len, "}"); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - return offset; } @@ -277,7 +274,7 @@ nft_rule_expr_cmp_snprintf_xml(char *buf, size_t size, struct nft_expr_cmp *cmp) { int len = size, offset = 0, ret; - ret = snprintf(buf, len, "%u%s", + ret = snprintf(buf, len, "%u%s", cmp->sreg, expr_cmp_str[cmp->op]); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); @@ -285,9 +282,6 @@ nft_rule_expr_cmp_snprintf_xml(char *buf, size_t size, struct nft_expr_cmp *cmp) NFT_OUTPUT_XML, 0, DATA_VALUE); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - ret = snprintf(buf+offset, len, ""); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - return offset; } diff --git a/src/jansson.c b/src/jansson.c index 5107eb5..affe8fe 100644 --- a/src/jansson.c +++ b/src/jansson.c @@ -215,13 +215,10 @@ int nft_jansson_data_reg_parse(json_t *root, const char *node_name, json_t *data; int ret; + /* It is necessary for the compatibility with cmpdata label. */ data = json_object_get(root, node_name); - if (data == NULL) { - err->error = NFT_PARSE_EMISSINGNODE; - err->node_name = node_name; - errno = EINVAL; - return -1; - } + if (data == NULL) + data = root; data = json_object_get(data, "data_reg"); if (data == NULL) { diff --git a/src/mxml.c b/src/mxml.c index b2cb95e..5e4f022 100644 --- a/src/mxml.c +++ b/src/mxml.c @@ -140,15 +140,10 @@ int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, node = mxmlFindElement(tree, tree, node_name, NULL, NULL, MXML_DESCEND_FIRST); - if (node == NULL || node->child == NULL) { - if (!(flags & NFT_XML_OPT)) { - err->error = NFT_PARSE_EMISSINGNODE; - err->node_name = node_name; - errno = EINVAL; - } - return DATA_NONE; - } + /* It is necessary for the compatibility with cmpdata label. */ + if (node == NULL || node->child == NULL) + node = tree; return nft_data_reg_xml_parse(data_reg, node, err); } -- cgit v1.2.3