-
-
Save cdecker/104eafb646accf6773a0926a2954cba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1: 4e34c0cf = 1: 2899bbcf plugin: Fix memory leak when requests are done | |
2: 1bc1bba3 = 2: ec592e05 plugin: Allow both array as well as object params in example plugin | |
3: 684a2a6b = 3: cc04d7ea plugin: The example plugin can now return errors | |
4: 31be8748 ! 4: 7bcf3e2e jsonrpc: Make an explicit jsonrpc struct | |
@@ -130,8 +130,7 @@ | |
+ streq(rpc->commands[i]->name, command->name)) | |
+ return false; | |
+ | |
-+ tal_resize(&rpc->commands, count + 1); | |
-+ rpc->commands[count] = command; | |
++ *tal_arr_expand(&rpc->commands) = command; | |
+ return true; | |
+} | |
+ | |
5: ece7fedc = 5: 6c0a4db8 jsonrpc: Split the jsonrpc object creation from starting to listen | |
6: 79a72cd8 = 6: bfdab943 plugin: Add pointer to jsonrpc so we can add new methods | |
7: aeb7768b ! 7: 93dcf895 plugin: Add plugin rpcmethods to the JSON-RPC interface | |
@@ -14,7 +14,7 @@ | |
+#include <common/memleak.h> | |
#include <errno.h> | |
#include <lightningd/json.h> | |
- #include <unistd.h> | |
+ #include <signal.h> | |
@@ | |
return true; | |
} | |
@@ -84,7 +84,13 @@ | |
+ cmd->deprecated = false; | |
+ cmd->dispatch = plugin_rpcmethod_dispatch; | |
+ tal_add_destructor(cmd, plugin_rpcmethod_destroy); | |
-+ jsonrpc_command_add(plugin->plugins->rpc, cmd); | |
++ if (!jsonrpc_command_add(plugin->plugins->rpc, cmd)) { | |
++ log_broken(plugin->log, | |
++ "Could not register method \"%s\", a method with " | |
++ "that name is already registered", | |
++ cmd->name); | |
++ return false; | |
++ } | |
+ return true; | |
+} | |
+ | |
@@ -92,7 +98,7 @@ | |
+{ | |
+ const char *buffer = req->plugin->buffer; | |
+ const jsmntok_t *cur, *methods; | |
-+ bool ok = true; | |
++ | |
+ /* This is the parent for all elements in the "options" array */ | |
+ int methpos; | |
+ | |
@@ -109,9 +115,9 @@ | |
+ } | |
+ | |
+ for (cur = methods + 1; cur->parent == methpos; cur = json_next(cur)) | |
-+ ok &= plugin_rpcmethod_add(req->plugin, buffer, cur); | |
-+ | |
-+ return ok; | |
++ if (!plugin_rpcmethod_add(req->plugin, buffer, cur)) | |
++ return false; | |
++ return true; | |
+} | |
+ | |
/** | |
@@ -123,8 +129,8 @@ | |
- if (!plugin_opts_add(req)) | |
- return; | |
-+ plugin_opts_add(req); | |
-+ plugin_rpcmethods_add(req); | |
++ if (!plugin_opts_add(req) || !plugin_rpcmethods_add(req)) | |
++ plugin_kill(plugin, "Failed to register options or methods"); | |
} | |
void plugins_init(struct plugins *plugins) | |
8: ce7adfbe ! 8: 6df8046d plugin: Remove added JSON-RPC methods if a plugin gets killed | |
@@ -94,6 +94,7 @@ | |
plugin->stop = true; | |
io_wake(plugin); | |
kill(plugin->pid, SIGKILL); | |
++ list_del(&plugin->list); | |
+ tal_free(plugin); | |
} | |
@@ -116,6 +117,6 @@ | |
cmd->dispatch = plugin_rpcmethod_dispatch; | |
- tal_add_destructor(cmd, plugin_rpcmethod_destroy); | |
+ tal_add_destructor2(cmd, plugin_rpcmethod_destroy, plugin->plugins->rpc); | |
- jsonrpc_command_add(plugin->plugins->rpc, cmd); | |
- return true; | |
- } | |
+ if (!jsonrpc_command_add(plugin->plugins->rpc, cmd)) { | |
+ log_broken(plugin->log, | |
+ "Could not register method \"%s\", a method with " | |
9: defdd371 ! 9: a33bb774 plugin: Plugins need a list of methods they registered | |
@@ -28,9 +28,9 @@ | |
} | |
@@ | |
- cmd->dispatch = plugin_rpcmethod_dispatch; | |
- tal_add_destructor2(cmd, plugin_rpcmethod_destroy, plugin->plugins->rpc); | |
- jsonrpc_command_add(plugin->plugins->rpc, cmd); | |
+ cmd->name); | |
+ return false; | |
+ } | |
+ *tal_arr_expand(&plugin->methods) = cmd->name; | |
return true; | |
} | |
10: 9c10909c = 10: 50d64e15 plugin: Make memleak happy | |
11: 225764b5 ! 11: 6f43b6ee plugin: Dispatch incoming RPC calls to appropriate plugin | |
@@ -12,9 +12,9 @@ | |
#include <errno.h> | |
#include <lightningd/json.h> | |
+#include <lightningd/lightningd.h> | |
+ #include <signal.h> | |
#include <unistd.h> | |
- struct plugin { | |
@@ | |
const char *json; | |
}; | |
@@ -92,11 +92,12 @@ | |
+ for (size_t i=0; i<tal_count(plugin->methods); i++) { | |
+ if (streq(request->method, plugin->methods[i])) { | |
+ request->plugin = plugin; | |
-+ break; | |
++ goto found; | |
+ } | |
+ } | |
+ } | |
+ | |
++found: | |
+ /* This should never happen, it'd mean that a plugin didn't | |
+ * cleanup after dying */ | |
+ assert(request->plugin); | |
12: 06dee468 ! 12: d21025bf plugin: Map results back to the incoming JSON-RPC request | |
@@ -30,8 +30,8 @@ | |
#include <lightningd/json.h> | |
+#include <lightningd/jsonrpc_errors.h> | |
#include <lightningd/lightningd.h> | |
+ #include <signal.h> | |
#include <unistd.h> | |
- | |
@@ | |
static void plugin_rpcmethod_cb(const struct plugin_request *req, | |
struct plugin_rpc_request *rpc_req) | |
@@ -55,15 +55,8 @@ | |
+ res = req->resulttok; | |
+ response = json_stream_success(rpc_req->cmd); | |
+ | |
-+ /* If this is a raw string result we'd be cropping the quotes from the | |
-+ * result, so add them back */ | |
-+ if (req->resulttok->type == JSMN_STRING) | |
-+ json_add_member(response, NULL, "\"%.*s\"", | |
-+ res->end - res->start, | |
-+ req->response + res->start); | |
-+ else | |
-+ json_add_member(response, NULL, "%.*s", res->end - res->start, | |
-+ req->response + res->start); | |
++ json_add_member(response, NULL, "%.*s", json_tok_len(res), | |
++ json_tok_contents(req->response, res)); | |
+ | |
+ command_success(rpc_req->cmd, response); | |
+ tal_free(rpc_req); | |
13: 1fb5b835 = 13: f2b29195 pytest: Add a test for the JSON-RPC passthrough | |
14: bcc041ab = 14: 7c3c63a9 plugin: Update documentation of the rpcmethods | |
15: bd46a443 < -: -------- fixup! jsonrpc: Make an explicit jsonrpc struct | |
16: 8c7e45d7 = 15: eafe32eb plugin: Make plugin_kill a printf-like function | |
17: cb7d0488 < -: -------- fixup! plugin: Add plugin rpcmethods to the JSON-RPC interface | |
18: 24e022f6 < -: -------- fixup! plugin: Dispatch incoming RPC calls to appropriate plugin | |
19: 9328c8d2 < -: -------- fixup! plugin: Map results back to the incoming JSON-RPC request | |
20: 78bf6022 = 16: 01e555a9 plugin: Iterate over the options from a plugin using the tok->size | |
21: 61fca542 < -: -------- fixup! plugin: Remove added JSON-RPC methods if a plugin gets killed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment