lib: Add global config namespace
authorTobias Brunner <tobias@strongswan.org>
Wed, 22 Jan 2014 10:50:39 +0000 (11:50 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 12 Feb 2014 13:34:31 +0000 (14:34 +0100)
38 files changed:
scripts/aes-test.c
scripts/crypt_burn.c
scripts/dh_speed.c
scripts/dnssec.c
scripts/fetch.c
scripts/hash_burn.c
scripts/key2keyid.c
scripts/keyid2sql.c
scripts/malloc_speed.c
scripts/pubkey_speed.c
scripts/tls_test.c
src/_copyright/_copyright.c
src/charon-cmd/charon-cmd.c
src/charon-nm/charon-nm.c
src/charon-tkm/src/charon-tkm.c
src/charon/charon.c
src/checksum/checksum_builder.c
src/conftest/conftest.c
src/dumm/ext/dumm.c
src/dumm/main.c
src/frontends/android/jni/libandroidbridge/charonservice.c
src/frontends/osx/charon-xpc/charon-xpc.c
src/libimcv/imcv.c
src/libimcv/imv/imv_policy_manager.c
src/libimcv/plugins/imv_os/pacman.c
src/libpts/plugins/imv_attestation/attest.c
src/libstrongswan/library.c
src/libstrongswan/library.h
src/libstrongswan/tests/test_runner.c
src/manager/main.c
src/medsrv/main.c
src/openac/openac.c
src/pki/pki.c
src/pool/pool.c
src/pt-tls-client/pt-tls-client.c
src/scepclient/scepclient.c
src/starter/starter.c
src/stroke/stroke.c

index f326b7e..eb94180 100644 (file)
@@ -556,7 +556,7 @@ int main(int argc, char *argv[])
        ctx.in = stdin;
        ctx.out = stdout;
 
-       library_init(NULL);
+       library_init(NULL, "aes-test");
        atexit(library_deinit);
 
        while (true)
index 8101f9c..729472e 100644 (file)
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
        int i = 0, limit = 0;
 
 
-       library_init(NULL);
+       library_init(NULL, "crypt_burn");
        lib->plugins->load(lib->plugins, PLUGINS);
        atexit(library_deinit);
 
index dc0a287..8a782d8 100644 (file)
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
                usage();
        }
 
-       library_init(NULL);
+       library_init(NULL, "dh_speed");
        lib->plugins->load(lib->plugins, argv[1]);
        atexit(library_deinit);
 
index 0cddfc4..9d35c7c 100644 (file)
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
        rr_set_t *rrset;
        rr_t *rr;
 
-       library_init(NULL);
+       library_init(NULL, "dnssec");
        atexit(library_deinit);
 
        dbg = dbg_dnssec;
index f58b37f..a7d98c9 100644 (file)
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
 {
        chunk_t res;
 
-       library_init(NULL);
+       library_init(NULL, "fetch");
        atexit(library_deinit);
        lib->plugins->load(lib->plugins, PLUGINS);
 
index 20e5642..97eab0d 100644 (file)
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
        char buffer[1024];
        int limit = 0, i = 0;
 
-       library_init(NULL);
+       library_init(NULL, "hash_burn");
        lib->plugins->load(lib->plugins, PLUGINS);
        atexit(library_deinit);
 
index 31f3bee..e9a4ee6 100644 (file)
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
        char buf[8096];
        int read;
 
-       library_init(NULL);
+       library_init(NULL, "key2keyid");
        lib->plugins->load(lib->plugins, PLUGINS);
        atexit(library_deinit);
 
index 6e9a133..4625789 100644 (file)
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
        char buf[8096];
        int read, n;
 
-       library_init(NULL);
+       library_init(NULL, "keyid2sql");
        lib->plugins->load(lib->plugins, PLUGINS);
        atexit(library_deinit);
 
index 85d51a2..2038098 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
        int sizes[16] = { 1, 13, 100, 1000, 16, 10000, 50, 17,
                                          123, 32, 8, 64, 8096, 1024, 123, 9 };
 
-       library_init(NULL);
+       library_init(NULL, "malloc_speed");
        atexit(library_deinit);
 
        print_mallinfo();
index f7e7516..66279ad 100644 (file)
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
                usage();
        }
 
-       library_init(NULL);
+       library_init(NULL, "pubkey_speed");
        lib->plugins->load(lib->plugins, argv[1]);
        atexit(library_deinit);
 
index e1e8ca8..7ec477a 100644 (file)
@@ -251,7 +251,7 @@ static void cleanup()
  */
 static void init()
 {
-       library_init(NULL);
+       library_init(NULL, "tls_test");
 
        dbg = dbg_tls;
 
index f9f0a85..806f780 100644 (file)
@@ -76,7 +76,7 @@ main(int argc, char *argv[])
        const char **notice = copyright;
        const char **co;
 
-       library_init(NULL);
+       library_init(NULL, "_copyright");
        atexit(library_deinit);
 
        while ((opt = getopt_long(argc, argv, "", opts, NULL)) != EOF)
index 0c24fd1..13f9785 100644 (file)
@@ -322,7 +322,7 @@ int main(int argc, char *argv[])
 
        dbg = dbg_stderr;
        atexit(library_deinit);
-       if (!library_init(NULL))
+       if (!library_init(NULL, "charon-cmd"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index 9ce6dba..12667ab 100644 (file)
@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
        dbg = dbg_syslog;
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "charon-nm"))
        {
                library_deinit();
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
index 3db0674..1e9fecd 100644 (file)
@@ -250,7 +250,7 @@ int main(int argc, char *argv[])
        dbg = dbg_syslog;
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, dmn_name))
        {
                library_deinit();
                exit(status);
index 340f852..d799691 100644 (file)
@@ -289,7 +289,7 @@ int main(int argc, char *argv[])
        dbg = dbg_stderr;
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "charon"))
        {
                library_deinit();
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
index ae9ba93..cc8185e 100644 (file)
@@ -136,7 +136,7 @@ int main(int argc, char* argv[])
        /* avoid confusing leak reports in build process */
        setenv("LEAK_DETECTIVE_DISABLE", "1", 0);
        /* don't use a strongswan.conf, forces integrity check to disabled */
-       library_init("");
+       library_init("", "checksum_builder");
        atexit(library_deinit);
 
        integrity = integrity_checker_create(NULL);
index faf9df9..d935058 100644 (file)
@@ -435,7 +435,7 @@ int main(int argc, char *argv[])
        char *suite_file = "suite.conf", *test_file = NULL, *preload, *plugins;
        file_logger_t *logger;
 
-       if (!library_init(NULL))
+       if (!library_init(NULL, "conftest"))
        {
                library_deinit();
                return SS_RC_LIBSTRONGSWAN_INTEGRITY;
index 5acda3a..03ecbe4 100644 (file)
@@ -774,7 +774,7 @@ void Init_dumm()
        /* there are too many to report, rubyruby... */
        setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
 
-       library_init(NULL);
+       library_init(NULL, "dumm");
 
        dumm = dumm_create(NULL);
 
index 4cdf468..a53e1f6 100644 (file)
@@ -479,7 +479,7 @@ int main(int argc, char *argv[])
        enumerator_t *enumerator;
        guest_t *guest;
 
-       library_init(NULL);
+       library_init(NULL, "dumm");
        gtk_init(&argc, &argv);
 
        pages = linked_list_create();
index 60485b6..d5a68bb 100644 (file)
@@ -600,7 +600,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, jboolean,
        dbg = dbg_android;
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "charon"))
        {
                library_deinit();
                return FALSE;
index 0a30ff8..74ad214 100644 (file)
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
 
        dbg = dbg_stderr;
        atexit(library_deinit);
-       if (!library_init(NULL))
+       if (!library_init(NULL, "charon-xpc"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index b5862da..aa55746 100644 (file)
@@ -109,7 +109,7 @@ bool libimcv_init(bool is_imv)
        else
        {
                /* we are the first to initialize libstrongswan */
-               if (!library_init(NULL))
+               if (!library_init(NULL, "libimcv"))
                {
                        return FALSE;
                }
index 61e0cd0..15d291a 100644 (file)
@@ -288,7 +288,7 @@ int main(int argc, char *argv[])
        atexit(library_deinit);
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "imv_policy_manager"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index 57cc62a..019e2ad 100644 (file)
@@ -466,12 +466,12 @@ int main(int argc, char *argv[])
        atexit(cleanup);
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "pacman"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
        if (!lib->plugins->load(lib->plugins,
-                       lib->settings->get_str(lib->settings, "attest.load", "sqlite")))
+                       lib->settings->get_str(lib->settings, "pacman.load", "sqlite")))
        {
                exit(SS_RC_INITIALIZATION_FAILED);
        }
index 4d25df3..6e63c26 100644 (file)
@@ -439,7 +439,7 @@ int main(int argc, char *argv[])
        atexit(library_deinit);
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "attest"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index 72fc2fa..e0876ef 100644 (file)
@@ -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,
        );
index e53cf09..4125328 100644 (file)
@@ -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.
index 1e46cfe..0b26ee1 100644 (file)
@@ -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,
index 5c845b1..b616908 100644 (file)
@@ -34,7 +34,7 @@ int main (int arc, char *argv[])
        bool debug;
        int threads, timeout;
 
-       library_init(NULL);
+       library_init(NULL, "manager");
        if (!lib->plugins->load(lib->plugins,
                        lib->settings->get_str(lib->settings, "manager.load", PLUGINS)))
        {
index 6f08b97..745fcc3 100644 (file)
@@ -33,7 +33,7 @@ int main(int arc, char *argv[])
        char *uri;
        int timeout, threads;
 
-       library_init(NULL);
+       library_init(NULL, "medsrv");
        if (!lib->plugins->load(lib->plugins,
                        lib->settings->get_str(lib->settings, "medsrv.load", PLUGINS)))
        {
index 1996025..8862e9a 100644 (file)
@@ -229,7 +229,7 @@ int main(int argc, char **argv)
 
        /* initialize library */
        atexit(library_deinit);
-       if (!library_init(NULL))
+       if (!library_init(NULL, "openac"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index ecc0702..eb614dd 100644 (file)
@@ -168,7 +168,7 @@ static void remove_callback()
 int main(int argc, char *argv[])
 {
        atexit(library_deinit);
-       if (!library_init(NULL))
+       if (!library_init(NULL, "pki"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index 05043cd..cc58f78 100644 (file)
@@ -1212,7 +1212,7 @@ int main(int argc, char *argv[])
        atexit(library_deinit);
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "pool"))
        {
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
index e7d75f0..90edb0c 100644 (file)
@@ -166,7 +166,7 @@ static void init()
                        PLUGIN_PROVIDE(CUSTOM, "pt-tls-client"),
                                PLUGIN_DEPENDS(CUSTOM, "tnccs-manager"),
        };
-       library_init(NULL);
+       library_init(NULL, "pt-tls-client");
        libtnccs_init();
 
        dbg = dbg_pt_tls;
index ec892cc..d7abcb4 100644 (file)
@@ -487,7 +487,7 @@ int main(int argc, char **argv)
        err_t ugh = NULL;
 
        /* initialize library */
-       if (!library_init(NULL))
+       if (!library_init(NULL, "scepclient"))
        {
                library_deinit();
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
index 06eb142..87ad66d 100644 (file)
@@ -419,7 +419,7 @@ int main (int argc, char **argv)
        bool attach_gdb = FALSE;
        bool load_warning = FALSE;
 
-       library_init(NULL);
+       library_init(NULL, "starter");
        atexit(library_deinit);
 
        libhydra_init("starter");
index 75f0145..69c8ea2 100644 (file)
@@ -480,7 +480,7 @@ int main(int argc, char *argv[])
        const stroke_token_t *token;
        int res = 0;
 
-       library_init(NULL);
+       library_init(NULL, "stroke");
        atexit(library_deinit);
 
        if (argc < 2)