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