diff --git a/common/json_command.h b/common/json_command.h index f703bcd74..163973020 100644 --- a/common/json_command.h +++ b/common/json_command.h @@ -36,8 +36,17 @@ command_fail_badparam(struct command *cmd, /* Also caller supplied: is this invoked simply to get usage? */ bool command_usage_only(const struct command *cmd); -/* Do we allow deprecated apis? */ -bool command_deprecated_apis(const struct command *cmd); +/* 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); /* Do we allow dev commands? */ bool command_dev_apis(const struct command *cmd); diff --git a/common/test/run-json_filter.c b/common/test/run-json_filter.c index 4c31e1550..2fccce6f0 100644 --- a/common/test/run-json_filter.c +++ b/common/test/run-json_filter.c @@ -15,9 +15,6 @@ struct command; /* Generated stub for command_check_only */ bool command_check_only(const struct command *cmd UNNEEDED) { fprintf(stderr, "command_check_only called!\n"); abort(); } -/* Generated stub for command_deprecated_apis */ -bool command_deprecated_apis(const struct command *cmd UNNEEDED) -{ fprintf(stderr, "command_deprecated_apis 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(); } diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index 2c051ee45..966f4314a 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -44,9 +44,6 @@ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED) /* Generated stub for command_check_only */ bool command_check_only(const struct command *cmd UNNEEDED) { fprintf(stderr, "command_check_only called!\n"); abort(); } -/* Generated stub for command_deprecated_apis */ -bool command_deprecated_apis(const struct command *cmd UNNEEDED) -{ fprintf(stderr, "command_deprecated_apis 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(); } diff --git a/common/test/run-param.c b/common/test/run-param.c index b75b52691..42697b9f2 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -99,11 +99,6 @@ bool command_check_only(const struct command *cmd) return cmd->mode == CMD_CHECK; } -bool command_deprecated_apis(const struct command *cmd) -{ - return cmd->deprecated_apis; -} - struct json { jsmntok_t *toks; char *buffer; diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 23e90b1e8..f3e19b8a5 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -652,6 +652,36 @@ struct json_filter **command_filter_ptr(struct command *cmd) return &cmd->filter; } +static bool command_deprecated_ok(const struct command *cmd) +{ + return cmd->ld->deprecated_apis; +} + +bool command_deprecated_in_ok(struct command *cmd, + const char *param, + const char *depr_start, + const char *depr_end) +{ + return lightningd_deprecated_in_ok(cmd->ld, + command_log(cmd), + command_deprecated_ok(cmd), + cmd->json_cmd->name, param, + depr_start, depr_end, + cmd->id); +} + +bool command_deprecated_out_ok(struct command *cmd, + const char *fieldname, + const char *depr_start, + const char *depr_end) +{ + return lightningd_deprecated_out_ok(cmd->ld, + command_deprecated_ok(cmd), + cmd->json_cmd->name, + fieldname, + depr_start, depr_end); +} + struct command_result *command_still_pending(struct command *cmd) { notleak_with_children(cmd); @@ -1425,11 +1455,6 @@ bool command_usage_only(const struct command *cmd) return cmd->mode == CMD_USAGE; } -bool command_deprecated_apis(const struct command *cmd) -{ - return cmd->ld->deprecated_apis; -} - bool command_dev_apis(const struct command *cmd) { return cmd->ld->developer; diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 5a917a45c..3702e08e0 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -63,6 +63,24 @@ bool json_to_jsonrpc_errcode(const char *buffer UNNEEDED, const jsmntok_t *tok U bool json_to_number(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, unsigned int *num UNNEEDED) { fprintf(stderr, "json_to_number called!\n"); abort(); } +/* Generated stub for lightningd_deprecated_in_ok */ +bool lightningd_deprecated_in_ok(struct lightningd *ld UNNEEDED, + struct logger *log UNNEEDED, + bool deprecated_apis UNNEEDED, + const char *subsys UNNEEDED, + const char *api UNNEEDED, + const char *start UNNEEDED, + const char *end UNNEEDED, + const char *details UNNEEDED) +{ fprintf(stderr, "lightningd_deprecated_in_ok called!\n"); abort(); } +/* Generated stub for lightningd_deprecated_out_ok */ +bool lightningd_deprecated_out_ok(struct lightningd *ld UNNEEDED, + bool deprecated_apis UNNEEDED, + const char *subsys UNNEEDED, + const char *api UNNEEDED, + const char *start UNNEEDED, + const char *end UNNEEDED) +{ fprintf(stderr, "lightningd_deprecated_out_ok called!\n"); abort(); } /* Generated stub for log_ */ void log_(struct logger *logger UNNEEDED, enum log_level level UNNEEDED, const struct node_id *node_id UNNEEDED, diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c index bd4e92e89..bd2db0097 100644 --- a/plugins/bkpr/test/run-bkpr_db.c +++ b/plugins/bkpr/test/run-bkpr_db.c @@ -32,6 +32,15 @@ void daemon_setup(const char *argv0 UNNEEDED, void (*backtrace_print)(const char *fmt UNNEEDED, ...) UNNEEDED, void (*backtrace_exit)(void)) { fprintf(stderr, "daemon_setup called!\n"); abort(); } +/* Generated stub for deprecated_ok_ */ +bool deprecated_ok_(bool deprecated_apis UNNEEDED, + const char *feature UNNEEDED, + const char *start UNNEEDED, + const char *end UNNEEDED, + const char **begs UNNEEDED, + void (*complain)(const char *feat UNNEEDED, bool allowing UNNEEDED, void *) UNNEEDED, + void *cbarg UNNEEDED) +{ fprintf(stderr, "deprecated_ok_ called!\n"); abort(); } /* Generated stub for first_fee_state */ enum htlc_state first_fee_state(enum side opener UNNEEDED) { fprintf(stderr, "first_fee_state called!\n"); abort(); } diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c index a082b9b26..accecc8fa 100644 --- a/plugins/bkpr/test/run-recorder.c +++ b/plugins/bkpr/test/run-recorder.c @@ -38,6 +38,15 @@ void daemon_setup(const char *argv0 UNNEEDED, void (*backtrace_print)(const char *fmt UNNEEDED, ...) UNNEEDED, void (*backtrace_exit)(void)) { fprintf(stderr, "daemon_setup called!\n"); abort(); } +/* Generated stub for deprecated_ok_ */ +bool deprecated_ok_(bool deprecated_apis UNNEEDED, + const char *feature UNNEEDED, + const char *start UNNEEDED, + const char *end UNNEEDED, + const char **begs UNNEEDED, + void (*complain)(const char *feat UNNEEDED, bool allowing UNNEEDED, void *) UNNEEDED, + void *cbarg UNNEEDED) +{ fprintf(stderr, "deprecated_ok_ called!\n"); abort(); } /* Generated stub for first_fee_state */ enum htlc_state first_fee_state(enum side opener UNNEEDED) { fprintf(stderr, "first_fee_state called!\n"); abort(); } diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 4ff1508b7..6ac428657 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -138,6 +139,55 @@ struct json_filter **command_filter_ptr(struct command *cmd) return &cmd->filter; } +static bool command_deprecated_ok(const struct command *cmd) +{ + return deprecated_apis; +} + +static void complain_deprecated(const char *feature, + bool allowing, + struct command *cmd) +{ + if (!allowing) { + /* Mild log message for disallowing */ + plugin_log(cmd->plugin, LOG_DBG, + "Note: disallowing deprecated %s for %s", + feature, cmd->id); + } else { + plugin_log(cmd->plugin, LOG_BROKEN, + "DEPRECATED API USED: %s by %s", + feature, cmd->id); + } +} + +bool command_deprecated_in_ok(struct command *cmd, + const char *param, + const char *depr_start, + const char *depr_end) +{ + return deprecated_ok(command_deprecated_ok(cmd), + param + ? tal_fmt(tmpctx, "%s.%s", cmd->methodname, param) + : cmd->methodname, + depr_start, depr_end, + /* FIXME: Get api begs from lightningd! */ + NULL, + complain_deprecated, cmd); +} + +bool command_deprecated_out_ok(struct command *cmd, + const char *fieldname, + const char *depr_start, + const char *depr_end) +{ + return deprecated_ok(command_deprecated_ok(cmd), + tal_fmt(tmpctx, "%s.%s", cmd->methodname, fieldname), + depr_start, depr_end, + /* FIXME: Get api begs from lightningd! */ + NULL, + NULL, NULL); +} + static void ld_send(struct plugin *plugin, struct json_stream *stream) { struct jstream *jstr = tal(plugin, struct jstream); @@ -500,11 +550,6 @@ bool command_usage_only(const struct command *cmd) return cmd->usage_only; } -bool command_deprecated_apis(const struct command *cmd) -{ - return deprecated_apis; -} - bool command_dev_apis(const struct command *cmd) { return cmd->plugin->developer;