summaryrefslogtreecommitdiffstats
path: root/src/json.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2020-12-16 16:39:09 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2020-12-18 12:33:22 +0100
commite6d1d0d6119585a5cd63fcc02c0eb98e30b095cb (patch)
tree3b8c7c29b6b80a54dbfd4d485b73ce00d0f417f5 /src/json.c
parent242965f452e64fef9faff6689df4b2c205823209 (diff)
src: add set element multi-statement support
Extend the set element infrastructure to support for several statements. This patch places the statements right after the key when printing it. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/json.c b/src/json.c
index 0b398bf0..585d3532 100644
--- a/src/json.c
+++ b/src/json.c
@@ -583,13 +583,15 @@ json_t *set_ref_expr_json(const struct expr *expr, struct output_ctx *octx)
json_t *set_elem_expr_json(const struct expr *expr, struct output_ctx *octx)
{
json_t *root = expr_print_json(expr->key, octx);
+ struct stmt *stmt;
json_t *tmp;
if (!root)
return NULL;
/* these element attributes require formal set elem syntax */
- if (expr->timeout || expr->expiration || expr->comment || expr->stmt) {
+ if (expr->timeout || expr->expiration || expr->comment ||
+ !list_empty(&expr->stmt_list)) {
root = json_pack("{s:o}", "val", root);
if (expr->timeout) {
@@ -604,11 +606,13 @@ json_t *set_elem_expr_json(const struct expr *expr, struct output_ctx *octx)
tmp = json_string(expr->comment);
json_object_set_new(root, "comment", tmp);
}
- if (expr->stmt) {
- tmp = stmt_print_json(expr->stmt, octx);
+ list_for_each_entry(stmt, &expr->stmt_list, list) {
+ tmp = stmt_print_json(stmt, octx);
/* XXX: detect and complain about clashes? */
json_object_update_missing(root, tmp);
json_decref(tmp);
+ /* TODO: only one statement per element. */
+ break;
}
return json_pack("{s:o}", "elem", root);
}