2018-12-08 11:09:25 +10:30
|
|
|
/* These functions must be supplied by any binary linking with common/param
|
|
|
|
* so it can fail commands. */
|
|
|
|
#ifndef LIGHTNING_COMMON_JSON_COMMAND_H
|
|
|
|
#define LIGHTNING_COMMON_JSON_COMMAND_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/compiler/compiler.h>
|
2022-07-04 13:19:38 +09:30
|
|
|
#include <common/json_parse.h>
|
2020-08-26 06:50:50 +09:30
|
|
|
#include <common/jsonrpc_errors.h>
|
2018-12-08 11:09:25 +10:30
|
|
|
|
|
|
|
struct command;
|
2018-12-16 15:19:06 +10:30
|
|
|
struct command_result;
|
2018-12-08 11:09:25 +10:30
|
|
|
|
|
|
|
/* Caller supplied this: param assumes it can call it. */
|
2022-09-18 09:50:50 +09:30
|
|
|
struct command_result *command_fail(struct command *cmd, enum jsonrpc_errcode code,
|
2018-12-16 15:19:06 +10:30
|
|
|
const char *fmt, ...)
|
2021-06-15 06:37:38 +09:30
|
|
|
PRINTF_FMT(3, 4) WARN_UNUSED_RESULT RETURNS_NONNULL;
|
2018-12-08 11:09:25 +10:30
|
|
|
|
2022-11-04 14:00:48 +10:30
|
|
|
/* Caller supplies this too: must provide this to reach into cmd */
|
|
|
|
struct json_filter **command_filter_ptr(struct command *cmd);
|
|
|
|
|
2020-08-26 06:50:50 +09:30
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
|
|
|
"%s: %s: invalid token '%.*s'",
|
|
|
|
paramname, msg,
|
|
|
|
json_tok_full_len(tok),
|
|
|
|
json_tok_full(buffer, tok));
|
|
|
|
}
|
|
|
|
|
2018-12-08 11:09:25 +10:30
|
|
|
/* Also caller supplied: is this invoked simply to get usage? */
|
|
|
|
bool command_usage_only(const struct command *cmd);
|
|
|
|
|
2023-07-06 17:06:50 +09:30
|
|
|
/* Do we allow deprecated apis? */
|
|
|
|
bool command_deprecated_apis(const struct command *cmd);
|
|
|
|
|
2018-12-08 11:09:25 +10:30
|
|
|
/* If so, this is called. */
|
|
|
|
void command_set_usage(struct command *cmd, const char *usage);
|
|
|
|
|
|
|
|
/* Also caller supplied: is this invoked simply to check parameters? */
|
|
|
|
bool command_check_only(const struct command *cmd);
|
|
|
|
|
|
|
|
#endif /* LIGHTNING_COMMON_JSON_COMMAND_H */
|