]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Support hook suffixes to use the same hook multiple times
authorMartin Willi <martin@revosec.ch>
Tue, 9 Nov 2010 10:17:20 +0000 (11:17 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 5 Jan 2011 15:45:42 +0000 (16:45 +0100)
src/conftest/conftest.c
src/conftest/hooks/add_notify.c
src/conftest/hooks/ignore_message.c
src/conftest/hooks/ike_auth_fill.c
src/conftest/hooks/unencrypted_notify.c
src/conftest/hooks/unsort_message.c

index 9be14111846eecea3ea75bc690578bf9d5f3f1c9..0d610c5b4f4f61f82d5270a7281cea0397bc2ca8 100644 (file)
@@ -214,19 +214,27 @@ static bool load_keys(settings_t *settings, char *dir)
 static bool load_hooks()
 {
        enumerator_t *enumerator;
-       char *name, buf[64];
-       hook_t *(*create)(void);
+       char *name, *pos, buf[64];
+       hook_t *(*create)(char*);
        hook_t *hook;
 
        enumerator = conftest->test->create_section_enumerator(conftest->test,
                                                                                                                   "hooks");
        while (enumerator->enumerate(enumerator, &name))
        {
-               snprintf(buf, sizeof(buf), "%s_hook_create", name);
+               pos = strchr(name, '-');
+               if (pos)
+               {
+                       snprintf(buf, sizeof(buf), "%.*s_hook_create", pos - name, name);
+               }
+               else
+               {
+                       snprintf(buf, sizeof(buf), "%s_hook_create", name);
+               }
                create = dlsym(RTLD_DEFAULT, buf);
                if (create)
                {
-                       hook = create();
+                       hook = create(name);
                        if (hook)
                        {
                                conftest->hooks->insert_last(conftest->hooks, hook);
index d73bdbaf8feec346ca0c8eb43ecd0b23658e2cc5..4ae7c2db700be64b39b4ab7e9f0b30b3f0f67da3 100644 (file)
@@ -111,7 +111,7 @@ METHOD(hook_t, destroy, void,
 /**
  * Create the IKE_AUTH fill hook
  */
-hook_t *add_notify_hook_create(void)
+hook_t *add_notify_hook_create(char *name)
 {
        private_add_notify_t *this;
 
@@ -123,17 +123,17 @@ hook_t *add_notify_hook_create(void)
                        .destroy = _destroy,
                },
                .req = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.add_notify.request", TRUE),
+                                                                               "hooks.%s.request", TRUE, name),
                .id = conftest->test->get_int(conftest->test,
-                                                                               "hooks.add_notify.id", 0),
+                                                                               "hooks.%s.id", 0, name),
                .type = conftest->test->get_str(conftest->test,
-                                                                               "hooks.add_notify.type", ""),
+                                                                               "hooks.%s.type", "", name),
                .data = conftest->test->get_str(conftest->test,
-                                                                               "hooks.add_notify.data", ""),
+                                                                               "hooks.%s.data", "", name),
                .spi = conftest->test->get_int(conftest->test,
-                                                                               "hooks.add_notify.spi", 0),
+                                                                               "hooks.%s.spi", 0, name),
                .esp = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.add_notify.esp", FALSE),
+                                                                               "hooks.%s.esp", FALSE, name),
        );
 
        return &this->hook;
index 33182dd9b759337741a669a6f128c3024b64ac45..210f3ac5085361c895f43af6951e17c25baddab0 100644 (file)
@@ -66,7 +66,7 @@ METHOD(hook_t, destroy, void,
 /**
  * Create the ignore_message hook
  */
-hook_t *ignore_message_hook_create(void)
+hook_t *ignore_message_hook_create(char *name)
 {
        private_ignore_message_t *this;
 
@@ -78,11 +78,11 @@ hook_t *ignore_message_hook_create(void)
                        .destroy = _destroy,
                },
                .in = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.ignore_message.inbound", TRUE),
+                                                                               "hooks.%s.inbound", TRUE, name),
                .req = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.ignore_message.request", TRUE),
+                                                                               "hooks.%s.request", TRUE, name),
                .id = conftest->test->get_int(conftest->test,
-                                                                               "hooks.ignore_message.id", 0),
+                                                                               "hooks.%s.id", 0, name),
        );
 
        return &this->hook;
index 7f3ff08c2a4e5bd1ca5685469b7e1df35e2121d8..0e1a1d38fd229806cd330d151f7136ee2dc57549 100644 (file)
@@ -121,7 +121,7 @@ METHOD(hook_t, destroy, void,
 /**
  * Create the IKE_AUTH fill hook
  */
-hook_t *ike_auth_fill_hook_create(void)
+hook_t *ike_auth_fill_hook_create(char *name)
 {
        private_ike_auth_fill_t *this;
 
@@ -133,11 +133,11 @@ hook_t *ike_auth_fill_hook_create(void)
                        .destroy = _destroy,
                },
                .req = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.ike_auth_fill.request", TRUE),
+                                                                               "hooks.%s.request", TRUE, name),
                .id = conftest->test->get_int(conftest->test,
-                                                                               "hooks.ike_auth_fill.id", 1),
+                                                                               "hooks.%s.id", 1, name),
                .bytes = conftest->test->get_int(conftest->test,
-                                                                               "hooks.ike_auth_fill.bytes", 0),
+                                                                               "hooks.%s.bytes", 0, name),
        );
 
        return &this->hook;
index 7db929614724092fe08a648ee5b0ff5f704c1ac0..1d7f42def33b0fe46063bad5c2ed27ecd4e43c24 100644 (file)
@@ -126,7 +126,7 @@ METHOD(hook_t, destroy, void,
 /**
  * Create the IKE_AUTH fill hook
  */
-hook_t *unencrypted_notify_hook_create(void)
+hook_t *unencrypted_notify_hook_create(char *name)
 {
        private_unencrypted_notify_t *this;
 
@@ -138,15 +138,15 @@ hook_t *unencrypted_notify_hook_create(void)
                        .destroy = _destroy,
                },
                .id = conftest->test->get_int(conftest->test,
-                                                                               "hooks.unencrypted_notify.id", 2),
+                                                                               "hooks.%s.id", 2, name),
                .type = conftest->test->get_str(conftest->test,
-                                                                               "hooks.unencrypted_notify.type", ""),
+                                                                               "hooks.%s.type", "", name),
                .data = conftest->test->get_str(conftest->test,
-                                                                               "hooks.unencrypted_notify.data", ""),
+                                                                               "hooks.%s.data", "", name),
                .spi = conftest->test->get_int(conftest->test,
-                                                                               "hooks.unencrypted_notify.spi", 0),
+                                                                               "hooks.%s.spi", 0, name),
                .esp = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.unencrypted_notify.esp", FALSE),
+                                                                               "hooks.%s.esp", FALSE, name),
        );
 
        return &this->hook;
index c12f55601fed91af51d96e9cc9ed52f3a2f68f3e..9af13e8e076c247dc953e01c6b8223af517ee4d1 100644 (file)
@@ -110,7 +110,7 @@ METHOD(hook_t, destroy, void,
 /**
  * Create the IKE_AUTH fill hook
  */
-hook_t *unsort_message_hook_create(void)
+hook_t *unsort_message_hook_create(char *name)
 {
        private_unsort_message_t *this;
 
@@ -122,11 +122,11 @@ hook_t *unsort_message_hook_create(void)
                        .destroy = _destroy,
                },
                .req = conftest->test->get_bool(conftest->test,
-                                                                               "hooks.unsort_message.request", TRUE),
+                                                                               "hooks.%s.request", TRUE, name),
                .id = conftest->test->get_int(conftest->test,
-                                                                               "hooks.unsort_message.id", 0),
+                                                                               "hooks.%s.id", 0, name),
                .order = conftest->test->get_str(conftest->test,
-                                                                               "hooks.unsort_message.order", ""),
+                                                                               "hooks.%s.order", "", name),
        );
 
        return &this->hook;