The ultimate goal is that all "struct expr_ops" have a "json()" hook set. It's also faster, to just create the JSON node, instead of creating a memory stream, write there using print only to get the sting. Signed-off-by: Thomas Haller <thaller@xxxxxxxxxx> --- The patches 1/2 and 2/2 replaces Subject: [PATCH nft 2/7] json: drop messages "warning: stmt ops chain have no json callback" Date: Tue, 31 Oct 2023 19:53:28 +0100 include/json.h | 4 ++++ src/expression.c | 2 ++ src/json.c | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/include/json.h b/include/json.h index 39be8928e8ee..134e503afe54 100644 --- a/include/json.h +++ b/include/json.h @@ -49,7 +49,9 @@ json_t *rt_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *numgen_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *hash_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *fib_expr_json(const struct expr *expr, struct output_ctx *octx); +json_t *symbol_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *constant_expr_json(const struct expr *expr, struct output_ctx *octx); +json_t *variable_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *socket_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *osf_expr_json(const struct expr *expr, struct output_ctx *octx); json_t *xfrm_expr_json(const struct expr *expr, struct output_ctx *octx); @@ -156,7 +158,9 @@ EXPR_PRINT_STUB(set_elem_catchall_expr) EXPR_PRINT_STUB(numgen_expr) EXPR_PRINT_STUB(hash_expr) EXPR_PRINT_STUB(fib_expr) +EXPR_PRINT_STUB(symbol_expr) EXPR_PRINT_STUB(constant_expr) +EXPR_PRINT_STUB(variable_expr) EXPR_PRINT_STUB(socket_expr) EXPR_PRINT_STUB(osf_expr) EXPR_PRINT_STUB(xfrm_expr) diff --git a/src/expression.c b/src/expression.c index a21dfec25722..d6a2e69db572 100644 --- a/src/expression.c +++ b/src/expression.c @@ -321,6 +321,7 @@ static const struct expr_ops symbol_expr_ops = { .type = EXPR_SYMBOL, .name = "symbol", .print = symbol_expr_print, + .json = symbol_expr_json, .clone = symbol_expr_clone, .destroy = symbol_expr_destroy, }; @@ -362,6 +363,7 @@ static const struct expr_ops variable_expr_ops = { .type = EXPR_VARIABLE, .name = "variable", .print = variable_expr_print, + .json = variable_expr_json, .clone = variable_expr_clone, .destroy = variable_expr_destroy, }; diff --git a/src/json.c b/src/json.c index 068c423addc7..0fd78b763af7 100644 --- a/src/json.c +++ b/src/json.c @@ -982,11 +982,21 @@ static json_t *datatype_json(const struct expr *expr, struct output_ctx *octx) expr->dtype->name); } +json_t *symbol_expr_json(const struct expr *expr, struct output_ctx *octx) +{ + return json_string(expr->identifier); +} + json_t *constant_expr_json(const struct expr *expr, struct output_ctx *octx) { return datatype_json(expr, octx); } +json_t *variable_expr_json(const struct expr *expr, struct output_ctx *octx) +{ + return json_string(expr->sym->identifier); +} + json_t *socket_expr_json(const struct expr *expr, struct output_ctx *octx) { return json_pack("{s:{s:s}}", "socket", "key", -- 2.41.0