summaryrefslogtreecommitdiffstats
path: root/src/jansson.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/jansson.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/jansson.c')
-rw-r--r--src/jansson.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/jansson.c b/src/jansson.c
index e62116b..3428f2f 100644
--- a/src/jansson.c
+++ b/src/jansson.c
@@ -89,22 +89,31 @@ bool nft_jansson_node_exist(json_t *root, const char *node_name)
return json_object_get(root, node_name) != NULL;
}
-json_t *nft_jansson_create_root(const char *json, json_error_t *error,
- struct nft_parse_err *err)
+json_t *nft_jansson_create_root(const void *json, json_error_t *error,
+ struct nft_parse_err *err, enum nft_parse_input input)
{
json_t *root;
- root = json_loadb(json, strlen(json), 0, error);
+ switch (input) {
+ case NFT_PARSE_BUFFER:
+ root = json_loadb(json, strlen(json), 0, error);
+ break;
+ default:
+ goto err;
+ }
+
if (root == NULL) {
err->error = NFT_PARSE_EBADINPUT;
err->line = error->line;
err->column = error->column;
err->node_name = error->source;
- errno = EINVAL;
- return NULL;
+ goto err;
}
return root;
+err:
+ errno = EINVAL;
+ return NULL;
}
json_t *nft_jansson_get_node(json_t *root, const char *node_name,