Migrated uci_config_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner
2011-10-04 14:34:25 +02:00
parent d3e4e92e4a
commit 3837aadf4c
+50 -56
View File
@@ -133,10 +133,8 @@ static u_int create_rekey(char *string)
return 12 * 3600; return 12 * 3600;
} }
/** METHOD(enumerator_t, peer_enumerator_enumerate, bool,
* Implementation of peer_enumerator_t.public.enumerate peer_enumerator_t *this, peer_cfg_t **cfg)
*/
static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
{ {
char *name, *ike_proposal, *esp_proposal, *ike_rekey, *esp_rekey; char *name, *ike_proposal, *esp_proposal, *ike_rekey, *esp_rekey;
char *local_id, *local_addr, *local_net; char *local_id, *local_addr, *local_net;
@@ -177,9 +175,9 @@ static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
name, 2, ike_cfg, CERT_SEND_IF_ASKED, UNIQUE_NO, name, 2, ike_cfg, CERT_SEND_IF_ASKED, UNIQUE_NO,
1, create_rekey(ike_rekey), 0, /* keytries, rekey, reauth */ 1, create_rekey(ike_rekey), 0, /* keytries, rekey, reauth */
1800, 900, /* jitter, overtime */ 1800, 900, /* jitter, overtime */
TRUE, 60, /* mobike, dpddelay */ TRUE, 60, /* mobike, dpddelay */
NULL, NULL, /* vip, pool */ NULL, NULL, /* vip, pool */
FALSE, NULL, NULL); /* mediation, med by, peer id */ FALSE, NULL, NULL); /* mediation, med by, peer id */
auth = auth_cfg_create(); auth = auth_cfg_create();
auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PSK); auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PSK);
auth->add(auth, AUTH_RULE_IDENTITY, auth->add(auth, AUTH_RULE_IDENTITY,
@@ -208,32 +206,30 @@ static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
return FALSE; return FALSE;
} }
/**
* Implementation of peer_enumerator_t.public.destroy METHOD(enumerator_t, peer_enumerator_destroy, void,
*/ peer_enumerator_t *this)
static void peer_enumerator_destroy(peer_enumerator_t *this)
{ {
DESTROY_IF(this->peer_cfg); DESTROY_IF(this->peer_cfg);
this->inner->destroy(this->inner); this->inner->destroy(this->inner);
free(this); free(this);
} }
/** METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
* Implementation of backend_t.create_peer_cfg_enumerator. private_uci_config_t *this, identification_t *me, identification_t *other)
*/
static enumerator_t* create_peer_cfg_enumerator(private_uci_config_t *this,
identification_t *me,
identification_t *other)
{ {
peer_enumerator_t *e = malloc_thing(peer_enumerator_t); peer_enumerator_t *e;
e->public.enumerate = (void*)peer_enumerator_enumerate; INIT(e,
e->public.destroy = (void*)peer_enumerator_destroy; .public = {
e->peer_cfg = NULL; .enumerate = (void*)_peer_enumerator_enumerate,
e->inner = this->parser->create_section_enumerator(this->parser, .destroy = _peer_enumerator_destroy,
},
.inner = this->parser->create_section_enumerator(this->parser,
"local_id", "remote_id", "local_addr", "remote_addr", "local_id", "remote_id", "local_addr", "remote_addr",
"local_net", "remote_net", "ike_proposal", "esp_proposal", "local_net", "remote_net", "ike_proposal", "esp_proposal",
"ike_rekey", "esp_rekey", NULL); "ike_rekey", "esp_rekey", NULL),
);
if (!e->inner) if (!e->inner)
{ {
free(e); free(e);
@@ -254,10 +250,8 @@ typedef struct {
enumerator_t *inner; enumerator_t *inner;
} ike_enumerator_t; } ike_enumerator_t;
/** METHOD(enumerator_t, ike_enumerator_enumerate, bool,
* Implementation of peer_enumerator_t.public.enumerate ike_enumerator_t *this, ike_cfg_t **cfg)
*/
static bool ike_enumerator_enumerate(ike_enumerator_t *this, ike_cfg_t **cfg)
{ {
char *local_addr, *remote_addr, *ike_proposal; char *local_addr, *remote_addr, *ike_proposal;
@@ -281,29 +275,27 @@ static bool ike_enumerator_enumerate(ike_enumerator_t *this, ike_cfg_t **cfg)
return FALSE; return FALSE;
} }
/** METHOD(enumerator_t, ike_enumerator_destroy, void,
* Implementation of ike_enumerator_t.public.destroy ike_enumerator_t *this)
*/
static void ike_enumerator_destroy(ike_enumerator_t *this)
{ {
DESTROY_IF(this->ike_cfg); DESTROY_IF(this->ike_cfg);
this->inner->destroy(this->inner); this->inner->destroy(this->inner);
free(this); free(this);
} }
/** METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
* Implementation of backend_t.create_ike_cfg_enumerator. private_uci_config_t *this, host_t *me, host_t *other)
*/
static enumerator_t* create_ike_cfg_enumerator(private_uci_config_t *this,
host_t *me, host_t *other)
{ {
ike_enumerator_t *e = malloc_thing(ike_enumerator_t); ike_enumerator_t *e;
e->public.enumerate = (void*)ike_enumerator_enumerate; INIT(e,
e->public.destroy = (void*)ike_enumerator_destroy; .public = {
e->ike_cfg = NULL; .enumerate = (void*)_ike_enumerator_enumerate,
e->inner = this->parser->create_section_enumerator(this->parser, .destroy = _ike_enumerator_destroy,
"local_addr", "remote_addr", "ike_proposal", NULL); },
.inner = this->parser->create_section_enumerator(this->parser,
"local_addr", "remote_addr", "ike_proposal", NULL),
);
if (!e->inner) if (!e->inner)
{ {
free(e); free(e);
@@ -312,10 +304,8 @@ static enumerator_t* create_ike_cfg_enumerator(private_uci_config_t *this,
return &e->public; return &e->public;
} }
/** METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
* implements backend_t.get_peer_cfg_by_name. private_uci_config_t *this, char *name)
*/
static peer_cfg_t *get_peer_cfg_by_name(private_uci_config_t *this, char *name)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
peer_cfg_t *current, *found = NULL; peer_cfg_t *current, *found = NULL;
@@ -336,10 +326,8 @@ static peer_cfg_t *get_peer_cfg_by_name(private_uci_config_t *this, char *name)
return found; return found;
} }
/** METHOD(uci_config_t, destroy, void,
* Implementation of uci_config_t.destroy. private_uci_config_t *this)
*/
static void destroy(private_uci_config_t *this)
{ {
free(this); free(this);
} }
@@ -349,13 +337,19 @@ static void destroy(private_uci_config_t *this)
*/ */
uci_config_t *uci_config_create(uci_parser_t *parser) uci_config_t *uci_config_create(uci_parser_t *parser)
{ {
private_uci_config_t *this = malloc_thing(private_uci_config_t); private_uci_config_t *this;
this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator; INIT(this,
this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator; .public = {
this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name; .backend = {
this->public.destroy = (void(*)(uci_config_t*))destroy; .create_peer_cfg_enumerator = _create_peer_cfg_enumerator,
this->parser = parser; .create_ike_cfg_enumerator = _create_ike_cfg_enumerator,
.get_peer_cfg_by_name = _get_peer_cfg_by_name,
},
.destroy = _destroy,
},
.parser = parser,
);
return &this->public; return &this->public;
} }