| 2064 | } |
| 2065 | |
| 2066 | static void ld_command_handle(struct plugin *plugin, |
| 2067 | const char *buffer, |
| 2068 | const jsmntok_t *toks) |
| 2069 | { |
| 2070 | const jsmntok_t *methtok, *paramstok, *filtertok; |
| 2071 | const char *methodname; |
| 2072 | struct command *cmd; |
| 2073 | const char *id; |
| 2074 | enum command_type type; |
| 2075 | |
| 2076 | methtok = json_get_member(buffer, toks, "method"); |
| 2077 | paramstok = json_get_member(buffer, toks, "params"); |
| 2078 | filtertok = json_get_member(buffer, toks, "filter"); |
| 2079 | |
| 2080 | if (!methtok || !paramstok) |
| 2081 | plugin_err(plugin, "Malformed JSON-RPC notification missing " |
| 2082 | "\"method\" or \"params\": %.*s", |
| 2083 | json_tok_full_len(toks), |
| 2084 | json_tok_full(buffer, toks)); |
| 2085 | |
| 2086 | methodname = json_strdup(NULL, buffer, methtok); |
| 2087 | id = json_get_id(tmpctx, buffer, toks); |
| 2088 | |
| 2089 | if (!id) |
| 2090 | type = COMMAND_TYPE_NOTIFICATION; |
| 2091 | else if (streq(methodname, "check")) |
| 2092 | type = COMMAND_TYPE_CHECK; |
| 2093 | else |
| 2094 | type = COMMAND_TYPE_NORMAL; |
| 2095 | |
| 2096 | cmd = new_command(plugin, plugin, |
| 2097 | id ? id : tal_fmt(tmpctx, "notification-%s", methodname), |
| 2098 | take(methodname), |
| 2099 | type); |
| 2100 | |
| 2101 | if (!plugin->manifested) { |
| 2102 | if (streq(cmd->methodname, "getmanifest")) { |
| 2103 | handle_getmanifest(cmd, buffer, paramstok); |
| 2104 | plugin->manifested = true; |
| 2105 | return; |
| 2106 | } |
| 2107 | plugin_err(plugin, "Did not receive 'getmanifest' yet, but got '%s'" |
| 2108 | " instead", cmd->methodname); |
| 2109 | } |
| 2110 | |
| 2111 | if (!plugin->initialized) { |
| 2112 | if (streq(cmd->methodname, "init")) { |
| 2113 | handle_init(cmd, buffer, paramstok); |
| 2114 | plugin->initialized = true; |
| 2115 | return; |
| 2116 | } |
| 2117 | plugin_err(plugin, "Did not receive 'init' yet, but got '%s'" |
| 2118 | " instead", cmd->methodname); |
| 2119 | } |
| 2120 | |
| 2121 | /* If that's a notification. */ |
| 2122 | if (cmd->type == COMMAND_TYPE_NOTIFICATION) { |
| 2123 | bool is_shutdown = streq(cmd->methodname, "shutdown"); |
no test coverage detected