Migrated ike_init to INIT/METHOD macros
authorAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 3 Oct 2011 20:28:32 +0000 (22:28 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 3 Oct 2011 20:28:32 +0000 (22:28 +0200)
src/libcharon/sa/tasks/ike_init.c

index 7aee809..b8e66c7 100644 (file)
@@ -221,10 +221,8 @@ static void process_payloads(private_ike_init_t *this, message_t *message)
        enumerator->destroy(enumerator);
 }
 
-/**
- * Implementation of task_t.process for initiator
- */
-static status_t build_i(private_ike_init_t *this, message_t *message)
+METHOD(task_t, build_i, status_t,
+       private_ike_init_t *this, message_t *message)
 {
        rng_t *rng;
 
@@ -287,10 +285,8 @@ static status_t build_i(private_ike_init_t *this, message_t *message)
        return NEED_MORE;
 }
 
-/**
- * Implementation of task_t.process for responder
- */
-static status_t process_r(private_ike_init_t *this, message_t *message)
+METHOD(task_t, process_r,  status_t,
+       private_ike_init_t *this, message_t *message)
 {
        rng_t *rng;
 
@@ -361,10 +357,8 @@ static bool derive_keys(private_ike_init_t *this,
        return TRUE;
 }
 
-/**
- * Implementation of task_t.build for responder
- */
-static status_t build_r(private_ike_init_t *this, message_t *message)
+METHOD(task_t, build_r, status_t,
+       private_ike_init_t *this, message_t *message)
 {
        /* check if we have everything we need */
        if (this->proposal == NULL ||
@@ -409,10 +403,8 @@ static status_t build_r(private_ike_init_t *this, message_t *message)
        return SUCCESS;
 }
 
-/**
- * Implementation of task_t.process for initiator
- */
-static status_t process_i(private_ike_init_t *this, message_t *message)
+METHOD(task_t, process_i, status_t,
+       private_ike_init_t *this, message_t *message)
 {
        enumerator_t *enumerator;
        payload_t *payload;
@@ -510,34 +502,14 @@ static status_t process_i(private_ike_init_t *this, message_t *message)
        return SUCCESS;
 }
 
-/**
- * Implementation of task_t.get_type
- */
-static task_type_t get_type(private_ike_init_t *this)
+METHOD(task_t, get_type, task_type_t,
+       private_ike_init_t *this)
 {
        return IKE_INIT;
 }
 
-/**
- * Implementation of task_t.get_type
- */
-static chunk_t get_lower_nonce(private_ike_init_t *this)
-{
-       if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
-                          min(this->my_nonce.len, this->other_nonce.len)) < 0)
-       {
-               return this->my_nonce;
-       }
-       else
-       {
-               return this->other_nonce;
-       }
-}
-
-/**
- * Implementation of task_t.migrate
- */
-static void migrate(private_ike_init_t *this, ike_sa_t *ike_sa)
+METHOD(task_t, migrate, void,
+       private_ike_init_t *this, ike_sa_t *ike_sa)
 {
        DESTROY_IF(this->proposal);
        chunk_free(&this->other_nonce);
@@ -549,10 +521,8 @@ static void migrate(private_ike_init_t *this, ike_sa_t *ike_sa)
        this->dh = this->keymat->create_dh(this->keymat, this->dh_group);
 }
 
-/**
- * Implementation of task_t.destroy
- */
-static void destroy(private_ike_init_t *this)
+METHOD(task_t, destroy, void,
+       private_ike_init_t *this)
 {
        DESTROY_IF(this->dh);
        DESTROY_IF(this->proposal);
@@ -562,40 +532,53 @@ static void destroy(private_ike_init_t *this)
        free(this);
 }
 
+METHOD(ike_init_t, get_lower_nonce, chunk_t,
+       private_ike_init_t *this)
+{
+       if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
+                          min(this->my_nonce.len, this->other_nonce.len)) < 0)
+       {
+               return this->my_nonce;
+       }
+       else
+       {
+               return this->other_nonce;
+       }
+}
+
 /*
  * Described in header.
  */
 ike_init_t *ike_init_create(ike_sa_t *ike_sa, bool initiator, ike_sa_t *old_sa)
 {
-       private_ike_init_t *this = malloc_thing(private_ike_init_t);
+       private_ike_init_t *this;
+
+       INIT(this,
+               .public = {
+                       .task = {
+                               .get_type = _get_type,
+                               .migrate = _migrate,
+                               .destroy = _destroy,
+                       },
+                       .get_lower_nonce = _get_lower_nonce,
+               },
+               .ike_sa = ike_sa,
+               .initiator = initiator,
+               .dh_group = MODP_NONE,
+               .keymat = ike_sa->get_keymat(ike_sa),
+               .old_sa = old_sa,
+       );
 
-       this->public.get_lower_nonce = (chunk_t(*)(ike_init_t*))get_lower_nonce;
-       this->public.task.get_type = (task_type_t(*)(task_t*))get_type;
-       this->public.task.migrate = (void(*)(task_t*,ike_sa_t*))migrate;
-       this->public.task.destroy = (void(*)(task_t*))destroy;
        if (initiator)
        {
-               this->public.task.build = (status_t(*)(task_t*,message_t*))build_i;
-               this->public.task.process = (status_t(*)(task_t*,message_t*))process_i;
+               this->public.task.build = _build_i;
+               this->public.task.process = _process_i;
        }
        else
        {
-               this->public.task.build = (status_t(*)(task_t*,message_t*))build_r;
-               this->public.task.process = (status_t(*)(task_t*,message_t*))process_r;
+               this->public.task.build = _build_r;
+               this->public.task.process = _process_r;
        }
 
-       this->ike_sa = ike_sa;
-       this->initiator = initiator;
-       this->dh_group = MODP_NONE;
-       this->dh = NULL;
-       this->keymat = ike_sa->get_keymat(ike_sa);
-       this->my_nonce = chunk_empty;
-       this->other_nonce = chunk_empty;
-       this->cookie = chunk_empty;
-       this->proposal = NULL;
-       this->config = NULL;
-       this->old_sa = old_sa;
-       this->retry = 0;
-
        return &this->public;
 }