| 1427 | #endif /* DEVELOPER */ |
| 1428 | |
| 1429 | static void ld_command_handle(struct plugin *plugin, |
| 1430 | const jsmntok_t *toks) |
| 1431 | { |
| 1432 | const jsmntok_t *methtok, *paramstok; |
| 1433 | struct command *cmd; |
| 1434 | |
| 1435 | methtok = json_get_member(plugin->buffer, toks, "method"); |
| 1436 | paramstok = json_get_member(plugin->buffer, toks, "params"); |
| 1437 | |
| 1438 | if (!methtok || !paramstok) |
| 1439 | plugin_err(plugin, "Malformed JSON-RPC notification missing " |
| 1440 | "\"method\" or \"params\": %.*s", |
| 1441 | json_tok_full_len(toks), |
| 1442 | json_tok_full(plugin->buffer, toks)); |
| 1443 | |
| 1444 | cmd = tal(plugin, struct command); |
| 1445 | cmd->plugin = plugin; |
| 1446 | cmd->usage_only = false; |
| 1447 | cmd->methodname = json_strdup(cmd, plugin->buffer, methtok); |
| 1448 | cmd->id = json_get_id(cmd, plugin->buffer, toks); |
| 1449 | |
| 1450 | if (!plugin->manifested) { |
| 1451 | if (streq(cmd->methodname, "getmanifest")) { |
| 1452 | handle_getmanifest(cmd, plugin->buffer, paramstok); |
| 1453 | plugin->manifested = true; |
| 1454 | return; |
| 1455 | } |
| 1456 | plugin_err(plugin, "Did not receive 'getmanifest' yet, but got '%s'" |
| 1457 | " instead", cmd->methodname); |
| 1458 | } |
| 1459 | |
| 1460 | if (!plugin->initialized) { |
| 1461 | if (streq(cmd->methodname, "init")) { |
| 1462 | handle_init(cmd, plugin->buffer, paramstok); |
| 1463 | plugin->initialized = true; |
| 1464 | return; |
| 1465 | } |
| 1466 | plugin_err(plugin, "Did not receive 'init' yet, but got '%s'" |
| 1467 | " instead", cmd->methodname); |
| 1468 | } |
| 1469 | |
| 1470 | /* If that's a notification. */ |
| 1471 | if (!cmd->id) { |
| 1472 | #if DEVELOPER |
| 1473 | bool is_shutdown = streq(cmd->methodname, "shutdown"); |
| 1474 | if (is_shutdown) |
| 1475 | memleak_check(plugin, cmd); |
| 1476 | #endif |
| 1477 | for (size_t i = 0; i < plugin->num_notif_subs; i++) { |
| 1478 | if (streq(cmd->methodname, |
| 1479 | plugin->notif_subs[i].name)) { |
| 1480 | plugin->notif_subs[i].handle(cmd, |
| 1481 | plugin->buffer, |
| 1482 | paramstok); |
| 1483 | return; |
| 1484 | } |
| 1485 | } |
| 1486 |
no test coverage detected