summaryrefslogtreecommitdiffstats
path: root/src/set.c
diff options
context:
space:
mode:
authorÁlvaro Neira Ayuso <alvaroneay@gmail.com>2013-09-12 19:16:37 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-09-13 09:43:59 +0200
commit4e02019fb2b8ddcf374c7e026dbdd7881dc09506 (patch)
tree5b249436293dc94d9d480de9ae5a264e134e6929 /src/set.c
parent04db2744603bd506470b4e1baf9deee16d43baca (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/set.c')
-rw-r--r--src/set.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/set.c b/src/set.c
index fe30e77..a4b644a 100644
--- a/src/set.c
+++ b/src/set.c
@@ -303,21 +303,16 @@ int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s)
}
EXPORT_SYMBOL(nft_set_nlmsg_parse);
-static int nft_set_json_parse(struct nft_set *s, const char *json)
-{
#ifdef JSON_PARSING
- json_t *root, *node, *array, *json_elem;
- json_error_t error;
+static int nft_jansson_parse_set(struct nft_set *s, json_t *tree)
+{
+ json_t *root, *array, *json_elem;
uint32_t uval32;
int family, i;
const char *valstr;
struct nft_set_elem *elem;
- node = nft_jansson_create_root(json, &error);
- if (node == NULL)
- return -1;
-
- root = nft_jansson_get_node(node, "set");
+ root = nft_jansson_get_node(tree, "set");
if (root == NULL)
return -1;
@@ -388,11 +383,26 @@ static int nft_set_json_parse(struct nft_set *s, const char *json)
}
- 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_set_json_parse(struct nft_set *s, 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_set(s, tree);
#else
errno = EOPNOTSUPP;
return -1;