mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
lightningd: add jsonrpc_request_start_raw instead of NULL method.
Since we want to use methodname to create id, don't overload it for a raw request. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ce0b765c96
commit
99f2019a24
4 changed files with 28 additions and 14 deletions
|
@ -1312,6 +1312,7 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n)
|
||||||
|
|
||||||
struct jsonrpc_request *jsonrpc_request_start_(
|
struct jsonrpc_request *jsonrpc_request_start_(
|
||||||
const tal_t *ctx, const char *method, struct log *log,
|
const tal_t *ctx, const char *method, struct log *log,
|
||||||
|
bool add_header,
|
||||||
void (*notify_cb)(const char *buffer,
|
void (*notify_cb)(const char *buffer,
|
||||||
const jsmntok_t *methodtok,
|
const jsmntok_t *methodtok,
|
||||||
const jsmntok_t *paramtoks,
|
const jsmntok_t *paramtoks,
|
||||||
|
@ -1327,22 +1328,21 @@ struct jsonrpc_request *jsonrpc_request_start_(
|
||||||
r->notify_cb = notify_cb;
|
r->notify_cb = notify_cb;
|
||||||
r->response_cb = response_cb;
|
r->response_cb = response_cb;
|
||||||
r->response_cb_arg = response_cb_arg;
|
r->response_cb_arg = response_cb_arg;
|
||||||
r->method = NULL;
|
r->method = tal_strdup(r, method);
|
||||||
r->stream = new_json_stream(r, NULL, log);
|
r->stream = new_json_stream(r, NULL, log);
|
||||||
|
|
||||||
/* If no method is specified we don't prefill the JSON-RPC
|
/* Disabling this serves as an escape hatch for plugin code to
|
||||||
* request with the header. This serves as an escape hatch to
|
* get a raw request to paste into, but get a valid request-id
|
||||||
* get a raw request, but get a valid request-id assigned. */
|
* assigned. */
|
||||||
if (method != NULL) {
|
if (add_header) {
|
||||||
r->method = tal_strdup(r, method);
|
|
||||||
json_object_start(r->stream, NULL);
|
json_object_start(r->stream, NULL);
|
||||||
json_add_string(r->stream, "jsonrpc", "2.0");
|
json_add_string(r->stream, "jsonrpc", "2.0");
|
||||||
json_add_u64(r->stream, "id", r->id);
|
json_add_u64(r->stream, "id", r->id);
|
||||||
json_add_string(r->stream, "method", method);
|
json_add_string(r->stream, "method", method);
|
||||||
json_object_start(r->stream, "params");
|
json_object_start(r->stream, "params");
|
||||||
if (log)
|
|
||||||
log_debug(log, "OUT:id=%"PRIu64, r->id);
|
|
||||||
}
|
}
|
||||||
|
if (log)
|
||||||
|
log_debug(log, "OUT:id=%"PRIu64, r->id);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n);
|
||||||
|
|
||||||
#define jsonrpc_request_start(ctx, method, log, notify_cb, response_cb, response_cb_arg) \
|
#define jsonrpc_request_start(ctx, method, log, notify_cb, response_cb, response_cb_arg) \
|
||||||
jsonrpc_request_start_( \
|
jsonrpc_request_start_( \
|
||||||
(ctx), (method), (log), \
|
(ctx), (method), (log), true, \
|
||||||
typesafe_cb_preargs(void, void *, (notify_cb), (response_cb_arg), \
|
typesafe_cb_preargs(void, void *, (notify_cb), (response_cb_arg), \
|
||||||
const char *buffer, \
|
const char *buffer, \
|
||||||
const jsmntok_t *idtok, \
|
const jsmntok_t *idtok, \
|
||||||
|
@ -229,8 +229,22 @@ void jsonrpc_notification_end(struct jsonrpc_notification *n);
|
||||||
const jsmntok_t *idtok), \
|
const jsmntok_t *idtok), \
|
||||||
(response_cb_arg))
|
(response_cb_arg))
|
||||||
|
|
||||||
|
#define jsonrpc_request_start_raw(ctx, method, log, notify_cb, response_cb, response_cb_arg) \
|
||||||
|
jsonrpc_request_start_( \
|
||||||
|
(ctx), (method), (log), false, \
|
||||||
|
typesafe_cb_preargs(void, void *, (notify_cb), (response_cb_arg), \
|
||||||
|
const char *buffer, \
|
||||||
|
const jsmntok_t *idtok, \
|
||||||
|
const jsmntok_t *methodtok, \
|
||||||
|
const jsmntok_t *paramtoks), \
|
||||||
|
typesafe_cb_preargs(void, void *, (response_cb), (response_cb_arg), \
|
||||||
|
const char *buffer, \
|
||||||
|
const jsmntok_t *toks, \
|
||||||
|
const jsmntok_t *idtok), \
|
||||||
|
(response_cb_arg))
|
||||||
|
|
||||||
struct jsonrpc_request *jsonrpc_request_start_(
|
struct jsonrpc_request *jsonrpc_request_start_(
|
||||||
const tal_t *ctx, const char *method, struct log *log,
|
const tal_t *ctx, const char *method, struct log *log, bool add_header,
|
||||||
void (*notify_cb)(const char *buffer,
|
void (*notify_cb)(const char *buffer,
|
||||||
const jsmntok_t *idtok,
|
const jsmntok_t *idtok,
|
||||||
const jsmntok_t *methodtok,
|
const jsmntok_t *methodtok,
|
||||||
|
|
|
@ -1129,9 +1129,9 @@ static struct command_result *plugin_rpcmethod_dispatch(struct command *cmd,
|
||||||
call = tal(plugin, struct plugin_rpccall);
|
call = tal(plugin, struct plugin_rpccall);
|
||||||
call->cmd = cmd;
|
call->cmd = cmd;
|
||||||
|
|
||||||
req = jsonrpc_request_start(plugin, NULL, plugin->log,
|
req = jsonrpc_request_start_raw(plugin, cmd->json_cmd->name, plugin->log,
|
||||||
plugin_notify_cb,
|
plugin_notify_cb,
|
||||||
plugin_rpcmethod_cb, call);
|
plugin_rpcmethod_cb, call);
|
||||||
call->request = req;
|
call->request = req;
|
||||||
call->plugin = plugin;
|
call->plugin = plugin;
|
||||||
list_add_tail(&plugin->pending_rpccalls, &call->list);
|
list_add_tail(&plugin->pending_rpccalls, &call->list);
|
||||||
|
|
|
@ -491,7 +491,7 @@ void jsonrpc_request_end(struct jsonrpc_request *request UNNEEDED)
|
||||||
{ fprintf(stderr, "jsonrpc_request_end called!\n"); abort(); }
|
{ fprintf(stderr, "jsonrpc_request_end called!\n"); abort(); }
|
||||||
/* Generated stub for jsonrpc_request_start_ */
|
/* Generated stub for jsonrpc_request_start_ */
|
||||||
struct jsonrpc_request *jsonrpc_request_start_(
|
struct jsonrpc_request *jsonrpc_request_start_(
|
||||||
const tal_t *ctx UNNEEDED, const char *method UNNEEDED, struct log *log UNNEEDED,
|
const tal_t *ctx UNNEEDED, const char *method UNNEEDED, struct log *log UNNEEDED, bool add_header UNNEEDED,
|
||||||
void (*notify_cb)(const char *buffer UNNEEDED,
|
void (*notify_cb)(const char *buffer UNNEEDED,
|
||||||
const jsmntok_t *idtok UNNEEDED,
|
const jsmntok_t *idtok UNNEEDED,
|
||||||
const jsmntok_t *methodtok UNNEEDED,
|
const jsmntok_t *methodtok UNNEEDED,
|
||||||
|
|
Loading…
Add table
Reference in a new issue