summaryrefslogtreecommitdiffstats
path: root/src/libnftables.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-10-27 12:02:02 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-29 15:07:35 +0100
commit7a6f12d75034fed940ce635e76a13123430f088e (patch)
treef58e0e41f725ae50820889fcc55712b13da6ac55 /src/libnftables.c
parent3c69cf7603534ef6df01ec079c6a4d3d3382f580 (diff)
src: add nft_ctx_output_{get,set}_json() to nft_ctx_output_{get,set}_flags
Add NFT_CTX_OUTPUT_JSON flag and display output in json format. Acked-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/libnftables.c')
-rw-r--r--src/libnftables.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/libnftables.c b/src/libnftables.c
index 6dc1be3d..ff7a53d2 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -352,22 +352,6 @@ void nft_ctx_output_set_echo(struct nft_ctx *ctx, bool val)
ctx->output.echo = val;
}
-bool nft_ctx_output_get_json(struct nft_ctx *ctx)
-{
-#ifdef HAVE_LIBJANSSON
- return ctx->output.json;
-#else
- return false;
-#endif
-}
-
-void nft_ctx_output_set_json(struct nft_ctx *ctx, bool val)
-{
-#ifdef HAVE_LIBJANSSON
- ctx->output.json = val;
-#endif
-}
-
static const struct input_descriptor indesc_cmdline = {
.type = INDESC_BUFFER,
.name = "<cmdline>",
@@ -425,7 +409,7 @@ int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf)
nlbuf = xzalloc(strlen(buf) + 2);
sprintf(nlbuf, "%s\n", buf);
- if (nft->output.json)
+ if (nft_output_json(&nft->output))
rc = nft_parse_json_buffer(nft, nlbuf, &msgs, &cmds);
if (rc == -EINVAL)
rc = nft_parse_bison_buffer(nft, nlbuf, &msgs, &cmds);
@@ -447,7 +431,7 @@ err:
}
free(nlbuf);
- if (!rc && nft->output.json && nft->output.echo)
+ if (!rc && nft_output_json(&nft->output) && nft->output.echo)
json_print_echo(nft);
return rc;
}
@@ -467,7 +451,7 @@ int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
filename = "/dev/stdin";
rc = -EINVAL;
- if (nft->output.json)
+ if (nft_output_json(&nft->output))
rc = nft_parse_json_filename(nft, filename, &msgs, &cmds);
if (rc == -EINVAL)
rc = nft_parse_bison_filename(nft, filename, &msgs, &cmds);
@@ -488,7 +472,7 @@ err:
nft->scanner = NULL;
}
- if (!rc && nft->output.json && nft->output.echo)
+ if (!rc && nft_output_json(&nft->output) && nft->output.echo)
json_print_echo(nft);
return rc;
}