mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
libplugin: pass configuration to plugin's 'init' callback
So that a plugin can, for example, know if it has been loaded on startup
This commit is contained in:
parent
017ee7c916
commit
0cd3823c98
@ -65,7 +65,8 @@ static struct command_result *json_autocleaninvoice(struct command *cmd,
|
||||
expired_by, cycle_seconds));
|
||||
}
|
||||
|
||||
static void init(struct plugin_conn *prpc)
|
||||
static void init(struct plugin_conn *prpc,
|
||||
const char *buf UNUSED, const jsmntok_t *config UNUSED)
|
||||
{
|
||||
rpc = prpc;
|
||||
|
||||
|
@ -513,21 +513,24 @@ static struct command_result *handle_init(struct command *init_cmd,
|
||||
const char *buf,
|
||||
const jsmntok_t *params,
|
||||
const struct plugin_option *opts,
|
||||
void (*init)(struct plugin_conn *))
|
||||
void (*init)(struct plugin_conn *,
|
||||
const char *buf, const jsmntok_t *))
|
||||
{
|
||||
const jsmntok_t *rpctok, *dirtok, *opttok, *t;
|
||||
const jsmntok_t *configtok, *rpctok, *dirtok, *opttok, *t;
|
||||
struct sockaddr_un addr;
|
||||
size_t i;
|
||||
char *dir;
|
||||
struct json_out *param_obj;
|
||||
|
||||
configtok = json_delve(buf, params, ".configuration");
|
||||
|
||||
/* Move into lightning directory: other files are relative */
|
||||
dirtok = json_delve(buf, params, ".configuration.lightning-dir");
|
||||
dirtok = json_delve(buf, configtok, ".lightning-dir");
|
||||
dir = json_strdup(tmpctx, buf, dirtok);
|
||||
if (chdir(dir) != 0)
|
||||
plugin_err("chdir to %s: %s", dir, strerror(errno));
|
||||
|
||||
rpctok = json_delve(buf, params, ".configuration.rpc-file");
|
||||
rpctok = json_delve(buf, configtok, ".rpc-file");
|
||||
rpc_conn.fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (rpctok->end - rpctok->start + 1 > sizeof(addr.sun_path))
|
||||
plugin_err("rpc filename '%.*s' too long",
|
||||
@ -547,7 +550,7 @@ static struct command_result *handle_init(struct command *init_cmd,
|
||||
take(param_obj),
|
||||
&rpc_conn,
|
||||
".allow-deprecated-apis"),
|
||||
"true");
|
||||
"true");
|
||||
opttok = json_get_member(buf, params, "options");
|
||||
json_for_each_obj(i, t, opttok) {
|
||||
char *opt = json_strdup(NULL, buf, t);
|
||||
@ -566,7 +569,7 @@ static struct command_result *handle_init(struct command *init_cmd,
|
||||
}
|
||||
|
||||
if (init)
|
||||
init(&rpc_conn);
|
||||
init(&rpc_conn, buf, configtok);
|
||||
|
||||
return command_success_str(init_cmd, NULL);
|
||||
}
|
||||
@ -700,7 +703,8 @@ void plugin_log(enum log_level l, const char *fmt, ...)
|
||||
}
|
||||
|
||||
void plugin_main(char *argv[],
|
||||
void (*init)(struct plugin_conn *rpc),
|
||||
void (*init)(struct plugin_conn *rpc,
|
||||
const char *buf, const jsmntok_t *),
|
||||
const enum plugin_restartability restartability,
|
||||
const struct plugin_command *commands,
|
||||
size_t num_commands, ...)
|
||||
|
@ -152,7 +152,8 @@ char *charp_option(const char *arg, char **p);
|
||||
|
||||
/* The main plugin runner: append with 0 or more plugin_option(), then NULL. */
|
||||
void NORETURN LAST_ARG_NULL plugin_main(char *argv[],
|
||||
void (*init)(struct plugin_conn *rpc),
|
||||
void (*init)(struct plugin_conn *rpc,
|
||||
const char *buf, const jsmntok_t *),
|
||||
const enum plugin_restartability restartability,
|
||||
const struct plugin_command *commands,
|
||||
size_t num_commands, ...);
|
||||
|
@ -1271,7 +1271,8 @@ static struct command_result *json_listpays(struct command *cmd,
|
||||
take(json_out_obj(NULL, "bolt11", b11str)));
|
||||
}
|
||||
|
||||
static void init(struct plugin_conn *rpc)
|
||||
static void init(struct plugin_conn *rpc,
|
||||
const char *buf UNUSED, const jsmntok_t *config UNUSED)
|
||||
{
|
||||
const char *field;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user