Merge branch 'master' of git.strongswan.org:strongswan
authorAndreas Steffen <andi@brisbane.(none)>
Fri, 26 Nov 2010 13:07:18 +0000 (14:07 +0100)
committerAndreas Steffen <andi@brisbane.(none)>
Fri, 26 Nov 2010 13:07:18 +0000 (14:07 +0100)
src/libcharon/config/backend_manager.c
src/libhydra/plugins/attr/attr_plugin.c
src/libhydra/plugins/attr_sql/attr_sql_plugin.c
src/libhydra/plugins/kernel_klips/kernel_klips_plugin.c
src/libhydra/plugins/kernel_netlink/kernel_netlink_plugin.c
src/libhydra/plugins/kernel_pfkey/kernel_pfkey_plugin.c
src/libhydra/plugins/kernel_pfroute/kernel_pfroute_plugin.c
src/libhydra/plugins/resolve/resolve_plugin.c

index 90ef585..7b69eda 100644 (file)
@@ -128,11 +128,8 @@ static ike_cfg_match_t get_ike_match(ike_cfg_t *cand, host_t *me, host_t *other)
        return match;
 }
 
-/**
- * implements backend_manager_t.get_ike_cfg.
- */
-static ike_cfg_t *get_ike_cfg(private_backend_manager_t *this,
-                                                         host_t *me, host_t *other)
+METHOD(backend_manager_t, get_ike_cfg, ike_cfg_t*,
+       private_backend_manager_t *this, host_t *me, host_t *other)
 {
        ike_cfg_t *current, *found = NULL;
        enumerator_t *enumerator;
@@ -308,12 +305,9 @@ static void insert_sorted(match_entry_t *entry, linked_list_t *list,
        }
 }
 
-/**
- * Implements backend_manager_t.create_peer_cfg_enumerator.
- */
-static enumerator_t *create_peer_cfg_enumerator(private_backend_manager_t *this,
-                                                       host_t *me, host_t *other, identification_t *my_id,
-                                                       identification_t *other_id)
+METHOD(backend_manager_t, create_peer_cfg_enumerator, enumerator_t*,
+       private_backend_manager_t *this, host_t *me, host_t *other,
+       identification_t *my_id, identification_t *other_id)
 {
        enumerator_t *enumerator;
        peer_data_t *data;
@@ -372,10 +366,8 @@ static enumerator_t *create_peer_cfg_enumerator(private_backend_manager_t *this,
                                                                        (void*)peer_enum_filter_destroy);
 }
 
-/**
- * implements backend_manager_t.get_peer_cfg_by_name.
- */
-static peer_cfg_t *get_peer_cfg_by_name(private_backend_manager_t *this, char *name)
+METHOD(backend_manager_t, get_peer_cfg_by_name, peer_cfg_t*,
+       private_backend_manager_t *this, char *name)
 {
        backend_t *backend;
        peer_cfg_t *config = NULL;
@@ -392,30 +384,24 @@ static peer_cfg_t *get_peer_cfg_by_name(private_backend_manager_t *this, char *n
        return config;
 }
 
-/**
- * Implementation of backend_manager_t.remove_backend.
- */
-static void remove_backend(private_backend_manager_t *this, backend_t *backend)
+METHOD(backend_manager_t, remove_backend, void,
+       private_backend_manager_t *this, backend_t *backend)
 {
        this->lock->write_lock(this->lock);
        this->backends->remove(this->backends, backend, NULL);
        this->lock->unlock(this->lock);
 }
 
-/**
- * Implementation of backend_manager_t.add_backend.
- */
-static void add_backend(private_backend_manager_t *this, backend_t *backend)
+METHOD(backend_manager_t, add_backend, void,
+       private_backend_manager_t *this, backend_t *backend)
 {
        this->lock->write_lock(this->lock);
        this->backends->insert_last(this->backends, backend);
        this->lock->unlock(this->lock);
 }
 
-/**
- * Implementation of backend_manager_t.destroy.
- */
-static void destroy(private_backend_manager_t *this)
+METHOD(backend_manager_t, destroy, void,
+       private_backend_manager_t *this)
 {
        this->backends->destroy(this->backends);
        this->lock->destroy(this->lock);
@@ -424,20 +410,24 @@ static void destroy(private_backend_manager_t *this)
 
 /*
  * Described in header-file
+
  */
 backend_manager_t *backend_manager_create()
 {
-       private_backend_manager_t *this = malloc_thing(private_backend_manager_t);
-
-       this->public.get_ike_cfg = (ike_cfg_t* (*)(backend_manager_t*, host_t*, host_t*))get_ike_cfg;
-       this->public.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_manager_t*,char*))get_peer_cfg_by_name;
-       this->public.create_peer_cfg_enumerator = (enumerator_t* (*)(backend_manager_t*,host_t*,host_t*,identification_t*,identification_t*))create_peer_cfg_enumerator;
-       this->public.add_backend = (void(*)(backend_manager_t*, backend_t *backend))add_backend;
-       this->public.remove_backend = (void(*)(backend_manager_t*, backend_t *backend))remove_backend;
-       this->public.destroy = (void (*)(backend_manager_t*))destroy;
+       private_backend_manager_t *this;
 
-       this->backends = linked_list_create();
-       this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT);
+       INIT(this,
+               .public = {
+                       .get_ike_cfg = _get_ike_cfg,
+                       .get_peer_cfg_by_name = _get_peer_cfg_by_name,
+                       .create_peer_cfg_enumerator = _create_peer_cfg_enumerator,
+                       .add_backend = _add_backend,
+                       .remove_backend = _remove_backend,
+                       .destroy = _destroy,
+               },
+               .backends = linked_list_create(),
+               .lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
+       );
 
        return &this->public;
 }
index 24c00bb..0f66b68 100644 (file)
@@ -36,10 +36,8 @@ struct private_attr_plugin_t {
        attr_provider_t *provider;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_attr_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_attr_plugin_t *this)
 {
        hydra->attributes->remove_provider(hydra->attributes, &this->provider->provider);
        this->provider->destroy(this->provider);
@@ -51,11 +49,16 @@ static void destroy(private_attr_plugin_t *this)
  */
 plugin_t *attr_plugin_create()
 {
-       private_attr_plugin_t *this = malloc_thing(private_attr_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_attr_plugin_t *this;
 
-       this->provider = attr_provider_create();
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .provider = attr_provider_create(),
+       );
        hydra->attributes->add_provider(hydra->attributes, &this->provider->provider);
 
        return &this->public.plugin;
index 70e7a22..ca9de02 100644 (file)
@@ -43,10 +43,8 @@ struct private_attr_sql_plugin_t {
 
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_attr_sql_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_attr_sql_plugin_t *this)
 {
        hydra->attributes->remove_provider(hydra->attributes, &this->attribute->provider);
        this->attribute->destroy(this->attribute);
@@ -59,21 +57,26 @@ static void destroy(private_attr_sql_plugin_t *this)
  */
 plugin_t *attr_sql_plugin_create()
 {
-       char *uri;
        private_attr_sql_plugin_t *this;
+       char *uri;
 
-       uri = lib->settings->get_str(lib->settings, "libhydra.plugins.attr-sql.database", NULL);
+       uri = lib->settings->get_str(lib->settings, "libhydra.plugins.attr-sql.database",
+                                                                                                NULL);
        if (!uri)
        {
                DBG1(DBG_CFG, "attr-sql plugin: database URI not set");
                return NULL;
        }
 
-       this = malloc_thing(private_attr_sql_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .db = lib->db->create(lib->db, uri),
+       );
 
-       this->db = lib->db->create(lib->db, uri);
        if (!this->db)
        {
                DBG1(DBG_CFG, "attr-sql plugin failed to connect to database");
index 1a22835..3c312ca 100644 (file)
@@ -32,10 +32,8 @@ struct private_kernel_klips_plugin_t {
        kernel_klips_plugin_t public;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_kernel_klips_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_kernel_klips_plugin_t *this)
 {
        hydra->kernel_interface->remove_ipsec_interface(hydra->kernel_interface,
                                                (kernel_ipsec_constructor_t)kernel_klips_ipsec_create);
@@ -47,10 +45,15 @@ static void destroy(private_kernel_klips_plugin_t *this)
  */
 plugin_t *kernel_klips_plugin_create()
 {
-       private_kernel_klips_plugin_t *this = malloc_thing(private_kernel_klips_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-
+       private_kernel_klips_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
        hydra->kernel_interface->add_ipsec_interface(hydra->kernel_interface,
                                                (kernel_ipsec_constructor_t)kernel_klips_ipsec_create);
 
index 212675d..9fc1a03 100644 (file)
@@ -33,10 +33,8 @@ struct private_kernel_netlink_plugin_t {
        kernel_netlink_plugin_t public;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_kernel_netlink_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_kernel_netlink_plugin_t *this)
 {
        hydra->kernel_interface->remove_ipsec_interface(hydra->kernel_interface,
                                        (kernel_ipsec_constructor_t)kernel_netlink_ipsec_create);
@@ -50,10 +48,15 @@ static void destroy(private_kernel_netlink_plugin_t *this)
  */
 plugin_t *kernel_netlink_plugin_create()
 {
-       private_kernel_netlink_plugin_t *this = malloc_thing(private_kernel_netlink_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_kernel_netlink_plugin_t *this;
 
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
        hydra->kernel_interface->add_ipsec_interface(hydra->kernel_interface,
                                        (kernel_ipsec_constructor_t)kernel_netlink_ipsec_create);
        hydra->kernel_interface->add_net_interface(hydra->kernel_interface,
index 781ba50..9e7a790 100644 (file)
@@ -32,10 +32,8 @@ struct private_kernel_pfkey_plugin_t {
        kernel_pfkey_plugin_t public;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_kernel_pfkey_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_kernel_pfkey_plugin_t *this)
 {
        hydra->kernel_interface->remove_ipsec_interface(hydra->kernel_interface,
                                                (kernel_ipsec_constructor_t)kernel_pfkey_ipsec_create);
@@ -47,10 +45,15 @@ static void destroy(private_kernel_pfkey_plugin_t *this)
  */
 plugin_t *kernel_pfkey_plugin_create()
 {
-       private_kernel_pfkey_plugin_t *this = malloc_thing(private_kernel_pfkey_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-
+       private_kernel_pfkey_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
        hydra->kernel_interface->add_ipsec_interface(hydra->kernel_interface,
                                                (kernel_ipsec_constructor_t)kernel_pfkey_ipsec_create);
 
index 5f351bd..a4cb53e 100644 (file)
@@ -32,10 +32,8 @@ struct private_kernel_pfroute_plugin_t {
        kernel_pfroute_plugin_t public;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_kernel_pfroute_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_kernel_pfroute_plugin_t *this)
 {
        hydra->kernel_interface->remove_net_interface(hydra->kernel_interface,
                                                (kernel_net_constructor_t)kernel_pfroute_net_create);
@@ -47,10 +45,15 @@ static void destroy(private_kernel_pfroute_plugin_t *this)
  */
 plugin_t *kernel_pfroute_plugin_create()
 {
-       private_kernel_pfroute_plugin_t *this = malloc_thing(private_kernel_pfroute_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-
+       private_kernel_pfroute_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
        hydra->kernel_interface->add_net_interface(hydra->kernel_interface,
                                                (kernel_net_constructor_t)kernel_pfroute_net_create);
 
index 5021295..ad18c70 100644 (file)
@@ -36,10 +36,8 @@ struct private_resolve_plugin_t {
        resolve_handler_t *handler;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_resolve_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_resolve_plugin_t *this)
 {
        hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler);
        this->handler->destroy(this->handler);
@@ -51,10 +49,16 @@ static void destroy(private_resolve_plugin_t *this)
  */
 plugin_t *resolve_plugin_create()
 {
-       private_resolve_plugin_t *this = malloc_thing(private_resolve_plugin_t);
+       private_resolve_plugin_t *this;
 
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-       this->handler = resolve_handler_create();
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+               .handler = resolve_handler_create(),
+       );
        hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
 
        return &this->public.plugin;