summaryrefslogtreecommitdiffstats
path: root/src/ruleset.c
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2014-01-09 12:19:06 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2014-01-09 17:17:37 +0100
commitfc423ae81487e906141f700c7b3515328ff62b7c (patch)
treed55537396d2ccca278df628853f4febf8ed4e697 /src/ruleset.c
parent2c21b41889abf93ff816b82b59e6bf2d4a084a61 (diff)
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 <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/ruleset.c')
-rw-r--r--src/ruleset.c28
1 files changed, 18 insertions, 10 deletions
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)