From 9bcac634141749788d7c2842e9d2c473effb71c2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 16 Feb 2026 17:24:33 +1030 Subject: [PATCH] libplugin: add command_finish_rawstr() for when we're simply repeating an entore response. Signed-off-by: Rusty Russell --- plugins/libplugin.c | 28 ++++++++++++++++++++++++---- plugins/libplugin.h | 7 +++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 7f4db9f42..ed888bdbe 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -473,11 +473,9 @@ struct json_stream *jsonrpc_stream_fail_data(struct command *cmd, return js; } -static struct command_result *command_complete(struct command *cmd, - struct json_stream *result) +static struct command_result *command_complete_nojson(struct command *cmd, + struct json_stream *result) { - /* Global object */ - json_object_end(result); json_stream_close(result, cmd); ld_send(cmd->plugin, result); tal_free(cmd); @@ -485,6 +483,14 @@ static struct command_result *command_complete(struct command *cmd, return &complete; } +static struct command_result *command_complete(struct command *cmd, + struct json_stream *result) +{ + /* Global object */ + json_object_end(result); + return command_complete_nojson(cmd, result); +} + struct command_result *command_finished(struct command *cmd, struct json_stream *response) { @@ -506,6 +512,20 @@ struct command_result *command_finished(struct command *cmd, return command_complete(cmd, response); } +struct command_result *command_finish_rawstr(struct command *cmd, + const char *json, + size_t json_len) +{ + struct json_stream *js = new_json_stream(cmd, cmd, NULL); + char *raw; + + assert(cmd->type == COMMAND_TYPE_NORMAL + || cmd->type == COMMAND_TYPE_HOOK); + raw = json_out_direct(js->jout, json_len); + memcpy(raw, json, json_len); + return command_complete_nojson(cmd, js); +} + struct command_result *WARN_UNUSED_RESULT command_still_pending(struct command *cmd) { diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 6b3ad7bfd..28772184e 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -363,6 +363,13 @@ WARN_UNUSED_RESULT struct command_result *command_still_pending(struct command *cmd) NON_NULL_ARGS(1); +/* Forward this raw JSON string as the command response */ +WARN_UNUSED_RESULT +struct command_result *command_finish_rawstr(struct command *cmd, + const char *json, + size_t json_len) + NO_NULL_ARGS; + /* Helper to create a zero or single-value JSON object; if @str is NULL, * object is empty. */ struct json_out *json_out_obj(const tal_t *ctx,