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

Function parse_request

lightningd/jsonrpc.c:1012–1136  ·  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

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