summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libnftables.c24
-rw-r--r--src/main.c4
-rw-r--r--src/monitor.c2
-rw-r--r--src/rule.c2
4 files changed, 9 insertions, 23 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;
}
diff --git a/src/main.c b/src/main.c
index 7cf3bb68..33e3bc6e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -272,7 +272,9 @@ int main(int argc, char * const *argv)
nft_ctx_output_set_echo(nft, true);
break;
case OPT_JSON:
- nft_ctx_output_set_json(nft, true);
+#ifdef HAVE_LIBJANSSON
+ output_flags |= NFT_CTX_OUTPUT_JSON;
+#endif
break;
case OPT_INVALID:
exit(EXIT_FAILURE);
diff --git a/src/monitor.c b/src/monitor.c
index 9e3c43dc..01480cd7 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -908,7 +908,7 @@ int netlink_echo_callback(const struct nlmsghdr *nlh, void *data)
if (!echo_monh.ctx->nft->output.echo)
return MNL_CB_OK;
- if (ctx->nft->output.json)
+ if (nft_output_json(&ctx->nft->output))
return json_events_cb(nlh, &echo_monh);
return netlink_events_cb(nlh, &echo_monh);
diff --git a/src/rule.c b/src/rule.c
index da1bdc44..86b68cb8 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -2127,7 +2127,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
{
struct table *table = NULL;
- if (ctx->nft->output.json)
+ if (nft_output_json(&ctx->nft->output))
return do_command_list_json(ctx, cmd);
if (cmd->handle.table.name != NULL)