mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-04 00:00:14 -04:00
Added a method to plugin_loader_t to add 'static' plugin features
This allows daemons and other components to register plugin features like those provided by plugins (following the same lifecycle). The added features are internally handled like they were added by a plugin.
This commit is contained in:
parent
e07122436c
commit
18d21a57df
@ -104,6 +104,78 @@ static void plugin_entry_destroy(plugin_entry_t *entry)
|
||||
free(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for static plugin features
|
||||
*/
|
||||
typedef struct {
|
||||
|
||||
/**
|
||||
* Implements plugin_t interface
|
||||
*/
|
||||
plugin_t public;
|
||||
|
||||
/**
|
||||
* Name of the module registering these features
|
||||
*/
|
||||
char *name;
|
||||
|
||||
/**
|
||||
* Static plugin features
|
||||
*/
|
||||
plugin_feature_t *features;
|
||||
|
||||
/**
|
||||
* Number of plugin features
|
||||
*/
|
||||
int count;
|
||||
|
||||
} static_features_t;
|
||||
|
||||
METHOD(plugin_t, get_static_name, char*,
|
||||
static_features_t *this)
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
||||
METHOD(plugin_t, get_static_features, int,
|
||||
static_features_t *this, plugin_feature_t *features[])
|
||||
{
|
||||
*features = this->features;
|
||||
return this->count;
|
||||
}
|
||||
|
||||
METHOD(plugin_t, static_destroy, void,
|
||||
static_features_t *this)
|
||||
{
|
||||
free(this->features);
|
||||
free(this->name);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a wrapper around static plugin features.
|
||||
*/
|
||||
static plugin_t *static_features_create(const char *name,
|
||||
plugin_feature_t features[], int count)
|
||||
{
|
||||
static_features_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.get_name = _get_static_name,
|
||||
.get_features = _get_static_features,
|
||||
.destroy = _static_destroy,
|
||||
},
|
||||
.name = strdup(name),
|
||||
.features = calloc(count, sizeof(plugin_feature_t)),
|
||||
.count = count,
|
||||
);
|
||||
|
||||
memcpy(this->features, features, sizeof(plugin_feature_t) * count);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare function for hashtable of loaded features.
|
||||
*/
|
||||
@ -554,6 +626,24 @@ static void purge_plugins(private_plugin_loader_t *this)
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
METHOD(plugin_loader_t, add_static_features, void,
|
||||
private_plugin_loader_t *this, const char *name,
|
||||
plugin_feature_t features[], int count, bool critical)
|
||||
{
|
||||
plugin_entry_t *entry;
|
||||
plugin_t *plugin;
|
||||
|
||||
plugin = static_features_create(name, features, count);
|
||||
|
||||
INIT(entry,
|
||||
.plugin = plugin,
|
||||
.critical = critical,
|
||||
.loaded = linked_list_create(),
|
||||
.failed = linked_list_create(),
|
||||
);
|
||||
this->plugins->insert_last(this->plugins, entry);
|
||||
}
|
||||
|
||||
METHOD(plugin_loader_t, load_plugins, bool,
|
||||
private_plugin_loader_t *this, char *path, char *list)
|
||||
{
|
||||
@ -740,6 +830,7 @@ plugin_loader_t *plugin_loader_create()
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.add_static_features = _add_static_features,
|
||||
.load = _load_plugins,
|
||||
.reload = _reload,
|
||||
.unload = _unload,
|
||||
|
@ -26,11 +26,35 @@ typedef struct plugin_loader_t plugin_loader_t;
|
||||
|
||||
#include <utils/enumerator.h>
|
||||
|
||||
/* to avoid circular references we can't include plugin_feature.h */
|
||||
struct plugin_feature_t;
|
||||
|
||||
/**
|
||||
* The plugin_loader loads plugins from a directory and initializes them
|
||||
*/
|
||||
struct plugin_loader_t {
|
||||
|
||||
/**
|
||||
* Add static plugin features, not loaded via plugins.
|
||||
*
|
||||
* Similar to features provided by plugins they are evaluated during load(),
|
||||
* and unloaded when unload() is called.
|
||||
*
|
||||
* If critical is TRUE load() will fail if any of the added features could
|
||||
* not be loaded.
|
||||
*
|
||||
* @note The name should be unique otherwise a plugin with the same name is
|
||||
* not loaded.
|
||||
*
|
||||
* @param name name of the component adding the features
|
||||
* @param features array of plugin features
|
||||
* @param count number of features in the array
|
||||
* @param critical TRUE if the features are critical
|
||||
*/
|
||||
void (*add_static_features) (plugin_loader_t *this, const char *name,
|
||||
struct plugin_feature_t *features, int count,
|
||||
bool critical);
|
||||
|
||||
/**
|
||||
* Load a list of plugins from a directory.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user