mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
plugin: Call next plugin that registered hook if result is continue
This commit is contained in:
parent
71e67ba47f
commit
a3ab3d2990
@ -87,6 +87,9 @@ void plugin_hook_unregister_all(struct plugin *plugin)
|
||||
plugin_hook_unregister(plugin, hooks[i]->name);
|
||||
}
|
||||
|
||||
/* Mutual recursion */
|
||||
static void plugin_hook_call_next(struct plugin_hook_request *ph_req);
|
||||
|
||||
/**
|
||||
* Callback to be passed to the jsonrpc_request.
|
||||
*
|
||||
@ -97,15 +100,26 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
|
||||
const jsmntok_t *idtok,
|
||||
struct plugin_hook_request *r)
|
||||
{
|
||||
const jsmntok_t *resulttok = json_get_member(buffer, toks, "result");
|
||||
const jsmntok_t *resulttok, *resrestok;
|
||||
struct db *db = r->db;
|
||||
struct plugin_destroyed *pd;
|
||||
bool more_plugins = r->current_plugin + 1 < tal_count(r->hook->plugins);
|
||||
|
||||
resulttok = json_get_member(buffer, toks, "result");
|
||||
|
||||
if (!resulttok)
|
||||
fatal("Plugin for %s returned non-result response %.*s",
|
||||
r->hook->name,
|
||||
toks->end - toks->start, buffer + toks->start);
|
||||
r->hook->name, toks->end - toks->start,
|
||||
buffer + toks->start);
|
||||
|
||||
resrestok = json_get_member(buffer, resulttok, "result");
|
||||
|
||||
/* If this is a hook response containing a `continue` and we have more
|
||||
* plugins queue the next call. */
|
||||
if (resrestok && json_tok_streq(buffer, resrestok, "continue") &&
|
||||
more_plugins) {
|
||||
plugin_hook_call_next(r);
|
||||
} else {
|
||||
/* If command is "plugin stop", this can free r! */
|
||||
pd = plugin_detect_destruction(r->plugin);
|
||||
db_begin_transaction(db);
|
||||
@ -114,6 +128,7 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
|
||||
if (!was_plugin_destroyed(pd))
|
||||
tal_free(r);
|
||||
}
|
||||
}
|
||||
|
||||
static void plugin_hook_call_next(struct plugin_hook_request *ph_req)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user