mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-02 12:44:26 +01:00
plugin: Move list of notification topics to each plugin
We want to ensure that plugins register their topics before sending any notification, so we need to remember which plugin registered which topics.
This commit is contained in:
committed by
Rusty Russell
parent
c8c2c33952
commit
2e27e4e443
@@ -26,15 +26,17 @@ bool notifications_topic_is_native(const char *topic)
|
||||
|
||||
bool notifications_have_topic(const struct plugins *plugins, const char *topic)
|
||||
{
|
||||
struct plugin *plugin;
|
||||
if (notifications_topic_is_native(topic))
|
||||
return true;
|
||||
|
||||
/* Some plugin at some point announced it'd be emitting
|
||||
* notifications to this topic. We don't care if it died, just
|
||||
* that it was a valid topic at some point in time. */
|
||||
for (size_t i=0; i<tal_count(plugins->notification_topics); i++)
|
||||
if (streq(plugins->notification_topics[i], topic))
|
||||
return true;
|
||||
* notifications to this topic. */
|
||||
list_for_each(&plugins->plugins, plugin, list) {
|
||||
for (size_t i = 0; i < tal_count(plugin->notification_topics); i++)
|
||||
if (streq(plugin->notification_topics[i], topic))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book,
|
||||
p->startup = true;
|
||||
p->json_cmds = tal_arr(p, struct command *, 0);
|
||||
p->blacklist = tal_arr(p, const char *, 0);
|
||||
p->notification_topics = tal_arr(p, const char *, 0);
|
||||
p->shutdown = false;
|
||||
p->plugin_idx = 0;
|
||||
#if DEVELOPER
|
||||
@@ -246,6 +245,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES,
|
||||
p->plugin_state = UNCONFIGURED;
|
||||
p->js_arr = tal_arr(p, struct json_stream *, 0);
|
||||
p->used = 0;
|
||||
p->notification_topics = tal_arr(p, const char *, 0);
|
||||
p->subscriptions = NULL;
|
||||
p->dynamic = false;
|
||||
p->index = plugins->plugin_idx++;
|
||||
@@ -1326,7 +1326,7 @@ static const char *plugin_notifications_add(const char *buffer,
|
||||
"missing or not a string.",
|
||||
i);
|
||||
|
||||
name = json_strdup(plugin->plugins, buffer, method);
|
||||
name = json_strdup(plugin, buffer, method);
|
||||
|
||||
if (notifications_topic_is_native(name))
|
||||
return tal_fmt(plugin,
|
||||
@@ -1335,7 +1335,7 @@ static const char *plugin_notifications_add(const char *buffer,
|
||||
"however only be sent by lightningd",
|
||||
name);
|
||||
|
||||
tal_arr_expand(&plugin->plugins->notification_topics, name);
|
||||
tal_arr_expand(&plugin->notification_topics, name);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -93,6 +93,10 @@ struct plugin {
|
||||
/* Parameters for dynamically-started plugins. */
|
||||
const char *parambuf;
|
||||
const jsmntok_t *params;
|
||||
|
||||
/* Notification topics that this plugin has registered with us
|
||||
* and that other plugins may subscribe to. */
|
||||
const char **notification_topics;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -128,10 +132,6 @@ struct plugins {
|
||||
/* Whether builtin plugins should be overridden as unimportant. */
|
||||
bool dev_builtin_plugins_unimportant;
|
||||
#endif /* DEVELOPER */
|
||||
|
||||
/* Notification topics that plugins have registered with us
|
||||
* and that other plugins may subscribe to. */
|
||||
const char **notification_topics;
|
||||
};
|
||||
|
||||
/* The value of a plugin option, which can have different types.
|
||||
|
||||
Reference in New Issue
Block a user