summaryrefslogtreecommitdiffstats
path: root/src/table.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-10-09 00:03:28 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-15 14:04:27 +0200
commit80077787f8f21da1efd8dc27a4c5767ab47a1df6 (patch)
tree01d9b399a1aad23d7ea1d1e1daa0ad98bec69e0a /src/table.c
parentaaf20ad0dc22d2ebcad1b2c43288e984f0efe2c3 (diff)
src: remove json support
We have better json support in libnftables these days. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/table.c')
-rw-r--r--src/table.c93
1 files changed, 1 insertions, 92 deletions
diff --git a/src/table.c b/src/table.c
index e7616f6..c987c5e 100644
--- a/src/table.c
+++ b/src/table.c
@@ -283,72 +283,14 @@ int nftnl_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_table *t)
return 0;
}
-#ifdef JSON_PARSING
-int nftnl_jansson_parse_table(struct nftnl_table *t, json_t *tree,
- struct nftnl_parse_err *err)
-{
- json_t *root;
- uint32_t flags, use;
- const char *str;
- int family;
-
- root = nftnl_jansson_get_node(tree, "table", err);
- if (root == NULL)
- return -1;
-
- str = nftnl_jansson_parse_str(root, "name", err);
- if (str != NULL)
- nftnl_table_set_str(t, NFTNL_TABLE_NAME, str);
-
- if (nftnl_jansson_parse_family(root, &family, err) == 0)
- nftnl_table_set_u32(t, NFTNL_TABLE_FAMILY, family);
-
- if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
- err) == 0)
- nftnl_table_set_u32(t, NFTNL_TABLE_FLAGS, flags);
-
- if (nftnl_jansson_parse_val(root, "use", NFTNL_TYPE_U32, &use, err) == 0)
- nftnl_table_set_u32(t, NFTNL_TABLE_USE, use);
-
- return 0;
-}
-#endif
-
-static int nftnl_table_json_parse(struct nftnl_table *t, const void *json,
- struct nftnl_parse_err *err,
- enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
- json_t *tree;
- json_error_t error;
- int ret;
-
- tree = nftnl_jansson_create_root(json, &error, err, input);
- if (tree == NULL)
- return -1;
-
- ret = nftnl_jansson_parse_table(t, tree, err);
-
- nftnl_jansson_free_root(tree);
-
- return ret;
-#else
- errno = EOPNOTSUPP;
- return -1;
-#endif
-}
-
static int nftnl_table_do_parse(struct nftnl_table *t, enum nftnl_parse_type type,
const void *data, struct nftnl_parse_err *err,
enum nftnl_parse_input input)
{
int ret;
- struct nftnl_parse_err perr = {};
switch (type) {
case NFTNL_PARSE_JSON:
- ret = nftnl_table_json_parse(t, data, &perr, input);
- break;
case NFTNL_PARSE_XML:
default:
ret = -1;
@@ -356,9 +298,6 @@ static int nftnl_table_do_parse(struct nftnl_table *t, enum nftnl_parse_type typ
break;
}
- if (err != NULL)
- *err = perr;
-
return ret;
}
@@ -376,28 +315,6 @@ int nftnl_table_parse_file(struct nftnl_table *t, enum nftnl_parse_type type,
return nftnl_table_do_parse(t, type, fp, err, NFTNL_PARSE_FILE);
}
-static int nftnl_table_export(char *buf, size_t size,
- const struct nftnl_table *t, int type)
-{
- NFTNL_BUF_INIT(b, buf, size);
-
- nftnl_buf_open(&b, type, TABLE);
- if (t->flags & (1 << NFTNL_TABLE_NAME))
- nftnl_buf_str(&b, type, t->name, NAME);
- if (t->flags & (1 << NFTNL_TABLE_FAMILY))
- nftnl_buf_str(&b, type, nftnl_family2str(t->family), FAMILY);
- if (t->flags & (1 << NFTNL_TABLE_FLAGS))
- nftnl_buf_u32(&b, type, t->table_flags, FLAGS);
- if (t->flags & (1 << NFTNL_TABLE_USE))
- nftnl_buf_u32(&b, type, t->use, USE);
- if (t->flags & (1 << NFTNL_TABLE_HANDLE))
- nftnl_buf_u64(&b, type, t->handle, HANDLE);
-
- nftnl_buf_close(&b, type, TABLE);
-
- return nftnl_buf_done(&b);
-}
-
static int nftnl_table_snprintf_default(char *buf, size_t size,
const struct nftnl_table *t)
{
@@ -412,24 +329,16 @@ static int nftnl_table_cmd_snprintf(char *buf, size_t size,
{
int ret, remain = size, offset = 0;
- ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
ret = nftnl_table_snprintf_default(buf + offset, remain, t);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
break;
case NFTNL_OUTPUT_XML:
case NFTNL_OUTPUT_JSON:
- ret = nftnl_table_export(buf + offset, remain, t, type);
- break;
default:
return -1;
}
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
- ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}