From 4640d18ef07b2d355ec0a4326adcb92317ba551a Mon Sep 17 00:00:00 2001 From: darosior Date: Sun, 26 May 2019 23:19:00 +0200 Subject: [PATCH] Plugins: allow to specify plugin option type in libplugin.c, then specify it to autoclean options --- plugins/autoclean.c | 2 ++ plugins/libplugin.c | 13 +++++++------ plugins/libplugin.h | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/autoclean.c b/plugins/autoclean.c index 1da6c66e5..3e45df829 100644 --- a/plugins/autoclean.c +++ b/plugins/autoclean.c @@ -84,10 +84,12 @@ int main(int argc, char *argv[]) setup_locale(); plugin_main(argv, init, commands, ARRAY_SIZE(commands), plugin_option("autocleaninvoice-cycle", + "string", "Perform cleanup of expired invoices every" " given seconds, or do not autoclean if 0", u64_option, &cycle_seconds), plugin_option("autocleaninvoice-expired-by", + "string", "If expired invoice autoclean enabled," " invoices that have expired for at least" " this given seconds are cleaned", diff --git a/plugins/libplugin.c b/plugins/libplugin.c index ea1e118b2..68fb3d1fe 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -439,11 +439,12 @@ handle_getmanifest(struct command *getmanifest_cmd, for (size_t i = 0; i < tal_count(opts); i++) { tal_append_fmt(¶ms, "{ 'name': '%s'," - " 'type': 'string'," - " 'description': '%s' }%s", - opts[i].name, - opts[i].description, - i == tal_count(opts) - 1 ? "" : ",\n"); + " 'type': '%s'," + " 'description': '%s' }%s", + opts[i].name, + opts[i].type, + opts[i].description, + i == tal_count(opts) - 1 ? "" : ",\n"); } tal_append_fmt(¶ms, @@ -507,7 +508,6 @@ static struct command_result *handle_init(struct command *init_cmd, &rpc_conn, ".allow-deprecated-apis"), "true"); - opttok = json_get_member(buf, params, "options"); json_for_each_obj(i, t, opttok) { char *opt = json_strdup(NULL, buf, t); @@ -695,6 +695,7 @@ void plugin_main(char *argv[], while ((optname = va_arg(ap, const char *)) != NULL) { struct plugin_option o; o.name = optname; + o.type = va_arg(ap, const char *); o.description = va_arg(ap, const char *); o.handle = va_arg(ap, char *(*)(const char *str, void *arg)); o.arg = va_arg(ap, void *); diff --git a/plugins/libplugin.h b/plugins/libplugin.h index fc7ca1992..dc3ce911f 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -29,6 +29,7 @@ struct plugin_command { /* Create an array of these, one for each --option you support. */ struct plugin_option { const char *name; + const char *type; const char *description; char *(*handle)(const char *str, void *arg); void *arg; @@ -119,8 +120,9 @@ struct plugin_timer *plugin_timer(struct plugin_conn *rpc, void PRINTF_FMT(2, 3) plugin_log(enum log_level l, const char *fmt, ...); /* Macro to define arguments */ -#define plugin_option(name, description, set, arg) \ +#define plugin_option(name, type, description, set, arg) \ (name), \ + (type), \ (description), \ typesafe_cb_preargs(char *, void *, (set), (arg), const char *), \ (arg)