Migrated ha plugin to INIT/METHOD macros

This commit is contained in:
Martin Willi
2010-07-26 10:15:17 +02:00
parent c74c4c2a20
commit 00c1bd0606
10 changed files with 198 additions and 253 deletions
+30 -39
View File
@@ -92,10 +92,8 @@ struct private_ha_tunnel_t {
ha_creds_t creds;
};
/**
* Implementation of ha_tunnel_t.is_sa
*/
static bool is_sa(private_ha_tunnel_t *this, ike_sa_t *ike_sa)
METHOD(ha_tunnel_t, is_sa, bool,
private_ha_tunnel_t *this, ike_sa_t *ike_sa)
{
peer_cfg_t *cfg = this->backend.cfg;
@@ -112,11 +110,8 @@ typedef struct {
shared_key_t *key;
} shared_enum_t;
/**
* Implementation of shared_enum_t.enumerate
*/
static bool shared_enumerate(shared_enum_t *this, shared_key_t **key,
id_match_t *me, id_match_t *other)
METHOD(enumerator_t, shared_enumerate, bool,
shared_enum_t *this, shared_key_t **key, id_match_t *me, id_match_t *other)
{
if (this->key)
{
@@ -135,12 +130,9 @@ static bool shared_enumerate(shared_enum_t *this, shared_key_t **key,
return FALSE;
}
/**
* Implements ha_creds_t.create_shared_enumerator
*/
static enumerator_t* create_shared_enumerator(ha_creds_t *this,
shared_key_type_t type, identification_t *me,
identification_t *other)
METHOD(ha_creds_t, create_shared_enumerator, enumerator_t*,
ha_creds_t *this, shared_key_type_t type,
identification_t *me, identification_t *other)
{
shared_enum_t *enumerator;
@@ -157,28 +149,25 @@ static enumerator_t* create_shared_enumerator(ha_creds_t *this,
return NULL;
}
enumerator = malloc_thing(shared_enum_t);
enumerator->public.enumerate = (void*)shared_enumerate;
enumerator->public.destroy = (void*)free;
enumerator->key = this->key;
INIT(enumerator,
.public = {
.enumerate = (void*)_shared_enumerate,
.destroy = (void*)free,
},
.key = this->key,
);
return &enumerator->public;
}
/**
* Implementation of backend_t.create_peer_cfg_enumerator.
*/
static enumerator_t* create_peer_cfg_enumerator(ha_backend_t *this,
identification_t *me, identification_t *other)
METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
ha_backend_t *this, identification_t *me, identification_t *other)
{
return enumerator_create_single(this->cfg, NULL);
}
/**
* Implementation of backend_t.create_ike_cfg_enumerator.
*/
static enumerator_t* create_ike_cfg_enumerator(ha_backend_t *this,
host_t *me, host_t *other)
METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
ha_backend_t *this, host_t *me, host_t *other)
{
return enumerator_create_single(this->cfg->get_ike_cfg(this->cfg), NULL);
}
@@ -207,7 +196,7 @@ static void setup_tunnel(private_ha_tunnel_t *this,
chunk_clone(chunk_create(secret, strlen(secret))));
this->creds.public.create_private_enumerator = (void*)return_null;
this->creds.public.create_cert_enumerator = (void*)return_null;
this->creds.public.create_shared_enumerator = (void*)create_shared_enumerator;
this->creds.public.create_shared_enumerator = (void*)_create_shared_enumerator;
this->creds.public.create_cdp_enumerator = (void*)return_null;
this->creds.public.cache_cert = (void*)nop;
@@ -248,8 +237,8 @@ static void setup_tunnel(private_ha_tunnel_t *this,
peer_cfg->add_child_cfg(peer_cfg, child_cfg);
this->backend.cfg = peer_cfg;
this->backend.public.create_peer_cfg_enumerator = (void*)create_peer_cfg_enumerator;
this->backend.public.create_ike_cfg_enumerator = (void*)create_ike_cfg_enumerator;
this->backend.public.create_peer_cfg_enumerator = (void*)_create_peer_cfg_enumerator;
this->backend.public.create_ike_cfg_enumerator = (void*)_create_ike_cfg_enumerator;
this->backend.public.get_peer_cfg_by_name = (void*)return_null;
charon->backends->add_backend(charon->backends, &this->backend.public);
@@ -258,10 +247,8 @@ static void setup_tunnel(private_ha_tunnel_t *this,
this->trap = charon->traps->install(charon->traps, peer_cfg, child_cfg);
}
/**
* Implementation of ha_tunnel_t.destroy.
*/
static void destroy(private_ha_tunnel_t *this)
METHOD(ha_tunnel_t, destroy, void,
private_ha_tunnel_t *this)
{
if (this->backend.cfg)
{
@@ -287,10 +274,14 @@ static void destroy(private_ha_tunnel_t *this)
*/
ha_tunnel_t *ha_tunnel_create(char *local, char *remote, char *secret)
{
private_ha_tunnel_t *this = malloc_thing(private_ha_tunnel_t);
private_ha_tunnel_t *this;
this->public.is_sa = (bool(*)(ha_tunnel_t*, ike_sa_t *ike_sa))is_sa;
this->public.destroy = (void(*)(ha_tunnel_t*))destroy;
INIT(this,
.public = {
.is_sa = _is_sa,
.destroy = _destroy,
},
);
setup_tunnel(this, local, remote, secret);