mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 16:44:20 +01:00
param: add ok flag to struct command
Callers to param() can now optionally set a flag to see if command_fail was called. This is necessary because the `cmd` is freed in case of failure. I spent a bit of time trying to extend the lifetime of the `cmd` to the end of parse_request(), but the destructors still needed to be called when they were, and it was getting ugly. So I took this minimal approach. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
committed by
Christian Decker
parent
30b67c0334
commit
1a4f355a7b
@@ -282,6 +282,8 @@ static void connection_complete_ok(struct json_connection *jcon,
|
|||||||
{
|
{
|
||||||
assert(id != NULL);
|
assert(id != NULL);
|
||||||
assert(result != NULL);
|
assert(result != NULL);
|
||||||
|
if (cmd->ok)
|
||||||
|
*(cmd->ok) = true;
|
||||||
|
|
||||||
/* This JSON is simple enough that we build manually */
|
/* This JSON is simple enough that we build manually */
|
||||||
json_done(jcon, cmd, take(tal_fmt(jcon,
|
json_done(jcon, cmd, take(tal_fmt(jcon,
|
||||||
@@ -310,6 +312,9 @@ static void connection_complete_error(struct json_connection *jcon,
|
|||||||
|
|
||||||
assert(id != NULL);
|
assert(id != NULL);
|
||||||
|
|
||||||
|
if (cmd->ok)
|
||||||
|
*(cmd->ok) = false;
|
||||||
|
|
||||||
json_done(jcon, cmd, take(tal_fmt(tmpctx,
|
json_done(jcon, cmd, take(tal_fmt(tmpctx,
|
||||||
"{ \"jsonrpc\": \"2.0\", "
|
"{ \"jsonrpc\": \"2.0\", "
|
||||||
" \"error\" : "
|
" \"error\" : "
|
||||||
@@ -452,6 +457,7 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
|
|||||||
json_tok_contents(jcon->buffer, id),
|
json_tok_contents(jcon->buffer, id),
|
||||||
json_tok_len(id));
|
json_tok_len(id));
|
||||||
c->mode = CMD_NORMAL;
|
c->mode = CMD_NORMAL;
|
||||||
|
c->ok = NULL;
|
||||||
list_add(&jcon->commands, &c->list);
|
list_add(&jcon->commands, &c->list);
|
||||||
tal_add_destructor(c, destroy_cmd);
|
tal_add_destructor(c, destroy_cmd);
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ struct command {
|
|||||||
enum command_mode mode;
|
enum command_mode mode;
|
||||||
/* This is created if mode is CMD_USAGE */
|
/* This is created if mode is CMD_USAGE */
|
||||||
const char *usage;
|
const char *usage;
|
||||||
|
bool *ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct json_connection {
|
struct json_connection {
|
||||||
|
|||||||
Reference in New Issue
Block a user