Add a helper function that parses and returns the jansson
tree, use it in the table parser.
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
int type, void *out);
const char *nft_jansson_value_parse_str(json_t *root, const char *tag);
bool nft_jansson_node_exist(json_t *root, const char *tag);
+json_t *nft_jansson_get_root(char *json, const char *tag, json_error_t *err);
#endif
const char *nft_family2str(uint32_t family);
{
return json_object_get(root, tag) != NULL;
}
+
+json_t *nft_jansson_get_root(char *json, const char *tag, json_error_t *err)
+{
+ json_t *root;
+
+ root = json_loadb(json, strlen(json), 0, err);
+ if (root == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ root = json_object_get(root, tag);
+ if (root == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ return root;
+}
#endif
const char *str;
int family;
- root = json_loadb(json, strlen(json), 0, &error);
- if (!root) {
- errno = EINVAL;
- goto err;
- }
-
- root = json_object_get(root, "table");
- if (root == NULL) {
- errno = EINVAL;
- goto err;
- }
+ root = nft_jansson_get_root(json, "table", &error);
+ if (root == NULL)
+ return -1;
str = nft_jansson_value_parse_str(root, "name");
if (str == NULL)