MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_plugin_control

Function json_plugin_control

lightningd/plugin_control.c:205–302  ·  view source on GitHub ↗

* A plugin command which permits to control plugins without restarting * lightningd. It takes a subcommand, and an optional subcommand parameter. */

Source from the content-addressed store, hash-verified

203 * lightningd. It takes a subcommand, and an optional subcommand parameter.
204 */
205static struct command_result *json_plugin_control(struct command *cmd,
206 const char *buffer,
207 const jsmntok_t *obj UNNEEDED,
208 const jsmntok_t *params)
209{
210 struct plugin_command *pcmd;
211 const char *subcmd;
212 subcmd = param_subcommand(cmd, buffer, params,
213 "start", "stop", "startdir",
214 "rescan", "list", NULL);
215 if (!subcmd)
216 return command_param_failed();
217
218 pcmd = tal(cmd, struct plugin_command);
219 pcmd->cmd = cmd;
220 pcmd->subcmd = subcmd;
221
222 if (streq(subcmd, "stop")) {
223 const char *plugin_name;
224
225 if (!param(cmd, buffer, params,
226 p_req("subcommand", param_ignore, cmd),
227 p_req("plugin", param_string, &plugin_name),
228 NULL))
229 return command_param_failed();
230
231 return plugin_dynamic_stop(cmd, plugin_name);
232 } else if (streq(subcmd, "start")) {
233 const char *plugin_path;
234 jsmntok_t *mod_params;
235
236 if (!param(cmd, buffer, params,
237 p_req("subcommand", param_ignore, cmd),
238 p_req("plugin", param_string, &plugin_path),
239 p_opt_any(),
240 NULL))
241 return command_param_failed();
242
243 /* Manually parse any remaining options (only for objects,
244 * since plugin options must be explicitly named!). */
245 if (params->type == JSMN_ARRAY) {
246 if (params->size != 2)
247 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
248 "Extra parameters must be in object");
249 mod_params = NULL;
250 } else {
251 mod_params = json_tok_copy(cmd, params);
252
253 json_tok_remove(&mod_params, mod_params,
254 json_get_member(buffer, mod_params,
255 "subcommand") - 1, 1);
256 json_tok_remove(&mod_params, mod_params,
257 json_get_member(buffer, mod_params,
258 "plugin") - 1, 1);
259 }
260 if (access(plugin_path, X_OK) != 0)
261 plugin_path = path_join(cmd,
262 cmd->ld->plugins->default_dir, plugin_path);

Callers

nothing calls this directly

Calls 14

plugin_dynamic_stopFunction · 0.85
json_tok_copyFunction · 0.85
json_tok_removeFunction · 0.85
path_joinFunction · 0.85
plugin_dynamic_startFunction · 0.85
plugin_dynamic_startdirFunction · 0.85
abortFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
param_subcommandFunction · 0.50

Tested by

no test coverage detected