aead: Support custom AEAD salt sizes
[strongswan.git] / src / libstrongswan / plugins / plugin_loader.h
1 /*
2 * Copyright (C) 2012-2014 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 * If \<ns>.load_modular is enabled (where \<ns> is lib->ns) the plugins to
71 * load are determined via a load option in their respective plugin config
72 * section e.g. \<ns>.plugins.\<plugin>.load = <priority|bool>.
73 * The oder is determined by the configured priority. If two plugins have
74 * the same priority the order as seen in list is preserved. Plugins not
75 * found in list are loaded first, in alphabetical order.
76 *
77 * @note Even though this method could be called multiple times this is
78 * currently not really supported in regards to plugin features and their
79 * dependencies (in particular soft dependencies).
80 *
81 * @param list space separated list of plugins to load
82 * @return TRUE if all critical plugins loaded successfully
83 */
84 bool (*load)(plugin_loader_t *this, char *list);
85
86 /**
87 * Add an additional search path for plugins.
88 *
89 * These will be searched in the order they were added.
90 *
91 * @param path path containing loadable plugins
92 */
93 void (*add_path)(plugin_loader_t *this, char *path);
94
95 /**
96 * Reload the configuration of one or multiple plugins.
97 *
98 * @param space separated plugin names to reload, NULL for all
99 * @return number of plugins that did support reloading
100 */
101 u_int (*reload)(plugin_loader_t *this, char *list);
102
103 /**
104 * Unload all loaded plugins.
105 */
106 void (*unload)(plugin_loader_t *this);
107
108 /**
109 * Create an enumerator over all loaded plugins.
110 *
111 * In addition to the plugin, the enumerator optionally provides a list of
112 * pointers to plugin features currently loaded.
113 * This list has to be destroyed.
114 *
115 * @return enumerator over plugin_t*, linked_list_t*
116 */
117 enumerator_t* (*create_plugin_enumerator)(plugin_loader_t *this);
118
119 /**
120 * Check if the given feature is available and loaded.
121 *
122 * @param feature feature to check
123 * @return TRUE if feature available
124 */
125 bool (*has_feature)(plugin_loader_t *this, struct plugin_feature_t feature);
126
127 /**
128 * Get a simple list the names of all loaded plugins.
129 *
130 * The function returns internal data, do not free.
131 *
132 * @return list of the names of all loaded plugins
133 */
134 char* (*loaded_plugins)(plugin_loader_t *this);
135
136 /**
137 * Log status about loaded plugins and features.
138 *
139 * @param level log level to use
140 */
141 void (*status)(plugin_loader_t *this, level_t level);
142
143 /**
144 * Unload loaded plugins, destroy plugin_loader instance.
145 */
146 void (*destroy)(plugin_loader_t *this);
147 };
148
149 /**
150 * Create a plugin_loader instance.
151 *
152 * @return plugin loader instance
153 */
154 plugin_loader_t *plugin_loader_create();
155
156 /**
157 * Convenience function to add plugin directories for the given plugins within
158 * the given base directory according to the conventions in the src/build tree.
159 *
160 * @param basedir base directory
161 * @param plugins space separated list of plugins
162 */
163 void plugin_loader_add_plugindirs(char *basedir, char *plugins);
164
165 #endif /** PLUGIN_LOADER_H_ @}*/