Migrated connect_manager_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner
2011-10-03 18:32:12 +02:00
parent 6401b18f12
commit 02846e5e7f
+91 -107
View File
@@ -130,25 +130,24 @@ static void endpoint_pair_destroy(endpoint_pair_t *this)
static endpoint_pair_t *endpoint_pair_create(endpoint_notify_t *initiator, static endpoint_pair_t *endpoint_pair_create(endpoint_notify_t *initiator,
endpoint_notify_t *responder, bool initiator_is_local) endpoint_notify_t *responder, bool initiator_is_local)
{ {
endpoint_pair_t *this = malloc_thing(endpoint_pair_t); endpoint_pair_t *this;
this->id = 0;
u_int32_t pi = initiator->get_priority(initiator); u_int32_t pi = initiator->get_priority(initiator);
u_int32_t pr = responder->get_priority(responder); u_int32_t pr = responder->get_priority(responder);
this->priority = pow(2, 32) * min(pi, pr) + 2 * max(pi, pr) + (pi > pr ? 1 : 0);
this->local = initiator_is_local ? initiator->get_base(initiator) INIT(this,
: responder->get_base(responder); .priority = pow(2, 32) * min(pi, pr) + 2 * max(pi, pr)
+ (pi > pr ? 1 : 0),
.local = initiator_is_local ? initiator->get_base(initiator)
: responder->get_base(responder),
.remote = initiator_is_local ? responder->get_host(responder)
: initiator->get_host(initiator),
.state = CHECK_WAITING,
);
this->local = this->local->clone(this->local); this->local = this->local->clone(this->local);
this->remote = initiator_is_local ? responder->get_host(responder)
: initiator->get_host(initiator);
this->remote = this->remote->clone(this->remote); this->remote = this->remote->clone(this->remote);
this->state = CHECK_WAITING;
this->retransmitted = 0;
this->packet = NULL;
return this; return this;
} }
@@ -239,23 +238,24 @@ static check_list_t *check_list_create(identification_t *initiator,
linked_list_t *initiator_endpoints, linked_list_t *initiator_endpoints,
bool is_initiator) bool is_initiator)
{ {
check_list_t *this = malloc_thing(check_list_t); check_list_t *this;
this->connect_id = chunk_clone(connect_id); INIT(this,
.connect_id = chunk_clone(connect_id),
this->initiator.id = initiator->clone(initiator); .initiator = {
this->initiator.key = chunk_clone(initiator_key); .id = initiator->clone(initiator),
this->initiator.endpoints = initiator_endpoints->clone_offset(initiator_endpoints, offsetof(endpoint_notify_t, clone)); .key = chunk_clone(initiator_key),
.endpoints = initiator_endpoints->clone_offset(initiator_endpoints,
this->responder.id = responder->clone(responder); offsetof(endpoint_notify_t, clone)),
this->responder.key = chunk_empty; },
this->responder.endpoints = NULL; .responder = {
.id = responder->clone(responder),
this->pairs = linked_list_create(); },
this->triggered = linked_list_create(); .pairs = linked_list_create(),
this->state = CHECK_NONE; .triggered = linked_list_create(),
this->is_initiator = is_initiator; .state = CHECK_NONE,
this->is_finishing = FALSE; .is_initiator = is_initiator,
);
return this; return this;
} }
@@ -294,11 +294,13 @@ static void initiated_destroy(initiated_t *this)
static initiated_t *initiated_create(identification_t *id, static initiated_t *initiated_create(identification_t *id,
identification_t *peer_id) identification_t *peer_id)
{ {
initiated_t *this = malloc_thing(initiated_t); initiated_t *this;
this->id = id->clone(id); INIT(this,
this->peer_id = peer_id->clone(peer_id); .id = id->clone(id),
this->mediated = linked_list_create(); .peer_id = peer_id->clone(peer_id),
.mediated = linked_list_create(),
);
return this; return this;
} }
@@ -351,16 +353,11 @@ static void check_destroy(check_t *this)
*/ */
static check_t *check_create() static check_t *check_create()
{ {
check_t *this = malloc_thing(check_t); check_t *this;
this->connect_id = chunk_empty; INIT(this,
this->auth = chunk_empty; .mid = 0,
this->endpoint_raw = chunk_empty; );
this->src = NULL;
this->dst = NULL;
this->endpoint = NULL;
this->mid = 0;
return this; return this;
} }
@@ -396,10 +393,12 @@ static void callback_data_destroy(callback_data_t *this)
static callback_data_t *callback_data_create(private_connect_manager_t *connect_manager, static callback_data_t *callback_data_create(private_connect_manager_t *connect_manager,
chunk_t connect_id) chunk_t connect_id)
{ {
callback_data_t *this = malloc_thing(callback_data_t); callback_data_t *this;
this->connect_manager = connect_manager; INIT(this,
this->connect_id = chunk_clone(connect_id); .connect_manager = connect_manager,
this->mid = 0; .connect_id = chunk_clone(connect_id),
.mid = 0,
);
return this; return this;
} }
@@ -443,11 +442,11 @@ static void initiate_data_destroy(initiate_data_t *this)
static initiate_data_t *initiate_data_create(check_list_t *checklist, static initiate_data_t *initiate_data_create(check_list_t *checklist,
initiated_t *initiated) initiated_t *initiated)
{ {
initiate_data_t *this = malloc_thing(initiate_data_t); initiate_data_t *this;
INIT(this,
this->checklist = checklist; .checklist = checklist,
this->initiated = initiated; .initiated = initiated,
);
return this; return this;
} }
@@ -1345,10 +1344,8 @@ static void process_request(private_connect_manager_t *this, check_t *check,
check_destroy(response); check_destroy(response);
} }
/** METHOD(connect_manager_t, process_check, void,
* Implementation of connect_manager_t.process_check. private_connect_manager_t *this, message_t *message)
*/
static void process_check(private_connect_manager_t *this, message_t *message)
{ {
if (message->parse_body(message, NULL) != SUCCESS) if (message->parse_body(message, NULL) != SUCCESS)
{ {
@@ -1411,12 +1408,9 @@ static void process_check(private_connect_manager_t *this, message_t *message)
check_destroy(check); check_destroy(check);
} }
/** METHOD(connect_manager_t, check_and_register, bool,
* Implementation of connect_manager_t.check_and_register. private_connect_manager_t *this, identification_t *id,
*/ identification_t *peer_id, ike_sa_id_t *mediated_sa)
static bool check_and_register(private_connect_manager_t *this,
identification_t *id, identification_t *peer_id,
ike_sa_id_t *mediated_sa)
{ {
initiated_t *initiated; initiated_t *initiated;
bool already_there = TRUE; bool already_there = TRUE;
@@ -1445,12 +1439,9 @@ static bool check_and_register(private_connect_manager_t *this,
return already_there; return already_there;
} }
/** METHOD(connect_manager_t, check_and_initiate, void,
* Implementation of connect_manager_t.check_and_initiate. private_connect_manager_t *this, ike_sa_id_t *mediation_sa,
*/ identification_t *id, identification_t *peer_id)
static void check_and_initiate(private_connect_manager_t *this,
ike_sa_id_t *mediation_sa, identification_t *id,
identification_t *peer_id)
{ {
initiated_t *initiated; initiated_t *initiated;
@@ -1477,14 +1468,10 @@ static void check_and_initiate(private_connect_manager_t *this,
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(connect_manager_t, set_initiator_data, status_t,
* Implementation of connect_manager_t.set_initiator_data. private_connect_manager_t *this, identification_t *initiator,
*/ identification_t *responder, chunk_t connect_id, chunk_t key,
static status_t set_initiator_data(private_connect_manager_t *this, linked_list_t *endpoints, bool is_initiator)
identification_t *initiator,
identification_t *responder,
chunk_t connect_id, chunk_t key,
linked_list_t *endpoints, bool is_initiator)
{ {
check_list_t *checklist; check_list_t *checklist;
@@ -1507,12 +1494,9 @@ static status_t set_initiator_data(private_connect_manager_t *this,
return SUCCESS; return SUCCESS;
} }
/** METHOD(connect_manager_t, set_responder_data, status_t,
* Implementation of connect_manager_t.set_responder_data. private_connect_manager_t *this, chunk_t connect_id, chunk_t key,
*/ linked_list_t *endpoints)
static status_t set_responder_data(private_connect_manager_t *this,
chunk_t connect_id, chunk_t key,
linked_list_t *endpoints)
{ {
check_list_t *checklist; check_list_t *checklist;
@@ -1541,10 +1525,8 @@ static status_t set_responder_data(private_connect_manager_t *this,
return SUCCESS; return SUCCESS;
} }
/** METHOD(connect_manager_t, stop_checks, status_t,
* Implementation of connect_manager_t.stop_checks. private_connect_manager_t *this, chunk_t connect_id)
*/
static status_t stop_checks(private_connect_manager_t *this, chunk_t connect_id)
{ {
check_list_t *checklist; check_list_t *checklist;
@@ -1568,16 +1550,16 @@ static status_t stop_checks(private_connect_manager_t *this, chunk_t connect_id)
return SUCCESS; return SUCCESS;
} }
/** METHOD(connect_manager_t, destroy, void,
* Implementation of connect_manager_t.destroy. private_connect_manager_t *this)
*/
static void destroy(private_connect_manager_t *this)
{ {
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
this->hasher->destroy(this->hasher); this->checklists->destroy_function(this->checklists,
this->checklists->destroy_function(this->checklists, (void*)check_list_destroy); (void*)check_list_destroy);
this->initiated->destroy_function(this->initiated, (void*)initiated_destroy); this->initiated->destroy_function(this->initiated,
(void*)initiated_destroy);
DESTROY_IF(this->hasher);
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
this->mutex->destroy(this->mutex); this->mutex->destroy(this->mutex);
@@ -1589,28 +1571,30 @@ static void destroy(private_connect_manager_t *this)
*/ */
connect_manager_t *connect_manager_create() connect_manager_t *connect_manager_create()
{ {
private_connect_manager_t *this = malloc_thing(private_connect_manager_t); private_connect_manager_t *this;
this->public.destroy = (void(*)(connect_manager_t*))destroy; INIT(this,
this->public.check_and_register = (bool(*)(connect_manager_t*,identification_t*,identification_t*,ike_sa_id_t*))check_and_register; .public = {
this->public.check_and_initiate = (void(*)(connect_manager_t*,ike_sa_id_t*,identification_t*,identification_t*))check_and_initiate; .destroy = _destroy,
this->public.set_initiator_data = (status_t(*)(connect_manager_t*,identification_t*,identification_t*,chunk_t,chunk_t,linked_list_t*,bool))set_initiator_data; .check_and_register = _check_and_register,
this->public.set_responder_data = (status_t(*)(connect_manager_t*,chunk_t,chunk_t,linked_list_t*))set_responder_data; .check_and_initiate = _check_and_initiate,
this->public.process_check = (void(*)(connect_manager_t*,message_t*))process_check; .set_initiator_data = _set_initiator_data,
this->public.stop_checks = (status_t(*)(connect_manager_t*,chunk_t))stop_checks; .set_responder_data = _set_responder_data,
.process_check = _process_check,
.stop_checks = _stop_checks,
},
.hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1),
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
.checklists = linked_list_create(),
.initiated = linked_list_create(),
);
this->hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
if (this->hasher == NULL) if (this->hasher == NULL)
{ {
DBG1(DBG_IKE, "unable to create connect manager, SHA1 not supported"); DBG1(DBG_IKE, "unable to create connect manager, SHA1 not supported");
free(this); destroy(this);
return NULL; return NULL;
} }
this->checklists = linked_list_create(); return &this->public;
this->initiated = linked_list_create();
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
return (connect_manager_t*)this;
} }