aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2011-05-06 09:50:02 +0200
committerMartin Willi <martin@revosec.ch>2011-05-16 15:24:15 +0200
commit4baf1f3bfece66766b78eddab33014ebaee99a89 (patch)
treefaf294100ca5dc82a81666dfb1e64ab44fb3091f
parent83245de0ac10cfd11034ad8dadf1695153c9c540 (diff)
downloadstrongswan-4baf1f3bfece66766b78eddab33014ebaee99a89.tar.bz2
strongswan-4baf1f3bfece66766b78eddab33014ebaee99a89.tar.xz
Migrated controller_t to INIT/METHOD macros
-rw-r--r--src/libcharon/control/controller.c195
-rw-r--r--src/libcharon/control/controller.h2
2 files changed, 98 insertions, 99 deletions
diff --git a/src/libcharon/control/controller.c b/src/libcharon/control/controller.c
index bc386b75e..09291c8c8 100644
--- a/src/libcharon/control/controller.c
+++ b/src/libcharon/control/controller.c
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 2007 Martin Willi
+ * Copyright (C) 2007-2011 Martin Willi
+ * Copyright (C) 2011 revosec AG
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -96,6 +97,7 @@ typedef struct interface_job_t interface_job_t;
* job for asynchronous listen operations
*/
struct interface_job_t {
+
/**
* job interface
*/
@@ -107,12 +109,9 @@ struct interface_job_t {
interface_listener_t listener;
};
-/**
- * listener log function
- */
-static bool listener_log(interface_listener_t *this, debug_t group,
- level_t level, int thread, ike_sa_t *ike_sa,
- char* format, va_list args)
+METHOD(listener_t, listener_log, bool,
+ interface_listener_t *this, debug_t group, level_t level, int thread,
+ ike_sa_t *ike_sa, char* format, va_list args)
{
if (this->ike_sa == ike_sa)
{
@@ -130,11 +129,8 @@ METHOD(job_t, get_priority_medium, job_priority_t,
return JOB_PRIO_MEDIUM;
}
-/**
- * Implementation of listener_t.ike_state_change
- */
-static bool listener_ike_state(interface_listener_t *this, ike_sa_t *ike_sa,
- ike_sa_state_t state)
+METHOD(listener_t, ike_state_change, bool,
+ interface_listener_t *this, ike_sa_t *ike_sa, ike_sa_state_t state)
{
if (this->ike_sa == ike_sa)
{
@@ -166,11 +162,9 @@ static bool listener_ike_state(interface_listener_t *this, ike_sa_t *ike_sa,
return TRUE;
}
-/**
- * Implementation of listener_t.child_state_change
- */
-static bool listener_child_state(interface_listener_t *this, ike_sa_t *ike_sa,
- child_sa_t *child_sa, child_sa_state_t state)
+METHOD(listener_t, child_state_change, bool,
+ interface_listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
+ child_sa_state_t state)
{
if (this->ike_sa == ike_sa)
{
@@ -197,10 +191,8 @@ static bool listener_child_state(interface_listener_t *this, ike_sa_t *ike_sa,
return TRUE;
}
-/**
- * cleanup job if job is never executed
- */
-static void recheckin(interface_job_t *job)
+METHOD(job_t, recheckin, void,
+ interface_job_t *job)
{
if (job->listener.ike_sa)
{
@@ -209,19 +201,15 @@ static void recheckin(interface_job_t *job)
}
}
-/**
- * Implementation of controller_t.create_ike_sa_iterator.
- */
-static enumerator_t* create_ike_sa_enumerator(controller_t *this, bool wait)
+METHOD(controller_t, create_ike_sa_enumerator, enumerator_t*,
+ private_controller_t *this, bool wait)
{
return charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager,
wait);
}
-/**
- * execute function for initiate
- */
-static status_t initiate_execute(interface_job_t *job)
+METHOD(job_t, initiate_execute, void,
+ interface_job_t *job)
{
ike_sa_t *ike_sa;
interface_listener_t *listener = &job->listener;
@@ -240,25 +228,26 @@ static status_t initiate_execute(interface_job_t *job)
if (ike_sa->initiate(ike_sa, listener->child_cfg, 0, NULL, NULL) == SUCCESS)
{
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
- return SUCCESS;
+ listener->status = SUCCESS;
+ }
+ else
+ {
+ charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
+ ike_sa);
+ listener->status = FAILED;
}
- charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, ike_sa);
- return FAILED;
}
-/**
- * Implementation of controller_t.initiate.
- */
-static status_t initiate(private_controller_t *this,
- peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
- controller_cb_t callback, void *param)
+METHOD(controller_t, initiate, status_t,
+ private_controller_t *this, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
+ controller_cb_t callback, void *param)
{
interface_job_t job = {
.listener = {
.public = {
- .log = (void*)listener_log,
- .ike_state_change = (void*)listener_ike_state,
- .child_state_change = (void*)listener_child_state,
+ .log = _listener_log,
+ .ike_state_change = _ike_state_change,
+ .child_state_change = _child_state_change,
},
.callback = callback,
.param = param,
@@ -267,23 +256,24 @@ static status_t initiate(private_controller_t *this,
.peer_cfg = peer_cfg,
},
.public = {
- .execute = (void*)initiate_execute,
+ .execute = _initiate_execute,
.get_priority = _get_priority_medium,
- .destroy = (void*)recheckin,
+ .destroy = _recheckin,
},
};
if (callback == NULL)
{
- return initiate_execute(&job);
+ initiate_execute(&job);
+ }
+ else
+ {
+ charon->bus->listen(charon->bus, &job.listener.public, &job.public);
}
- charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
return job.listener.status;
}
-/**
- * execute function for terminate_ike
- */
-static status_t terminate_ike_execute(interface_job_t *job)
+METHOD(job_t, terminate_ike_execute, void,
+ interface_job_t *job)
{
interface_listener_t *listener = &job->listener;
ike_sa_t *ike_sa = listener->ike_sa;
@@ -294,25 +284,27 @@ static status_t terminate_ike_execute(interface_job_t *job)
{
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
/* delete failed */
- return FAILED;
+ listener->status = FAILED;
+ }
+ else
+ {
+ charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
+ ike_sa);
+ listener->status = SUCCESS;
}
- charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, ike_sa);
- return SUCCESS;
}
-/**
- * Implementation of controller_t.terminate_ike.
- */
-static status_t terminate_ike(controller_t *this, u_int32_t unique_id,
- controller_cb_t callback, void *param)
+METHOD(controller_t, terminate_ike, status_t,
+ controller_t *this, u_int32_t unique_id,
+ controller_cb_t callback, void *param)
{
ike_sa_t *ike_sa;
interface_job_t job = {
.listener = {
.public = {
- .log = (void*)listener_log,
- .ike_state_change = (void*)listener_ike_state,
- .child_state_change = (void*)listener_child_state,
+ .log = _listener_log,
+ .ike_state_change = _ike_state_change,
+ .child_state_change = _child_state_change,
},
.callback = callback,
.param = param,
@@ -320,9 +312,9 @@ static status_t terminate_ike(controller_t *this, u_int32_t unique_id,
.id = unique_id,
},
.public = {
- .execute = (void*)terminate_ike_execute,
+ .execute = _terminate_ike_execute,
.get_priority = _get_priority_medium,
- .destroy = (void*)recheckin,
+ .destroy = _recheckin,
},
};
@@ -337,18 +329,19 @@ static status_t terminate_ike(controller_t *this, u_int32_t unique_id,
if (callback == NULL)
{
- return terminate_ike_execute(&job);
+ terminate_ike_execute(&job);
+ }
+ else
+ {
+ charon->bus->listen(charon->bus, &job.listener.public, &job.public);
+ /* checkin of the ike_sa happend in the thread that executed the job */
+ charon->bus->set_sa(charon->bus, NULL);
}
- charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
- /* checkin of the ike_sa happend in the thread that executed the job */
- charon->bus->set_sa(charon->bus, NULL);
return job.listener.status;
}
-/**
- * execute function for terminate_child
- */
-static status_t terminate_child_execute(interface_job_t *job)
+METHOD(job_t, terminate_child_execute, void,
+ interface_job_t *job)
{
interface_listener_t *listener = &job->listener;
ike_sa_t *ike_sa = listener->ike_sa;
@@ -359,17 +352,18 @@ static status_t terminate_child_execute(interface_job_t *job)
child_sa->get_spi(child_sa, TRUE)) != DESTROY_ME)
{
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
- return SUCCESS;
+ listener->status = SUCCESS;
+ }
+ else
+ {
+ charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
+ ike_sa);
+ listener->status = FAILED;
}
- charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, ike_sa);
- return FAILED;
}
-/**
- * Implementation of controller_t.terminate_child.
- */
-static status_t terminate_child(controller_t *this, u_int32_t reqid,
- controller_cb_t callback, void *param)
+METHOD(controller_t, terminate_child, status_t,
+ controller_t *this, u_int32_t reqid, controller_cb_t callback, void *param)
{
ike_sa_t *ike_sa;
child_sa_t *child_sa;
@@ -377,9 +371,9 @@ static status_t terminate_child(controller_t *this, u_int32_t reqid,
interface_job_t job = {
.listener = {
.public = {
- .log = (void*)listener_log,
- .ike_state_change = (void*)listener_ike_state,
- .child_state_change = (void*)listener_child_state,
+ .log = _listener_log,
+ .ike_state_change = _ike_state_change,
+ .child_state_change = _child_state_change,
},
.callback = callback,
.param = param,
@@ -387,9 +381,9 @@ static status_t terminate_child(controller_t *this, u_int32_t reqid,
.id = reqid,
},
.public = {
- .execute = (void*)terminate_child_execute,
+ .execute = _terminate_child_execute,
.get_priority = _get_priority_medium,
- .destroy = (void*)recheckin,
+ .destroy = _recheckin,
},
};
@@ -426,11 +420,14 @@ static status_t terminate_child(controller_t *this, u_int32_t reqid,
if (callback == NULL)
{
- return terminate_child_execute(&job);
+ terminate_child_execute(&job);
+ }
+ else
+ {
+ charon->bus->listen(charon->bus, &job.listener.public, &job.public);
+ /* checkin of the ike_sa happend in the thread that executed the job */
+ charon->bus->set_sa(charon->bus, NULL);
}
- charon->bus->listen(charon->bus, &job.listener.public, (job_t*)&job);
- /* checkin of the ike_sa happend in the thread that executed the job */
- charon->bus->set_sa(charon->bus, NULL);
return job.listener.status;
}
@@ -438,15 +435,13 @@ static status_t terminate_child(controller_t *this, u_int32_t reqid,
* See header
*/
bool controller_cb_empty(void *param, debug_t group, level_t level,
- ike_sa_t *ike_sa, char *format, va_list args)
+ ike_sa_t *ike_sa, char *format, va_list args)
{
return TRUE;
}
-/**
- * Implementation of stroke_t.destroy.
- */
-static void destroy(private_controller_t *this)
+METHOD(controller_t, destroy, void,
+ private_controller_t *this)
{
free(this);
}
@@ -456,13 +451,17 @@ static void destroy(private_controller_t *this)
*/
controller_t *controller_create(void)
{
- private_controller_t *this = malloc_thing(private_controller_t);
+ private_controller_t *this;
- this->public.create_ike_sa_enumerator = (enumerator_t*(*)(controller_t*, bool))create_ike_sa_enumerator;
- this->public.initiate = (status_t(*)(controller_t*,peer_cfg_t*,child_cfg_t*,controller_cb_t,void*))initiate;
- this->public.terminate_ike = (status_t(*)(controller_t*,u_int32_t,controller_cb_t, void*))terminate_ike;
- this->public.terminate_child = (status_t(*)(controller_t*,u_int32_t,controller_cb_t, void *param))terminate_child;
- this->public.destroy = (void (*)(controller_t*))destroy;
+ INIT(this,
+ .public = {
+ .create_ike_sa_enumerator = _create_ike_sa_enumerator,
+ .initiate = _initiate,
+ .terminate_ike = _terminate_ike,
+ .terminate_child = _terminate_child,
+ .destroy = _destroy,
+ },
+ );
return &this->public;
}
diff --git a/src/libcharon/control/controller.h b/src/libcharon/control/controller.h
index cf0f0a18b..738c1d409 100644
--- a/src/libcharon/control/controller.h
+++ b/src/libcharon/control/controller.h
@@ -56,7 +56,7 @@ typedef struct controller_t controller_t;
*
* Passing NULL as callback to the managers function calls them asynchronously.
* If a callback is specified, they are called synchronously. There is a default
- * callback "controller_cb_empty" if you wan't to call a function
+ * callback "controller_cb_empty" if you want to call a function
* synchronously, but don't need a callback.
*/
struct controller_t {