netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alvaro Neira Ayuso <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [libnftnl PATCH] set: refactor code in json parse function
Date: Fri, 23 Jan 2015 15:49:51 +0100	[thread overview]
Message-ID: <1422024596-8839-1-git-send-email-alvaroneay@gmail.com> (raw)

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


             reply	other threads:[~2015-01-23 14:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 14:49 Alvaro Neira Ayuso [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422024596-8839-1-git-send-email-alvaroneay@gmail.com \
    --to=alvaroneay@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).