pkcs12: Add plugin dependencies with soft dependencies on the most common algorithms
[strongswan.git] / src / libstrongswan / plugins / plugin_loader.h
1 /*
2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Copyright (C) 2007 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup plugin_loader plugin_loader
19 * @{ @ingroup plugins
20 */
21
22 #ifndef PLUGIN_LOADER_H_
23 #define PLUGIN_LOADER_H_
24
25 typedef struct plugin_loader_t plugin_loader_t;
26
27 #include <collections/enumerator.h>
28 #include <utils/debug.h>
29
30 /* to avoid circular references we can't include plugin_feature.h */
31 struct plugin_feature_t;
32
33 /**
34 * The plugin_loader loads plugins from a directory and initializes them
35 */
36 struct plugin_loader_t {
37
38 /**
39 * Add static plugin features, not loaded via plugins.
40 *
41 * Similar to features provided by plugins they are evaluated during load(),
42 * and unloaded when unload() is called.
43 *
44 * If critical is TRUE load() will fail if any of the added features could
45 * not be loaded.
46 *
47 * @note The name should be unique otherwise a plugin with the same name is
48 * not loaded.
49 *
50 * @param name name of the component adding the features
51 * @param features array of plugin features
52 * @param count number of features in the array
53 * @param critical TRUE if the features are critical
54 */
55 void (*add_static_features) (plugin_loader_t *this, const char *name,
56 struct plugin_feature_t *features, int count,
57 bool critical);
58
59 /**
60 * Load a list of plugins.
61 *
62 * Each plugin in list may have an ending exclamation mark (!) to mark it
63 * as a critical plugin. If loading a critical plugin fails, plugin loading
64 * is aborted and FALSE is returned.
65 *
66 * Additional paths can be added with add_path(), these will be searched
67 * for the plugins first, in the order they were added, then the default
68 * path follows.
69 *
70 * @note Even though this method could be called multiple times this is
71 * currently not really supported in regards to plugin features and their
72 * dependencies (in particular soft dependencies).
73 *
74 * @param list space separated list of plugins to load
75 * @return TRUE if all critical plugins loaded successfully
76 */
77 bool (*load)(plugin_loader_t *this, char *list);
78
79 /**
80 * Add an additional search path for plugins.
81 *
82 * These will be searched in the order they were added.
83 *
84 * @param path path containing loadable plugins
85 */
86 void (*add_path)(plugin_loader_t *this, char *path);
87
88 /**
89 * Reload the configuration of one or multiple plugins.
90 *
91 * @param space separated plugin names to reload, NULL for all
92 * @return number of plugins that did support reloading
93 */
94 u_int (*reload)(plugin_loader_t *this, char *list);
95
96 /**
97 * Unload all loaded plugins.
98 */
99 void (*unload)(plugin_loader_t *this);
100
101 /**
102 * Create an enumerator over all loaded plugins.
103 *
104 * In addition to the plugin, the enumerator optionally provides a list of
105 * pointers to plugin features currently loaded.
106 * This list has to be destroyed.
107 *
108 * @return enumerator over plugin_t*, linked_list_t*
109 */
110 enumerator_t* (*create_plugin_enumerator)(plugin_loader_t *this);
111
112 /**
113 * Check if the given feature is available and loaded.
114 *
115 * @param feature feature to check
116 * @return TRUE if feature available
117 */
118 bool (*has_feature)(plugin_loader_t *this, struct plugin_feature_t feature);
119
120 /**
121 * Get a simple list the names of all loaded plugins.
122 *
123 * The function returns internal data, do not free.
124 *
125 * @return list of the names of all loaded plugins
126 */
127 char* (*loaded_plugins)(plugin_loader_t *this);
128
129 /**
130 * Log status about loaded plugins and features.
131 *
132 * @param level log level to use
133 */
134 void (*status)(plugin_loader_t *this, level_t level);
135
136 /**
137 * Unload loaded plugins, destroy plugin_loader instance.
138 */
139 void (*destroy)(plugin_loader_t *this);
140 };
141
142 /**
143 * Create a plugin_loader instance.
144 *
145 * @return plugin loader instance
146 */
147 plugin_loader_t *plugin_loader_create();
148
149 #endif /** PLUGIN_LOADER_H_ @}*/