@@ -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)
@@ -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,
};
@@ -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",
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@redhat.com> --- 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(+)