Migrated remaining plugin_t implementations to INIT/METHOD macros
authorMartin Willi <martin@revosec.ch>
Mon, 11 Apr 2011 14:41:25 +0000 (16:41 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 15 Apr 2011 08:07:12 +0000 (10:07 +0200)
18 files changed:
src/libcharon/plugins/eap_aka/eap_aka_plugin.c
src/libcharon/plugins/eap_aka_3gpp2/eap_aka_3gpp2_plugin.c
src/libcharon/plugins/eap_gtc/eap_gtc_plugin.c
src/libcharon/plugins/eap_mschapv2/eap_mschapv2_plugin.c
src/libcharon/plugins/eap_sim/eap_sim_plugin.c
src/libcharon/plugins/eap_sim_file/eap_sim_file_plugin.c
src/libcharon/plugins/eap_simaka_pseudonym/eap_simaka_pseudonym_plugin.c
src/libcharon/plugins/eap_simaka_reauth/eap_simaka_reauth_plugin.c
src/libcharon/plugins/load_tester/load_tester_plugin.c
src/libcharon/plugins/medcli/medcli_plugin.c
src/libcharon/plugins/medsrv/medsrv_plugin.c
src/libcharon/plugins/nm/nm_plugin.c
src/libcharon/plugins/smp/smp.c
src/libcharon/plugins/uci/uci_plugin.c
src/libcharon/plugins/unit_tester/unit_tester.c
src/libcharon/plugins/updown/updown_plugin.c
src/libstrongswan/plugins/plugin_loader.c
src/pluto/plugins/xauth/xauth_plugin.c

index f928339..92f5e66 100644 (file)
 
 #include <daemon.h>
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(eap_aka_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       eap_aka_plugin_t *this)
 {
        charon->eap->remove_method(charon->eap,
                                                           (eap_constructor_t)eap_aka_server_create);
@@ -37,9 +35,13 @@ static void destroy(eap_aka_plugin_t *this)
  */
 plugin_t *eap_aka_plugin_create()
 {
-       eap_aka_plugin_t *this = malloc_thing(eap_aka_plugin_t);
+       eap_aka_plugin_t *this;
 
-       this->plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .plugin = {
+                       .destroy = _destroy,
+               },
+       );
 
        charon->eap->add_method(charon->eap, EAP_AKA, 0, EAP_SERVER,
                                                        (eap_constructor_t)eap_aka_server_create);
index 626e833..fc971b3 100644 (file)
@@ -48,10 +48,8 @@ struct private_eap_aka_3gpp2_t {
        eap_aka_3gpp2_functions_t *functions;
 };
 
-/**
- * Implementation of eap_aka_3gpp2_t.destroy.
- */
-static void destroy(private_eap_aka_3gpp2_t *this)
+METHOD(plugin_t, destroy, void,
+       private_eap_aka_3gpp2_t *this)
 {
        charon->sim->remove_card(charon->sim, &this->card->card);
        charon->sim->remove_provider(charon->sim, &this->provider->provider);
@@ -66,11 +64,17 @@ static void destroy(private_eap_aka_3gpp2_t *this)
  */
 plugin_t *eap_aka_3gpp2_plugin_create()
 {
-       private_eap_aka_3gpp2_t *this = malloc_thing(private_eap_aka_3gpp2_t);
+       private_eap_aka_3gpp2_t *this;
 
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               this->functions = eap_aka_3gpp2_functions_create();
+       );
 
-       this->functions = eap_aka_3gpp2_functions_create();
        if (!this->functions)
        {
                free(this);
index 91ba84b..4eb587d 100644 (file)
 /* missing in cababilities.h */
 #define CAP_AUDIT_WRITE 29
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(eap_gtc_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       eap_gtc_plugin_t *this)
 {
        charon->eap->remove_method(charon->eap,
                                                           (eap_constructor_t)eap_gtc_create_server);
@@ -39,9 +37,13 @@ static void destroy(eap_gtc_plugin_t *this)
  */
 plugin_t *eap_gtc_plugin_create()
 {
-       eap_gtc_plugin_t *this = malloc_thing(eap_gtc_plugin_t);
+       eap_gtc_plugin_t *this;
 
-       this->plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .plugin = {
+                       .destroy = _destroy,
+               },
+       );
 
        /* required for PAM authentication */
        charon->keep_cap(charon, CAP_AUDIT_WRITE);
index a7b41dd..f8130e6 100644 (file)
 
 #include <daemon.h>
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(eap_mschapv2_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       eap_mschapv2_plugin_t *this)
 {
        charon->eap->remove_method(charon->eap,
                                                           (eap_constructor_t)eap_mschapv2_create_server);
@@ -36,9 +34,13 @@ static void destroy(eap_mschapv2_plugin_t *this)
  */
 plugin_t *eap_mschapv2_plugin_create()
 {
-       eap_mschapv2_plugin_t *this = malloc_thing(eap_mschapv2_plugin_t);
+       eap_mschapv2_plugin_t *this;
 
-       this->plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .plugin = {
+                       .destroy = _destroy,
+               },
+       );
 
        charon->eap->add_method(charon->eap, EAP_MSCHAPV2, 0, EAP_SERVER,
                                                        (eap_constructor_t)eap_mschapv2_create_server);
index f0c9722..8eae6d7 100644 (file)
 
 #include <daemon.h>
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(eap_sim_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       eap_sim_plugin_t *this)
 {
        charon->eap->remove_method(charon->eap,
                                                           (eap_constructor_t)eap_sim_server_create);
@@ -37,9 +35,13 @@ static void destroy(eap_sim_plugin_t *this)
  */
 plugin_t *eap_sim_plugin_create()
 {
-       eap_sim_plugin_t *this = malloc_thing(eap_sim_plugin_t);
+       eap_sim_plugin_t *this;
 
-       this->plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .plugin = {
+                       .destroy = _destroy,
+               },
+       );
 
        charon->eap->add_method(charon->eap, EAP_SIM, 0, EAP_SERVER,
                                                        (eap_constructor_t)eap_sim_server_create);
index 4f25c35..5bb9a9a 100644 (file)
@@ -50,10 +50,8 @@ struct private_eap_sim_file_t {
        eap_sim_file_triplets_t *triplets;
 };
 
-/**
- * Implementation of eap_sim_file_t.destroy.
- */
-static void destroy(private_eap_sim_file_t *this)
+METHOD(plugin_t, destroy, void,
+       private_eap_sim_file_t *this)
 {
        charon->sim->remove_card(charon->sim, &this->card->card);
        charon->sim->remove_provider(charon->sim, &this->provider->provider);
@@ -68,12 +66,18 @@ static void destroy(private_eap_sim_file_t *this)
  */
 plugin_t *eap_sim_file_plugin_create()
 {
-       private_eap_sim_file_t *this = malloc_thing(private_eap_sim_file_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_eap_sim_file_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .triplets = eap_sim_file_triplets_create(TRIPLET_FILE),
+               .provider = eap_sim_file_provider_create(this->triplets),
+       );
 
-       this->triplets = eap_sim_file_triplets_create(TRIPLET_FILE);
-       this->provider = eap_sim_file_provider_create(this->triplets);
        if (!this->provider)
        {
                this->triplets->destroy(this->triplets);
index 81b9d7b..c4a1ec2 100644 (file)
@@ -42,10 +42,8 @@ struct private_eap_simaka_pseudonym_t {
        eap_simaka_pseudonym_provider_t *provider;
 };
 
-/**
- * Implementation of eap_simaka_pseudonym_t.destroy.
- */
-static void destroy(private_eap_simaka_pseudonym_t *this)
+METHOD(plugin_t, destroy, void,
+       private_eap_simaka_pseudonym_t *this)
 {
        charon->sim->remove_card(charon->sim, &this->card->card);
        charon->sim->remove_provider(charon->sim, &this->provider->provider);
@@ -61,11 +59,15 @@ plugin_t *eap_simaka_pseudonym_plugin_create()
 {
        private_eap_simaka_pseudonym_t *this;
 
-       this = malloc_thing(private_eap_simaka_pseudonym_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .provider = eap_simaka_pseudonym_provider_create(),
+       );
 
-       this->provider = eap_simaka_pseudonym_provider_create();
        if (!this->provider)
        {
                free(this);
index 987a0e1..fc7a0b2 100644 (file)
@@ -42,10 +42,8 @@ struct private_eap_simaka_reauth_t {
        eap_simaka_reauth_provider_t *provider;
 };
 
-/**
- * Implementation of eap_simaka_reauth_t.destroy.
- */
-static void destroy(private_eap_simaka_reauth_t *this)
+METHOD(plugin_t, destroy, void,
+       private_eap_simaka_reauth_t *this)
 {
        charon->sim->remove_card(charon->sim, &this->card->card);
        charon->sim->remove_provider(charon->sim, &this->provider->provider);
@@ -59,11 +57,17 @@ static void destroy(private_eap_simaka_reauth_t *this)
  */
 plugin_t *eap_simaka_reauth_plugin_create()
 {
-       private_eap_simaka_reauth_t *this = malloc_thing(private_eap_simaka_reauth_t);
+       private_eap_simaka_reauth_t *this;
 
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .provider = eap_simaka_reauth_provider_create(),
+       );
 
-       this->provider = eap_simaka_reauth_provider_create();
        if (!this->provider)
        {
                free(this);
index 8fd65ad..e9092e1 100644 (file)
@@ -146,10 +146,8 @@ static job_requeue_t do_load_test(private_load_tester_plugin_t *this)
        return JOB_REQUEUE_NONE;
 }
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_load_tester_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_load_tester_plugin_t *this)
 {
        this->iterations = -1;
        this->mutex->lock(this->mutex);
@@ -188,32 +186,37 @@ plugin_t *load_tester_plugin_create()
                return NULL;
        }
 
-       this = malloc_thing(private_load_tester_plugin_t);
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .delay = lib->settings->get_int(lib->settings,
+                                       "charon.plugins.load-tester.delay", 0),
+               .iterations = lib->settings->get_int(lib->settings,
+                                       "charon.plugins.load-tester.iterations", 1),
+               .initiators = lib->settings->get_int(lib->settings,
+                                       "charon.plugins.load-tester.initiators", 0),
+               .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+               .condvar = condvar_create(CONDVAR_TYPE_DEFAULT),
+               .config = load_tester_config_create(),
+               .creds = load_tester_creds_create(),
+               .listener = load_tester_listener_create(shutdown_on),
+       );
 
        lib->crypto->add_dh(lib->crypto, MODP_NULL, plugin_name,
                                                (dh_constructor_t)load_tester_diffie_hellman_create);
+       charon->backends->add_backend(charon->backends, &this->config->backend);
+       lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
+       charon->bus->add_listener(charon->bus, &this->listener->listener);
 
-       this->delay = lib->settings->get_int(lib->settings,
-                                       "charon.plugins.load-tester.delay", 0);
-       this->iterations = lib->settings->get_int(lib->settings,
-                                       "charon.plugins.load-tester.iterations", 1);
-       this->initiators = lib->settings->get_int(lib->settings,
-                                       "charon.plugins.load-tester.initiators", 0);
        if (lib->settings->get_bool(lib->settings,
                                        "charon.plugins.load-tester.shutdown_when_complete", 0))
        {
                shutdown_on = this->iterations * this->initiators;
        }
 
-       this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
-       this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
-       this->config = load_tester_config_create();
-       this->creds = load_tester_creds_create();
-       this->listener = load_tester_listener_create(shutdown_on);
-       charon->backends->add_backend(charon->backends, &this->config->backend);
-       lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
-       charon->bus->add_listener(charon->bus, &this->listener->listener);
 
        if (lib->settings->get_bool(lib->settings,
                                        "charon.plugins.load-tester.fake_kernel", FALSE))
index 6befbf4..30608a0 100644 (file)
@@ -54,10 +54,8 @@ struct private_medcli_plugin_t {
        medcli_listener_t *listener;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_medcli_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_medcli_plugin_t *this)
 {
        charon->bus->remove_listener(charon->bus, &this->listener->listener);
        charon->backends->remove_backend(charon->backends, &this->config->backend);
@@ -75,9 +73,15 @@ static void destroy(private_medcli_plugin_t *this)
 plugin_t *medcli_plugin_create()
 {
        char *uri;
-       private_medcli_plugin_t *this = malloc_thing(private_medcli_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_medcli_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        uri = lib->settings->get_str(lib->settings,
                                                                 "medcli.database", NULL);
index c150346..214a433 100644 (file)
@@ -48,10 +48,8 @@ struct private_medsrv_plugin_t {
        medsrv_config_t *config;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_medsrv_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_medsrv_plugin_t *this)
 {
        charon->backends->remove_backend(charon->backends, &this->config->backend);
        lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
@@ -67,9 +65,15 @@ static void destroy(private_medsrv_plugin_t *this)
 plugin_t *medsrv_plugin_create()
 {
        char *uri;
-       private_medsrv_plugin_t *this = malloc_thing(private_medsrv_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_medsrv_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        uri = lib->settings->get_str(lib->settings,
                                                                 "medsrv.database", NULL);
index fd0580b..860b83d 100644 (file)
@@ -67,10 +67,8 @@ static job_requeue_t run(private_nm_plugin_t *this)
        return JOB_REQUEUE_NONE;
 }
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_nm_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_nm_plugin_t *this)
 {
        if (this->loop)
        {
@@ -96,22 +94,27 @@ static void destroy(private_nm_plugin_t *this)
  */
 plugin_t *nm_plugin_create()
 {
-       private_nm_plugin_t *this = malloc_thing(private_nm_plugin_t);
+       private_nm_plugin_t *this;
 
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-
-       this->loop = NULL;
        g_type_init ();
        if (!g_thread_supported())
        {
                g_thread_init(NULL);
        }
 
-       this->creds = nm_creds_create();
-       this->handler = nm_handler_create();
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .creds = nm_creds_create(),
+               .handler = nm_handler_create(),
+               .plugin = nm_strongswan_plugin_new(this->creds, this->handler),
+       );
+
        hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
        lib->credmgr->add_set(lib->credmgr, &this->creds->set);
-       this->plugin = nm_strongswan_plugin_new(this->creds, this->handler);
        if (!this->plugin)
        {
                DBG1(DBG_CFG, "DBUS binding failed");
index 60937f2..0e6cf2a 100644 (file)
@@ -707,10 +707,8 @@ static job_requeue_t dispatch(private_smp_t *this)
        return JOB_REQUEUE_DIRECT;
 }
 
-/**
- * Implementation of itnerface_t.destroy.
- */
-static void destroy(private_smp_t *this)
+METHOD(plugin_t, destroy, void,
+       private_smp_t *this)
 {
        this->job->cancel(this->job);
        close(this->socket);
@@ -723,10 +721,16 @@ static void destroy(private_smp_t *this)
 plugin_t *smp_plugin_create()
 {
        struct sockaddr_un unix_addr = { AF_UNIX, IPSEC_PIDDIR "/charon.xml"};
-       private_smp_t *this = malloc_thing(private_smp_t);
+       private_smp_t *this;
        mode_t old;
 
-       this->public.plugin.destroy = (void (*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        /* set up unix socket */
        this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
index 4790ef4..6d6d5d2 100644 (file)
@@ -58,10 +58,8 @@ struct private_uci_plugin_t {
        uci_control_t *control;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_uci_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_uci_plugin_t *this)
 {
        charon->backends->remove_backend(charon->backends, &this->config->backend);
        lib->credmgr->remove_set(lib->credmgr, &this->creds->credential_set);
@@ -77,14 +75,20 @@ static void destroy(private_uci_plugin_t *this)
  */
 plugin_t *uci_plugin_create()
 {
-       private_uci_plugin_t *this = malloc_thing(private_uci_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_uci_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .parser = uci_parser_create(UCI_PACKAGE),
+               .config = uci_config_create(this->parser),
+               .creds = uci_creds_create(this->parser),
+               .control = uci_control_create(),
+       );
 
-       this->parser = uci_parser_create(UCI_PACKAGE);
-       this->config = uci_config_create(this->parser);
-       this->creds = uci_creds_create(this->parser);
-       this->control = uci_control_create();
        charon->backends->add_backend(charon->backends, &this->config->backend);
        lib->credmgr->add_set(lib->credmgr, &this->creds->credential_set);
 
index 5f6f94e..4a0347a 100644 (file)
@@ -92,10 +92,8 @@ static void run_tests(private_unit_tester_t *this)
                 success, run, failed, skipped);
 }
 
-/**
- * Implementation of 2007_t.destroy
- */
-static void destroy(private_unit_tester_t *this)
+METHOD(plugin_t, destroy, void,
+       private_unit_tester_t *this)
 {
        free(this);
 }
@@ -105,9 +103,15 @@ static void destroy(private_unit_tester_t *this)
  */
 plugin_t *unit_tester_plugin_create()
 {
-       private_unit_tester_t *this = malloc_thing(private_unit_tester_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_unit_tester_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        run_tests(this);
 
index 9d0591e..8b790cb 100644 (file)
@@ -36,10 +36,8 @@ struct private_updown_plugin_t {
        updown_listener_t *listener;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_updown_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_updown_plugin_t *this)
 {
        charon->bus->remove_listener(charon->bus, &this->listener->listener);
        this->listener->destroy(this->listener);
@@ -51,11 +49,17 @@ static void destroy(private_updown_plugin_t *this)
  */
 plugin_t *updown_plugin_create()
 {
-       private_updown_plugin_t *this = malloc_thing(private_updown_plugin_t);
+       private_updown_plugin_t *this;
 
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .listener = updown_listener_create(),
+       );
 
-       this->listener = updown_listener_create();
        charon->bus->add_listener(charon->bus, &this->listener->listener);
 
        return &this->public.plugin;
index 65bb35d..222ebb9 100644 (file)
@@ -258,7 +258,7 @@ plugin_loader_t *plugin_loader_create()
 
        INIT(this,
                .public = {
-                       .load = _load,
+                       .load = _load_plugins,
                        .unload = _unload,
                        .create_plugin_enumerator = _create_plugin_enumerator,
                        .destroy = _destroy,
index 74e16ea..8414649 100644 (file)
 #include "xauth_plugin.h"
 #include "xauth_default_provider.h"
 #include "xauth_default_verifier.h"
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(xauth_plugin_t *this)
+
+METHOD(plugin_t, destroy, void,
+       xauth_plugin_t *this)
 {
        free(this);
 }
@@ -31,9 +30,13 @@ static void destroy(xauth_plugin_t *this)
  */
 plugin_t *xauth_plugin_create()
 {
-       xauth_plugin_t *this = malloc_thing(xauth_plugin_t);
+       xauth_plugin_t *this;
 
-       this->plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .plugin = {
+                       .destroy = _destroy,
+               },
+       );
 
        pluto->xauth->add_provider(pluto->xauth, xauth_default_provider_create());
        pluto->xauth->add_verifier(pluto->xauth, xauth_default_verifier_create());