diff options
author | Tobias Brunner <tobias@strongswan.org> | 2014-01-22 11:50:39 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2014-02-12 14:34:31 +0100 |
commit | 34d3bfcf14b31011e7b880f7ad1dfeba27aaeae6 (patch) | |
tree | 45d8c0a54e1ac5f7454cf1f00b311aa48f5d705f /src/libstrongswan | |
parent | 4f8bd6d4049e2c1ce9aa33dd61522414fb078ec0 (diff) | |
download | strongswan-34d3bfcf14b31011e7b880f7ad1dfeba27aaeae6.tar.bz2 strongswan-34d3bfcf14b31011e7b880f7ad1dfeba27aaeae6.tar.xz |
lib: Add global config namespace
Diffstat (limited to 'src/libstrongswan')
-rw-r--r-- | src/libstrongswan/library.c | 4 | ||||
-rw-r--r-- | src/libstrongswan/library.h | 16 | ||||
-rw-r--r-- | src/libstrongswan/tests/test_runner.c | 4 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index 72fc2fa44..e0876ef9f 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -145,6 +145,7 @@ void library_deinit() threads_deinit(); backtrace_deinit(); + free((void*)this->public.ns); free(this); lib = NULL; } @@ -234,7 +235,7 @@ static bool check_memwipe() /* * see header file */ -bool library_init(char *settings) +bool library_init(char *settings, const char *namespace) { private_library_t *this; printf_hook_t *pfh; @@ -250,6 +251,7 @@ bool library_init(char *settings) .public = { .get = _get, .set = _set, + .ns = strdup(namespace ?: "libstrongswan"), }, .ref = 1, ); diff --git a/src/libstrongswan/library.h b/src/libstrongswan/library.h index e53cf09e2..4125328b7 100644 --- a/src/libstrongswan/library.h +++ b/src/libstrongswan/library.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2010-2014 Tobias Brunner * Copyright (C) 2008 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -140,6 +141,12 @@ struct library_t { bool (*set)(library_t *this, char *name, void *object); /** + * Namespace used for settings etc. (i.e. the name of the binary that uses + * the library) + */ + const char *ns; + + /** * Printf hook registering facility */ printf_hook_t *printf_hook; @@ -239,12 +246,17 @@ struct library_t { * Initialize library, creates "lib" instance. * * library_init() may be called multiple times in a single process, but each - * caller should call library_deinit() for each call to library_init(). + * caller must call library_deinit() for each call to library_init(). + * + * The settings and namespace arguments are only used on the first call. * * @param settings file to read settings from, may be NULL for default + * @param namespace name of the binary that uses the library, determines + * the first section name when reading config options. + * Defaults to libstrongswan if NULL. * @return FALSE if integrity check failed */ -bool library_init(char *settings); +bool library_init(char *settings, const char *namespace); /** * Deinitialize library, destroys "lib" instance. diff --git a/src/libstrongswan/tests/test_runner.c b/src/libstrongswan/tests/test_runner.c index 1e46cfe8e..0b26ee128 100644 --- a/src/libstrongswan/tests/test_runner.c +++ b/src/libstrongswan/tests/test_runner.c @@ -65,7 +65,7 @@ static array_t *load_suites(test_configuration_t configs[], bool old = FALSE; int i; - library_init(NULL); + library_init(NULL, "test-runner"); test_setup_handler(); @@ -178,7 +178,7 @@ static bool call_fixture(test_case_t *tcase, bool up) */ static bool pre_test(test_runner_init_t init) { - library_init(NULL); + library_init(NULL, "test-runner"); /* use non-blocking RNG to generate keys fast */ lib->settings->set_default_str(lib->settings, |