Refactor the parsing ruleset element functions calls in xml/json to do that calls in the functions nft_ruleset_*_parse_ruleset. This patch is used in follow up patches. Signed-off-by: Alvaro Neira Ayuso <alvaroneay@xxxxxxxxx> --- src/ruleset.c | 59 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/ruleset.c b/src/ruleset.c index a397824..6488d72 100644 --- a/src/ruleset.c +++ b/src/ruleset.c @@ -332,6 +332,24 @@ err: #endif +static int nft_ruleset_json_parse_ruleset(struct nft_ruleset *rs, json_t *array, + struct nft_parse_err *err) +{ + if (nft_ruleset_json_parse_tables(rs, array, err) != 0) + return -1; + + if (nft_ruleset_json_parse_chains(rs, array, err) != 0) + return -1; + + if (nft_ruleset_json_parse_sets(rs, array, err) != 0) + return -1; + + if (nft_ruleset_json_parse_rules(rs, array, err) != 0) + return -1; + + return 0; +} + static int nft_ruleset_json_parse(struct nft_ruleset *rs, const void *json, struct nft_parse_err *err, enum nft_parse_input input) { @@ -349,16 +367,7 @@ static int nft_ruleset_json_parse(struct nft_ruleset *rs, const void *json, goto err; } - if (nft_ruleset_json_parse_tables(rs, array, err) != 0) - goto err; - - if (nft_ruleset_json_parse_chains(rs, array, err) != 0) - goto err; - - if (nft_ruleset_json_parse_sets(rs, array, err) != 0) - goto err; - - if (nft_ruleset_json_parse_rules(rs, array, err) != 0) + if (nft_ruleset_json_parse_ruleset(rs, array, err) != 0) goto err; nft_jansson_free_root(root); @@ -539,6 +548,25 @@ err_free: } #endif +static int nft_ruleset_xml_parse_ruleset(struct nft_ruleset *rs, + mxml_node_t *tree, + struct nft_parse_err *err) +{ + if (nft_ruleset_xml_parse_tables(rs, tree, err) != 0) + return -1; + + if (nft_ruleset_xml_parse_chains(rs, tree, err) != 0) + return -1; + + if (nft_ruleset_xml_parse_sets(rs, tree, err) != 0) + return -1; + + if (nft_ruleset_xml_parse_rules(rs, tree, err, rs->set_list) != 0) + return -1; + + return 0; +} + static int nft_ruleset_xml_parse(struct nft_ruleset *rs, const void *xml, struct nft_parse_err *err, enum nft_parse_input input) { @@ -549,16 +577,7 @@ static int nft_ruleset_xml_parse(struct nft_ruleset *rs, const void *xml, if (tree == NULL) return -1; - if (nft_ruleset_xml_parse_tables(rs, tree, err) != 0) - goto err; - - if (nft_ruleset_xml_parse_chains(rs, tree, err) != 0) - goto err; - - if (nft_ruleset_xml_parse_sets(rs, tree, err) != 0) - goto err; - - if (nft_ruleset_xml_parse_rules(rs, tree, err, rs->set_list) != 0) + if (nft_ruleset_xml_parse_ruleset(rs, tree, err) != 0) goto err; mxmlDelete(tree); -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html