diff options
author | Álvaro Neira Ayuso <alvaroneay@gmail.com> | 2013-09-12 19:16:37 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-09-13 09:43:59 +0200 |
commit | 4e02019fb2b8ddcf374c7e026dbdd7881dc09506 (patch) | |
tree | 5b249436293dc94d9d480de9ae5a264e134e6929 /src/table.c | |
parent | 04db2744603bd506470b4e1baf9deee16d43baca (diff) |
src: json: refactor json parsing to allow tree based navigation
This patch refactors nft_*_json_parse to provide a new
intermediate function nft_jansson_parse_chain which will
allows us to navigate the entire json tree containing the
ruleset.
Signed-off-by: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/table.c')
-rw-r--r-- | src/table.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/table.c b/src/table.c index 8d20be5..838c5ee 100644 --- a/src/table.c +++ b/src/table.c @@ -266,20 +266,15 @@ err: #endif } -static int nft_table_json_parse(struct nft_table *t, const char *json) -{ #ifdef JSON_PARSING - json_t *root, *node; - json_error_t error; +static int nft_jansson_parse_table(struct nft_table *t, json_t *tree) +{ + json_t *root; uint32_t flags; const char *str; int family; - node = nft_jansson_create_root(json, &error); - if (node == NULL) - return -1; - - root = nft_jansson_get_node(node, "table"); + root = nft_jansson_get_node(tree, "table"); if (root == NULL) return -1; @@ -299,11 +294,25 @@ static int nft_table_json_parse(struct nft_table *t, const char *json) nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, flags); - nft_jansson_free_root(node); + nft_jansson_free_root(tree); return 0; err: - nft_jansson_free_root(node); + nft_jansson_free_root(tree); return -1; +} +#endif + +static int nft_table_json_parse(struct nft_table *t, const char *json) +{ +#ifdef JSON_PARSING + json_t *tree; + json_error_t error; + + tree = nft_jansson_create_root(json, &error); + if (tree == NULL) + return -1; + + return nft_jansson_parse_table(t, tree); #else errno = EOPNOTSUPP; return -1; |