2018-12-08 01:39:25 +01:00
|
|
|
/* 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 05:49:38 +02:00
|
|
|
#include <common/json_parse.h>
|
2020-08-25 23:20:50 +02:00
|
|
|
#include <common/jsonrpc_errors.h>
|
2024-06-22 17:04:33 +02:00
|
|
|
#include <common/status_levels.h>
|
2018-12-08 01:39:25 +01:00
|
|
|
|
|
|
|
struct command;
|
2018-12-16 05:49:06 +01:00
|
|
|
struct command_result;
|
2018-12-08 01:39:25 +01:00
|
|
|
|
|
|
|
/* Caller supplied this: param assumes it can call it. */
|
2022-09-18 02:20:50 +02:00
|
|
|
struct command_result *command_fail(struct command *cmd, enum jsonrpc_errcode code,
|
2018-12-16 05:49:06 +01:00
|
|
|
const char *fmt, ...)
|
2021-06-14 23:07:38 +02:00
|
|
|
PRINTF_FMT(3, 4) WARN_UNUSED_RESULT RETURNS_NONNULL;
|
2018-12-08 01:39:25 +01:00
|
|
|
|
2022-11-04 04:30:48 +01:00
|
|
|
/* Caller supplies this too: must provide this to reach into cmd */
|
|
|
|
struct json_filter **command_filter_ptr(struct command *cmd);
|
|
|
|
|
2024-06-22 17:04:33 +02:00
|
|
|
/* Do some logging (complaining!) about this command misuse */
|
|
|
|
void command_log(struct command *cmd, enum log_level level,
|
|
|
|
const char *fmt, ...)
|
|
|
|
PRINTF_FMT(3, 4);
|
|
|
|
|
2018-12-08 01:39:25 +01:00
|
|
|
/* Also caller supplied: is this invoked simply to get usage? */
|
|
|
|
bool command_usage_only(const struct command *cmd);
|
|
|
|
|
2024-01-25 01:28:54 +01:00
|
|
|
/* Caller supplies this too: they tried to use a deprecated parameter (or cmd). */
|
|
|
|
bool command_deprecated_in_ok(struct command *cmd,
|
|
|
|
const char *param,
|
|
|
|
const char *depr_start,
|
|
|
|
const char *depr_end);
|
|
|
|
|
|
|
|
/* Caller supplies this: should we output this deprecated thing */
|
|
|
|
bool command_deprecated_out_ok(struct command *cmd,
|
|
|
|
const char *fieldname,
|
|
|
|
const char *depr_start,
|
|
|
|
const char *depr_end);
|
2023-07-06 09:36:50 +02:00
|
|
|
|
2023-09-21 07:36:27 +02:00
|
|
|
/* Do we allow dev commands? */
|
|
|
|
bool command_dev_apis(const struct command *cmd);
|
|
|
|
|
2018-12-08 01:39:25 +01:00
|
|
|
/* 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);
|
|
|
|
|
2024-04-04 05:36:11 +02:00
|
|
|
/* To return after param_check() succeeds but we're still
|
|
|
|
* command_check_only(cmd). */
|
|
|
|
struct command_result *command_check_done(struct command *cmd)
|
|
|
|
WARN_UNUSED_RESULT;
|
|
|
|
|
2024-06-22 17:05:33 +02:00
|
|
|
/* Convenient wrapper for "paramname: msg: invalid token '.*%s'" */
|
2024-06-24 05:45:50 +02:00
|
|
|
struct command_result *command_fail_badparam(struct command *cmd,
|
|
|
|
const char *paramname,
|
|
|
|
const char *buffer,
|
|
|
|
const jsmntok_t *tok,
|
|
|
|
const char *msg);
|
2024-06-22 17:05:33 +02:00
|
|
|
|
2018-12-08 01:39:25 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_JSON_COMMAND_H */
|