Merge branch 'nm-gtk4'
[strongswan.git] / src / libstrongswan / library.h
1 /*
2 * Copyright (C) 2010-2018 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * HSR 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 libstrongswan libstrongswan
19 *
20 * @defgroup asn1 asn1
21 * @ingroup libstrongswan
22 *
23 * @defgroup bio bio
24 * @ingroup libstrongswan
25 *
26 * @defgroup collections collections
27 * @ingroup libstrongswan
28 *
29 * @defgroup credentials credentials
30 * @ingroup libstrongswan
31 *
32 * @defgroup keys keys
33 * @ingroup credentials
34 *
35 * @defgroup certificates certificates
36 * @ingroup credentials
37 *
38 * @defgroup containers containers
39 * @ingroup credentials
40 *
41 * @defgroup sets sets
42 * @ingroup credentials
43 *
44 * @defgroup crypto crypto
45 * @ingroup libstrongswan
46 *
47 * @defgroup database database
48 * @ingroup libstrongswan
49 *
50 * @defgroup fetcher fetcher
51 * @ingroup libstrongswan
52 *
53 * @defgroup resolver resolver
54 * @ingroup libstrongswan
55 *
56 * @defgroup ipsec ipsec
57 * @ingroup libstrongswan
58 *
59 * @defgroup networking networking
60 * @ingroup libstrongswan
61 *
62 * @defgroup streams streams
63 * @ingroup networking
64 *
65 * @defgroup plugins plugins
66 * @ingroup libstrongswan
67 *
68 * @defgroup processing processing
69 * @ingroup libstrongswan
70 *
71 * @defgroup jobs jobs
72 * @ingroup processing
73 *
74 * @defgroup selectors selectors
75 * @ingroup libstrongswan
76 *
77 * @defgroup threading threading
78 * @ingroup libstrongswan
79 *
80 * @defgroup utils utils
81 * @ingroup libstrongswan
82 *
83 * @defgroup compat compat
84 * @ingroup utils
85 */
86
87 /**
88 * @defgroup library library
89 * @{ @ingroup libstrongswan
90 */
91
92 #ifndef LIBRARY_H_
93 #define LIBRARY_H_
94
95 #ifndef CONFIG_H_INCLUDED
96 # error config.h not included, pass "-include [...]/config.h" to gcc
97 #endif
98
99 /* make sure we include printf_hook.h and utils.h first */
100 #include "utils/printf_hook/printf_hook.h"
101 #include "utils/utils.h"
102 #include "networking/host_resolver.h"
103 #include "networking/streams/stream_manager.h"
104 #include "processing/processor.h"
105 #include "processing/scheduler.h"
106 #include "processing/watcher.h"
107 #include "crypto/crypto_factory.h"
108 #include "crypto/proposal/proposal_keywords.h"
109 #include "fetcher/fetcher_manager.h"
110 #include "resolver/resolver_manager.h"
111 #include "database/database_factory.h"
112 #include "credentials/credential_factory.h"
113 #include "credentials/credential_manager.h"
114 #include "credentials/cred_encoding.h"
115 #include "metadata/metadata_factory.h"
116 #include "utils/chunk.h"
117 #include "utils/capabilities.h"
118 #include "utils/integrity_checker.h"
119 #include "utils/leak_detective.h"
120 #include "plugins/plugin_loader.h"
121 #include "settings/settings.h"
122
123 typedef struct library_t library_t;
124
125 /**
126 * Libstrongswan library context, contains library relevant globals.
127 */
128 struct library_t {
129
130 /**
131 * Get an arbitrary object registered by name.
132 *
133 * @param name name of the object to get
134 * @return object, NULL if none found
135 */
136 void* (*get)(library_t *this, char *name);
137
138 /**
139 * (Un-)Register an arbitrary object using the given name.
140 *
141 * @param name name to register object under
142 * @param object object to register, NULL to unregister
143 * @return TRUE if registered, FALSE if name already taken
144 */
145 bool (*set)(library_t *this, char *name, void *object);
146
147 /**
148 * Namespace used for settings etc. (i.e. the name of the binary that uses
149 * the library)
150 */
151 const char *ns;
152
153 /**
154 * Main configuration file passed to library_init(), the default, or NULL
155 */
156 char *conf;
157
158 /**
159 * Printf hook registering facility
160 */
161 printf_hook_t *printf_hook;
162
163 /**
164 * Proposal keywords registry
165 */
166 proposal_keywords_t *proposal;
167
168 /**
169 * POSIX capability dropping
170 */
171 capabilities_t *caps;
172
173 /**
174 * crypto algorithm registry and factory
175 */
176 crypto_factory_t *crypto;
177
178 /**
179 * credential constructor registry and factory
180 */
181 credential_factory_t *creds;
182
183 /**
184 * Manager for the credential set backends
185 */
186 credential_manager_t *credmgr;
187
188 /**
189 * Credential encoding registry and factory
190 */
191 cred_encoding_t *encoding;
192
193 /**
194 * Registry and factory for metadata creation
195 */
196 metadata_factory_t *metadata;
197
198 /**
199 * URL fetching facility
200 */
201 fetcher_manager_t *fetcher;
202
203 /**
204 * Manager for DNS resolvers
205 */
206 resolver_manager_t *resolver;
207
208 /**
209 * database construction factory
210 */
211 database_factory_t *db;
212
213 /**
214 * plugin loading facility
215 */
216 plugin_loader_t *plugins;
217
218 /**
219 * process jobs using a thread pool
220 */
221 processor_t *processor;
222
223 /**
224 * schedule jobs
225 */
226 scheduler_t *scheduler;
227
228 /**
229 * File descriptor monitoring
230 */
231 watcher_t *watcher;
232
233 /**
234 * Streams and Services
235 */
236 stream_manager_t *streams;
237
238 /**
239 * resolve hosts by DNS name
240 */
241 host_resolver_t *hosts;
242
243 /**
244 * various settings loaded from settings file
245 */
246 settings_t *settings;
247
248 /**
249 * integrity checker to verify code integrity
250 */
251 integrity_checker_t *integrity;
252
253 /**
254 * Leak detective, if built and enabled
255 */
256 leak_detective_t *leak_detective;
257 };
258
259 /**
260 * Initialize library, creates "lib" instance.
261 *
262 * library_init() may be called multiple times in a single process, but each
263 * caller must call library_deinit() for each call to library_init().
264 *
265 * The settings and namespace arguments are only used on the first call.
266 *
267 * @param settings file to read settings from, may be NULL for default or
268 * "" to not load any settings
269 * @param namespace name of the binary that uses the library, determines
270 * the first section name when reading config options.
271 * Defaults to libstrongswan if NULL.
272 * @return FALSE if integrity check failed or settings are invalid
273 */
274 bool library_init(char *settings, const char *namespace);
275
276 /**
277 * Deinitialize library, destroys "lib" instance.
278 */
279 void library_deinit();
280
281 /**
282 * Library instance, set after library_init() and before library_deinit() calls.
283 */
284 extern library_t *lib;
285
286 /**
287 * Add additional names used as alias for the namespace registered with
288 * library_init().
289 *
290 * To be called from __attribute__((constructor)) functions.
291 *
292 * @param ns additional namespace
293 */
294 void library_add_namespace(char *ns);
295
296 #endif /** LIBRARY_H_ @}*/