netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libnftnl PATCH] set: refactor code in json parse function
@ 2015-01-23 14:49 Alvaro Neira Ayuso
  2015-01-23 14:49 ` [libnftnl PATCH 1/5] src: add command tag in json/xml export support Alvaro Neira Ayuso
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Alvaro Neira Ayuso @ 2015-01-23 14:49 UTC (permalink / raw)
  To: netfilter-devel

This patch refactor code to parse the set in two functions
nft_jansson_parse_set_info and nft_jansson_parse_set. Those changes is used
in follow up patches.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
 src/set.c |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/set.c b/src/set.c
index 61e0632..4fd786a 100644
--- a/src/set.c
+++ b/src/set.c
@@ -410,19 +410,15 @@ int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s)
 EXPORT_SYMBOL(nft_set_nlmsg_parse);
 
 #ifdef JSON_PARSING
-int nft_jansson_parse_set(struct nft_set *s, json_t *tree,
-			  struct nft_parse_err *err)
+static int nft_jansson_parse_set_info(struct nft_set *s, json_t *tree,
+				      struct nft_parse_err *err)
 {
-	json_t *root, *array, *json_elem;
+	json_t *root = tree, *array, *json_elem;
 	uint32_t flags, key_type, key_len, data_type, data_len, policy, size;
 	int family, i;
 	const char *name, *table;
 	struct nft_set_elem *elem;
 
-	root = nft_jansson_get_node(tree, "set", err);
-	if (root == NULL)
-		return -1;
-
 	name = nft_jansson_parse_str(root, "name", err);
 	if (name == NULL)
 		return -1;
@@ -503,6 +499,18 @@ int nft_jansson_parse_set(struct nft_set *s, json_t *tree,
 
 	return 0;
 }
+
+int nft_jansson_parse_set(struct nft_set *s, json_t *tree,
+			  struct nft_parse_err *err)
+{
+	json_t *root;
+
+	root = nft_jansson_get_node(tree, "set", err);
+	if (root == NULL)
+		return -1;
+
+	return nft_jansson_parse_set_info(s, root, err);
+}
 #endif
 
 static int nft_set_json_parse(struct nft_set *s, const void *json,
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-23 14:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-23 14:49 [libnftnl PATCH] set: refactor code in json parse function Alvaro Neira Ayuso
2015-01-23 14:49 ` [libnftnl PATCH 1/5] src: add command tag in json/xml export support Alvaro Neira Ayuso
2015-01-23 14:49 ` [libnftnl PATCH 2/5] src: add support to import json/xml with the new syntax Alvaro Neira Ayuso
2015-01-23 14:49 ` [libnftnl PATCH 3/5] ruleset: consolidate code in json/xml import support Alvaro Neira Ayuso
2015-01-23 14:49 ` [libnftnl PATCH 4/5] example: Parse and create netlink message using the new parsing functions Alvaro Neira Ayuso
2015-01-23 14:49 ` [libnftnl PATCH 5/5] test: update json/xml tests to the new syntax Alvaro Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).