From fc423ae81487e906141f700c7b3515328ff62b7c Mon Sep 17 00:00:00 2001 From: Arturo Borrero Date: Thu, 9 Jan 2014 12:19:06 +0100 Subject: src: rework and generalize the build/parse system The intention behind this patch is to prepare the introduction of the new API that will allow us to parse files that contain the rule-sets expressed in XML/JSON format. This adds the NFT_PARSE_BUFFER that indicates that the input is provided in a buffer, which is what we currently support. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/ruleset.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/ruleset.c') diff --git a/src/ruleset.c b/src/ruleset.c index a12efa9..c6bcc4b 100644 --- a/src/ruleset.c +++ b/src/ruleset.c @@ -330,14 +330,14 @@ err: #endif -static int nft_ruleset_json_parse(struct nft_ruleset *rs, const char *json, - struct nft_parse_err *err) +static int nft_ruleset_json_parse(struct nft_ruleset *rs, const void *json, + struct nft_parse_err *err, enum nft_parse_input input) { #ifdef JSON_PARSING json_t *root, *array; json_error_t error; - root = nft_jansson_create_root(json, &error, err); + root = nft_jansson_create_root(json, &error, err, input); if (root == NULL) return -1; @@ -534,13 +534,13 @@ err_free: } #endif -static int nft_ruleset_xml_parse(struct nft_ruleset *rs, const char *xml, - struct nft_parse_err *err) +static int nft_ruleset_xml_parse(struct nft_ruleset *rs, const void *xml, + struct nft_parse_err *err, enum nft_parse_input input) { #ifdef XML_PARSING mxml_node_t *tree; - tree = nft_mxml_build_tree(xml, "nftables", err); + tree = nft_mxml_build_tree(xml, "nftables", err, input); if (tree == NULL) return -1; @@ -567,17 +567,19 @@ err: #endif } -int nft_ruleset_parse(struct nft_ruleset *r, enum nft_parse_type type, - const char *data, struct nft_parse_err *err) +static int +nft_ruleset_do_parse(struct nft_ruleset *r, enum nft_parse_type type, + const void *data, struct nft_parse_err *err, + enum nft_parse_input input) { int ret; switch (type) { case NFT_PARSE_XML: - ret = nft_ruleset_xml_parse(r, data, err); + ret = nft_ruleset_xml_parse(r, data, err, input); break; case NFT_PARSE_JSON: - ret = nft_ruleset_json_parse(r, data, err); + ret = nft_ruleset_json_parse(r, data, err, input); break; default: ret = -1; @@ -587,6 +589,12 @@ int nft_ruleset_parse(struct nft_ruleset *r, enum nft_parse_type type, return ret; } + +int nft_ruleset_parse(struct nft_ruleset *r, enum nft_parse_type type, + const char *data, struct nft_parse_err *err) +{ + return nft_ruleset_do_parse(r, type, data, err, NFT_PARSE_BUFFER); +} EXPORT_SYMBOL(nft_ruleset_parse); static const char *nft_ruleset_o_opentag(uint32_t type) -- cgit v1.2.3