plugin-loader: Add optional filter for plugin features

In some cases, the algorithms that have been compiled into a plugin have
to be disabled at runtime. Based on the array returned by the get_features()
function the optionally provided function can strip algorithms or even
callbacks or registrations from a plugin, giving us a handy and powerful way
for runtime feature configuration aside from the plugin list.

Signed-off-by: Thomas Egerer <[email protected]>
This commit is contained in:
Thomas Egerer
2021-02-04 16:39:27 +01:00
committed by Tobias Brunner
parent e6a6fc33b6
commit 2566eb2194
+21 -1
View File
@@ -93,6 +93,12 @@ struct private_plugin_loader_t {
/** Number of features in critical plugins that failed to load */
int critical;
} stats;
/**
* Fetch features from the given plugin, can optionally be overridden to
* modify feature arrays at loading time
*/
int (*get_features)(plugin_t *plugin, plugin_feature_t *features[]);
};
/**
@@ -886,6 +892,14 @@ static void load_features(private_plugin_loader_t *this)
enumerator->destroy(enumerator);
}
/**
* Default implementation for plugin feature retrieval
*/
static int get_features_default(plugin_t *plugin, plugin_feature_t *features[])
{
return plugin->get_features(plugin, features);
}
/**
* Register plugin features provided by the given plugin
*/
@@ -904,7 +918,7 @@ static void register_features(private_plugin_loader_t *this,
return;
}
reg = NULL;
count = entry->plugin->get_features(entry->plugin, &feature);
count = this->get_features(entry->plugin, &feature);
for (i = 0; i < count; i++)
{
switch (feature->kind)
@@ -1449,8 +1463,14 @@ plugin_loader_t *plugin_loader_create()
.features = hashlist_create(
(hashtable_hash_t)registered_feature_hash,
(hashtable_equals_t)registered_feature_equals, 64),
.get_features = dlsym(RTLD_DEFAULT, "plugin_loader_feature_filter"),
);
if (!this->get_features)
{
this->get_features = get_features_default;
}
return &this->public;
}