mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
common: move now-enlarged command_fail_badparam into its own source file.
It's getting a bit awkward to inline now: it's non-trivial. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
f33c5188ef
commit
9fd29d35dd
16 changed files with 118 additions and 102 deletions
|
@ -56,6 +56,7 @@ COMMON_SRC_NOGEN := \
|
|||
common/iso4217.c \
|
||||
common/json_blinded_path.c \
|
||||
common/json_channel_type.c \
|
||||
common/json_command.c \
|
||||
common/json_filter.c \
|
||||
common/json_param.c \
|
||||
common/json_parse.c \
|
||||
|
@ -115,7 +116,6 @@ COMMON_HEADERS_NOGEN := $(COMMON_SRC_NOGEN:.c=.h) \
|
|||
common/gossip_constants.h \
|
||||
common/hsm_version.h \
|
||||
common/htlc.h \
|
||||
common/json_command.h \
|
||||
common/jsonrpc_errors.h \
|
||||
common/overflows.h
|
||||
|
||||
|
|
33
common/json_command.c
Normal file
33
common/json_command.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "config.h"
|
||||
#include <common/json_command.h>
|
||||
|
||||
struct command_result *
|
||||
command_fail_badparam(struct command *cmd,
|
||||
const char *paramname,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
const char *msg)
|
||||
{
|
||||
if (command_dev_apis(cmd)) {
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%s: %s: invalid token '%.*s'",
|
||||
paramname, msg,
|
||||
json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
||||
/* Someone misconfigured LNBITS with "" around the rune, and so the
|
||||
* user got a message about a bad rune parameter which *contained the
|
||||
* rune itself*!. LNBITS should probably swallow any JSONRPC2_* error
|
||||
* itself, but it is quite possibly not the only case where this case
|
||||
* where this can happen. So we are a little circumspect in this
|
||||
* case. */
|
||||
command_log(cmd, LOG_INFORM,
|
||||
"Invalid parameter %s (%s): token '%.*s'",
|
||||
paramname, msg,
|
||||
json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%s: %s: invalid token (see logs for details)",
|
||||
paramname, msg);
|
||||
}
|
|
@ -54,35 +54,10 @@ struct command_result *command_check_done(struct command *cmd)
|
|||
WARN_UNUSED_RESULT;
|
||||
|
||||
/* Convenient wrapper for "paramname: msg: invalid token '.*%s'" */
|
||||
static inline struct command_result *
|
||||
command_fail_badparam(struct command *cmd,
|
||||
const char *paramname,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
const char *msg)
|
||||
{
|
||||
if (command_dev_apis(cmd)) {
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%s: %s: invalid token '%.*s'",
|
||||
paramname, msg,
|
||||
json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
||||
/* Someone misconfigured LNBITS with "" around the rune, and so the
|
||||
* user got a message about a bad rune parameter which *contained the
|
||||
* rune itself*!. LNBITS should probably swallow any JSONRPC2_* error
|
||||
* itself, but it is quite possibly not the only case where this case
|
||||
* where this can happen. So we are a little circumspect in this
|
||||
* case. */
|
||||
command_log(cmd, LOG_INFORM,
|
||||
"Invalid parameter %s (%s): token '%.*s'",
|
||||
paramname, msg,
|
||||
json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%s: %s: invalid token (see logs for details)",
|
||||
paramname, msg);
|
||||
}
|
||||
struct command_result *command_fail_badparam(struct command *cmd,
|
||||
const char *paramname,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
const char *msg);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_JSON_COMMAND_H */
|
||||
|
|
|
@ -33,11 +33,13 @@ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_e
|
|||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_set_usage */
|
||||
void command_set_usage(struct command *cmd UNNEEDED, const char *usage UNNEEDED)
|
||||
{ fprintf(stderr, "command_set_usage called!\n"); abort(); }
|
||||
|
|
|
@ -62,11 +62,13 @@ struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_e
|
|||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_set_usage */
|
||||
void command_set_usage(struct command *cmd UNNEEDED, const char *usage UNNEEDED)
|
||||
{ fprintf(stderr, "command_set_usage called!\n"); abort(); }
|
||||
|
|
|
@ -50,22 +50,16 @@ struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u
|
|||
/* Generated stub for amount_tx_fee */
|
||||
struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED)
|
||||
{ fprintf(stderr, "amount_tx_fee called!\n"); abort(); }
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
/* Generated stub for command_fail */
|
||||
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_filter_ptr */
|
||||
struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_filter_ptr called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for fmt_amount_sat */
|
||||
char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED)
|
||||
{ fprintf(stderr, "fmt_amount_sat called!\n"); abort(); }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "config.h"
|
||||
#include "../bech32.c"
|
||||
#include "../json_command.c"
|
||||
#include "../json_filter.c"
|
||||
#include "../json_parse.c"
|
||||
#include "../json_parse_simple.c"
|
||||
|
@ -56,14 +57,17 @@ bool command_deprecated_in_ok(struct command *cmd,
|
|||
return true;
|
||||
}
|
||||
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for command_check_done */
|
||||
struct command_result *command_check_done(struct command *cmd)
|
||||
|
||||
{ fprintf(stderr, "command_check_done called!\n"); abort(); }
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
/* Generated stub for command_filter_ptr */
|
||||
struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_filter_ptr called!\n"); abort(); }
|
||||
|
|
|
@ -116,6 +116,7 @@ LIGHTNINGD_COMMON_OBJS := \
|
|||
common/key_derive.o \
|
||||
common/keyset.o \
|
||||
common/json_channel_type.o \
|
||||
common/json_command.o \
|
||||
common/json_filter.o \
|
||||
common/json_param.o \
|
||||
common/json_parse.o \
|
||||
|
|
|
@ -156,14 +156,18 @@ bool command_deprecated_out_ok(struct command *cmd UNNEEDED,
|
|||
const char *depr_start UNNEEDED,
|
||||
const char *depr_end UNNEEDED)
|
||||
{ fprintf(stderr, "command_deprecated_out_ok called!\n"); abort(); }
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
/* Generated stub for command_fail */
|
||||
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_failed */
|
||||
struct command_result *command_failed(struct command *cmd UNNEEDED,
|
||||
struct json_stream *result)
|
||||
|
@ -172,11 +176,6 @@ struct command_result *command_failed(struct command *cmd UNNEEDED,
|
|||
/* Generated stub for command_its_complicated */
|
||||
struct command_result *command_its_complicated(const char *why UNNEEDED)
|
||||
{ fprintf(stderr, "command_its_complicated called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for command_logger */
|
||||
struct logger *command_logger(struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_logger called!\n"); abort(); }
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for db_begin_transaction_ */
|
||||
void db_begin_transaction_(struct db *db UNNEEDED, const char *location UNNEEDED)
|
||||
{ fprintf(stderr, "db_begin_transaction_ called!\n"); abort(); }
|
||||
|
|
|
@ -3,19 +3,13 @@
|
|||
#include <common/setup.h>
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
/* Generated stub for command_fail */
|
||||
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_param_failed */
|
||||
struct command_result *command_param_failed(void)
|
||||
|
||||
|
|
|
@ -14,19 +14,13 @@ void notify_log(struct lightningd *ld UNNEEDED, const struct log_entry *l UNNEED
|
|||
{ }
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
/* Generated stub for command_fail */
|
||||
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_param_failed */
|
||||
struct command_result *command_param_failed(void)
|
||||
|
||||
|
|
|
@ -159,6 +159,7 @@ PLUGIN_COMMON_OBJS := \
|
|||
common/deprecation.o \
|
||||
common/features.o \
|
||||
common/hash_u5.o \
|
||||
common/json_command.o \
|
||||
common/json_param.o \
|
||||
common/json_parse.o \
|
||||
common/json_parse_simple.o \
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
/* Generated stub for account_entry_tag_str */
|
||||
const char *account_entry_tag_str(enum account_entry_tag tag UNNEEDED)
|
||||
{ fprintf(stderr, "account_entry_tag_str called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for daemon_developer_mode */
|
||||
bool daemon_developer_mode(char *argv[])
|
||||
{ fprintf(stderr, "daemon_developer_mode called!\n"); abort(); }
|
||||
|
|
|
@ -30,6 +30,13 @@
|
|||
/* Generated stub for account_entry_tag_str */
|
||||
const char *account_entry_tag_str(enum account_entry_tag tag UNNEEDED)
|
||||
{ fprintf(stderr, "account_entry_tag_str called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for daemon_developer_mode */
|
||||
bool daemon_developer_mode(char *argv[])
|
||||
{ fprintf(stderr, "daemon_developer_mode called!\n"); abort(); }
|
||||
|
|
|
@ -135,24 +135,23 @@ bool command_deprecated_out_ok(struct command *cmd UNNEEDED,
|
|||
const char *depr_start UNNEEDED,
|
||||
const char *depr_end UNNEEDED)
|
||||
{ fprintf(stderr, "command_deprecated_out_ok called!\n"); abort(); }
|
||||
/* Generated stub for command_dev_apis */
|
||||
bool command_dev_apis(const struct command *cmd UNNEEDED)
|
||||
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
|
||||
/* Generated stub for command_fail */
|
||||
struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_fail called!\n"); abort(); }
|
||||
/* Generated stub for command_fail_badparam */
|
||||
struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
|
||||
const char *paramname UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
const char *msg UNNEEDED)
|
||||
{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
|
||||
/* Generated stub for command_failed */
|
||||
struct command_result *command_failed(struct command *cmd UNNEEDED,
|
||||
struct json_stream *result)
|
||||
|
||||
{ fprintf(stderr, "command_failed called!\n"); abort(); }
|
||||
/* Generated stub for command_log */
|
||||
void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
{ fprintf(stderr, "command_log called!\n"); abort(); }
|
||||
/* Generated stub for command_param_failed */
|
||||
struct command_result *command_param_failed(void)
|
||||
|
||||
|
@ -599,9 +598,6 @@ bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEE
|
|||
/* Generated stub for json_tok_full */
|
||||
const char *json_tok_full(const char *buffer UNNEEDED, const jsmntok_t *t UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_full called!\n"); abort(); }
|
||||
/* Generated stub for json_tok_full_len */
|
||||
int json_tok_full_len(const jsmntok_t *t UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_full_len called!\n"); abort(); }
|
||||
/* Generated stub for json_tok_streq */
|
||||
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue