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

Function parse_request

lightningd/jsonrpc.c:1008–1132  ·  view source on GitHub ↗

We return struct command_result so command_fail return value has a natural * sink; we don't actually use the result. */

Source from the content-addressed store, hash-verified

1006/* We return struct command_result so command_fail return value has a natural
1007 * sink; we don't actually use the result. */
1008static struct command_result *
1009parse_request(struct json_connection *jcon,
1010 const char *buffer,
1011 const jsmntok_t tok[],
1012 const char **methodname)
1013{
1014 const jsmntok_t *method, *id, *params, *filter, *jsonrpc;
1015 struct command *c;
1016 struct rpc_command_hook_payload *rpc_hook;
1017 bool completed;
1018
1019 if (tok[0].type != JSMN_OBJECT) {
1020 json_command_malformed(jcon, "null",
1021 "Expected {} for json command");
1022 return NULL;
1023 }
1024
1025 method = json_get_member(buffer, tok, "method");
1026 params = json_get_member(buffer, tok, "params");
1027 filter = json_get_member(buffer, tok, "filter");
1028 id = json_get_member(buffer, tok, "id");
1029
1030 if (!id) {
1031 json_command_malformed(jcon, "null", "No id");
1032 return NULL;
1033 }
1034
1035 if (id->type != JSMN_STRING && id->type != JSMN_PRIMITIVE) {
1036 json_command_malformed(jcon, "null",
1037 "Expected string/primitive for id");
1038 return NULL;
1039 }
1040
1041 jsonrpc = json_get_member(buffer, tok, "jsonrpc");
1042 if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) {
1043 json_command_malformed(jcon, "null", "jsonrpc: \"2.0\" must be specified in the request");
1044 return NULL;
1045 }
1046
1047 /* Allocate the command off of the `jsonrpc` object and not
1048 * the connection since the command may outlive `conn`. */
1049 c = tal(jcon->ld->jsonrpc, struct command);
1050 c->jcon = jcon;
1051 c->send_notifications = jcon->notifications_enabled;
1052 c->ld = jcon->ld;
1053 c->pending = false;
1054 c->json_stream = NULL;
1055 c->id_is_string = (id->type == JSMN_STRING);
1056 /* Include "" around string */
1057 c->id = tal_strndup(c,
1058 json_tok_full(buffer, id),
1059 json_tok_full_len(id));
1060 c->mode = CMD_NORMAL;
1061 c->filter = NULL;
1062 list_add_tail(&jcon->commands, &c->list);
1063 tal_add_destructor(c, destroy_command);
1064
1065 if (!method || !params) {

Callers 1

read_jsonFunction · 0.85

Calls 14

json_command_malformedFunction · 0.85
json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
find_cmdFunction · 0.85
parse_filterFunction · 0.85
json_dup_contentsFunction · 0.85
trace_span_tagFunction · 0.85
trace_span_endFunction · 0.85
command_failFunction · 0.70
log_ioFunction · 0.70
command_deprecated_in_okFunction · 0.70
command_still_pendingFunction · 0.70

Tested by

no test coverage detected