From 0e441647906c29fd2169844e6fdfc8b3c6b386e9 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Thu, 21 May 2026 12:59:35 +0200 Subject: [PATCH] MT#61856 control_ng: appeal to parser via local ptr If already having the local ptr, then why not to use it, instead of using directly the globally visible object. In the `control_ng_process_payload()` add a pointer to the `ng_parser_json` parser. Change-Id: I9d656733991e2d99c18aa1cc6d705ed053f57f0a --- daemon/control_ng.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/daemon/control_ng.c b/daemon/control_ng.c index cd5ebdabe..cf00cf03d 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -696,7 +696,7 @@ static void prepare_resp_ctx(ng_command_ctx_t *command_ctx, const ng_parser_t *p { /* init as dict by default, if requested */ if (native) - ng_parser_native.init(&command_ctx->parser_ctx, &command_ctx->ngbuf->buffer); + parser->init(&command_ctx->parser_ctx, &command_ctx->ngbuf->buffer); command_ctx->resp = parser->dict(&command_ctx->parser_ctx); assert(command_ctx->resp.gen != NULL); } @@ -712,6 +712,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons ng_command_ctx_t command_ctx = {.opmode = -1}; const ng_parser_t *parser = &ng_parser_native; + const ng_parser_t *json_parser = &ng_parser_json; command_ctx.ngbuf = *ngbufp = ng_buffer_new(ref); @@ -723,7 +724,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons /* Bencode dictionary */ if (data->s[0] == 'd') { - ng_parser_native.init(&command_ctx.parser_ctx, &command_ctx.ngbuf->buffer); + parser->init(&command_ctx.parser_ctx, &command_ctx.ngbuf->buffer); command_ctx.req.benc = bencode_decode_expect_str(&command_ctx.ngbuf->buffer, data, BENCODE_DICTIONARY); errstr = "Could not decode bencode dictionary"; @@ -735,7 +736,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons /* JSON */ else if (data->s[0] == '{') { - ng_parser_json.init(&command_ctx.parser_ctx, &command_ctx.ngbuf->buffer); + json_parser->init(&command_ctx.parser_ctx, &command_ctx.ngbuf->buffer); command_ctx.ngbuf->json = json_parser_new(); errstr = "Failed to parse JSON document"; if (!json_parser_load_from_data(command_ctx.ngbuf->json, data->s, data->len, NULL)) { @@ -744,7 +745,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons } command_ctx.req.json = json_parser_get_root(command_ctx.ngbuf->json); errstr = "Could not decode JSON dictionary"; - if (!command_ctx.req.json || !ng_parser_json.is_dict(command_ctx.req)) { + if (!command_ctx.req.json || !json_parser->is_dict(command_ctx.req)) { prepare_resp_ctx(&command_ctx, parser, false); goto err_send; }