- return value cleanup
authorMartin Willi <martin@strongswan.org>
Mon, 28 Nov 2005 20:29:47 +0000 (20:29 -0000)
committerMartin Willi <martin@strongswan.org>
Mon, 28 Nov 2005 20:29:47 +0000 (20:29 -0000)
85 files changed:
Source/charon/encoding/message.c
Source/charon/encoding/payloads/encryption_payload.c
Source/charon/encoding/payloads/sa_payload.c
Source/charon/network/host.c
Source/charon/network/host.h
Source/charon/network/packet.c
Source/charon/queues/event_queue.c
Source/charon/queues/event_queue.h
Source/charon/queues/job_queue.c
Source/charon/queues/job_queue.h
Source/charon/queues/jobs/delete_ike_sa_job.c
Source/charon/queues/send_queue.c
Source/charon/queues/send_queue.h
Source/charon/sa/ike_sa.c
Source/charon/sa/ike_sa.h
Source/charon/sa/ike_sa_id.c
Source/charon/sa/ike_sa_id.h
Source/charon/sa/ike_sa_manager.c
Source/charon/sa/ike_sa_manager.h
Source/charon/sa/states/ike_auth_requested.c
Source/charon/sa/states/ike_sa_established.c
Source/charon/sa/states/ike_sa_init_requested.c
Source/charon/sa/states/ike_sa_init_responded.c
Source/charon/sa/states/ike_sa_init_responded.h
Source/charon/sa/states/initiator_init.c
Source/charon/sa/states/responder_init.c
Source/charon/sa/states/responder_init.h
Source/charon/sa/states/state.h
Source/charon/testcases/aes_cbc_crypter_test.c
Source/charon/testcases/diffie_hellman_test.c
Source/charon/testcases/hasher_test.c
Source/charon/testcases/hmac_signer_test.c
Source/charon/testcases/ike_sa_id_test.c
Source/charon/testcases/ike_sa_manager_test.c
Source/charon/testcases/linked_list_test.c
Source/charon/testcases/parser_test.c
Source/charon/testcases/receiver_test.c
Source/charon/testcases/scheduler_test.c
Source/charon/testcases/send_queue_test.c
Source/charon/testcases/sender_test.c
Source/charon/testcases/thread_pool_test.c
Source/charon/threads/receiver.c
Source/charon/threads/receiver.h
Source/charon/threads/scheduler.c
Source/charon/threads/scheduler.h
Source/charon/threads/sender.c
Source/charon/threads/sender.h
Source/charon/threads/thread_pool.c
Source/charon/threads/thread_pool.h
Source/charon/transforms/crypters/aes_cbc_crypter.c
Source/charon/transforms/crypters/aes_cbc_crypter.h
Source/charon/transforms/crypters/crypter.c
Source/charon/transforms/crypters/crypter.h
Source/charon/transforms/diffie_hellman.c
Source/charon/transforms/diffie_hellman.h
Source/charon/transforms/hashers/hasher.c
Source/charon/transforms/hashers/hasher.h
Source/charon/transforms/hashers/md5_hasher.c
Source/charon/transforms/hashers/md5_hasher.h
Source/charon/transforms/hashers/sha1_hasher.c
Source/charon/transforms/hashers/sha1_hasher.h
Source/charon/transforms/hmac.c
Source/charon/transforms/hmac.h
Source/charon/transforms/prf_plus.c
Source/charon/transforms/prf_plus.h
Source/charon/transforms/prfs/hmac_prf.c
Source/charon/transforms/prfs/hmac_prf.h
Source/charon/transforms/prfs/prf.h
Source/charon/transforms/signers/hmac_signer.c
Source/charon/transforms/signers/hmac_signer.h
Source/charon/transforms/signers/signer.c
Source/charon/transforms/signers/signer.h
Source/charon/utils/gmp_helper.c
Source/charon/utils/gmp_helper.h
Source/charon/utils/iterator.h
Source/charon/utils/linked_list.c
Source/charon/utils/linked_list.h
Source/charon/utils/logger.c
Source/charon/utils/logger.h
Source/charon/utils/logger_manager.c
Source/charon/utils/logger_manager.h
Source/charon/utils/randomizer.c
Source/charon/utils/randomizer.h
Source/charon/utils/tester.c
Source/charon/utils/tester.h

index 5f949df..ad9e075 100644 (file)
@@ -254,7 +254,7 @@ status_t get_supported_payloads (private_message_t *this, supported_payload_entr
  */
 static void set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id)
 {
-       ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id));
+       this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
 }
 
 /**
@@ -266,7 +266,7 @@ static status_t get_ike_sa_id (private_message_t *this,ike_sa_id_t **ike_sa_id)
        {
                return FAILED;
        }
-       this->ike_sa_id->clone(this->ike_sa_id,ike_sa_id);
+       *ike_sa_id = this->ike_sa_id->clone(this->ike_sa_id);
        return SUCCESS;
 }
 
@@ -641,12 +641,7 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
                /* get next payload type */
                current_payload_type = current_payload->get_next_type(current_payload);
                
-               status = this->payloads->insert_last(this->payloads,current_payload);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "%s on adding payload", mapping_find(status_m, status));
-                       return status;;
-               }
+               this->payloads->insert_last(this->payloads,current_payload);
                
        }
        return this->public.verify(&(this->public));
index c6a08af..6bef3bf 100644 (file)
@@ -287,9 +287,9 @@ static size_t get_length(private_encryption_payload_t *this)
 /**
  * Implementation of payload_t.create_payload_iterator.
  */
-static status_t create_payload_iterator (private_encryption_payload_t *this, iterator_t **iterator, bool forward)
+static void create_payload_iterator (private_encryption_payload_t *this, iterator_t **iterator, bool forward)
 {
-       return (this->payloads->create_iterator(this->payloads, iterator, forward));
+       this->payloads->create_iterator(this->payloads, iterator, forward);
 }
 
 /**
index 1a137de..92e08a0 100644 (file)
@@ -126,11 +126,7 @@ static status_t verify(private_sa_payload_t *this)
        }
 
        /* check proposal numbering */          
-       status = this->proposals->create_iterator(this->proposals,&iterator,TRUE);
-       if (status != SUCCESS)
-       {
-               return status;
-       }
+       this->proposals->create_iterator(this->proposals,&iterator,TRUE);
        
        while(iterator->has_next(iterator))
        {
index daba379..65dcf7b 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file host.c
  * 
- * @brief host object, identifies a host and defines some useful functions on it.
+ * @brief Implementation of host_t.
  * 
  */
 
@@ -110,28 +110,20 @@ static u_int16_t get_port(private_host_t *this)
 /**
  * Implements host_t.destroy
  */
-static status_t destroy(private_host_t *this)
+static void destroy(private_host_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
 /**
  * Implements host_t.clone.
  */
-static status_t clone(private_host_t *this, host_t **other)
+static private_host_t *clone(private_host_t *this)
 {
        private_host_t *new = allocator_alloc_thing(private_host_t);
-       
-       if (new == NULL)
-       {
-               return OUT_OF_RES;      
-       }       
                
        memcpy(new, this, sizeof(private_host_t));
-       *other = (host_t*)new;
-       
-       return SUCCESS;
+       return new;
 }
 
 
@@ -141,17 +133,13 @@ static status_t clone(private_host_t *this, host_t **other)
 host_t *host_create(int family, char *address, u_int16_t port)
 {
        private_host_t *this = allocator_alloc_thing(private_host_t);
-       if (this == NULL)
-       {
-               return NULL;    
-       }
        
        this->public.get_sockaddr = (sockaddr_t* (*) (host_t*))get_sockaddr;
        this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len;
-       this->public.clone = (status_t (*) (host_t*, host_t**))clone;
+       this->public.clone = (host_t* (*) (host_t*))clone;
        this->public.get_address = (char* (*) (host_t *))get_address;
        this->public.get_port = (u_int16_t (*) (host_t *))get_port;
-       this->public.destroy = (status_t (*) (host_t*))destroy;
+       this->public.destroy = (void (*) (host_t*))destroy;
        
        this->family = family;
 
index e1779f5..cf9064a 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file host.h
  *
- * @brief host object, identifies a host and defines some useful functions on it.
+ * @brief Interface of host_t.
  *
  */
 
 typedef struct host_t host_t;
 /**
  * @brief Representates a Host
+ * 
+ * Host object, identifies a host and defines some useful functions on it.
  */
 struct host_t {
        /** 
         * @brief Build a clone of this host object.
         * 
         * @param this                  object to clone
-        * @param [out]other    address where to allocate the clone
-        * @return                              
-        *                                              - SUCCESS, or
-        *                                              - OUT_OF_RES
+        * @return                              cloned host
         */
-        
-       status_t (*clone) (host_t *this, host_t **other);
+       host_t *(*clone) (host_t *this);
+       
        /** 
         * @brief Get a pointer to the internal sockaddr struct.
         * 
@@ -100,7 +99,7 @@ struct host_t {
         * @param this                  calling
         * @return                              SUCCESS in any case
         */
-       status_t (*destroy) (host_t *this);
+       void (*destroy) (host_t *this);
 };
 
 /**
@@ -112,10 +111,9 @@ struct host_t {
  * @param address              string of an address, such as "152.96.193.130"
  * @param port                 port number
  * @return                             the host_t object or NULL, when
- *                                             not enough ressources, or
  *                                             family not supported.
  */
 host_t *host_create(int family, char *address, u_int16_t port);
-
+                 
 
 #endif /*HOST_H_*/
index ea7af27..f2d7ef7 100644 (file)
@@ -76,7 +76,7 @@ static status_t clone (private_packet_t *this, packet_t **clone)
        
        if (this->public.destination != NULL)
        {
-               this->public.destination->clone(this->public.destination, &(other->destination));
+               other->destination = this->public.destination->clone(this->public.destination);
        }
        else {
                other->destination = NULL;
@@ -84,7 +84,7 @@ static status_t clone (private_packet_t *this, packet_t **clone)
        
        if (this->public.source != NULL)
        {
-               this->public.source->clone(this->public.source, &(other->source));
+               other->source = this->public.source->clone(this->public.source);
        }
        else {
                other->source = NULL;
index eb33330..6954bf2 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file event_queue.c
  *
- * @brief Event-Queue based on class linked_list_t
+ * @brief Implementation of event_queue_t
  *
  */
 
@@ -54,19 +54,17 @@ struct event_t{
         * @brief Destroys a event_t object.
         *
         * @param event_t       calling object
-        * @returns                     always SUCCESS
         */
-       status_t (*destroy) (event_t *event);
+       void (*destroy) (event_t *event);
 };
 
 
 /**
- * @brief implements function destroy of event_t
+ * implements event_t.destroy
  */
-static status_t event_destroy(event_t *event)
+static void event_destroy(event_t *event)
 {
        allocator_free(event);
-       return SUCCESS;
 }
 
 /**
@@ -75,17 +73,11 @@ static status_t event_destroy(event_t *event)
  * @param time absolute time to fire the event
  * @param job  job to add to job-queue at specific time
  *
- * @returns
- *                             - created event_t object 
- *                             - NULL if memory allocation failed
+ * @returns            created event_t object 
  */
 static event_t *event_create(timeval_t time, job_t *job)
 {
        event_t *this = allocator_alloc_thing(event_t);
-       if (this == NULL)
-       {
-               return this;
-       }
 
        this->destroy = event_destroy;
        this->time = time;
@@ -149,8 +141,7 @@ static long time_difference(struct timeval *end_time, struct timeval *start_time
 
 
 /**
- * Implements function get_count of event_queue_t.
- * See #event_queue_s.get_count for description.
+ * Implements event_queue_t.get_count
  */
 static int get_count (private_event_queue_t *this)
 {
@@ -162,14 +153,14 @@ static int get_count (private_event_queue_t *this)
 }
 
 /**
- * Implements function get of event_queue_t.
- * See #event_queue_s.get for description.
+ * Implements event_queue_t.get
  */
-static status_t get(private_event_queue_t *this, job_t **job)
+static job_t *get(private_event_queue_t *this)
 {
        timespec_t timeout;
        timeval_t current_time;
        event_t * next_event;
+       job_t *job;
        int oldstate;
 
        pthread_mutex_lock(&(this->mutex));
@@ -205,7 +196,7 @@ static status_t get(private_event_queue_t *this, job_t **job)
                        /* event available */
                        this->list->remove_first(this->list,(void **) &next_event);
 
-                       *job = next_event->job;
+                       job = next_event->job;
 
                        next_event->destroy(next_event);
                        break;
@@ -216,23 +207,19 @@ static status_t get(private_event_queue_t *this, job_t **job)
 
        pthread_mutex_unlock(&(this->mutex));
 
-       return SUCCESS;
+       return job;
 }
 
 /**
  * Implements function add_absolute of event_queue_t.
  * See #event_queue_s.add_absolute for description.
  */
-static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t time)
+static void add_absolute(private_event_queue_t *this, job_t *job, timeval_t time)
 {
        event_t *event = event_create(time,job);
        event_t *current_event;
        status_t status;
 
-       if (event == NULL)
-       {
-               return FAILED;
-       }
        pthread_mutex_lock(&(this->mutex));
 
        /* while just used to break out */
@@ -240,7 +227,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
        {
                if (this->list->get_count(this->list) == 0)
                {
-                       status = this->list->insert_first(this->list,event);
+                       this->list->insert_first(this->list,event);
                        break;
                }
 
@@ -250,7 +237,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
                if (time_difference(&(event->time), &(current_event->time)) >= 0)
                {
                        /* my event has to be fired after the last event in list */
-                       status = this->list->insert_last(this->list,event);
+                       this->list->insert_last(this->list,event);
                        break;
                }
 
@@ -260,18 +247,13 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
                if (time_difference(&(event->time), &(current_event->time)) < 0)
                {
                        /* my event has to be fired before the first event in list */
-                       status = this->list->insert_first(this->list,event);
+                       this->list->insert_first(this->list,event);
                        break;
                }
 
                iterator_t * iterator;
 
-               status = this->list->create_iterator(this->list,&iterator,TRUE);
-               if (status != SUCCESS)
-               {
-                       break;
-               }
-
+               this->list->create_iterator(this->list,&iterator,TRUE);
 
                iterator->has_next(iterator);
                /* first element has not to be checked (already done) */
@@ -283,7 +265,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
                        if (time_difference(&(event->time), &(current_event->time)) <= 0)
                        {
                                /* my event has to be fired before the current event in list */
-                               status = iterator->insert_before(iterator,event);
+                               iterator->insert_before(iterator,event);
                                break;
                        }
                }
@@ -293,19 +275,12 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
 
        pthread_cond_signal( &(this->condvar));
        pthread_mutex_unlock(&(this->mutex));
-
-       if (status != SUCCESS)
-       {
-               event->destroy(event);
-       }
-       return status;
 }
 
 /**
- * Implements function add_relative of event_queue_t.
- * See #event_queue_s.add_relative for description.
+ * Implements  event_queue_t.add_relative.
  */
-static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
+static void add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
 {
        timeval_t current_time;
        timeval_t time;
@@ -316,15 +291,14 @@ static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
        time.tv_usec = ((current_time.tv_usec + micros) % 1000000);
        time.tv_sec = current_time.tv_sec + ((current_time.tv_usec + micros)/ 1000000);
 
-       return this->add_absolute(this, job, time);
+       this->add_absolute(this, job, time);
 }
 
 
 /**
- * Implements function destroy of event_queue_t.
- * See #event_queue_s.destroy for description.
+ * Implements event_queue_t.destroy.
  */
-static status_t event_queue_destroy(private_event_queue_t *this)
+static void event_queue_destroy(private_event_queue_t *this)
 {
        while (this->list->get_count(this->list) > 0)
        {
@@ -345,7 +319,6 @@ static status_t event_queue_destroy(private_event_queue_t *this)
        pthread_cond_destroy(&(this->condvar));
 
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -353,26 +326,15 @@ static status_t event_queue_destroy(private_event_queue_t *this)
  */
 event_queue_t *event_queue_create()
 {
-       linked_list_t *linked_list = linked_list_create();
-       if (linked_list == NULL)
-       {
-               return NULL;
-       }
-
        private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t);
-       if (this == NULL)
-       {
-               linked_list->destroy(linked_list);
-               return NULL;
-       }
 
        this->public.get_count = (int (*) (event_queue_t *event_queue)) get_count;
-       this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get;
-       this->public.add_absolute = (status_t (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute;
-       this->public.add_relative = (status_t (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative;
-       this->public.destroy = (status_t (*) (event_queue_t *event_queue)) event_queue_destroy;
+       this->public.get = (job_t *(*) (event_queue_t *event_queue)) get;
+       this->public.add_absolute = (void (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute;
+       this->public.add_relative = (void (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative;
+       this->public.destroy = (void (*) (event_queue_t *event_queue)) event_queue_destroy;
 
-       this->list = linked_list;
+       this->list = linked_list_create();;
        pthread_mutex_init(&(this->mutex), NULL);
        pthread_cond_init(&(this->condvar), NULL);
 
index 4f3d543..ed0a858 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file event_queue.h
  *
- * @brief Event-Queue based on class linked_list_t
+ * @brief Interface of job_queue_t.
  *
  */
 
@@ -53,10 +53,9 @@ struct event_queue_t {
         *
         * @param event_queue   calling object
         * @param[out] job              pointer to a job pointer where to job is returned to
-        * @return                              - SUCCESS if succeeded
-        *                                              - FAILED otherwisesa
+        * @return                              next job
         */
-       status_t (*get) (event_queue_t *event_queue, job_t **job);
+       job_t *(*get) (event_queue_t *event_queue);
 
        /**
         * @brief Adds a event to the queue, using a relative time.
@@ -68,11 +67,8 @@ struct event_queue_t {
         * @param event_queue   calling object
         * @param[in] job               job to add to the queue (job is not copied)
         * @param[in] time              relative time, when the event has to get fired
-        * @returns
-        *                                              - SUCCESS if succeeded
-        *                                              - FAILED otherwise
         */
-       status_t (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms);
+       void (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms);
 
        /**
         * @brief Adds a event to the queue, using an absolute time.
@@ -84,11 +80,8 @@ struct event_queue_t {
         * @param event_queue   calling object
         * @param[in]                   job job to add to the queue (job is not copied)
         * @param[in]                   absolute time time, when the event has to get fired
-        * @returns
-        *                                              - SUCCESS if succeeded
-        *                                              - FAILED otherwise
         */
-       status_t (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time);
+       void (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time);
 
        /**
         * @brief Destroys a event_queue object.
@@ -100,15 +93,13 @@ struct event_queue_t {
         * @param event_queue   calling object
         * @returns                             always SUCCESS
         */
-       status_t (*destroy) (event_queue_t *event_queue);
+       void (*destroy) (event_queue_t *event_queue);
 };
 
 /**
  * @brief Creates an empty event_queue
  *
- * @returns
- *                     - Empty event_queue_t object
- *                     - NULL if memory allocation failed
+ * @returns            event_queue
  */
 event_queue_t *event_queue_create();
 #endif /*EVENT_QUEUE_H_*/
index bd11d0b..d6e8f6b 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file job_queue.c
  *
- * @brief Job-Queue based on linked_list_t
+ * @brief Implementation of job_queue_t
  *
  */
 
@@ -56,7 +56,7 @@ struct private_job_queue_t {
 
 
 /**
- * @brief implements function get_count of job_queue_t
+ * implements job_queue_t.get_count
  */
 static int get_count(private_job_queue_t *this)
 {
@@ -68,11 +68,12 @@ static int get_count(private_job_queue_t *this)
 }
 
 /**
- * @brief implements function get of job_queue_t
+ * implements job_queue_t.get
  */
-static status_t get(private_job_queue_t *this, job_t **job)
+static job_t *get(private_job_queue_t *this)
 {
        int oldstate;
+       job_t *job;
        pthread_mutex_lock(&(this->mutex));
        /* go to wait while no jobs available */
        while(this->list->get_count(this->list) == 0)
@@ -87,28 +88,26 @@ static status_t get(private_job_queue_t *this, job_t **job)
                pthread_setcancelstate(oldstate, NULL);
                pthread_cleanup_pop(0);
        }
-       this->list->remove_first(this->list,(void **) job);
+       this->list->remove_first(this->list,(void **) &job);
        pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
+       return job;
 }
 
 /**
- * @brief implements function add of job_queue_t
+ * implements function job_queue_t.add
  */
-static status_t add(private_job_queue_t *this, job_t *job)
+static void add(private_job_queue_t *this, job_t *job)
 {
        pthread_mutex_lock(&(this->mutex));
        this->list->insert_last(this->list,job);
        pthread_cond_signal( &(this->condvar));
        pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
 }
 
 /**
- * @brief implements function destroy of job_queue_t
- *
+ * implements job_queue_t.destroy
  */
-static status_t job_queue_destroy (private_job_queue_t *this)
+static void job_queue_destroy (private_job_queue_t *this)
 {
        while (this->list->get_count(this->list) > 0)
        {
@@ -127,7 +126,6 @@ static status_t job_queue_destroy (private_job_queue_t *this)
        pthread_cond_destroy(&(this->condvar));
 
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -136,25 +134,14 @@ static status_t job_queue_destroy (private_job_queue_t *this)
  */
 job_queue_t *job_queue_create()
 {
-       linked_list_t *linked_list = linked_list_create();
-       if (linked_list == NULL)
-       {
-               return NULL;
-       }
-
        private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t);
-       if (this == NULL)
-       {
-               linked_list->destroy(linked_list);
-               return NULL;
-       }
 
        this->public.get_count = (int(*)(job_queue_t*))get_count;
-       this->public.get = (status_t(*)(job_queue_t*, job_t**))get;
-       this->public.add = (status_t(*)(job_queue_t*, job_t*))add;
-       this->public.destroy = (status_t(*)(job_queue_t*))job_queue_destroy;
+       this->public.get = (job_t*(*)(job_queue_t*))get;
+       this->public.add = (void(*)(job_queue_t*, job_t*))add;
+       this->public.destroy = (void(*)(job_queue_t*))job_queue_destroy;
 
-       this->list = linked_list;
+       this->list = linked_list_create();
        pthread_mutex_init(&(this->mutex), NULL);
        pthread_cond_init(&(this->condvar), NULL);
 
index 4c7c122..b0a3066 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file job_queue.h
  *
- * @brief Job-Queue based on linked_list_t
+ * @brief Interface of job_queue_t-
  *
  */
 
@@ -39,8 +39,8 @@ struct job_queue_t {
        /**
         * @brief returns number of jobs in queue
         *
-        * @param job_queue_t calling object
-        * @returns number of items in queue
+        * @param job_queue_t   calling object
+        * @returns                     number of items in queue
         */
        int (*get_count) (job_queue_t *job_queue);
 
@@ -48,14 +48,13 @@ struct job_queue_t {
         * @brief get the next job from the queue
         *
         * If the queue is empty, this function blocks until a job can be returned.
-        *
         * After using, the returned job has to get destroyed by the caller.
         *
-        * @param job_queue_t calling object
-        * @param[out] job pointer to a job pointer where to job is returned to
-        * @returns SUCCESS if succeeded, FAILED otherwise
+        * @param job_queue_t   calling object
+        * @param[out] job              pointer to a job pointer where to job is returned to
+        * @return                              job
         */
-       status_t (*get) (job_queue_t *job_queue, job_t **job);
+       job_t *(*get) (job_queue_t *job_queue);
 
        /**
         * @brief adds a job to the queue
@@ -66,9 +65,8 @@ struct job_queue_t {
         *
         * @param job_queue_t calling object
         * @param[in] job job to add to the queue (job is not copied)
-        * @returns SUCCESS if succeeded, FAILED otherwise
         */
-       status_t (*add) (job_queue_t *job_queue, job_t *job);
+       void (*add) (job_queue_t *job_queue, job_t *job);
 
        /**
         * @brief destroys a job_queue object
@@ -78,9 +76,8 @@ struct job_queue_t {
         * after calling this function.
         *
         * @param job_queue_t calling object
-        * @returns SUCCESS if succeeded, FAILED otherwise
         */
-       status_t (*destroy) (job_queue_t *job_queue);
+       void (*destroy) (job_queue_t *job_queue);
 };
 
 /**
@@ -89,4 +86,5 @@ struct job_queue_t {
  * @return job_queue_t empty job_queue
  */
 job_queue_t *job_queue_create();
+
 #endif /*JOB_QUEUE_H_*/
index b87c4dc..5041d1f 100644 (file)
@@ -96,11 +96,7 @@ delete_ike_sa_job_t *delete_ike_sa_job_create(ike_sa_id_t *ike_sa_id)
        this->public.destroy = (status_t (*)(delete_ike_sa_job_t *)) destroy;
        
        /* private variables */
-       if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
-       {
-               allocator_free(this);
-               return NULL;
-       }
+       this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
        
        return &(this->public);
 }
index 5782ce1..af72402 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file send_queue.c
  *
- * @brief Send-Queue based on linked_list_t
+ * @brief Implementation of send_queue_t.
  *
  */
 
@@ -59,7 +59,7 @@ struct private_send_queue_t {
 
 
 /**
- * @brief implements function get_count of send_queue_t
+ * implements send_queue_t.get_count
  */
 static int get_count(private_send_queue_t *this)
 {
@@ -71,11 +71,12 @@ static int get_count(private_send_queue_t *this)
 }
 
  /**
- * @brief implements function get of send_queue_t
+ * implements send_queue_t.get
  */
-static status_t get(private_send_queue_t *this, packet_t **packet)
+static packet_t *get(private_send_queue_t *this)
 {
        int oldstate;
+       packet_t *packet;
        pthread_mutex_lock(&(this->mutex));
        /* go to wait while no packets available */
        
@@ -90,28 +91,26 @@ static status_t get(private_send_queue_t *this, packet_t **packet)
                pthread_setcancelstate(oldstate, NULL);
                pthread_cleanup_pop(0);
        }
-       this->list->remove_first(this->list,(void **) packet);
+       this->list->remove_first(this->list,(void **)&packet);
        pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
+       return packet;
 }
 
  /**
- * @brief implements function add of send_queue_t
+ * implements send_queue_t.add
  */
-static status_t add(private_send_queue_t *this, packet_t *packet)
+static void add(private_send_queue_t *this, packet_t *packet)
 {
        pthread_mutex_lock(&(this->mutex));
        this->list->insert_last(this->list,packet);
        pthread_cond_signal( &(this->condvar));
        pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
 }
 
  /**
- * @brief implements function destroy of send_queue_t
- *
+ * implements send_queue_t.destroy
  */
-static status_t destroy (private_send_queue_t *this)
+static void destroy (private_send_queue_t *this)
 {
 
        /* destroy all packets in list before destroying list */
@@ -132,7 +131,6 @@ static status_t destroy (private_send_queue_t *this)
        pthread_cond_destroy(&(this->condvar));
 
        allocator_free(this);
-       return SUCCESS;
 }
 
  /*
@@ -141,25 +139,14 @@ static status_t destroy (private_send_queue_t *this)
  */
 send_queue_t *send_queue_create()
 {
-       linked_list_t *linked_list = linked_list_create();
-       if (linked_list == NULL)
-       {
-               return NULL;
-       }
-
        private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t);
-       if (this == NULL)
-       {
-               linked_list->destroy(linked_list);
-               return NULL;
-       }
-
+       
        this->public.get_count = (int(*)(send_queue_t*)) get_count;
-       this->public.get = (status_t(*)(send_queue_t*, packet_t**)) get;
-       this->public.add = (status_t(*)(send_queue_t*, packet_t*)) add;
-       this->public.destroy = (status_t(*)(send_queue_t*)) destroy;
+       this->public.get = (packet_t*(*)(send_queue_t*)) get;
+       this->public.add = (void(*)(send_queue_t*, packet_t*)) add;
+       this->public.destroy = (void(*)(send_queue_t*)) destroy;
 
-       this->list = linked_list;
+       this->list = linked_list_create();
        pthread_mutex_init(&(this->mutex), NULL);
        pthread_cond_init(&(this->condvar), NULL);
 
index 572c40e..f023f29 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file send_queue.h
  *
- * @brief Send-Queue based on linked_list_t
+ * @brief Interface of send_queue_t.
  *
  */
 
@@ -40,40 +40,38 @@ struct send_queue_t {
        /**
         * @brief returns number of packets in queue
         *
-        * @param send_queue_t calling object
-        * @param[out] count integer pointer to store the count in
-        * @returns number of items in queue
+        * @param send_queue_t  calling object
+        * @param[out]                  count integer pointer to store the count in
+        * @returns                     number of items in queue
         */
        int (*get_count) (send_queue_t *send_queue);
 
        /**
-        * @brief get the next packet from the queue
+        * @brief get the next packet from the queue.
         *
         * If the queue is empty, this function blocks until a packet can be returned.
         *
         * After using, the returned packet has to get destroyed by the caller.
         *
-        * @param send_queue_t calling object
-        * @param[out] packet pointer to a packet_t pointer where to packet is returned to
-        * @returns SUCCESS if succeeded, FAILED otherwise
+        * @param send_queue_t  calling object
+        * @param[out] packet   pointer to a packet_t pointer where to packet is returned to
         */
-       status_t (*get) (send_queue_t *send_queue, packet_t **packet);
+       packet_t *(*get) (send_queue_t *send_queue);
 
        /**
-        * @brief adds a packet to the queue
+        * @brief adds a packet to the queue.
         *
         * This function is non blocking and adds a packet_t to the list.
         * The specific packet object has to get destroyed by the thread which
         * removes the packet.
         *
-        * @param send_queue_t calling object
-        * @param[in] packet packet_t to add to the queue (packet is not copied)
-        * @returns SUCCESS if succeeded, FAILED otherwise
+        * @param send_queue_t  calling object
+        * @param packet                packet_t to add to the queue (packet is not copied)
         */
-       status_t (*add) (send_queue_t *send_queue, packet_t *packet);
+       void (*add) (send_queue_t *send_queue, packet_t *packet);
 
        /**
-        * @brief destroys a send_queue object
+        * @brief destroys a send_queue object.
         *
         * @warning The caller of this function has to make sure
         * that no thread is going to add or get a packet from the send_queue
@@ -82,11 +80,11 @@ struct send_queue_t {
         * @param send_queue_t calling object
         * @returns SUCCESS if succeeded, FAILED otherwise
         */
-       status_t (*destroy) (send_queue_t *send_queue);
+       void (*destroy) (send_queue_t *send_queue);
 };
 
 /**
- * @brief Creates an empty send_queue_t
+ * @brief Creates an empty send_queue_t.
  *
  * @return send_queue_t empty send_queue_t
  */
index 2b1fe94..33a7fd3 100644 (file)
@@ -206,14 +206,13 @@ struct private_ike_sa_t {
 
 
 /**
- * @brief implements function process_message of protected_ike_sa_t
+ * Implements protected_ike_sa_t.process_message.
  */
 static status_t process_message (private_ike_sa_t *this, message_t *message)
-{      
+{
        u_int32_t message_id;
        exchange_type_t exchange_type;
        bool is_request;
-       status_t status;
        
        /* we must process each request or response from remote host */
 
@@ -228,7 +227,7 @@ static status_t process_message (private_ike_sa_t *this, message_t *message)
        /* 
         * It has to be checked, if the message has to be resent cause of lost packets!
         */
-       if (is_request && ( message_id == (this->message_id_in - 1)))
+       if (is_request && (message_id == (this->message_id_in - 1)))
        {
                /* message can be resent ! */
                this->logger->log(this->logger, CONTROL|MORE, "Resent message detected. Send stored reply");
@@ -257,61 +256,34 @@ static status_t process_message (private_ike_sa_t *this, message_t *message)
        
        /* now the message is processed by the current state object */
        /* the current state does change the current change to the next one*/
-       status = this->current_state->process_message(this->current_state,message);
-
-       return status;
+       return this->current_state->process_message(this->current_state,message);
 }
 
 /**
- * @brief Implements function build_message of protected_ike_sa_t.
+ * Implements protected_ike_sa_t.build_message.
  */
-static status_t build_message(private_ike_sa_t *this, exchange_type_t type, bool request, message_t **message)
+static void build_message(private_ike_sa_t *this, exchange_type_t type, bool request, message_t **message)
 {
-       status_t status;
        message_t *new_message; 
        host_t *source, *destination;
 
        this->logger->log(this->logger, CONTROL|MORE, "build empty message");   
        new_message = message_create(); 
-       if (new_message == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not create empty message object");   
-               return OUT_OF_RES;
-       }
-       
-       status  = this->me.host->clone(this->me.host, &source);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not clone my host information");
-               new_message->destroy(new_message);
-               return status;  
-       }
-       status = this->other.host->clone(this->other.host, &destination);       
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not clone other host information");
-               source->destroy(source);
-               new_message->destroy(new_message);
-               return status;  
-       }
        
+       source = this->me.host->clone(this->me.host);
+       destination = this->other.host->clone(this->other.host);        
+
        new_message->set_source(new_message, source);
        new_message->set_destination(new_message, destination);
-       
        new_message->set_exchange_type(new_message, type);
        new_message->set_request(new_message, request);
-       
        new_message->set_message_id(new_message, (request) ? this->message_id_out : this->message_id_in);
-
        new_message->set_ike_sa_id(new_message, this->ike_sa_id);
-               
        *message = new_message;
-       
-       return SUCCESS;
 }
 
 /**
- * @brief implements function process_configuration of protected_ike_sa_t
+ * Implements protected_ike_sa_t.process_configuration.
  */
 static status_t initialize_connection(private_ike_sa_t *this, char *name)
 {
@@ -336,7 +308,7 @@ static status_t initialize_connection(private_ike_sa_t *this, char *name)
 }
 
 /**
- * @brief implements function protected_ike_sa_t.get_id
+ * Implements protected_ike_sa_t.get_id.
  */
 static ike_sa_id_t* get_id(private_ike_sa_t *this)
 {
@@ -344,14 +316,13 @@ static ike_sa_id_t* get_id(private_ike_sa_t *this)
 }
 
 /**
- * @brief implements function protected_ike_sa_t.compute_secrets
+ * Implements protected_ike_sa_t.compute_secrets.
  */
-static status_t compute_secrets (private_ike_sa_t *this,chunk_t dh_shared_secret,chunk_t initiator_nonce, chunk_t responder_nonce)
+static void compute_secrets(private_ike_sa_t *this,chunk_t dh_shared_secret,chunk_t initiator_nonce, chunk_t responder_nonce)
 {
        chunk_t concatenated_nonces;
        chunk_t skeyseed;
        chunk_t prf_plus_seed;
-       status_t status;
        u_int64_t initiator_spi;
        u_int64_t responder_spi;
        prf_plus_t *prf_plus;
@@ -362,11 +333,7 @@ static status_t compute_secrets (private_ike_sa_t *this,chunk_t dh_shared_secret
         */
        concatenated_nonces.len = (initiator_nonce.len + responder_nonce.len);
        concatenated_nonces.ptr = allocator_alloc(concatenated_nonces.len);
-       if (concatenated_nonces.ptr == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal errror: Could not allocate memory for concatenated nonces");
-               return FAILED;
-       }
+
        /* first is initiator */
        memcpy(concatenated_nonces.ptr,initiator_nonce.ptr,initiator_nonce.len);
        /* second is responder */
@@ -374,28 +341,15 @@ static status_t compute_secrets (private_ike_sa_t *this,chunk_t dh_shared_secret
 
        this->logger->log_chunk(this->logger, RAW, "Nonce data", &concatenated_nonces);
 
-
        /* status of set_key is not checked */
-       status = this->prf->set_key(this->prf,concatenated_nonces);
+       this->prf->set_key(this->prf,concatenated_nonces);
+
+       this->prf->allocate_bytes(this->prf,dh_shared_secret,&skeyseed);
 
-       status = this->prf->allocate_bytes(this->prf,dh_shared_secret,&skeyseed);
-       if (status != SUCCESS)
-       {
-               allocator_free_chunk(&concatenated_nonces);
-               this->logger->log(this->logger, ERROR, "Fatal errror: Could not allocate bytes for skeyseed");
-               return status;
-       }
        allocator_free_chunk(&concatenated_nonces);
 
        prf_plus_seed.len = (initiator_nonce.len + responder_nonce.len + 16);
        prf_plus_seed.ptr = allocator_alloc(prf_plus_seed.len);
-       if (prf_plus_seed.ptr == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal errror: Could not allocate memory for prf+ seed");
-               allocator_free_chunk(&skeyseed);
-               return FAILED;
-       }
-       
        
        /* first is initiator */
        memcpy(prf_plus_seed.ptr,initiator_nonce.ptr,initiator_nonce.len);
@@ -412,113 +366,45 @@ static status_t compute_secrets (private_ike_sa_t *this,chunk_t dh_shared_secret
        this->logger->log_chunk(this->logger, PRIVATE | MORE, "PRF+ Seed", &prf_plus_seed);
 
        this->logger->log(this->logger, CONTROL | MOST, "Set new key of prf object");
-       status = this->prf->set_key(this->prf,skeyseed);
+       this->prf->set_key(this->prf,skeyseed);
        allocator_free_chunk(&skeyseed);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal errror: Could not allocate memory for prf+ seed");
-               allocator_free_chunk(&prf_plus_seed);
-               return FAILED;
-       }
-        
        this->logger->log(this->logger, CONTROL | MOST, "Create new prf+ object");
        prf_plus = prf_plus_create(this->prf, prf_plus_seed);
        allocator_free_chunk(&prf_plus_seed);
-       if (prf_plus == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal errror: prf+ object could not be created");
-               return FAILED;
-       }
        
-       status = prf_plus->allocate_bytes(prf_plus,this->prf->get_block_size(this->prf),&(this->secrets.d_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_d");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->prf->get_block_size(this->prf),&(this->secrets.d_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_d secret", &(this->secrets.d_key));
 
-       status = prf_plus->allocate_bytes(prf_plus,this->crypter_initiator->get_block_size(this->crypter_initiator),&(this->secrets.ei_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_ei");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->crypter_initiator->get_block_size(this->crypter_initiator),&(this->secrets.ei_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_ei secret", &(this->secrets.ei_key));
-       status = this->crypter_initiator->set_key(this->crypter_initiator,this->secrets.ei_key);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not set encryption key initiator crypter");
-               return status;
-       }
+       this->crypter_initiator->set_key(this->crypter_initiator,this->secrets.ei_key);
 
-       status = prf_plus->allocate_bytes(prf_plus,this->crypter_responder->get_block_size(this->crypter_responder),&(this->secrets.er_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_er");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->crypter_responder->get_block_size(this->crypter_responder),&(this->secrets.er_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_er secret", &(this->secrets.er_key));
-       status = this->crypter_responder->set_key(this->crypter_responder,this->secrets.er_key);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not set encryption key responder crypter");
-               return status;
-       }
+       this->crypter_responder->set_key(this->crypter_responder,this->secrets.er_key);
 
-       status = prf_plus->allocate_bytes(prf_plus,this->signer_initiator->get_block_size(this->signer_initiator),&(this->secrets.ai_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_ai");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->signer_initiator->get_block_size(this->signer_initiator),&(this->secrets.ai_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_ai secret", &(this->secrets.ai_key));
-       status = this->signer_initiator->set_key(this->signer_initiator,this->secrets.ai_key);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not set key for initiator signer");
-               return status;
-       }
+       this->signer_initiator->set_key(this->signer_initiator,this->secrets.ai_key);
 
-       status = prf_plus->allocate_bytes(prf_plus,this->signer_responder->get_block_size(this->signer_responder),&(this->secrets.ar_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_ar");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->signer_responder->get_block_size(this->signer_responder),&(this->secrets.ar_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_ar secret", &(this->secrets.ar_key));
-       status = this->signer_responder->set_key(this->signer_responder,this->secrets.ar_key);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not set key for responder signer");
-               return status;
-       }       
+       this->signer_responder->set_key(this->signer_responder,this->secrets.ar_key);
 
-       status = prf_plus->allocate_bytes(prf_plus,this->crypter_responder->get_block_size(this->crypter_responder),&(this->secrets.pi_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_pi");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->crypter_responder->get_block_size(this->crypter_responder),&(this->secrets.pi_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_pi secret", &(this->secrets.pi_key));
        
-       status = prf_plus->allocate_bytes(prf_plus,this->crypter_responder->get_block_size(this->crypter_responder),&(this->secrets.pr_key));
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR | MORE, "Could not allocate bytes from prf+ for Sk_pr");
-               return status;
-       }
+       prf_plus->allocate_bytes(prf_plus,this->crypter_responder->get_block_size(this->crypter_responder),&(this->secrets.pr_key));
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_pr secret", &(this->secrets.pr_key));
        
        prf_plus->destroy(prf_plus);
-
-       return SUCCESS;
 }
 
 /**
- * @brief implements function resend_last_reply of protected_ike_sa_t
+ * Implements protected_ike_sa_t.resend_last_reply.
  */
-status_t resend_last_reply (private_ike_sa_t *this)
+static status_t resend_last_reply(private_ike_sa_t *this)
 {
        packet_t *packet;
        status_t status;
@@ -530,37 +416,22 @@ status_t resend_last_reply (private_ike_sa_t *this)
                return status;
        }
        
-       status = global_send_queue->add(global_send_queue, packet);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not add packet to send queue");
-               packet->destroy(packet);
-               return status;
-       }               
+       global_send_queue->add(global_send_queue, packet);
        return SUCCESS;
 }
 
-status_t create_delete_job (private_ike_sa_t *this)
+/**
+ * Implements protected_ike_sa_t.resend_last_reply.
+ */
+static status_t create_delete_job(private_ike_sa_t *this)
 {
        job_t *delete_job;
-       status_t status;
 
        this->logger->log(this->logger, CONTROL | MORE, "Going to create job to delete this IKE_SA");
 
        delete_job = (job_t *) delete_ike_sa_job_create(this->ike_sa_id);
-       if (delete_job == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Job to delete IKE SA could not be created");
-               return FAILED;
-       }
-       
-       status = global_job_queue->add(global_job_queue,delete_job);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "%s Job to delete IKE SA could not be added to job queue",mapping_find(status_m,status));
-               delete_job->destroy_all(delete_job);
-               return status;
-       }
+       global_job_queue->add(global_job_queue,delete_job);
+
        return SUCCESS;
 }
 
@@ -636,96 +507,87 @@ static status_t create_transforms_from_proposal (private_ike_sa_t *this,proposal
        u_int16_t pseudo_random_function;
        u_int16_t pseudo_random_function_key_length;
        
-       this    ->logger->log(this->logger, CONTROL|MORE, "Going to create transform objects for proposal");
+       this->logger->log(this->logger, CONTROL|MORE, "Going to create transform objects for proposal");
        
-       this    ->logger->log(this->logger, CONTROL|MOST, "Get encryption transform type");
+       this->logger->log(this->logger, CONTROL|MOST, "Get encryption transform type");
        status = proposal->get_info_for_transform_type(proposal,ENCRYPTION_ALGORITHM,&(encryption_algorithm),&(encryption_algorithm_key_length));
        if (status != SUCCESS)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "Could not get encryption transform type");
+               this->logger->log(this->logger, ERROR|MORE, "Could not get encryption transform type");
                return status;
        }
-       this    ->logger->log(this->logger, CONTROL|MORE, "Encryption algorithm: %s with keylength %d",mapping_find(encryption_algorithm_m,encryption_algorithm),encryption_algorithm_key_length);
+       this->logger->log(this->logger, CONTROL|MORE, "Encryption algorithm: %s with keylength %d",mapping_find(encryption_algorithm_m,encryption_algorithm),encryption_algorithm_key_length);
        
-       this    ->logger->log(this->logger, CONTROL|MOST, "Get integrity transform type");
+       this->logger->log(this->logger, CONTROL|MOST, "Get integrity transform type");
        status = proposal->get_info_for_transform_type(proposal,INTEGRITY_ALGORITHM,&(integrity_algorithm),&(integrity_algorithm_key_length));
        if (status != SUCCESS)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "Could not get integrity transform type");
+               this->logger->log(this->logger, ERROR|MORE, "Could not get integrity transform type");
                return status;
        }
-       this    ->logger->log(this->logger, CONTROL|MORE, "integrity algorithm: %s with keylength %d",mapping_find(integrity_algorithm_m,integrity_algorithm),integrity_algorithm_key_length);
+       this->logger->log(this->logger, CONTROL|MORE, "integrity algorithm: %s with keylength %d",mapping_find(integrity_algorithm_m,integrity_algorithm),integrity_algorithm_key_length);
        
-       this    ->logger->log(this->logger, CONTROL|MOST, "Get prf transform type");
+       this->logger->log(this->logger, CONTROL|MOST, "Get prf transform type");
        status = proposal->get_info_for_transform_type(proposal,PSEUDO_RANDOM_FUNCTION,&(pseudo_random_function),&(pseudo_random_function_key_length));
        if (status != SUCCESS)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "Could not prf transform type");
+               this->logger->log(this->logger, ERROR|MORE, "Could not prf transform type");
                return status;
        }
-       this    ->logger->log(this->logger, CONTROL|MORE, "prf: %s with keylength %d",mapping_find(pseudo_random_function_m,pseudo_random_function),pseudo_random_function_key_length);
-
-
+       this->logger->log(this->logger, CONTROL|MORE, "prf: %s with keylength %d",mapping_find(pseudo_random_function_m,pseudo_random_function),pseudo_random_function_key_length);
        
-
        if (this->prf != NULL)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy existing prf_t object");
                this->prf->destroy(this->prf);
        }
        this->prf = prf_create(pseudo_random_function);
        if (this->prf == NULL)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "prf does not seem to be supported!");
+               this->logger->log(this->logger, ERROR|MORE, "prf not supported!");
                return FAILED;
        }
        
        if (this->crypter_initiator != NULL)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy existing initiator crypter_t object");
                this->crypter_initiator->destroy(this->crypter_initiator);
        }
        this->crypter_initiator = crypter_create(encryption_algorithm,encryption_algorithm_key_length);
        if (this->crypter_initiator == NULL)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "encryption algorithm does not seem to be supported!");
+               this->logger->log(this->logger, ERROR|MORE, "encryption algorithm not supported!");
                return FAILED;
        }
 
        if (this->crypter_responder != NULL)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy existing responder crypter_t object");
                this->crypter_responder->destroy(this->crypter_responder);
        }
        this->crypter_responder = crypter_create(encryption_algorithm,encryption_algorithm_key_length);
        if (this->crypter_responder == NULL)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "encryption algorithm does not seem to be supported!");
+               this->logger->log(this->logger, ERROR|MORE, "encryption algorithm not supported!");
                return FAILED;
        }
        
        if (this->signer_initiator != NULL)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy existing initiator signer_t object");
                this->signer_initiator->destroy(this->signer_initiator);
        }
        this->signer_initiator = signer_create(integrity_algorithm);
        if (this->signer_initiator == NULL)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "integrity algorithm does not seem to be supported!");
+               this->logger->log(this->logger, ERROR|MORE, "integrity algorithm not supported!");
                return FAILED;
        }
        
-       
        if (this->signer_responder != NULL)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy existing responder signer_t object");
                this->signer_responder->destroy(this->signer_responder);
        }
        this->signer_responder = signer_create(integrity_algorithm);
        if (this->signer_responder == NULL)
        {
-               this    ->logger->log(this->logger, ERROR|MORE, "integrity algorithm does not seem to be supported!");
+               this->logger->log(this->logger, ERROR|MORE, "integrity algorithm not supported!");
                return FAILED;
        }
 
@@ -745,50 +607,47 @@ static randomizer_t *get_randomizer (private_ike_sa_t *this)
  */
 static status_t set_last_requested_message (private_ike_sa_t *this,message_t * message)
 {
-       if (    this->last_requested_message != NULL)
+       if (this->last_requested_message != NULL)
        {
                /* destroy message */
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy stored last requested message");
                this->last_requested_message->destroy(this->last_requested_message);
        }
 
        if (message->get_message_id(message) != this->message_id_out)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "last requested message could not be set cause id was not as expected");
+               this->logger->log(this->logger, CONTROL|MOST, "last requested message could not be set cause id was not as expected");
                return FAILED;
        }
-       this    ->logger->log(this->logger, CONTROL|MOST, "replace last requested message with new one");
-       this->last_requested_message     = message;
+       this->logger->log(this->logger, CONTROL|MOST, "replace last requested message with new one");
+       this->last_requested_message = message;
 
        /* message counter can now be increased */
-       this    ->logger->log(this->logger, CONTROL|MOST, "Increate message counter for outgoing messages");
+       this->logger->log(this->logger, CONTROL|MOST, "Increate message counter for outgoing messages");
        this->message_id_out++;
        return SUCCESS; 
 }
 
-
 /**
  * Implementation of protected_ike_sa_t.set_last_responded_message.
  */
 static status_t set_last_responded_message (private_ike_sa_t *this,message_t * message)
 {
-       if (    this->last_responded_message != NULL)
+       if (this->last_responded_message != NULL)
        {
                /* destroy message */
-               this    ->logger->log(this->logger, CONTROL|MOST, "Destroy stored last responded message");
                this->last_responded_message->destroy(this->last_responded_message);
        }
        if (message->get_message_id(message) != this->message_id_in)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "last responded message could not be set cause id was not as expected");
+               this->logger->log(this->logger, CONTROL|MOST, "last responded message could not be set cause id was not as expected");
                return FAILED;
                
        }
-       this    ->logger->log(this->logger, CONTROL|MOST, "replace last responded message with new one");
-       this->last_responded_message     = message;
+       this->logger->log(this->logger, CONTROL|MOST, "replace last responded message with new one");
+       this->last_responded_message = message;
 
        /* message counter can now be increased */
-       this    ->logger->log(this->logger, CONTROL|MOST, "Increate message counter for incoming messages");
+       this->logger->log(this->logger, CONTROL|MOST, "Increate message counter for incoming messages");
        this->message_id_in++;
 
        return SUCCESS;
@@ -796,11 +655,10 @@ static status_t set_last_responded_message (private_ike_sa_t *this,message_t * m
 
 
 /**
- * @brief implements function destroy of protected_ike_sa_t
+ * Implements protected_ike_sa_t.destroy.
  */
-static status_t destroy (private_ike_sa_t *this)
+static void destroy (private_ike_sa_t *this)
 {
-       
        this->logger->log(this->logger, CONTROL | MORE, "Going to destroy IKE_SA");
 
        /* destroy child sa's */
@@ -808,7 +666,7 @@ static status_t destroy (private_ike_sa_t *this)
        while (this->child_sas->get_count(this->child_sas) > 0)
        {
                void *child_sa;
-               if (this->child_sas->remove_first(this->child_sas,&child_sa) != SUCCESS)
+               if (this->child_sas->remove_first(this->child_sas, &child_sa) != SUCCESS)
                {
                        break;
                }
@@ -817,95 +675,64 @@ static status_t destroy (private_ike_sa_t *this)
        this->child_sas->destroy(this->child_sas);
 
        this->logger->log(this->logger, CONTROL | MOST, "Destroy secrets");
-       if (this->secrets.d_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.d_key.ptr);
-       }
-       if (this->secrets.ai_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.ai_key.ptr);
-       }
-       if (this->secrets.ar_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.ar_key.ptr);
-       }
-       if (this->secrets.ei_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.ei_key.ptr);
-       }
-       if (this->secrets.er_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.er_key.ptr);
-       }
-       if (this->secrets.pi_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.pi_key.ptr);
-       }
-       if (this->secrets.pr_key.ptr != NULL)
-       {
-               allocator_free(this->secrets.pr_key.ptr);
-       }
        
-       if (    this->crypter_initiator != NULL)
+       allocator_free(this->secrets.d_key.ptr);
+       allocator_free(this->secrets.ai_key.ptr);
+       allocator_free(this->secrets.ar_key.ptr);
+       allocator_free(this->secrets.ei_key.ptr);
+       allocator_free(this->secrets.er_key.ptr);
+       allocator_free(this->secrets.pi_key.ptr);
+       allocator_free(this->secrets.pr_key.ptr);
+       
+       if (this->crypter_initiator != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy initiator crypter");
                this->crypter_initiator->destroy(this->crypter_initiator);
        }
        
-       if (    this->crypter_responder != NULL)
+       if (this->crypter_responder != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy responder crypter");
                this->crypter_responder->destroy(this->crypter_responder);
        }
        
-       if (    this->signer_initiator != NULL)
+       if (this->signer_initiator != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy initiator signer");
                this->signer_initiator->destroy(this->signer_initiator);
        }
 
        if (this->signer_responder != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy responder signer");
                this->signer_responder->destroy(this->signer_responder);
        }
        
        if (this->prf != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy prf");
                this->prf->destroy(this->prf);
        }
        
        /* destroy ike_sa_id */
-       this->logger->log(this->logger, CONTROL | MOST, "Destroy assigned ike_sa_id");
        this->ike_sa_id->destroy(this->ike_sa_id);
 
        /* destroy stored requested message */
        if (this->last_requested_message != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy last requested message");
                this->last_requested_message->destroy(this->last_requested_message);
        }
        
        /* destroy stored responded messages */
        if (this->last_responded_message != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy last responded message");
                this->last_responded_message->destroy(this->last_responded_message);
        }
        
-       this->logger->log(this->logger, CONTROL | MOST, "Destroy randomizer");
        this->randomizer->destroy(this->randomizer);
 
        if (this->me.host != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy host informations of me");
                this->me.host->destroy(this->me.host);
        }
        
        if (this->other.host != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy host informations of other");
                this->other.host->destroy(this->other.host);
        }
        
@@ -913,11 +740,9 @@ static status_t destroy (private_ike_sa_t *this)
        this->current_state->destroy(this->current_state);
        
        this->logger->log(this->logger, CONTROL | MOST, "Destroy logger of IKE_SA");
-       
        global_logger_manager->destroy_logger(global_logger_manager, this->logger);
 
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -926,20 +751,16 @@ static status_t destroy (private_ike_sa_t *this)
 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
 {
        private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t);
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* Public functions */
        this->protected.public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
        this->protected.public.initialize_connection = (status_t(*)(ike_sa_t*, char*)) initialize_connection;
        this->protected.public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
-       this->protected.public.destroy = (status_t(*)(ike_sa_t*))destroy;
+       this->protected.public.destroy = (void(*)(ike_sa_t*))destroy;
        
        /* protected functions */
-       this->protected.build_message = (status_t (*) (protected_ike_sa_t *, exchange_type_t , bool , message_t **)) build_message;
-       this->protected.compute_secrets = (status_t (*) (protected_ike_sa_t *,chunk_t ,chunk_t , chunk_t )) compute_secrets;
+       this->protected.build_message = (void (*) (protected_ike_sa_t *, exchange_type_t , bool , message_t **)) build_message;
+       this->protected.compute_secrets = (void (*) (protected_ike_sa_t *,chunk_t ,chunk_t , chunk_t )) compute_secrets;
        this->protected.get_logger = (logger_t *(*) (protected_ike_sa_t *)) get_logger;         
        this->protected.get_my_host = (host_t *(*) (protected_ike_sa_t *)) get_my_host;
        this->protected.get_other_host = (host_t *(*) (protected_ike_sa_t *)) get_other_host;
@@ -958,36 +779,10 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
 
        /* initialize private fields */
        this->logger = global_logger_manager->create_logger(global_logger_manager, IKE_SA, NULL);
-       if (this->logger ==  NULL)
-       {
-               allocator_free(this);
-       }
        
-       if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not clone ike_sa_id");
-               global_logger_manager->destroy_logger(global_logger_manager,this->logger);
-               allocator_free(this);
-               return NULL;
-       }
+       this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
        this->child_sas = linked_list_create();
-       if (this->child_sas == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create list for child_sa's");
-               this->ike_sa_id->destroy(this->ike_sa_id);
-               global_logger_manager->destroy_logger(global_logger_manager,this->logger);
-               allocator_free(this);
-               return NULL;
-       }
        this->randomizer = randomizer_create();
-       if (this->randomizer == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create list for child_sa's");
-               this->child_sas->destroy(this->child_sas);
-               this->ike_sa_id->destroy(this->ike_sa_id);
-               global_logger_manager->destroy_logger(global_logger_manager,this->logger);
-               allocator_free(this);
-       }
        
        this->me.host = NULL;
        this->other.host = NULL;
@@ -995,29 +790,19 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        this->last_responded_message = NULL;
        this->message_id_out = 0;
        this->message_id_in = 0;
-       this->secrets.d_key.ptr = NULL;
-       this->secrets.d_key.len = 0;
-       this->secrets.ai_key.ptr = NULL;
-       this->secrets.ai_key.len = 0;
-       this->secrets.ar_key.ptr = NULL;
-       this->secrets.ar_key.len = 0;
-       this->secrets.ei_key.ptr = NULL;        
-       this->secrets.ei_key.len = 0;
-       this->secrets.er_key.ptr = NULL;
-       this->secrets.er_key.len = 0;
-       this->secrets.pi_key.ptr = NULL;
-       this->secrets.pi_key.len = 0;
-       this->secrets.pr_key.ptr = NULL;
-       this->secrets.pr_key.len = 0;
+       this->secrets.d_key = CHUNK_INITIALIZER;
+       this->secrets.ai_key = CHUNK_INITIALIZER;
+       this->secrets.ar_key = CHUNK_INITIALIZER;
+       this->secrets.ei_key = CHUNK_INITIALIZER;       
+       this->secrets.er_key = CHUNK_INITIALIZER;
+       this->secrets.pi_key = CHUNK_INITIALIZER;
+       this->secrets.pr_key = CHUNK_INITIALIZER;
        this->crypter_initiator = NULL;
        this->crypter_responder = NULL;
        this->signer_initiator = NULL;
        this->signer_responder = NULL;
        this->prf = NULL;
        
-
-
-
        /* at creation time, IKE_SA is in a initiator state */
        if (ike_sa_id->is_initiator(ike_sa_id))
        {
@@ -1027,17 +812,5 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        {
                this->current_state = (state_t *) responder_init_create(&(this->protected));
        }
-       
-       if (this->current_state == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create state object");
-               this->child_sas->destroy(this->child_sas);
-               this->ike_sa_id->destroy(this->ike_sa_id);
-               global_logger_manager->destroy_logger(global_logger_manager,this->logger);
-               this->randomizer->destroy(this->randomizer);
-               allocator_free(this);
-       }
-
-
        return &(this->protected.public);
 }
index 8ea445b..9545822 100644 (file)
@@ -1,8 +1,7 @@
 /**
  * @file ike_sa.h
  *
- * @brief Class ike_sa_t. An object of this type is managed by an
- * ike_sa_manager_t object and represents an IKE_SA
+ * @brief Interface of ike_sa_id_t.
  *
  */
 
@@ -45,8 +44,8 @@
 typedef struct ike_sa_t ike_sa_t;
 
 /**
- * @brief This class is used to represent an IKE_SA
- *
+ * @brief Class ike_sa_t. An object of this type is managed by an
+ * ike_sa_manager_t object and represents an IKE_SA.
  */
 struct ike_sa_t {
 
@@ -60,7 +59,7 @@ struct ike_sa_t {
        status_t (*process_message) (ike_sa_t *this,message_t *message);
 
        /**
-        * Initiate a new connection with given configuration name
+        * @brief Initiate a new connection with given configuration name.
         * 
         * @param this                  calling object
         * @param name                  name of the configuration
@@ -69,26 +68,28 @@ struct ike_sa_t {
        status_t (*initialize_connection) (ike_sa_t *this, char *name);
 
        /**
-        * @brief Get the id of the SA
+        * @brief Get the id of the SA.
         *
-        * @param this ike_sa_t-message_t object object
-        * @return ike_sa's ike_sa_id_t
+        * @param this                  ike_sa_t object object
+        * @return                              ike_sa's ike_sa_id_t
         */
        ike_sa_id_t* (*get_id) (ike_sa_t *this);
 
        /**
-        * @brief Destroys a ike_sa_t object
+        * @brief Destroys a ike_sa_t object.
         *
-        * @param this ike_sa_t object
-        * @return SUCCESSFUL if succeeded, FAILED otherwise
+        * @param this                  ike_sa_t object
         */
-       status_t (*destroy) (ike_sa_t *this);
+       void (*destroy) (ike_sa_t *this);
 };
 
 typedef struct protected_ike_sa_t protected_ike_sa_t;
 
 /**
- * Protected data of an ike_sa_t object
+ * @brief Protected data of an ike_sa_t object.
+ * 
+ * This members should only be accessed from 
+ * the varius state classes.
  */
 struct protected_ike_sa_t {
 
@@ -105,15 +106,12 @@ struct protected_ike_sa_t {
         * 
         * Used in every state.
         * 
-        * @param this          calling object
-        * @param type          exchange type of new message
-        * @param request       TRUE, if message has to be a request
-        * @param message       new message is stored at this location
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
+        * @param this                          calling object
+        * @param type                          exchange type of new message
+        * @param request                       TRUE, if message has to be a request
+        * @param message                       new message is stored at this location
         */
-       status_t (*build_message) (protected_ike_sa_t *this, exchange_type_t type, bool request, message_t **message);
+       void (*build_message) (protected_ike_sa_t *this, exchange_type_t type, bool request, message_t **message);
 
        /**
         * Initiate a new connection with given configuration name
@@ -122,9 +120,8 @@ struct protected_ike_sa_t {
         * @param dh_shared_secret      shared secret of diffie hellman exchange
         * @param initiator_nonce       nonce of initiator
         * @param responder_nonce       nonce of responder
-        * @return                                      TODO
         */
-       status_t (*compute_secrets) (protected_ike_sa_t *this,chunk_t dh_shared_secret,chunk_t initiator_nonce, chunk_t responder_nonce);
+       void (*compute_secrets) (protected_ike_sa_t *this,chunk_t dh_shared_secret,chunk_t initiator_nonce, chunk_t responder_nonce);
        
        /**
         * Gets the internal stored logger_t object for given ike_sa_t object.
@@ -234,14 +231,14 @@ struct protected_ike_sa_t {
 /**
  * Creates an ike_sa_t object with a specific ike_sa_id_t object
  *
- * @param[in] ike_sa_id ike_sa_id_t object to associate with new IKE_SA.
- *                                             The object is internal getting cloned
- *                                             and so has to be destroyed by the caller.
+ * @param[in] ike_sa_id        ike_sa_id_t object to associate with new IKE_SA.
+ *                                                     The object is internal getting cloned
+ *                                                     and so has to be destroyed by the caller.
  *
  * @warning the Content of internal ike_sa_id_t object can change over time
- *                     e.g. when a IKE_SA_INIT has been finished
+ *                     e.g. when a IKE_SA_INIT has been finished.
  *
- * @return created ike_sa_t object
+ * @return                                     created ike_sa_t object
  */
 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id);
 
index 5429595..f5c93cf 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file ike_sa_id.c
  *
- * @brief Class for identification of an IKE_SA
+ * @brief Implementation of ike_sa_id_t.
  *
  */
 
@@ -39,9 +39,6 @@ struct private_ike_sa_id_t {
         */
        ike_sa_id_t public;
 
-
-       /* Private values */
-
         /**
          * SPI of Initiator
          */
@@ -61,22 +58,23 @@ struct private_ike_sa_id_t {
 
 
 /**
- * @brief implements function set_responder_spi of ike_sa_id_t
+ * implements ike_sa_id_t.set_responder_spi.
  */
-static status_t set_responder_spi (private_ike_sa_id_t *this, u_int64_t responder_spi)
+static void set_responder_spi (private_ike_sa_id_t *this, u_int64_t responder_spi)
 {
        this->responder_spi = responder_spi;
-       return SUCCESS;
 }
 
-static status_t set_initiator_spi(private_ike_sa_id_t *this, u_int64_t initiator_spi)
+/**
+ * implements ike_sa_id_t.set_initiator_spi.
+ */
+static void set_initiator_spi(private_ike_sa_id_t *this, u_int64_t initiator_spi)
 {
        this->initiator_spi = initiator_spi;
-       return SUCCESS;
 }
 
 /**
- * @brief implements ike_sa_id_t.get_initiator_spi
+ * implements ike_sa_id_t.get_initiator_spi.
  */
 static u_int64_t get_initiator_spi (private_ike_sa_id_t *this)
 {
@@ -84,7 +82,7 @@ static u_int64_t get_initiator_spi (private_ike_sa_id_t *this)
 }
 
 /**
- * @brief implements ike_sa_id_t.get_responder_spi
+ * implements ike_sa_id_t.get_responder_spi.
  */
 static u_int64_t get_responder_spi (private_ike_sa_id_t *this)
 {
@@ -92,51 +90,40 @@ static u_int64_t get_responder_spi (private_ike_sa_id_t *this)
 }
 
 /**
- * @brief implements function equals of ike_sa_id_t
+ * implements ike_sa_id_t.get_responder_spi.
  */
-static status_t equals (private_ike_sa_id_t *this,private_ike_sa_id_t *other, bool *are_equal)
+static bool equals (private_ike_sa_id_t *this, private_ike_sa_id_t *other)
 {
        if ((this == NULL)||(other == NULL))
        {
-               return FAILED;
+               return FALSE;
        }
        if ((this->is_initiator_flag == other->is_initiator_flag) &&
                (this->initiator_spi == other->initiator_spi) &&
                (this->responder_spi == other->responder_spi))
-
        {
                /* private_ike_sa_id's are equal */
-               *are_equal = TRUE;
+               return TRUE;
        }
        else
        {
                /* private_ike_sa_id's are not equal */
-               *are_equal = FALSE;
+               return FALSE;
        }
-
-       return SUCCESS;
 }
 
 /**
- * @brief implements function replace_values of ike_sa_id_t
+ * implements ike_sa_id_t.replace_values.
  */
-status_t replace_values (private_ike_sa_id_t *this, private_ike_sa_id_t *other)
+static void replace_values(private_ike_sa_id_t *this, private_ike_sa_id_t *other)
 {
-       if ((this == NULL) || (other == NULL))
-       {
-               return FAILED;
-       }
-
        this->initiator_spi = other->initiator_spi;
        this->responder_spi = other->responder_spi;
        this->is_initiator_flag = other->is_initiator_flag;
-
-       return SUCCESS;
 }
 
-
 /**
- * @brief implements ike_sa_id_t.is_initiator
+ * implements ike_sa_id_t.is_initiator.
  */
 static bool is_initiator(private_ike_sa_id_t *this)
 {
@@ -144,7 +131,7 @@ static bool is_initiator(private_ike_sa_id_t *this)
 }
 
 /**
- * @brief implements ike_sa_id_t.switch_initiator
+ * implements ike_sa_id_t.switch_initiator.
  */
 static bool switch_initiator(private_ike_sa_id_t *this)
 {
@@ -159,24 +146,20 @@ static bool switch_initiator(private_ike_sa_id_t *this)
        return this->is_initiator_flag;
 }
 
-
 /**
- * @brief implements function clone of ike_sa_id_t
+ * implements ike_sa_id_t.clone.
  */
-static status_t clone (private_ike_sa_id_t *this, ike_sa_id_t **clone_of_this)
+static ike_sa_id_t* clone(private_ike_sa_id_t *this)
 {
-       *clone_of_this = ike_sa_id_create(this->initiator_spi, this->responder_spi, this->is_initiator_flag);
-
-       return (*clone_of_this == NULL) ? OUT_OF_RES : SUCCESS;
+       return ike_sa_id_create(this->initiator_spi, this->responder_spi, this->is_initiator_flag);
 }
 
 /**
- * @brief implements function destroy of ike_sa_id_t
+ * implements ike_sa_id_t.clone.
  */
-static status_t destroy (private_ike_sa_id_t *this)
+static void destroy(private_ike_sa_id_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -185,24 +168,20 @@ static status_t destroy (private_ike_sa_id_t *this)
 ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiator_flag)
 {
        private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t);
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* Public functions */
-       this->public.set_responder_spi = (status_t(*)(ike_sa_id_t*,u_int64_t)) set_responder_spi;
-       this->public.set_initiator_spi = (status_t(*)(ike_sa_id_t*,u_int64_t)) set_initiator_spi;
+       this->public.set_responder_spi = (void(*)(ike_sa_id_t*,u_int64_t)) set_responder_spi;
+       this->public.set_initiator_spi = (void(*)(ike_sa_id_t*,u_int64_t)) set_initiator_spi;
        this->public.get_responder_spi = (u_int64_t(*)(ike_sa_id_t*)) get_responder_spi;
        this->public.get_initiator_spi = (u_int64_t(*)(ike_sa_id_t*)) get_initiator_spi;
-       this->public.equals = (status_t(*)(ike_sa_id_t*,ike_sa_id_t*,bool*)) equals;
-       this->public.replace_values = (status_t(*)(ike_sa_id_t*,ike_sa_id_t*)) replace_values;
+       this->public.equals = (bool(*)(ike_sa_id_t*,ike_sa_id_t*)) equals;
+       this->public.replace_values = (void(*)(ike_sa_id_t*,ike_sa_id_t*)) replace_values;
 
        this->public.is_initiator = (bool(*)(ike_sa_id_t*)) is_initiator;
        this->public.switch_initiator = (bool(*)(ike_sa_id_t*)) switch_initiator;
 
-       this->public.clone = (status_t(*)(ike_sa_id_t*,ike_sa_id_t**)) clone;
-       this->public.destroy = (status_t(*)(ike_sa_id_t*))destroy;
+       this->public.clone = (ike_sa_id_t*(*)(ike_sa_id_t*)) clone;
+       this->public.destroy = (void(*)(ike_sa_id_t*))destroy;
 
        /* private data */
        this->initiator_spi = initiator_spi;
index 7eb8a32..2b4b643 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file ike_sa_id.h
  *
- * @brief Class for identification of an IKE_SA
+ * @brief Interface of ike_sa_id_t.
  *
  */
 
@@ -42,98 +42,96 @@ struct ike_sa_id_t {
         *
         * This function is called when a request or reply of a IKE_SA_INIT is received.
         *
-        * @param this ike_sa_id_t object
-        * @param responder_spi SPI of responder to set
-        * @return SUCCESSFUL in any case
+        * @param this                          ike_sa_id_t object
+        * @param responder_spi         SPI of responder to set
         */
-       status_t (*set_responder_spi) (ike_sa_id_t *this, u_int64_t responder_spi);
+       void (*set_responder_spi) (ike_sa_id_t *this, u_int64_t responder_spi);
 
        /**
         * @brief Sets the SPI of the initiator.
         *
         *
-        * @param this ike_sa_id_t object
-        * @param initiator_spi SPI to set
-        * @return SUCCESSFUL in any case
+        * @param this                          ike_sa_id_t object
+        * @param initiator_spi         SPI to set
         */
-       status_t (*set_initiator_spi) (ike_sa_id_t *this, u_int64_t initiator_spi);
+       void (*set_initiator_spi) (ike_sa_id_t *this, u_int64_t initiator_spi);
 
        /**
-        * @brief Returns the initiator spi
+        * @brief Returns the initiator spi.
         *
-        * @param this ike_sa_id_t object
-        * @return spi of the initiator
+        * @param this                          ike_sa_id_t object
+        * @return                                      spi of the initiator
         */
        u_int64_t (*get_initiator_spi) (ike_sa_id_t *this);
 
        /**
-        * @brief Returns the responder spi
+        * @brief Returns the responder spi.
         *
-        * @param this ike_sa_id_t object
-        * @return spi of the responder
+        * @param this                          ike_sa_id_t object
+        * @return                                      spi of the responder
         */
        u_int64_t (*get_responder_spi) (ike_sa_id_t *this);
 
        /**
-        * @brief Check if two ike_sa_ids are equal
+        * @brief Check if two ike_sa_ids are equal.
         *
-        * @param this ike_sa_id_t object
-        * @param other ike_sa_id object to check if equal
-        * @param are_equal is set to TRUE, if given ike_sa_ids are equal, FALSE otherwise
-        * @return SUCCESSFUL if succeeded, FAILED otherwise
+        * @param this                          ike_sa_id_t object
+        * @param other                         ike_sa_id object to check if equal
+        * @return                                      TRUE if given ike_sa_ids are equal, FALSE otherwise
         */
-       status_t (*equals) (ike_sa_id_t *this,ike_sa_id_t *other, bool *are_equal);
+       bool (*equals) (ike_sa_id_t *this, ike_sa_id_t *other);
 
        /**
-        * @brief Replace the values of a given ike_sa_id_t object with values
-        * from another ike_sa_id_t object
+        * @brief Replace the values of a given ike_sa_id_t object with values.
+        * from another ike_sa_id_t object.
         *
-        * @param this ike_sa_id_t object
-        * @param other ike_sa_id_t object which values will be taken
-        * @return SUCCESSFUL if succeeded, FAILED otherwise
+        * @param this                          ike_sa_id_t object
+        * @param other                         ike_sa_id_t object which values will be taken
         */
-       status_t (*replace_values) (ike_sa_id_t *this, ike_sa_id_t *other);
+       void (*replace_values) (ike_sa_id_t *this, ike_sa_id_t *other);
 
        /**
-        * @brief gets the initiator flag
+        * @brief gets the initiator flag.
         *
-        * @param this ike_sa_id_t object
-        * @return TRUE if we are the original initator
+        * @param this                          ike_sa_id_t object
+        * @return                                      TRUE if we are the original initator
         */
        bool (*is_initiator) (ike_sa_id_t *this);
 
        /**
-        * @brief switches the initiator flag
+        * @brief switches the initiator flag.
         * 
-        * @param this ike_sa_id_t object
-        * @return TRUE if we are the original initator after switch
+        * @param this                          ike_sa_id_t object
+        * @return                                      TRUE if we are the original initator after switch
         */
        bool (*switch_initiator) (ike_sa_id_t *this);
 
        /**
-        * @brief Clones a given ike_sa_id_t object
+        * @brief Clones a given ike_sa_id_t object.
         *
-        * @param this ike_sa_id_t object
-        * @param clone_of_this ike_sa_id_t object which will be created
-        * @return SUCCESSFUL if succeeded, FAILED otherwise
+        * @param this                          ike_sa_id_t object
+        * @return                                      cloned ike_sa_id
         */
-       status_t (*clone) (ike_sa_id_t *this,ike_sa_id_t **clone_of_this);
+       ike_sa_id_t *(*clone) (ike_sa_id_t *this);
 
        /**
-        * @brief Destroys a ike_sa_id_tobject
+        * @brief Destroys a ike_sa_id_tobject.
         *
-        * @param this ike_sa_id_t object
-        * @return SUCCESSFUL if succeeded, FAILED otherwise
+        * @param this                          ike_sa_id_t object
         */
-       status_t (*destroy) (ike_sa_id_t *this);
+       void (*destroy) (ike_sa_id_t *this);
 };
 
 /**
- * Creates an ike_sa_id_t object with specific spi's and defined role
+ * @brief Creates an ike_sa_id_t object with specific spi's and defined role
  *
  * @warning The initiator SPI and role is not changeable after initiating a ike_sa_id object
+ * 
+ * @param initiator_spi                        initiators spi
+ * @param responder_spi                        responders spi
+ * @param is_initiator                 TRUE if we are the original initiator
+ * @return                                             created ike_sa_id_t object
  */
-
 ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiaor);
 
 #endif /*IKE_SA_ID_H_*/
index 8348dae..698d693 100644 (file)
@@ -96,11 +96,6 @@ static ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
 {
        ike_sa_entry_t *this = allocator_alloc_thing(ike_sa_entry_t);
 
-       if (this == NULL)
-       {
-               return NULL;
-       }
-
        /* destroy function */
        this->destroy = ike_sa_entry_destroy;
        
@@ -113,22 +108,11 @@ static ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
        this->driveout_waiting_threads = FALSE;
        
        /* ike_sa_id is always cloned */
-       ike_sa_id->clone(ike_sa_id, &(this->ike_sa_id));
-       if (this->ike_sa_id == NULL)
-       {
-               allocator_free(this);   
-               return NULL;
-       }
-       
+       this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
+
        /* create new ike_sa */
        this->ike_sa = ike_sa_create(ike_sa_id);
-       if (this->ike_sa == NULL)
-       {
-               this->ike_sa_id->destroy(this->ike_sa_id);
-               allocator_free(this);   
-               return NULL;
-               
-       }
+
        return this;
 }
 
@@ -149,11 +133,9 @@ struct private_ike_sa_manager_t {
         * we give out SPIs incremental
         *
         * @param this                  the ike_sa_manager
-        * @param spi[out]              spi will be written here
-        * @return                              SUCCESS or,
-        *                                              OUT_OF_RES when we already served 2^64 SPIs ;-)
+        * @return                              the next spi
         */
-        status_t (*get_next_spi) (private_ike_sa_manager_t *this, u_int64_t *spi);
+       u_int64_t (*get_next_spi) (private_ike_sa_manager_t *this);
 
        /**
         * @brief find the ike_sa_entry in the list by SPIs
@@ -167,7 +149,6 @@ struct private_ike_sa_manager_t {
         * @return                              
         *                                              - SUCCESS when found,
         *                                              - NOT_FOUND when no such ike_sa_id in list
-        *                                              - OUT_OF_RES
         */
         status_t (*get_entry_by_id) (private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, ike_sa_entry_t **entry);
 
@@ -183,7 +164,6 @@ struct private_ike_sa_manager_t {
         * @return                              
         *                                              - SUCCESS when found,
         *                                              - NOT_FOUND when no such ike_sa_id in list
-        *                                              - OUT_OF_RES
         */
         status_t (*get_entry_by_sa) (private_ike_sa_manager_t *this, ike_sa_t *ike_sa, ike_sa_entry_t **entry);
         
@@ -221,7 +201,7 @@ struct private_ike_sa_manager_t {
 
 
 /**
- * @see private_ike_sa_manager_t.get_entry_by_id
+ * Implements private_ike_sa_manager_t.get_entry_by_id.
  */
 static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, ike_sa_entry_t **entry)
 {
@@ -230,22 +210,14 @@ static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike
        status_t status;
        
        /* create iterator over list of ike_sa's */
-       status = list->create_iterator(list, &iterator, TRUE);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger,ERROR,"Fatal Error: could not create iterator: %s",mapping_find(status_m,status));
-               /* out of res */
-               return status;
-       }
-       
+       list->create_iterator(list, &iterator, TRUE);
+
        /* default status */
        status = NOT_FOUND;
        
-       
        while (iterator->has_next(iterator))
        {
                ike_sa_entry_t *current;
-               bool are_equal = FALSE;
                
                iterator->current(iterator, (void**)&current);
                if (current->ike_sa_id->get_responder_spi(current->ike_sa_id) == 0) {
@@ -259,10 +231,9 @@ static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike
                                break;
                        }
                }
-               current->ike_sa_id->equals(current->ike_sa_id, ike_sa_id, &are_equal);
-               if (are_equal)
+                if (current->ike_sa_id->equals(current->ike_sa_id, ike_sa_id))
                {
-                       this->logger->log(this->logger,CONTROL | MOST,"Found entry by full ID");
+                       this->logger->log(this->logger,CONTROL | MOST,"Found entry by full ID");
                        *entry = current;
                        status = SUCCESS;
                        break;
@@ -274,7 +245,7 @@ static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike
 }
 
 /**
- * @see private_ike_sa_manager_t.get_entry_by_sa
+ * Implements private_ike_sa_manager_t.get_entry_by_sa.
  */
 static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa, ike_sa_entry_t **entry)
 {
@@ -282,12 +253,7 @@ static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa
        iterator_t *iterator;
        status_t status;
        
-       status = list->create_iterator(list, &iterator, TRUE);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger,ERROR,"Fatal Error: could not create iterator: %s",mapping_find(status_m,status));
-               return status;
-       }
+       list->create_iterator(list, &iterator, TRUE);
        
        /* default status */
        status = NOT_FOUND;
@@ -306,11 +272,12 @@ static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa
                }
        }
        iterator->destroy(iterator);
+       
        return status;
 }
 
 /**
- * @see private_ike_sa_manager_s.delete_entry
+ * Implements private_ike_sa_manager_s.delete_entry.
  */
 static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *entry)
 {
@@ -318,13 +285,7 @@ static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *ent
        iterator_t *iterator;
        status_t status;
        
-       status = list->create_iterator(list, &iterator, TRUE);
-       
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger,ERROR,"Fatal Error: could not create iterator: %s",mapping_find(status_m,status));
-               return status;
-       }
+       list->create_iterator(list, &iterator, TRUE);
 
        status = NOT_FOUND;     
        
@@ -347,85 +308,47 @@ static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *ent
 
 
 /**
- * @see private_ike_sa_manager_t.get_next_spi
+ * Implements private_ike_sa_manager_t.get_next_spi.
  */
-static status_t get_next_spi(private_ike_sa_manager_t *this, u_int64_t *spi)
+static u_int64_t get_next_spi(private_ike_sa_manager_t *this)
 {
        this->next_spi++;
        if (this->next_spi == 0) {
-               /* our software ran so incredible stable, we have no more
-                * SPIs to give away :-/.  */
-               this->logger->log(this->logger,CONTROL | MOST,"No more SPI values available. WOW!");
-               return OUT_OF_RES;
+               /* TODO handle overflow,
+                * delete all SAs or so
+                */
        }
-       *spi = this->next_spi;
-       return SUCCESS;
+       return this->next_spi;
 }
 
 /**
  * Implementation of ike_sa_manager.create_and_checkout.
  */
-static status_t create_and_checkout(private_ike_sa_manager_t *this,ike_sa_t **ike_sa)
+static void create_and_checkout(private_ike_sa_manager_t *this,ike_sa_t **ike_sa)
 {
-       status_t retval;
        u_int64_t initiator_spi;
        ike_sa_entry_t *new_ike_sa_entry;
        ike_sa_id_t *new_ike_sa_id;
 
-       retval = this->get_next_spi(this, &initiator_spi);
-       if (retval == SUCCESS)
-       {
-               new_ike_sa_id =         ike_sa_id_create(0, 0, TRUE);
-               if (new_ike_sa_id != NULL)
-               {
-                       new_ike_sa_id->set_initiator_spi(new_ike_sa_id, initiator_spi);
-       
-                       /* create entry */
-                       new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
-                       new_ike_sa_id->destroy(new_ike_sa_id);
-                       if (new_ike_sa_entry != NULL)
-                       { 
-                               /* each access is locked */
-                               pthread_mutex_lock(&(this->mutex));
-                               
-                               retval = this->ike_sa_list->insert_last(this->ike_sa_list, new_ike_sa_entry);
+       initiator_spi = this->get_next_spi(this);
+       new_ike_sa_id = ike_sa_id_create(0, 0, TRUE);
+       new_ike_sa_id->set_initiator_spi(new_ike_sa_id, initiator_spi);
+
+       /* create entry */
+       new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
+       new_ike_sa_id->destroy(new_ike_sa_id);
+
+       /* each access is locked */
+       pthread_mutex_lock(&(this->mutex));
        
-                               if (retval == SUCCESS)
-                               {
-                                       /* check ike_sa out */
-                                       this->logger->log(this->logger,CONTROL | MORE ,"New IKE_SA created and added to list of known IKE_SA's");
-                                       new_ike_sa_entry->checked_out = TRUE;
-                                       *ike_sa = new_ike_sa_entry->ike_sa;
-                                       /* DON'T use return, we must unlock the mutex! */
-                               }
-                               else
-                               {
-                                       /* ike_sa_entry could not be added to list*/
-                                       this->logger->log(this->logger,ERROR,"Fatal error: ike_sa_entry_t could not be added to list");
-                               }
-                               pthread_mutex_unlock(&(this->mutex));
-                       }
-                       else
-                       {
-                               /* new ike_sa_entry could not be created */
-                               this->logger->log(this->logger,ERROR,"Fatal error: ike_sa_entry_t could not be created");       
-                               retval = OUT_OF_RES;
-                       }
-               }
-               else
-               {
-                       /* new ike_sa_id could not be created */
-                       this->logger->log(this->logger,ERROR,"Fatal error: ike_sa_id_t could not be created");  
-                       retval = OUT_OF_RES;
-               }
-       }
-       else
-       {
-               /* next SPI could not be created */
-               this->logger->log(this->logger,ERROR,"Fatal error: Next SPI could not be created");
-       }
+       this->ike_sa_list->insert_last(this->ike_sa_list, new_ike_sa_entry);
 
-       return retval;
+       /* check ike_sa out */
+       this->logger->log(this->logger,CONTROL | MORE ,"New IKE_SA created and added to list of known IKE_SA's");
+       new_ike_sa_entry->checked_out = TRUE;
+       *ike_sa = new_ike_sa_entry->ike_sa;
+
+       pthread_mutex_unlock(&(this->mutex));
 }
 
 /**
@@ -436,13 +359,13 @@ static status_t checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id,
        bool responder_spi_set;
        bool initiator_spi_set;
        status_t retval;
-
+       
        /* each access is locked */
        pthread_mutex_lock(&(this->mutex));
-
+       
        responder_spi_set = (FALSE != ike_sa_id->get_responder_spi(ike_sa_id));
        initiator_spi_set = (FALSE != ike_sa_id->get_initiator_spi(ike_sa_id));
-
+       
        if (initiator_spi_set && responder_spi_set)
        {
                /* we SHOULD have an IKE_SA for these SPIs in the list,
@@ -461,44 +384,44 @@ static status_t checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id,
                        }
                        else
                        {
-                               /* is this IKE_SA already checked out ?? 
-                                * are we welcome to get this SA ? */
-                               while (entry->checked_out && !entry->driveout_waiting_threads)  
-                               { 
-                                       /* so wait until we can get it for us.
-                                        * we register us as waiting.
-                                        */
-                                       entry->waiting_threads++;
-                                       pthread_cond_wait(&(entry->condvar), &(this->mutex));
-                                       entry->waiting_threads--;
-                               }
-                               
-                               /* hm, a deletion request forbids us to get this SA, go home */
-                               if (entry->driveout_waiting_threads)
-                               {
-                                       /* we must signal here, others are interested that we leave */
-                                       pthread_cond_signal(&(entry->condvar));
-                                       this->logger->log(this->logger,CONTROL|MORE,"Drive out waiting thread for existing IKE_SA");
-                                       retval = NOT_FOUND;
-                               }
-                               else
-                               {
-                                       this->logger->log(this->logger,CONTROL|MOST,"IKE SA successfully checked out");
-                                       /* ok, this IKE_SA is finally ours */
-                                       entry->checked_out = TRUE;
-                                       *ike_sa = entry->ike_sa;
-                                       /* DON'T use return, we must unlock the mutex! */
-                                       retval = SUCCESS; 
-                               }
-                       }
-                }
-                else
-                {
-                       this->logger->log(this->logger,ERROR | MORE,"IKE SA not stored in known IKE_SA list");
-                       /* looks like there is no such IKE_SA, better luck next time... */
-                       /* DON'T use return, we must unlock the mutex! */
-                       retval = NOT_FOUND;
-                }
+                               /* is this IKE_SA already checked out ?? 
+                                * are we welcome to get this SA ? */
+                               while (entry->checked_out && !entry->driveout_waiting_threads)  
+                               { 
+                                       /* so wait until we can get it for us.
+                                        * we register us as waiting.
+                                        */
+                                       entry->waiting_threads++;
+                                       pthread_cond_wait(&(entry->condvar), &(this->mutex));
+                                       entry->waiting_threads--;
+                               }
+                               
+                               /* hm, a deletion request forbids us to get this SA, go home */
+                               if (entry->driveout_waiting_threads)
+                               {
+                                       /* we must signal here, others are interested that we leave */
+                                       pthread_cond_signal(&(entry->condvar));
+                                       this->logger->log(this->logger,CONTROL|MORE,"Drive out waiting thread for existing IKE_SA");
+                                       retval = NOT_FOUND;
+                               }
+                               else
+                               {
+                                       this->logger->log(this->logger,CONTROL|MOST,"IKE SA successfully checked out");
+                                       /* ok, this IKE_SA is finally ours */
+                                       entry->checked_out = TRUE;
+                                       *ike_sa = entry->ike_sa;
+                                       /* DON'T use return, we must unlock the mutex! */
+                                       retval = SUCCESS; 
+                               }
+                       }
+               }
+               else
+               {
+                       this->logger->log(this->logger,ERROR | MORE,"IKE SA not stored in known IKE_SA list");
+                       /* looks like there is no such IKE_SA, better luck next time... */
+                       /* DON'T use return, we must unlock the mutex! */
+                       retval = NOT_FOUND;
+               }
        }
        else if (initiator_spi_set && !responder_spi_set)
        {
@@ -512,53 +435,29 @@ static status_t checkout(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id,
                u_int64_t responder_spi;
                ike_sa_entry_t *new_ike_sa_entry;
                
-
+               
                /* set SPIs, we are the responder */
-               retval = this->get_next_spi(this, &responder_spi);
-
-               if (retval == SUCCESS)
-               { /* next SPI could be created */
-                       
-                       /* we also set arguments spi, so its still valid */
-                       ike_sa_id->set_responder_spi(ike_sa_id, responder_spi);
-                       
-                       /* create entry */
-                       new_ike_sa_entry = ike_sa_entry_create(ike_sa_id);
-                       if (new_ike_sa_entry != NULL)
-                       { 
-                               retval = this->ike_sa_list->insert_last(this->ike_sa_list, new_ike_sa_entry);
-                               if (retval == SUCCESS)
-                               {
-                                       /* check ike_sa out */
-                                       this->logger->log(this->logger,CONTROL | MORE ,"IKE_SA added to list of known IKE_SA's");
-                                       new_ike_sa_entry->checked_out = TRUE;
-                                       *ike_sa = new_ike_sa_entry->ike_sa;
-                       
-                                        /* DON'T use return, we must unlock the mutex! */
-                               }
-                               else
-                               {
-                                       /* ike_sa_entry could not be added to list*/
-                                       this->logger->log(this->logger,ERROR,"Fatal error: ike_sa_entry could not be added to list");
-                               }                       
-                       }
-                       else
-                       {
-                               /* new ike_sa_entry could not be created */
-                               this->logger->log(this->logger,ERROR,"Fatal error: ike_sa_entry could not be created");                 
-                               retval = OUT_OF_RES;
-                       }
-               }
-               else
-               { /* next SPI could not be created */
-                       this->logger->log(this->logger,ERROR,"Fatal error: Next SPI could not be created");
-               }
+               responder_spi = this->get_next_spi(this);
+               
+               /* we also set arguments spi, so its still valid */
+               ike_sa_id->set_responder_spi(ike_sa_id, responder_spi);
+               
+               /* create entry */
+               new_ike_sa_entry = ike_sa_entry_create(ike_sa_id);
                
+               this->ike_sa_list->insert_last(this->ike_sa_list, new_ike_sa_entry);
+               
+               /* check ike_sa out */
+               this->logger->log(this->logger,CONTROL | MORE ,"IKE_SA added to list of known IKE_SA's");
+               new_ike_sa_entry->checked_out = TRUE;
+               *ike_sa = new_ike_sa_entry->ike_sa;
+               
+               retval = SUCCESS;
        }
        else
        {
                /* responder set, initiator not: here is something seriously wrong! */
-               this->logger->log(this->logger,ERROR | MORE,"Invalid IKE_SA SPI's");
+               this->logger->log(this->logger,ERROR | MORE, "Invalid IKE_SA SPI's");
                /* DON'T use return, we must unlock the mutex! */
                retval = INVALID_ARG;
        }
@@ -647,14 +546,13 @@ static status_t checkin_and_delete(private_ike_sa_manager_t *this, ike_sa_t *ike
                this->logger->log(this->logger,ERROR,"Fatal Error: Tried to checkin and delete nonexisting IKE_SA");
                retval = NOT_FOUND;
        }
-
+       
        pthread_mutex_unlock(&(this->mutex));
        return retval;
 }
 
 /**
- * Implements ike_sa_manager_t-function delete.
- * @see ike_sa_manager_t.delete.
+ * Implements ike_sa_manager_t.delete.
  */
 static status_t delete(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id)
 {
@@ -697,15 +595,13 @@ static status_t delete(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id)
 }
 
 /**
- * Implements ike_sa_manager_t-function destroy.
- * @see ike_sa_manager_t.destroy.
+ * Implements ike_sa_manager_t.destroy.
  */
-static status_t destroy(private_ike_sa_manager_t *this)
+static void destroy(private_ike_sa_manager_t *this)
 {
        /* destroy all list entries */
        linked_list_t *list = this->ike_sa_list;
        iterator_t *iterator;
-       status_t status;
        ike_sa_entry_t *entry;
        
        pthread_mutex_lock(&(this->mutex));
@@ -713,13 +609,7 @@ static status_t destroy(private_ike_sa_manager_t *this)
        this->logger->log(this->logger,CONTROL | MORE,"Going to destroy IKE_SA manager and all managed IKE_SA's");
        
        /* Step 1: drive out all waiting threads  */
-       status = list->create_iterator(list, &iterator, TRUE);
-       
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger,ERROR,"Fatal Error: Create of iterator while destroying IKE_SA-Manager failed");
-               return FAILED;
-       }
+       list->create_iterator(list, &iterator, TRUE);
 
        this->logger->log(this->logger,CONTROL | MOST,"Set driveout flags for all stored IKE_SA's");
        while (iterator->has_next(iterator))
@@ -761,8 +651,6 @@ static status_t destroy(private_ike_sa_manager_t *this)
        global_logger_manager->destroy_logger(global_logger_manager,this->logger);
 
        allocator_free(this);
-       
-       return SUCCESS;
 }
 
 /*
@@ -773,8 +661,8 @@ ike_sa_manager_t *ike_sa_manager_create()
        private_ike_sa_manager_t *this = allocator_alloc_thing(private_ike_sa_manager_t);
 
        /* assign public functions */
-       this->public.destroy = (status_t(*)(ike_sa_manager_t*))destroy;
-       this->public.create_and_checkout = (status_t(*)(ike_sa_manager_t*, ike_sa_t **sa))create_and_checkout;
+       this->public.destroy = (void(*)(ike_sa_manager_t*))destroy;
+       this->public.create_and_checkout = (void(*)(ike_sa_manager_t*, ike_sa_t **sa))create_and_checkout;
        this->public.checkout = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t *sa_id, ike_sa_t **sa))checkout;
        this->public.checkin = (status_t(*)(ike_sa_manager_t*, ike_sa_t *sa))checkin;
        this->public.delete = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t *sa_id))delete;
@@ -788,20 +676,8 @@ ike_sa_manager_t *ike_sa_manager_create()
 
        /* initialize private variables */
        this->logger = global_logger_manager->create_logger(global_logger_manager,IKE_SA_MANAGER,NULL);
-       if (this->logger == NULL)
-       {
-               allocator_free(this);
-               return NULL;
-       }
        
        this->ike_sa_list = linked_list_create();
-       if (this->ike_sa_list == NULL)
-       {
-               this->logger->log(this->logger,ERROR,"Fatal error: Failed to create list for managed IKE_SA");
-               global_logger_manager->destroy_logger(global_logger_manager,this->logger);
-               allocator_free(this);
-               return NULL;
-       }
 
        pthread_mutex_init(&(this->mutex), NULL);
 
index 4ef1bf7..ae54e61 100644 (file)
@@ -58,7 +58,6 @@ struct ike_sa_manager_t {
         * @returns                                     
         *                                                      - SUCCESS if checkout successful
         *                                                      - NOT_FOUND when no such SA is available
-        *                                                      - OUT_OF_RES
         */
        status_t (*checkout) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *sa_id, ike_sa_t **ike_sa);
        
@@ -73,12 +72,9 @@ struct ike_sa_manager_t {
         * 
         * @param ike_sa_manager        the manager object
         * @param ike_sa[out]           checked out SA
-        * @returns                                     
-        *                                                      - SUCCESS if checkout successful
-        *                                                      - OUT_OF_RES
         */
-       status_t (*create_and_checkout) (ike_sa_manager_t* ike_sa_manager,ike_sa_t **ike_sa);
-       
+       void (*create_and_checkout) (ike_sa_manager_t* ike_sa_manager,ike_sa_t **ike_sa);
        /**
         * @brief Checkin the SA after usage
         * 
@@ -88,8 +84,9 @@ struct ike_sa_manager_t {
         * @param ike_sa_manager        the manager object
         * @param ike_sa_id[in/out]     the SA identifier, will be updated
         * @param ike_sa[out]           checked out SA
-        * @returns                                     SUCCESS if checked in
-        *                                                      NOT_FOUND when not found (shouldn't happen!)
+        * @returns                             
+        *                                                      - SUCCESS if checked in
+        *                                                      - NOT_FOUND when not found (shouldn't happen!)
         */
        status_t (*checkin) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
        /**
@@ -100,17 +97,20 @@ struct ike_sa_manager_t {
         *  
         * @param ike_sa_manager        the manager object
         * @param ike_sa_id[in/out]     the SA identifier
-        * @returns                                     SUCCESS if found
-        *                                                      NOT_FOUND when no such SA is available
+        * @returns                             
+        *                                                      - SUCCESS if found
+        *                                                      - NOT_FOUND when no such SA is available
         */
        status_t (*delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *ike_sa_id);
+       
        /**
         * @brief delete a checked out SA
-        *  
+        *
         * @param ike_sa_manager        the manager object
         * @param ike_sa                        SA to delete
-        * @returns                             SUCCESS if found
-        *                                                      NOT_FOUND when no such SA is available
+        * @returns                             
+        *                                                      - SUCCESS if found
+        *                                                      - NOT_FOUND when no such SA is available
         */
        status_t (*checkin_and_delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
        
@@ -120,15 +120,14 @@ struct ike_sa_manager_t {
         * Threads will be driven out, so all SAs can be deleted cleanly
         * 
         * @param ike_sa_manager the manager object
-        * @returns SUCCESS if succeeded, FAILED otherwise
         */
-       status_t (*destroy) (ike_sa_manager_t *ike_sa_manager);
+       void (*destroy) (ike_sa_manager_t *ike_sa_manager);
 };
 
 /**
  * @brief Create a manager
  * 
- * @returns the manager
+ * @returns    the created manager
  */
 ike_sa_manager_t *ike_sa_manager_create();
 
index 43af215..28ff3a0 100644 (file)
@@ -63,10 +63,9 @@ static ike_sa_state_t get_state(private_ike_auth_requested_t *this)
 /**
  * Implements state_t.get_state
  */
-static status_t destroy(private_ike_auth_requested_t *this)
+static void destroy(private_ike_auth_requested_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
 /* 
@@ -75,16 +74,11 @@ static status_t destroy(private_ike_auth_requested_t *this)
 ike_auth_requested_t *ike_auth_requested_create(protected_ike_sa_t *ike_sa)
 {
        private_ike_auth_requested_t *this = allocator_alloc_thing(private_ike_auth_requested_t);
-       
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
        this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
-       this->public.state_interface.destroy  = (status_t (*) (state_t *)) destroy;
+       this->public.state_interface.destroy  = (void (*) (state_t *)) destroy;
        
        /* private data */
        this->ike_sa = ike_sa;
index f9c68f1..d1f9a6b 100644 (file)
@@ -63,10 +63,9 @@ static ike_sa_state_t get_state(private_ike_sa_established_t *this)
 /**
  * Implements state_t.get_state
  */
-static status_t destroy(private_ike_sa_established_t *this)
+static void destroy(private_ike_sa_established_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
 /* 
@@ -75,16 +74,11 @@ static status_t destroy(private_ike_sa_established_t *this)
 ike_sa_established_t *ike_sa_established_create(protected_ike_sa_t *ike_sa)
 {
        private_ike_sa_established_t *this = allocator_alloc_thing(private_ike_sa_established_t);
-       
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
        this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
-       this->public.state_interface.destroy  = (status_t (*) (state_t *)) destroy;
+       this->public.state_interface.destroy  = (void (*) (state_t *)) destroy;
        
        /* private data */
        this->ike_sa = ike_sa;
index 4f79143..f301b30 100644 (file)
@@ -138,13 +138,8 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
                                
                                
                                /* get the list of suggested proposals */ 
-                               status = sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
-                               if (status != SUCCESS)
-                               {       
-                                       this->logger->log(this->logger, ERROR, "Fatal errror: Could not create iterator on suggested proposals");
-                                       payloads->destroy(payloads);
-                                       return status;
-                               }
+                               sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
+
                                
                                /* now let the configuration-manager check the selected proposals*/
                                this->logger->log(this->logger, CONTROL | MOST, "Check suggested proposals");
@@ -194,14 +189,8 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
                        case KEY_EXCHANGE:
                        {
                                ke_payload_t *ke_payload = (ke_payload_t*)payload;
-               
-                               status = this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "Could not set other public value for DH exchange. Status %s",mapping_find(status_m,status));
-                                       payloads->destroy(payloads);
-                                       return OUT_OF_RES;
-                               }
+                               
+                               this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
                                
                                /* shared secret is computed AFTER processing of all payloads... */                             
                                break;
@@ -209,28 +198,16 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
                        case NONCE:
                        {
                                nonce_payload_t         *nonce_payload = (nonce_payload_t*)payload;
-                                                               
-                               if (this->received_nonce.ptr != NULL)
-                               {
-                                       this->logger->log(this->logger, CONTROL | MOST, "Destroy existing received nonce");
-                                       allocator_free(this->received_nonce.ptr);
-                                       this->received_nonce.ptr = NULL;
-                                       this->received_nonce.len = 0;
-                               }
-
-                               status = nonce_payload->get_nonce(nonce_payload, &(this->received_nonce));
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "Fatal error: Could not get received nonce");
-                                       payloads->destroy(payloads);
-                                       return OUT_OF_RES;
-                               }
                                
+                               allocator_free(this->received_nonce.ptr);
+                               this->received_nonce = CHUNK_INITIALIZER;
+                               
+                               nonce_payload->get_nonce(nonce_payload, &(this->received_nonce));
                                break;
                        }
                        default:
                        {
-                               this->logger->log(this->logger, ERROR, "Fatal errror: Payload type not supported!!!!");
+                               this->logger->log(this->logger, ERROR, "Payload type not supported!!!!");
                                payloads->destroy(payloads);
                                return FAILED;
                        }
@@ -239,31 +216,16 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
                        
        }
        payloads->destroy(payloads);
-
-       if (this->shared_secret.ptr != NULL)
-       {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy existing shared_secret");
-               allocator_free(this->shared_secret.ptr);
-               this->shared_secret.ptr = NULL;
-               this->shared_secret.len = 0;
-       }
-
-
+       
+       allocator_free(this->shared_secret.ptr);
+       this->shared_secret = CHUNK_INITIALIZER;
+       
        /* store shared secret  */
        this->logger->log(this->logger, CONTROL | MOST, "Retrieve shared secret and store it");
        status = this->diffie_hellman->get_shared_secret(this->diffie_hellman, &(this->shared_secret));         
        this->logger->log_chunk(this->logger, PRIVATE, "Shared secret", &this->shared_secret);
        
-       status = this->ike_sa->compute_secrets(this->ike_sa,this->shared_secret,this->sent_nonce, this->received_nonce);
-       if (status != SUCCESS)
-       {
-               /* secrets could not be computed */
-               this->logger->log(this->logger, ERROR | MORE, "Secrets could not be computed!");
-               return status;
-       }
-       
-       
-       
+       this->ike_sa->compute_secrets(this->ike_sa,this->shared_secret,this->sent_nonce, this->received_nonce);
 
        /****************************
         * 
@@ -285,7 +247,6 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
 
 //     response->destroy(response);
 
-
        
        return SUCCESS;
 }
@@ -301,31 +262,17 @@ static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
 /**
  * Implements state_t.get_state
  */
-static status_t destroy(private_ike_sa_init_requested_t *this)
+static void destroy(private_ike_sa_init_requested_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to destroy state of type ike_sa_init_requested_t");
        
        this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie hellman object");
        this->diffie_hellman->destroy(this->diffie_hellman);
-       if (this->sent_nonce.ptr != NULL)
-       {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
-               allocator_free(this->sent_nonce.ptr);
-       }
-       if (this->received_nonce.ptr != NULL)
-       {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
-               allocator_free(this->received_nonce.ptr);
-       }
-
-       if (this->shared_secret.ptr != NULL)
-       {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy shared secret");
-               allocator_free(this->shared_secret.ptr);
-       }
        
+       allocator_free(this->sent_nonce.ptr);
+       allocator_free(this->received_nonce.ptr);
+       allocator_free(this->shared_secret.ptr);
        allocator_free(this);
-       return SUCCESS;
 }
 
 /* 
@@ -335,22 +282,15 @@ ike_sa_init_requested_t *ike_sa_init_requested_create(protected_ike_sa_t *ike_sa
 {
        private_ike_sa_init_requested_t *this = allocator_alloc_thing(private_ike_sa_init_requested_t);
        
-       if (this == NULL)
-       {
-               return NULL;
-       }
-
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
        this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
-       this->public.state_interface.destroy  = (status_t (*) (state_t *)) destroy;
+       this->public.state_interface.destroy  = (void (*) (state_t *)) destroy;
        
        /* private data */
        this->ike_sa = ike_sa;
-       this->received_nonce.ptr = NULL;
-       this->received_nonce.len = 0;
-       this->shared_secret.ptr = NULL;
-       this->shared_secret.len = 0;
+       this->received_nonce = CHUNK_INITIALIZER;
+       this->shared_secret = CHUNK_INITIALIZER;
        this->logger = this->ike_sa->get_logger(this->ike_sa);
        this->diffie_hellman = diffie_hellman;
        this->sent_nonce = sent_nonce;
index 7bc3ee4..c4f7e2d 100644 (file)
@@ -111,16 +111,11 @@ static status_t destroy(private_ike_sa_init_responded_t *this)
 ike_sa_init_responded_t *ike_sa_init_responded_create(protected_ike_sa_t *ike_sa, chunk_t shared_secret, chunk_t received_nonce, chunk_t sent_nonce)
 {
        private_ike_sa_init_responded_t *this = allocator_alloc_thing(private_ike_sa_init_responded_t);
-       
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
        this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
-       this->public.state_interface.destroy  = (status_t (*) (state_t *)) destroy;
+       this->public.state_interface.destroy  = (void (*) (state_t *)) destroy;
        
        /* private data */
        this->ike_sa = ike_sa;
index 5e87170..2e1fabc 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file ike_sa_init_responded.h
  * 
- * @brief State of a IKE_SA after responding to an IKE_SA_INIT request
+ * @brief Interface of ike_sa_init_responded_t.
  * 
  */
 
index 1ffc324..b1e25a4 100644 (file)
@@ -91,11 +91,8 @@ struct private_initiator_init_t {
         * 
         * @param this          calling object
         * @param message       the created message will be stored at this location
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_ike_sa_init_request) (private_initiator_init_t *this, message_t **message);
+       void (*build_ike_sa_init_request) (private_initiator_init_t *this, message_t **message);
        
        /**
         * Builds the SA payload for this state.
@@ -103,11 +100,8 @@ struct private_initiator_init_t {
         * @param this          calling object
         * @param payload       The generated SA payload object of type ke_payload_t is 
         *                                      stored at this location.
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_sa_payload) (private_initiator_init_t *this, payload_t **payload);
+       void (*build_sa_payload) (private_initiator_init_t *this, payload_t **payload);
 
        /**
         * Builds the KE payload for this state.
@@ -115,22 +109,17 @@ struct private_initiator_init_t {
         * @param this          calling object
         * @param payload       The generated KE payload object of type ke_payload_t is 
         *                                      stored at this location.
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_ke_payload) (private_initiator_init_t *this, payload_t **payload);
+       void (*build_ke_payload) (private_initiator_init_t *this, payload_t **payload);
+       
        /**
         * Builds the NONCE payload for this state.
         * 
         * @param this          calling object
         * @param payload       The generated NONCE payload object of type ke_payload_t is 
         *                                      stored at this location.
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_nonce_payload) (private_initiator_init_t *this, payload_t **payload);  
+       void (*build_nonce_payload) (private_initiator_init_t *this, payload_t **payload);      
        
        /**
         * Destroy function called internally of this class after state change succeeded.
@@ -138,9 +127,8 @@ struct private_initiator_init_t {
         * This destroy function does not destroy objects which were passed to the new state.
         * 
         * @param this          calling object
-        * @return                      SUCCESS in any case
         */
-       status_t (*destroy_after_state_change) (private_initiator_init_t *this);
+       void (*destroy_after_state_change) (private_initiator_init_t *this);
 };
 
 /**
@@ -148,18 +136,18 @@ struct private_initiator_init_t {
  */
 static status_t initiate_connection (private_initiator_init_t *this, char *name)
 {
-       iterator_t      *proposal_iterator;
-       ike_sa_init_requested_t         *next_state;
-       message_t                               *message;
-       packet_t                                *packet;
-       status_t                                status;
-       host_t                                  *my_host;
-       host_t                                  *other_host;
-       randomizer_t                            *randomizer;
+       iterator_t *proposal_iterator;
+       ike_sa_init_requested_t *next_state;
+       message_t *message;
+       packet_t *packet;
+       status_t status;
+       host_t *my_host;
+       host_t *other_host;
+       randomizer_t *randomizer;
        
-
        this->logger->log(this->logger, CONTROL, "Initializing connection %s",name);
        
+       /* get local host */
        status = global_configuration_manager->get_local_host(global_configuration_manager, name, &my_host);
        if (status != SUCCESS)
        {       
@@ -168,6 +156,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
        }
        this->ike_sa->set_my_host(this->ike_sa,my_host);
        
+       /* get remote host */
        status = global_configuration_manager->get_remote_host(global_configuration_manager, name, &other_host);
        if (status != SUCCESS)
        {       
@@ -176,22 +165,17 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
        }
        this->ike_sa->set_other_host(this->ike_sa,other_host);
        
+       /* get dh group */
        status = global_configuration_manager->get_dh_group_number(global_configuration_manager, name, &(this->dh_group_number), this->dh_group_priority);
        if (status != SUCCESS)
-       {       
+       {
                this->logger->log(this->logger, ERROR | MORE, "Could not retrieve DH group number configuration for %s",name);
                return INVALID_ARG;
        }
 
-       status = this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
-               return status;  
-       }
-       
+       /* get proposals */
+       this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
        status = global_configuration_manager->get_proposals_for_host(global_configuration_manager, this->ike_sa->get_other_host(this->ike_sa), proposal_iterator);
-       /* not needed anymore */
        proposal_iterator->destroy(proposal_iterator);
        if (status != SUCCESS)
        {
@@ -202,70 +186,45 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
        /* a diffie hellman object could allready exist caused by an failed initiate_connection call */ 
        if (this->diffie_hellman == NULL)
        {
-               this    ->logger->log(this->logger, CONTROL|MOST, "create diffie hellman object");
                this->diffie_hellman = diffie_hellman_create(this->dh_group_number);
        }
        
        if (this->diffie_hellman == NULL)
        {
                this->logger->log(this->logger, ERROR, "Object of type diffie_hellman_t could not be created!");
-               return FAILED;                  
+               return FAILED;
        }
        
        if (this->sent_nonce.ptr != NULL)
        {
-               this->logger->log(this->logger, ERROR, "Free existing sent nonce!");
                allocator_free(this->sent_nonce.ptr);
                this->sent_nonce = CHUNK_INITIALIZER;
        }
 
-       this    ->logger->log(this->logger, CONTROL|MOST, "Get pseudo random bytes for nonce");
+       this->logger->log(this->logger, CONTROL|MOST, "Get pseudo random bytes for nonce");
        randomizer = this->ike_sa->get_randomizer(this->ike_sa);
-       if (randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce)) != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not create nonce!");
-               return OUT_OF_RES;
-       }
-       this    ->logger->log(this->logger, RAW|MOST, "Nonce",&(this->sent_nonce));
+       randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
+
+       this->logger->log(this->logger, RAW|MOST, "Nonce",&(this->sent_nonce));
+
+       this->build_ike_sa_init_request (this,&message);
 
-       
-       
-       status = this->build_ike_sa_init_request (this,&message);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not build IKE_SA_INIT request message");
-               return status;
-       }
-       
        /* generate packet */   
        this->logger->log(this->logger, CONTROL|MOST, "generate packet from message");
        status = message->generate(message, NULL, NULL, &packet);
        if (status != SUCCESS)
        {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not generate packet from message");
+               this->logger->log(this->logger, ERROR, "could not generate packet from message");
                message->destroy(message);
                return status;
        }
        
        this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
-       status = global_send_queue->add(global_send_queue, packet);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not add packet to send queue");
-               packet->destroy(packet);
-               message->destroy(message);
-               return status;
-       }
+       global_send_queue->add(global_send_queue, packet);
 
        /* state can now be changed */
        this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
        next_state = ike_sa_init_requested_create(this->ike_sa, this->dh_group_number, this->diffie_hellman, this->sent_nonce);
-       if (next_state == NULL)
-       {
-               this    ->logger->log(this->logger, ERROR, "Fatal error: could not create next state object of type ike_sa_init_requested_t");
-               message->destroy(message);
-               return FAILED;
-       }
 
        /* last message can now be set */
        status = this->ike_sa->set_last_requested_message(this->ike_sa, message);
@@ -282,7 +241,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
        this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
 
        /* state has NOW changed :-) */
-       this->logger->log(this->logger, CONTROL|MORE, "Changed state of IKE_SA from %s to %s",mapping_find(ike_sa_state_m,INITIATOR_INIT),mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED) );
+       this->logger->log(this->logger, CONTROL|MORE, "Changed state of IKE_SA from %s to %s", mapping_find(ike_sa_state_m,INITIATOR_INIT),mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED) );
 
        this->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
        this->destroy_after_state_change(this);
@@ -293,200 +252,99 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
 /**
  * implements private_initiator_init_t.build_ike_sa_init_request
  */
-static status_t build_ike_sa_init_request (private_initiator_init_t *this, message_t **request)
+static void build_ike_sa_init_request (private_initiator_init_t *this, message_t **request)
 {
-       status_t status;
        payload_t *payload;
        message_t *message;
        
        /* going to build message */
-       this    ->logger->log(this->logger, CONTROL|MOST, "Going to build message");
-       status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, TRUE, &message);
-       if (status != SUCCESS)
-       {       
-               this->logger->log(this->logger, ERROR, "Could not build empty message");
-               return status;
-       }
-
-       /* build SA payload */          
-       status = this->build_sa_payload(this, &payload);
-       if (status != SUCCESS)
-       {       
-               this->logger->log(this->logger, ERROR, "Could not build SA payload");
-               message->destroy(message);
-               return status;
-       }
+       this->logger->log(this->logger, CONTROL|MOST, "Going to build message");
+       this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, TRUE, &message);
        
-       this    ->logger->log(this->logger, CONTROL|MOST, "add SA payload to message");
+       /* build SA payload */          
+       this->build_sa_payload(this, &payload);
+       this->logger->log(this->logger, CONTROL|MOST, "add SA payload to message");
        message->add_payload(message, payload);
-
+       
        /* build KE payload */
-       status = this->build_ke_payload(this, &payload);
-       if (status != SUCCESS)
-       {       
-               this->logger->log(this->logger, ERROR, "Could not build KE payload");
-               message->destroy(message);
-               return status;
-       }
-
-       this    ->logger->log(this->logger, CONTROL|MOST, "add KE payload to message");
+       this->build_ke_payload(this, &payload);
+       this->logger->log(this->logger, CONTROL|MOST, "add KE payload to message");
        message->add_payload(message, payload);
        
        /* build Nonce payload */
-       status = this->build_nonce_payload(this, &payload);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not build NONCE payload");
-               message->destroy(message);
-               return status;
-       }
-
-       this    ->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message");
+       this->build_nonce_payload(this, &payload);
+       this->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message");
        message->add_payload(message, payload);
        
        *request = message;
-       return SUCCESS;
 }
 
 /**
  * implements private_initiator_init_t.build_sa_payload
  */
-static status_t build_sa_payload(private_initiator_init_t *this, payload_t **payload)
+static void build_sa_payload(private_initiator_init_t *this, payload_t **payload)
 {
        sa_payload_t* sa_payload;
        iterator_t *proposal_iterator;
-       status_t status;
        
-       /* SA payload takes proposals from this->ike_sa_init_data.proposals and writes them to the created sa_payload */
+       /* SA payload takes proposals from this->ike_sa_init_data.proposals 
+        * and writes them to the created sa_payload 
+        */
 
        this->logger->log(this->logger, CONTROL|MORE, "building sa payload");
-       status = this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
-               return status;  
-       }
+       this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
        
        sa_payload = sa_payload_create();
-       if (sa_payload == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create SA payload object");
-               return OUT_OF_RES;
-       }
        
        while (proposal_iterator->has_next(proposal_iterator))
        {
                proposal_substructure_t *current_proposal;
                proposal_substructure_t *current_proposal_clone;
-               status = proposal_iterator->current(proposal_iterator,(void **) &current_proposal);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "Could not get current proposal needed to copy");
-                       proposal_iterator->destroy(proposal_iterator);
-                       sa_payload->destroy(sa_payload);
-                       return status;  
-               }
-               status = current_proposal->clone(current_proposal,&current_proposal_clone);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "Could not clone current proposal");
-                       proposal_iterator->destroy(proposal_iterator);
-                       sa_payload->destroy(sa_payload);
-                       return status;  
-               }
-               
-               status = sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "Could not add cloned proposal to SA payload");
-                       proposal_iterator->destroy(proposal_iterator);
-                       sa_payload->destroy(sa_payload);
-                       return status;  
-               }
+               proposal_iterator->current(proposal_iterator,(void **) &current_proposal);
 
+               current_proposal->clone(current_proposal,&current_proposal_clone);
+               
+               sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone);
        }
        proposal_iterator->destroy(proposal_iterator);
        
-       this->logger->log(this->logger, CONTROL|MORE, "sa payload builded");
-
        *payload = (payload_t *) sa_payload;    
-       return SUCCESS;
 }
 
 /**
  * implements private_initiator_init_t.build_ke_payload
  */
-static status_t build_ke_payload(private_initiator_init_t *this, payload_t **payload)
+static void build_ke_payload(private_initiator_init_t *this, payload_t **payload)
 {
        ke_payload_t *ke_payload;
        chunk_t key_data;
-       status_t status;
-
+       
        this->logger->log(this->logger, CONTROL|MORE, "building ke payload");
        
-
-       this    ->logger->log(this->logger, CONTROL|MORE, "get public dh value to send in ke payload");
-       status = this->diffie_hellman->get_my_public_value(this->diffie_hellman,&key_data);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not get my DH public value");
-               return status;
-       }
+       this->diffie_hellman->get_my_public_value(this->diffie_hellman,&key_data);
 
        ke_payload = ke_payload_create();
-       if (ke_payload == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Could not create KE payload");
-               allocator_free_chunk(&key_data);
-               return OUT_OF_RES;      
-       }
        ke_payload->set_dh_group_number(ke_payload, this->dh_group_number);
-       if (ke_payload->set_key_exchange_data(ke_payload, key_data) != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not set key exchange data of KE payload");
-               ke_payload->destroy(ke_payload);
-               allocator_free_chunk(&key_data);
-               return OUT_OF_RES;
-       }
-       allocator_free_chunk(&key_data);
+       ke_payload->set_key_exchange_data(ke_payload, key_data);
        
-       this->logger->log(this->logger, CONTROL|MORE, "ke payload builded");
-
+       allocator_free_chunk(&key_data);
        *payload = (payload_t *) ke_payload;
-       return SUCCESS;                 
 }
 
 /**
  * implements private_initiator_init_t.build_nonce_payload
  */
-static status_t build_nonce_payload(private_initiator_init_t *this, payload_t **payload)
+static void build_nonce_payload(private_initiator_init_t *this, payload_t **payload)
 {
        nonce_payload_t *nonce_payload;
-       status_t status;
        
        this->logger->log(this->logger, CONTROL|MORE, "building nonce payload");
-
-       nonce_payload = nonce_payload_create();
-       if (nonce_payload == NULL)
-       {       
-               this->logger->log(this->logger, ERROR, "Fatal error: could not create nonce payload object");
-               return OUT_OF_RES;      
-       }
-
-       status = nonce_payload->set_nonce(nonce_payload, this->sent_nonce);
        
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not set nonce data of payload");
-               nonce_payload->destroy(nonce_payload);
-               return status;
-       }
-               
-       *payload = (payload_t *) nonce_payload;
+       nonce_payload = nonce_payload_create();
        
-       this->logger->log(this->logger, CONTROL|MORE, "nonce payload builded");
+       nonce_payload->set_nonce(nonce_payload, this->sent_nonce);
        
-       return SUCCESS;
+       *payload = (payload_t *) nonce_payload;
 }
 
 /**
@@ -510,7 +368,7 @@ static ike_sa_state_t get_state(private_initiator_init_t *this)
 /**
  * Implements state_t.get_state
  */
-static status_t destroy(private_initiator_init_t *this)
+static void destroy(private_initiator_init_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to destroy initiator_init_t state object");
 
@@ -535,15 +393,13 @@ static status_t destroy(private_initiator_init_t *this)
                this->logger->log(this->logger, CONTROL | MOST, "Free memory of sent nonce");
                allocator_free(this->sent_nonce.ptr);
        }
-       
        allocator_free(this);
-       return SUCCESS;
 }
 
 /**
  * Implements private_initiator_init_t.destroy_after_state_change
  */
-static status_t destroy_after_state_change (private_initiator_init_t *this)
+static void destroy_after_state_change (private_initiator_init_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to destroy initiator_init_t state object");
        
@@ -557,7 +413,6 @@ static status_t destroy_after_state_change (private_initiator_init_t *this)
        }
        this->proposals->destroy(this->proposals);
        allocator_free(this);
-       return SUCCESS;
 }
 
 /* 
@@ -566,16 +421,11 @@ static status_t destroy_after_state_change (private_initiator_init_t *this)
 initiator_init_t *initiator_init_create(protected_ike_sa_t *ike_sa)
 {
        private_initiator_init_t *this = allocator_alloc_thing(private_initiator_init_t);
-       
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
        this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
-       this->public.state_interface.destroy  = (status_t (*) (state_t *)) destroy;
+       this->public.state_interface.destroy  = (void (*) (state_t *)) destroy;
        
        /* public functions */
        this->public.initiate_connection = (status_t (*)(initiator_init_t *, char *)) initiate_connection;
@@ -593,11 +443,6 @@ initiator_init_t *initiator_init_create(protected_ike_sa_t *ike_sa)
        this->logger = this->ike_sa->get_logger(this->ike_sa);
        this->proposals = linked_list_create();
        this->sent_nonce = CHUNK_INITIALIZER;
-       if (this->proposals == NULL)
-       {
-               allocator_free(this);
-               return NULL;
-       }
-       
+
        return &(this->public);
 }
index 0d93a5b..57e7503 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file responder_init.c
  * 
- * @brief Start state of a IKE_SA as responder
+ * @brief Implementation of responder_init_t.
  * 
  */
 
@@ -99,11 +99,8 @@ struct private_responder_init_t {
         * @param this          calling object
         * @param payload       The generated SA payload object of type ke_payload_t is 
         *                                      stored at this location.
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_sa_payload) (private_responder_init_t *this, payload_t **payload);
+       void (*build_sa_payload) (private_responder_init_t *this, payload_t **payload);
 
        /**
         * Builds the KE payload for this state.
@@ -111,22 +108,17 @@ struct private_responder_init_t {
         * @param this          calling object
         * @param payload       The generated KE payload object of type ke_payload_t is 
         *                                      stored at this location.
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_ke_payload) (private_responder_init_t *this, payload_t **payload);
+       void (*build_ke_payload) (private_responder_init_t *this, payload_t **payload);
+       
        /**
         * Builds the NONCE payload for this state.
         * 
         * @param this          calling object
         * @param payload       The generated NONCE payload object of type ke_payload_t is 
         *                                      stored at this location.
-        * @return                      
-        *                                      - SUCCESS
-        *                                      - OUT_OF_RES
         */
-       status_t (*build_nonce_payload) (private_responder_init_t *this, payload_t **payload);  
+       void (*build_nonce_payload) (private_responder_init_t *this, payload_t **payload);      
        
        /**
         * Destroy function called internally of this class after state change succeeded.
@@ -134,9 +126,8 @@ struct private_responder_init_t {
         * This destroy function does not destroy objects which were passed to the new state.
         * 
         * @param this          calling object
-        * @return                      SUCCESS in any case
         */
-       status_t (*destroy_after_state_change) (private_responder_init_t *this);
+       void (*destroy_after_state_change) (private_responder_init_t *this);
 };
 
 /**
@@ -175,20 +166,8 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
        message->get_destination(message, &destination);
        
        /* we need to clone them, since we destroy the message later */
-       status = destination->clone(destination, &my_host);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not clone my host informations");
-               return status;  
-       }
-       status = source->clone(source, &other_host);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not clone other host informations");
-               my_host->destroy(my_host);
-               return status;  
-       }
-
+       my_host = destination->clone(destination);
+       other_host = source->clone(source);
        
        this->ike_sa->set_my_host(this->ike_sa, my_host);
        this->ike_sa->set_other_host(this->ike_sa, other_host);
@@ -198,7 +177,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
        if (status != SUCCESS)
        {
                this->logger->log(this->logger, ERROR | MORE, "Could not parse body of request message");
-               return status;  
+               return status;
        }
 
        /* iterate over incoming payloads. We can be sure, the message contains only accepted payloads! */
@@ -219,24 +198,11 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
                                sa_payload_t *sa_payload = (sa_payload_t*)payload;
                                iterator_t *suggested_proposals, *accepted_proposals;
                                proposal_substructure_t *accepted_proposal;
-
-                               status = this->proposals->create_iterator(this->proposals, &accepted_proposals, FALSE);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
-                                       payloads->destroy(payloads);
-                                       return status;  
-                               }
+                               
+                               this->proposals->create_iterator(this->proposals, &accepted_proposals, FALSE);
                                
                                /* get the list of suggested proposals */ 
-                               status = sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
-                               if (status != SUCCESS)
-                               {       
-                                       this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on suggested proposals");
-                                       accepted_proposals->destroy(accepted_proposals);
-                                       payloads->destroy(payloads);
-                                       return status;
-                               }
+                               sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
                                
                                /* now let the configuration-manager select a subset of the proposals */
                                status = global_configuration_manager->select_proposals_for_host(global_configuration_manager,
@@ -253,7 +219,6 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
                                /* iterators are not needed anymore */                  
                                suggested_proposals->destroy(suggested_proposals);
                                
-                               
                                /* let the ike_sa create their own transforms from proposal informations */
                                accepted_proposals->reset(accepted_proposals);
                                /* TODO check for true*/
@@ -309,19 +274,12 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
                                {
                                        this->logger->log(this->logger, ERROR, "Could not generate DH object");
                                        payloads->destroy(payloads);
-                                       return OUT_OF_RES;
+                                       return NOT_SUPPORTED;
                                }
 
                                this->logger->log(this->logger, CONTROL | MORE, "Set other DH public value");
                                
-                               status = dh->set_other_public_value(dh, ke_payload->get_key_exchange_data(ke_payload));
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "Could not set other DH public value");
-                                       dh->destroy(dh);
-                                       payloads->destroy(payloads);
-                                       return OUT_OF_RES;
-                               }
+                               dh->set_other_public_value(dh, ke_payload->get_key_exchange_data(ke_payload));
 
                                this->diffie_hellman = dh;
                                
@@ -332,22 +290,11 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
                        {
                                nonce_payload_t *nonce_payload = (nonce_payload_t*)payload;
 
-                               if (this->received_nonce.ptr != NULL)
-                               {
-                                       this->logger->log(this->logger, CONTROL | MOST, "Destroy stored received nonce");
-                                       allocator_free(this->received_nonce.ptr);
-                                       this->received_nonce.ptr = NULL;
-                                       this->received_nonce.len = 0;
-                               }
+                               allocator_free(this->received_nonce.ptr);
+                               this->received_nonce = CHUNK_INITIALIZER;
 
                                this->logger->log(this->logger, CONTROL | MORE, "Get nonce value and store it");
-                               status = nonce_payload->get_nonce(nonce_payload, &(this->received_nonce));
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "Fatal error: Could not get nonce");
-                                       payloads->destroy(payloads);
-                                       return OUT_OF_RES;
-                               }
+                               nonce_payload->get_nonce(nonce_payload, &(this->received_nonce));
                                
                                this->logger->log(this->logger, CONTROL | MORE, "Nonce Payload processed");
                                break;
@@ -356,11 +303,9 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
                        {
                                this->logger->log(this->logger, ERROR | MORE, "Payload type not supported!");
                                payloads->destroy(payloads);
-                               return OUT_OF_RES;
+                               return NOT_SUPPORTED;
                        }
-                               
                }
-                       
        }
        /* iterator can be destroyed */
        payloads->destroy(payloads);
@@ -371,63 +316,31 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
        
        randomizer = this->ike_sa->get_randomizer(this->ike_sa);
        
-       if (randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce)) != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not create nonce!");
-               return OUT_OF_RES;
-       }
-       
+       randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
+
        /* store shared secret  */
        this->logger->log(this->logger, CONTROL | MOST, "Retrieve shared secret and store it");
        status = this->diffie_hellman->get_shared_secret(this->diffie_hellman, &shared_secret);
        this->logger->log_chunk(this->logger, PRIVATE, "Shared secret", &shared_secret);
 
-       status = this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->received_nonce, this->sent_nonce);
-       if (status != SUCCESS)
-       {
-               /* secrets could not be computed */
-               this->logger->log(this->logger, ERROR | MORE, "Secrets could not be computed!");
-               return status;
-       }
+       this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->received_nonce, this->sent_nonce);
 
        /* set up the reply */
-       status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not create empty message");
-               return status;  
-       }
+       this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response);
+
        
        /* build SA payload */          
-       status = this->build_sa_payload(this, &payload);
-       if (status != SUCCESS)
-       {       
-               this->logger->log(this->logger, ERROR, "Could not build SA payload");
-               return status;
-       }
-       
+       this->build_sa_payload(this, &payload);
        this->logger->log(this->logger, CONTROL|MOST, "add SA payload to message");
        response->add_payload(response, payload);
        
        /* build KE payload */
-       status = this->build_ke_payload(this,&payload);
-       if (status != SUCCESS)
-       {       
-               this->logger->log(this->logger, ERROR, "Could not build KE payload");
-               return status;
-       }
-
+       this->build_ke_payload(this,&payload);
        this->logger->log(this->logger, CONTROL|MOST, "add KE payload to message");
        response->add_payload(response, payload);
        
        /* build Nonce payload */
-       status = this->build_nonce_payload(this, &payload);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not build NONCE payload");
-               return status;
-       }
-
+       this->build_nonce_payload(this, &payload);
        this->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message");
        response->add_payload(response, payload);
        
@@ -436,30 +349,17 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
        status = response->generate(response, NULL, NULL, &packet);
        if (status != SUCCESS)
        {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not generate packet from message");
+               this->logger->log(this->logger, ERROR, "could not generate packet from message");
                return status;
        }
        
-       this    ->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
-       status = global_send_queue->add(global_send_queue, packet);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not add packet to send queue");
-               packet->destroy(packet);
-               return status;
-       }
+       this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
+        global_send_queue->add(global_send_queue, packet);
 
        /* state can now be changed */
-       this    ->logger->log(this->logger, CONTROL|MOST, "Create next state object");
+       this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
 
        next_state = ike_sa_init_responded_create(this->ike_sa, shared_secret, this->received_nonce, this->sent_nonce);
-
-       if (next_state == NULL)
-       {
-               this    ->logger->log(this->logger, ERROR, "Fatal error: could not create next state object of type ike_sa_init_responded_t");
-               allocator_free_chunk(&shared_secret);
-               return FAILED;
-       }
        
        /* last message can now be set */
        status = this->ike_sa->set_last_responded_message(this->ike_sa, response);
@@ -475,9 +375,9 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
        /* state can now be changed */
        this->ike_sa->set_new_state(this->ike_sa, (state_t *) next_state);
        /* state has NOW changed :-) */
-       this    ->logger->log(this->logger, CONTROL|MORE, "Changed state of IKE_SA from %s to %s",mapping_find(ike_sa_state_m,RESPONDER_INIT),mapping_find(ike_sa_state_m,IKE_SA_INIT_RESPONDED) );
+       this->logger->log(this->logger, CONTROL|MORE, "Changed state of IKE_SA from %s to %s",mapping_find(ike_sa_state_m,RESPONDER_INIT),mapping_find(ike_sa_state_m,IKE_SA_INIT_RESPONDED) );
 
-       this    ->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
+       this->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
        this->destroy_after_state_change(this); 
        
        return SUCCESS;
@@ -486,142 +386,67 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
 /**
  * implements private_initiator_init_t.build_sa_payload
  */
-static status_t build_sa_payload(private_responder_init_t *this, payload_t **payload)
+static void build_sa_payload(private_responder_init_t *this, payload_t **payload)
 {
        sa_payload_t* sa_payload;
        iterator_t *proposal_iterator;
-       status_t status;
-       
        
        /* SA payload takes proposals from this->ike_sa_init_data.proposals and writes them to the created sa_payload */
-
+       
        this->logger->log(this->logger, CONTROL|MORE, "building sa payload");
        
-       status = this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
-               return status;  
-       }
+       this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
        
        sa_payload = sa_payload_create();
-       if (sa_payload == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: Could not create SA payload object");
-               return OUT_OF_RES;
-       }
        
        while (proposal_iterator->has_next(proposal_iterator))
        {
                proposal_substructure_t *current_proposal;
                proposal_substructure_t *current_proposal_clone;
-               status = proposal_iterator->current(proposal_iterator,(void **) &current_proposal);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "Could not get current proposal needed to copy");
-                       proposal_iterator->destroy(proposal_iterator);
-                       sa_payload->destroy(sa_payload);
-                       return status;  
-               }
-               status = current_proposal->clone(current_proposal,&current_proposal_clone);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "Could not clone current proposal");
-                       proposal_iterator->destroy(proposal_iterator);
-                       sa_payload->destroy(sa_payload);
-                       return status;  
-               }
                
-               status = sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone);
-               if (status != SUCCESS)
-               {
-                       this->logger->log(this->logger, ERROR, "Could not add cloned proposal to SA payload");
-                       proposal_iterator->destroy(proposal_iterator);
-                       sa_payload->destroy(sa_payload);
-                       return status;  
-               }
-
+               proposal_iterator->current(proposal_iterator,(void **) &current_proposal);
+               current_proposal->clone(current_proposal,&current_proposal_clone);
+               sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone);
        }
-
-       proposal_iterator->destroy(proposal_iterator);  
        
-       this->logger->log(this->logger, CONTROL|MORE, "sa payload builded");
+       proposal_iterator->destroy(proposal_iterator);  
        
        *payload = (payload_t *) sa_payload;
-       
-       return SUCCESS;
 }
 
 /**
  * implements private_initiator_init_t.build_ke_payload
  */
-static status_t build_ke_payload(private_responder_init_t *this, payload_t **payload)
+static void build_ke_payload(private_responder_init_t *this, payload_t **payload)
 {
        ke_payload_t *ke_payload;
        chunk_t key_data;
-       status_t status;
 
        this->logger->log(this->logger, CONTROL|MORE, "building ke payload");
-       
-
-       this    ->logger->log(this->logger, CONTROL|MORE, "get public dh value to send in ke payload");
-       status = this->diffie_hellman->get_my_public_value(this->diffie_hellman,&key_data);
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not get my DH public value");
-               return status;
-       }
+       this->diffie_hellman->get_my_public_value(this->diffie_hellman,&key_data);
 
        ke_payload = ke_payload_create();
-       if (ke_payload == NULL)
-       {
-               this->logger->log(this->logger, ERROR, "Could not create KE payload");
-               allocator_free_chunk(&key_data);
-               return OUT_OF_RES;      
-       }
        ke_payload->set_dh_group_number(ke_payload, MODP_1024_BIT);
-       if (ke_payload->set_key_exchange_data(ke_payload, key_data) != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Could not set key exchange data of KE payload");
-               ke_payload->destroy(ke_payload);
-               allocator_free_chunk(&key_data);
-               return OUT_OF_RES;
-       }
-       allocator_free_chunk(&key_data);
 
+       allocator_free_chunk(&key_data);
        *payload = (payload_t *) ke_payload;
-       return SUCCESS;                 
 }
 
 /**
  * implements private_initiator_init_t.build_nonce_payload
  */
-static status_t build_nonce_payload(private_responder_init_t *this, payload_t **payload)
+static void build_nonce_payload(private_responder_init_t *this, payload_t **payload)
 {
        nonce_payload_t *nonce_payload;
        status_t status;
        
        this->logger->log(this->logger, CONTROL|MORE, "building nonce payload");
-
+       
        nonce_payload = nonce_payload_create();
-       if (nonce_payload == NULL)
-       {       
-               this->logger->log(this->logger, ERROR, "Fatal error: could not create nonce payload object");
-               return OUT_OF_RES;      
-       }
-
+       
        status = nonce_payload->set_nonce(nonce_payload, this->sent_nonce);
        
-       if (status != SUCCESS)
-       {
-               this->logger->log(this->logger, ERROR, "Fatal error: could not set nonce data of payload");
-               nonce_payload->destroy(nonce_payload);
-               return status;
-       }
-               
        *payload = (payload_t *) nonce_payload;
-       
-       return SUCCESS;
 }
 
 
@@ -636,7 +461,7 @@ static ike_sa_state_t get_state(private_responder_init_t *this)
 /**
  * Implements state_t.get_state
  */
-static status_t destroy(private_responder_init_t *this)
+static void destroy(private_responder_init_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder init state object");
        
@@ -650,35 +475,20 @@ static status_t destroy(private_responder_init_t *this)
        }
        this->proposals->destroy(this->proposals);
        
-       if (this->sent_nonce.ptr != NULL)
-       {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
-               allocator_free(this->sent_nonce.ptr);
-       }
+       allocator_free(this->sent_nonce.ptr);
+       allocator_free(this->received_nonce.ptr);
 
-       if (this->received_nonce.ptr != NULL)
-       {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
-               allocator_free(this->received_nonce.ptr);
-       }
-       
-       /* destroy diffie hellman object */
        if (this->diffie_hellman != NULL)
        {
-               this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object");
                this->diffie_hellman->destroy(this->diffie_hellman);
        }
-       
        allocator_free(this);
-               
-       return SUCCESS;
-       
 }
 
 /**
  * Implements private_responder_init_t.destroy_after_state_change
  */
-static status_t destroy_after_state_change (private_responder_init_t *this)
+static void destroy_after_state_change (private_responder_init_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder_init_t state object");
        
@@ -700,7 +510,6 @@ static status_t destroy_after_state_change (private_responder_init_t *this)
        }
        
        allocator_free(this);
-       return SUCCESS;
 }
 
 /* 
@@ -709,16 +518,11 @@ static status_t destroy_after_state_change (private_responder_init_t *this)
 responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa)
 {
        private_responder_init_t *this = allocator_alloc_thing(private_responder_init_t);
-       
-       if (this == NULL)
-       {
-               return NULL;
-       }
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
        this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
-       this->public.state_interface.destroy  = (status_t (*) (state_t *)) destroy;
+       this->public.state_interface.destroy  = (void (*) (state_t *)) destroy;
        
        /* private functions */
        this->build_sa_payload = build_sa_payload;
@@ -729,16 +533,9 @@ responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa)
        /* private data */
        this->ike_sa = ike_sa;
        this->logger = this->ike_sa->get_logger(this->ike_sa);
-       this->sent_nonce.ptr = NULL;
-       this->sent_nonce.len = 0;
-       this->received_nonce.ptr = NULL;
-       this->received_nonce.len = 0;
+       this->sent_nonce = CHUNK_INITIALIZER;
+       this->received_nonce = CHUNK_INITIALIZER;
        this->proposals = linked_list_create();
-       if (this->proposals == NULL)
-       {
-               allocator_free(this);
-               return NULL;
-       }
-       
+
        return &(this->public);
 }
index 592cb61..1606579 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file responder_init.h
  * 
- * @brief Start state of a IKE_SA as responder
+ * @brief Interface of responder_init_t.
  * 
  */
 
@@ -31,7 +31,7 @@ typedef struct responder_init_t responder_init_t;
 
 /**
  * @brief This class represents an IKE_SA state when initializing.
- * a connection as responder
+ * a connection as responder.
  *
  */
 struct responder_init_t {
@@ -45,7 +45,9 @@ struct responder_init_t {
 /**
  * Constructor of class responder_init_t
  * 
- * @param ike_sa       assigned IKE_SA
+ * @param ike_sa assigned IKE_SA
+ * 
+ * @return responder_init state
  */
 responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa);
 
index 7a8f843..471822f 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file state.h
  * 
- * @brief Interface for a specific IKE_SA state
+ * @brief Interface for a specific IKE_SA state.
  * 
  */
 
@@ -83,7 +83,7 @@ typedef struct state_t state_t;
 struct state_t {
 
        /**
-        * @brief Processes a incoming IKEv2-Message of type message_t
+        * @brief Processes a incoming IKEv2-Message of type message_t.
         *
         * @param this                  state_t object
         * @param[in]                   message message_t object to process
@@ -94,7 +94,7 @@ struct state_t {
        status_t (*process_message) (state_t *this,message_t *message);
 
        /**
-        * @brief Get the current state
+        * @brief Get the current state.
         *
         * @param this  state_t object
         * @return              state 
@@ -102,12 +102,11 @@ struct state_t {
        ike_sa_state_t (*get_state) (state_t *this);
 
        /**
-        * @brief Destroys a state_t object
+        * @brief Destroys a state_t object.
         *
-        * @param this  state_t object
-        * @return              SUCCESS in any case
+        * @param this  state_t object to destroy
         */
-       status_t (*destroy) (state_t *this);
+       void (*destroy) (state_t *this);
 };
 
 
index 7b6e844..25a25b3 100644 (file)
@@ -77,8 +77,7 @@ void test_aes_cbc_crypter(tester_t *tester)
        
        allocator_free_chunk(&decrypted1);
         
-       tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
-       
+       crypter->destroy(crypter);
        
        
        /*
@@ -133,7 +132,7 @@ void test_aes_cbc_crypter(tester_t *tester)
        
        allocator_free_chunk(&decrypted2);
 
-       tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
+       crypter->destroy(crypter);
         
        /*
         * Test 3 of RFC3603
@@ -197,10 +196,8 @@ void test_aes_cbc_crypter(tester_t *tester)
        logger->log_chunk(logger,RAW,"decrypted :", &decrypted3);
        
        allocator_free_chunk(&decrypted3);
-        
-       tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
        
-
+       crypter->destroy(crypter);
        
        global_logger_manager->destroy_logger(global_logger_manager,logger);
 }
index 83758c9..ee2c30b 100644 (file)
@@ -54,8 +54,8 @@ void test_diffie_hellman(tester_t *tester)
        tester->assert_true(tester,(    other_diffie_hellman->get_my_public_value(other_diffie_hellman,&other_public_value) == SUCCESS), "get_my_public_value call check");
        logger->log_chunk(logger,RAW,"Other public value",&other_public_value);
 
-       tester->assert_true(tester,(    my_diffie_hellman->set_other_public_value(my_diffie_hellman,other_public_value) == SUCCESS), "set_other_public_value call check");
-       tester->assert_true(tester,(    other_diffie_hellman->set_other_public_value(other_diffie_hellman,my_public_value) == SUCCESS), "set_other_public_value call check");
+       my_diffie_hellman->set_other_public_value(my_diffie_hellman,other_public_value);
+       other_diffie_hellman->set_other_public_value(other_diffie_hellman,my_public_value);
 
        allocator_free(my_public_value.ptr);
        allocator_free(other_public_value.ptr);
@@ -71,7 +71,7 @@ void test_diffie_hellman(tester_t *tester)
        allocator_free(my_secret.ptr);
        allocator_free(other_secret.ptr);       
                
-       tester->assert_true(tester,(my_diffie_hellman->destroy(my_diffie_hellman) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(other_diffie_hellman->destroy(other_diffie_hellman) == SUCCESS), "destroy call check");
+       my_diffie_hellman->destroy(my_diffie_hellman);
+       other_diffie_hellman->destroy(other_diffie_hellman);
        global_logger_manager->destroy_logger(global_logger_manager,logger);
 }
index db2d183..d7679ce 100644 (file)
@@ -90,7 +90,7 @@ void test_md5_hasher(tester_t *tester)
        tester->assert_true(tester, hash_chunk.len == 16, "hash len");
        tester->assert_false(tester, memcmp(hash_chunk.ptr, hash_abcd, hash_chunk.len), "hash for abcd...");
        allocator_free(hash_chunk.ptr);
-       tester->assert_true(tester, (hasher->destroy(hasher) == SUCCESS), "destroy call test");
+       hasher->destroy(hasher);
 }
 
 /* 
@@ -168,5 +168,5 @@ void test_sha1_hasher(tester_t *tester)
        tester->assert_false(tester, memcmp(hash_buffer, hash_aaa, 20), "hash for aaa...");
        
 
-       tester->assert_true(tester, (hasher->destroy(hasher) == SUCCESS), "destroy call test");
+       hasher->destroy(hasher);
 }
index f11107d..1e437bb 100644 (file)
@@ -108,8 +108,7 @@ void test_hmac_md5_signer(tester_t *tester)
        
        
 
-       tester->assert_true(tester, (signer->destroy(signer) == SUCCESS), "signer destroy call check");
-       
+       signer->destroy(signer);        
        global_logger_manager->destroy_logger(global_logger_manager,logger);
 }
 
@@ -205,10 +204,7 @@ void test_hmac_sha1_signer(tester_t *tester)
                tester->assert_true(tester, (valid == FALSE), "Signature not valid check");
        }
        
-       
-
-       tester->assert_true(tester, (signer->destroy(signer) == SUCCESS), "signer destroy call check");
-       
+       signer->destroy(signer);
        global_logger_manager->destroy_logger(global_logger_manager,logger);
 
 }
index 7864c98..960e451 100644 (file)
@@ -83,11 +83,11 @@ void test_ike_sa_id(tester_t *tester)
        
        
        /* check destroy functionality */
-       tester->assert_true(tester,(ike_sa_id->destroy(ike_sa_id) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(equal->destroy(equal) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(clone->destroy(clone) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(other1->destroy(other1) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(other2->destroy(other2) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(other3->destroy(other3) == SUCCESS), "destroy call check");
-       tester->assert_true(tester,(other4->destroy(other4) == SUCCESS), "destroy call check");
+       ike_sa_id->destroy(ike_sa_id);
+       equal->destroy(equal);
+       clone->destroy(clone);
+       other1->destroy(other1);
+       other2->destroy(other2);
+       other3->destroy(other3);
+       other4->destroy(other4);
 }
index f497791..733665f 100644 (file)
@@ -95,8 +95,7 @@ void test_ike_sa_manager(tester_t *tester)
         * 
         */
 
-       status = td.isam->create_and_checkout(td.isam, &ike_sa);
-       tester->assert_true(tester, (status == SUCCESS), "checkout unexisting IKE_SA");
+       td.isam->create_and_checkout(td.isam, &ike_sa);
        /* for testing purposes, we manipulate the responder spi.
         * this is usually done be the response from the communication partner, 
         * but we don't have one...
@@ -212,8 +211,7 @@ void test_ike_sa_manager(tester_t *tester)
        /* let them go acquiring */
        sleep(1);
        
-       status = td.isam->destroy(td.isam);
-       tester->assert_true(tester, (status == SUCCESS), "ike_sa_manager destruction");
+       td.isam->destroy(td.isam);
        
        for (i = 0; i < thread_count; i++) 
        {
index 85a84e2..dd666c4 100644 (file)
@@ -84,7 +84,7 @@ void test_linked_list(tester_t *tester)
        tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
        tester->assert_true(tester,(linked_list->get_count(linked_list) == 3), "count check");
        
-       tester->assert_true(tester,(linked_list->destroy(linked_list) == SUCCESS), "destroy call check");
+       linked_list->destroy(linked_list);
 }
 
  /*
@@ -105,7 +105,7 @@ void test_linked_list_iterator(tester_t *tester)
        iterator_t * iterator2;
        
        
-       tester->assert_true(tester,(linked_list->create_iterator(linked_list,&iterator,TRUE) == SUCCESS), "create_iterator for it 1 call check");
+       linked_list->create_iterator(linked_list,&iterator,TRUE);
        
        tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check");  
        iterator->current(iterator,&value);
@@ -115,7 +115,7 @@ void test_linked_list_iterator(tester_t *tester)
        iterator->current(iterator,&value);
        tester->assert_true(tester,(strcmp((char *) value,"four") == 0), "it 1 current value check");
 
-       tester->assert_true(tester,(linked_list->create_iterator(linked_list,&iterator2,FALSE) == SUCCESS), "create_iterator for it 2 call check");
+       linked_list->create_iterator(linked_list,&iterator2,FALSE);
 
        tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");        
        iterator2->current(iterator2,&value);
@@ -147,10 +147,8 @@ void test_linked_list_iterator(tester_t *tester)
        tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");        
        tester->assert_false(tester,iterator2->has_next(iterator2), "it 2 has_next value check");       
 
-       tester->assert_true(tester,(iterator->destroy(iterator) == SUCCESS), "it 1 destroy call check");
-       
-       tester->assert_true(tester,(iterator2->destroy(iterator2) == SUCCESS), "it 2 destroy call check");
-       
+       iterator->destroy(iterator);
+       iterator2->destroy(iterator2);
        linked_list->destroy(linked_list);
 }
 
@@ -180,12 +178,12 @@ void test_linked_list_insert_and_remove(tester_t *tester)
        iterator->current(iterator,&value);
        tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
 
-       tester->assert_true(tester,(iterator->insert_before(iterator,"before_three") == SUCCESS), "insert_before call check");
+       iterator->insert_before(iterator,"before_three");
        iterator->current(iterator,&value);
        tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
 
 
-       tester->assert_true(tester,(iterator->insert_after(iterator,"after_three") == SUCCESS), "insert_after call check");
+       iterator->insert_after(iterator,"after_three");
        iterator->current(iterator,&value);
        tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
        
index aa735d4..b597203 100644 (file)
@@ -179,8 +179,6 @@ void test_parser_with_sa_payload(tester_t *tester)
        }
        proposals->destroy(proposals);
        
-       
-
        sa_payload->destroy(sa_payload);
 }
 
index f90a660..a1dd35e 100644 (file)
@@ -83,5 +83,5 @@ void test_receiver(tester_t *tester)
                job->destroy(job);
        }
 
-       tester->assert_true(tester, (receiver->destroy(receiver) == SUCCESS), "destroy call check");
+       receiver->destroy(receiver);
 }
index 390d3be..425b436 100644 (file)
@@ -88,5 +88,5 @@ void test_scheduler(tester_t *tester)
        }
 
        /* destruction test */
-       tester->assert_true(tester, (scheduler->destroy(scheduler) == SUCCESS), "destroy call check");
+       scheduler->destroy(scheduler);
 }
index 24b3ada..7e3d0bc 100644 (file)
@@ -138,5 +138,5 @@ void test_send_queue(tester_t *tester)
 
        /* the send-queue has to have diserd_value count entries*/
        tester->assert_true(tester,(send_queue->get_count(send_queue) == desired_value), "count value check");
-       tester->assert_true(tester,(send_queue->destroy(send_queue) == SUCCESS), "destroy call check");
+       send_queue->destroy(send_queue);
 }
index 3ce30ca..da018ad 100644 (file)
@@ -73,5 +73,5 @@ void test_sender(tester_t *tester)
                received_packet->destroy(received_packet);
        }
 
-       tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
+       sender->destroy(sender);
 }
index ad3200c..a72b880 100644 (file)
@@ -37,5 +37,5 @@ void test_thread_pool(tester_t *tester)
        thread_pool_t *pool = thread_pool_create(desired_pool_size);
        pool_size = pool->get_pool_size(pool);
        tester->assert_true(tester, (desired_pool_size == pool_size), "thread creation");
-       tester->assert_true(tester, (pool->destroy(pool) == SUCCESS), "threadpool destruction");
+       pool->destroy(pool);
 }
index b78ebcf..e2fb192 100644 (file)
@@ -61,8 +61,6 @@ struct private_receiver_t {
          * logger for the receiver
          */
         logger_t *logger;
-        
-
 };
 
 /**
@@ -84,15 +82,8 @@ static void receive_packets(private_receiver_t * this)
                {
                        this->logger->log(this->logger, CONTROL, "creating job from packet");
                        current_job = (job_t *) incoming_packet_job_create(current_packet);
-                       if (current_job == NULL)
-                       {
-                               this->logger->log(this->logger, ERROR, "job creation failed");
-                       }
 
-                       if (global_job_queue->add(global_job_queue,current_job) != SUCCESS)
-                       {
-                               this->logger->log(this->logger, ERROR, "job queueing failed");
-                       }
+                       global_job_queue->add(global_job_queue,current_job);
 
                }
                /* bad bad, rebuild the socket ? */
@@ -103,7 +94,7 @@ static void receive_packets(private_receiver_t * this)
 /**
  * Implementation of receiver_t's destroy function
  */
-static status_t destroy(private_receiver_t *this)
+static void destroy(private_receiver_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to terminate receiver thread");
        pthread_cancel(this->assigned_thread);
@@ -114,7 +105,6 @@ static status_t destroy(private_receiver_t *this)
        global_logger_manager->destroy_logger(global_logger_manager, this->logger);
 
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -124,14 +114,10 @@ receiver_t * receiver_create()
 {
        private_receiver_t *this = allocator_alloc_thing(private_receiver_t);
 
-       this->public.destroy = (status_t(*)(receiver_t*)) destroy;
+       this->public.destroy = (void(*)(receiver_t*)) destroy;
        this->receive_packets = receive_packets;
        
        this->logger = global_logger_manager->create_logger(global_logger_manager, RECEIVER, NULL);
-       if (this->logger == NULL)
-       {
-               allocator_free(this);
-       }
        
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->receive_packets, this) != 0)
        {
index 9b02165..a7269b7 100644 (file)
@@ -42,10 +42,8 @@ struct receiver_t {
         * @brief Destroys a receiver_t
         *
         * @param receiver      receiver object
-        * @return 
-        *                              - SUCCESS in any case
         */
-       status_t (*destroy) (receiver_t *receiver);
+       void (*destroy) (receiver_t *receiver);
 };
 
 /**
index 774bd3a..cc051e7 100644 (file)
@@ -43,7 +43,6 @@ struct private_scheduler_t {
         */
         scheduler_t public;
         
-        
        /**
         * @brief Get events from the event queue and add them to to job queue.
         *
@@ -53,16 +52,15 @@ struct private_scheduler_t {
         */
        void (*get_events) (private_scheduler_t *this);
 
-        /**
-         * Assigned thread to the scheduler_t object
-         */
-        pthread_t assigned_thread;
-        
-        /** 
-         * logger for this scheduler
-         */
-        logger_t *logger;
-
+       /**
+        * Assigned thread to the scheduler_t object
+        */
+       pthread_t assigned_thread;
+       
+       /** 
+        * logger for this scheduler
+        */
+       logger_t *logger;
 };
 
 /**
@@ -81,7 +79,7 @@ static void get_events(private_scheduler_t * this)
        {
                this->logger->log(this->logger, CONTROL|MORE, "waiting for next event...");
                /* get a job, this block until one is available */
-               global_event_queue->get(global_event_queue, &current_job);
+               current_job = global_event_queue->get(global_event_queue);
                /* queue the job in the job queue, workers will eat them */
                global_job_queue->add(global_job_queue, current_job);
                this->logger->log(this->logger, CONTROL, "got event, added job %s to job-queue.", 
@@ -92,7 +90,7 @@ static void get_events(private_scheduler_t * this)
 /**
  * Implementation of scheduler_t's destroy function
  */
-static status_t destroy(private_scheduler_t *this)
+static void destroy(private_scheduler_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to terminate scheduler thread");
        pthread_cancel(this->assigned_thread);
@@ -103,7 +101,6 @@ static status_t destroy(private_scheduler_t *this)
        global_logger_manager->destroy_logger(global_logger_manager, this->logger);
 
        allocator_free(this);
-       return SUCCESS;
 }
 
 
@@ -111,20 +108,15 @@ scheduler_t * scheduler_create()
 {
        private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t);
 
-       this->public.destroy = (status_t(*)(scheduler_t*)) destroy;
+       this->public.destroy = (void(*)(scheduler_t*)) destroy;
        this->get_events = get_events;
        
        this->logger = global_logger_manager->create_logger(global_logger_manager, SCHEDULER, NULL);
-       if (this->logger == NULL)
-       {
-               allocator_free(this);
-               return NULL;    
-       }
        
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->get_events, this) != 0)
        {
                /* thread could not be created  */
-               this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");       
+               this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");
                global_logger_manager->destroy_logger(global_logger_manager, this->logger);
                allocator_free(this);
                return NULL;
index 9eeccbb..da41cd6 100644 (file)
@@ -41,10 +41,8 @@ struct scheduler_t {
         * @brief Destroys a scheduler object.
         * 
         * @param scheduler     scheduler object
-        * @return 
-        *                                              - SUCCESS in any case
         */
-       status_t (*destroy) (scheduler_t *scheduler);
+       void (*destroy) (scheduler_t *scheduler);
 };
 
 /**
@@ -54,8 +52,8 @@ struct scheduler_t {
  * and adds them to the job queue.
  * 
  * @return 
- *                     - the created scheduler_t instance, or
- *                     - NULL if thread could not be started
+ *                             - the created scheduler_t instance, or
+ *                             - NULL if thread could not be started
  * 
  * @ingroup threads
  */
index 2b33c0d..bdd7ccf 100644 (file)
@@ -78,24 +78,22 @@ static void send_packets(private_sender_t * this)
 
        while (1)
        {
-               while (global_send_queue->get(global_send_queue,&current_packet) == SUCCESS)
+               current_packet = global_send_queue->get(global_send_queue);
+               this->logger->log(this->logger, CONTROL|MORE, "got a packet, sending it");
+               status = global_socket->send(global_socket,current_packet);
+               if (status != SUCCESS)
                {
-                       this->logger->log(this->logger, CONTROL|MORE, "got a packet, sending it");
-                       status = global_socket->send(global_socket,current_packet);
-                       if (status != SUCCESS)
-                       {
-                               this->logger->log(this->logger, ERROR, "sending failed, socket returned %s", 
-                                                                       mapping_find(status_m, status));
-                       }
-                       current_packet->destroy(current_packet);
+                       this->logger->log(this->logger, ERROR, "sending failed, socket returned %s", 
+                                                               mapping_find(status_m, status));
                }
+               current_packet->destroy(current_packet);
        }
 }
 
 /**
  * implements sender_t.destroy
  */
-static status_t destroy(private_sender_t *this)
+static void destroy(private_sender_t *this)
 {
        this->logger->log(this->logger, CONTROL | MORE, "Going to terminate sender thread");
        pthread_cancel(this->assigned_thread);
@@ -106,7 +104,6 @@ static status_t destroy(private_sender_t *this)
        global_logger_manager->destroy_logger(global_logger_manager, this->logger);
 
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -117,15 +114,10 @@ sender_t * sender_create()
        private_sender_t *this = allocator_alloc_thing(private_sender_t);
 
        this->send_packets = send_packets;
-       this->public.destroy = (status_t(*)(sender_t*)) destroy;
+       this->public.destroy = (void(*)(sender_t*)) destroy;
        
        this->logger = global_logger_manager->create_logger(global_logger_manager, SENDER, NULL);
-       if (this->logger == NULL)
-       {
-               allocator_free(this);
-               return NULL;    
-       }
-       
+
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->send_packets, this) != 0)
        {
                this->logger->log(this->logger, ERROR, "Sender thread could not be created");
index 5ddad80..1192ef7 100644 (file)
@@ -38,10 +38,8 @@ struct sender_t {
         * @brief Destroys a sender object
         *
         * @param sender        sender object
-        * @return 
-        *                                      - SUCCESS in any case
         */
-       status_t (*destroy) (sender_t *sender);
+       void (*destroy) (sender_t *sender);
 };
 
 
index dc60deb..8e8bd8f 100644 (file)
@@ -81,15 +81,18 @@ struct private_thread_pool_t {
        /**
         * number of running threads
         */
-        size_t pool_size;
+       size_t pool_size;
+       
        /**
         * array of thread ids
         */
        pthread_t *threads;
+       
        /**
         * logger of the threadpool
         */
        logger_t *pool_logger;
+       
        /**
         * logger of the worker threads
         */
@@ -112,7 +115,7 @@ static void process_jobs(private_thread_pool_t *this)
                job_t *job;
                job_type_t job_type;
                
-               global_job_queue->get(global_job_queue, &job);
+               job = global_job_queue->get(global_job_queue);
                job_type = job->get_type(job);
                this->worker_logger->log(this->worker_logger, CONTROL|MORE, "got a job of type %s", 
                                                                 mapping_find(job_type_m,job_type));
@@ -148,15 +151,14 @@ static void process_jobs(private_thread_pool_t *this)
 /**
  * implementation of private_thread_pool_t.process_incoming_packet_job
  */
-void process_incoming_packet_job(private_thread_pool_t *this, incoming_packet_job_t *job)
+static void process_incoming_packet_job(private_thread_pool_t *this, incoming_packet_job_t *job)
 {
        packet_t        *packet;
        message_t       *message;
        ike_sa_t        *ike_sa;
        ike_sa_id_t *ike_sa_id;
        status_t        status;
-                               
-                               
+       
        if (job->get_packet(job,&packet) != SUCCESS)
        {
                this->worker_logger->log(this->worker_logger, ERROR, "packet in job could not be retrieved!");                          
@@ -239,7 +241,7 @@ void process_incoming_packet_job(private_thread_pool_t *this, incoming_packet_jo
 /**
  * implementation of private_thread_pool_t.process_initiate_ike_sa_job
  */
-void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_job_t *job)
+static void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_job_t *job)
 {
        /*
         * Initiatie an IKE_SA:
@@ -249,19 +251,12 @@ void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_jo
         */
        ike_sa_t *ike_sa;
        status_t status;
-                                                       
-                                       
+       
+       
        this->worker_logger->log(this->worker_logger, CONTROL|MOST, "create and checking out IKE SA");
-                               
-       status = global_ike_sa_manager->create_and_checkout(global_ike_sa_manager, &ike_sa);
-       if (status != SUCCESS)
-       {
-               this->worker_logger->log(this->worker_logger, ERROR, "%s by checking out new IKE_SA, job rejected.", 
-                                                                mapping_find(status_m, status));
-               return;
-       }
-                               
-                               
+       
+       global_ike_sa_manager->create_and_checkout(global_ike_sa_manager, &ike_sa);
+       
        this->worker_logger->log(this->worker_logger, CONTROL|MOST, "initializing connection \"%s\"", 
                                                         job->get_configuration_name(job));
        status = ike_sa->initialize_connection(ike_sa, job->get_configuration_name(job));
@@ -272,7 +267,7 @@ void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_jo
                global_ike_sa_manager->checkin_and_delete(global_ike_sa_manager, ike_sa);
                return;
        }
-                               
+       
        this->worker_logger->log(this->worker_logger, CONTROL|MOST, "checking in IKE SA");
        status = global_ike_sa_manager->checkin(global_ike_sa_manager, ike_sa);
        if (status != SUCCESS)
@@ -285,7 +280,7 @@ void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_jo
 /**
  * implementation of private_thread_pool_t.process_delete_ike_sa_job
  */
-void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa_job_t *job)
+static void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa_job_t *job)
 {
        status_t status;
        ike_sa_id_t *ike_sa_id = job->get_ike_sa_id(job);
@@ -294,7 +289,7 @@ void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa_job_t
                                                         ike_sa_id->get_initiator_spi(ike_sa_id),
                                                         ike_sa_id->get_responder_spi(ike_sa_id),
                                                         ike_sa_id->is_initiator(ike_sa_id) ? "initiator" : "responder");
-                                                                       
+       
        status = global_ike_sa_manager->delete(global_ike_sa_manager, ike_sa_id);
        if (status != SUCCESS)
        {
@@ -315,7 +310,7 @@ static size_t get_pool_size(private_thread_pool_t *this)
 /**
  * Implementation of thread_pool_t.destroy
  */
-static status_t destroy(private_thread_pool_t *this)
+static void destroy(private_thread_pool_t *this)
 {      
        int current;
        /* flag thread for termination */
@@ -335,11 +330,8 @@ static status_t destroy(private_thread_pool_t *this)
        global_logger_manager->destroy_logger(global_logger_manager, this->worker_logger);
        allocator_free(this->threads);
        allocator_free(this);
-       return SUCCESS;
 }
 
-#include <stdio.h>
-
 /*
  * see header
  */
@@ -348,13 +340,9 @@ thread_pool_t *thread_pool_create(size_t pool_size)
        int current;
        
        private_thread_pool_t *this = allocator_alloc_thing(private_thread_pool_t);
-       if (this == NULL)
-       {
-               return NULL;
-       }
        
        /* fill in public fields */
-       this->public.destroy = (status_t(*)(thread_pool_t*))destroy;
+       this->public.destroy = (void(*)(thread_pool_t*))destroy;
        this->public.get_pool_size = (size_t(*)(thread_pool_t*))get_pool_size;
        
        this->process_jobs = process_jobs;
@@ -364,26 +352,10 @@ thread_pool_t *thread_pool_create(size_t pool_size)
        this->pool_size = pool_size;
        
        this->threads = allocator_alloc(sizeof(pthread_t) * pool_size);
-       if (this->threads == NULL)
-       {
-               allocator_free(this);
-               return NULL;
-       }       
+
        this->pool_logger = global_logger_manager->create_logger(global_logger_manager,THREAD_POOL,NULL);
-       if (this->threads == NULL)
-       {
-               allocator_free(this);
-               allocator_free(this->threads);
-               return NULL;
-       }       
+
        this->worker_logger = global_logger_manager->create_logger(global_logger_manager,WORKER,NULL);
-       if (this->threads == NULL)
-       {
-               global_logger_manager->destroy_logger(global_logger_manager, this->pool_logger);
-               allocator_free(this);
-               allocator_free(this->threads);
-               return NULL;
-       }       
        
        /* try to create as many threads as possible, up tu pool_size */
        for (current = 0; current < pool_size; current++) 
index 46166bf..2dcef33 100644 (file)
@@ -52,10 +52,8 @@ struct thread_pool_t {
         * sends cancellation request to all threads and AWAITS their termination.
         * 
         * @param thread_pool   thread_pool_t object
-        * @return                              
-        *                                              - SUCCESS in any case
         */
-       status_t (*destroy) (thread_pool_t *thread_pool);
+       void (*destroy) (thread_pool_t *thread_pool);
 };
 
 /**
index 1800d24..97855e7 100644 (file)
@@ -1474,90 +1474,90 @@ static status_t set_key (private_aes_cbc_crypter_t *this, chunk_t key)
 {
        u_int32_t    *kf, *kt, rci, f = 0;
        u_int8_t *in_key = key.ptr;
-
+       
        if (key.len != this->blocksize)
        {
                return INVALID_ARG;
        }
-
-    this->aes_Nrnd = (this->aes_Nkey > (this->aes_Ncol) ? this->aes_Nkey : (this->aes_Ncol)) + 6; 
-
-    this->aes_e_key[0] = const_word_in(in_key     );
-    this->aes_e_key[1] = const_word_in(in_key +  4);
-    this->aes_e_key[2] = const_word_in(in_key +  8);
-    this->aes_e_key[3] = const_word_in(in_key + 12);
-
-    kf = this->aes_e_key; 
-    kt = kf + nc * (this->aes_Nrnd + 1) - this->aes_Nkey; 
-    rci = 0;
-
-    switch(this->aes_Nkey)
+       
+       this->aes_Nrnd = (this->aes_Nkey > (this->aes_Ncol) ? this->aes_Nkey : (this->aes_Ncol)) + 6; 
+       
+       this->aes_e_key[0] = const_word_in(in_key     );
+       this->aes_e_key[1] = const_word_in(in_key +  4);
+       this->aes_e_key[2] = const_word_in(in_key +  8);
+       this->aes_e_key[3] = const_word_in(in_key + 12);
+       
+       kf = this->aes_e_key; 
+       kt = kf + nc * (this->aes_Nrnd + 1) - this->aes_Nkey; 
+       rci = 0;
+       
+       switch(this->aes_Nkey)
+       {
+       case 4: do
+                       {   kf[4] = kf[0] ^ ls_box(kf[3],3) ^ rcon_tab[rci++];
+                               kf[5] = kf[1] ^ kf[4];
+                               kf[6] = kf[2] ^ kf[5];
+                               kf[7] = kf[3] ^ kf[6];
+                               kf += 4;
+                       }
+                       while(kf < kt);
+                       break;
+       
+       case 6: this->aes_e_key[4] = const_word_in(in_key + 16);
+                       this->aes_e_key[5] = const_word_in(in_key + 20);
+                       do
+                       {   kf[ 6] = kf[0] ^ ls_box(kf[5],3) ^ rcon_tab[rci++];
+                               kf[ 7] = kf[1] ^ kf[ 6];
+                               kf[ 8] = kf[2] ^ kf[ 7];
+                               kf[ 9] = kf[3] ^ kf[ 8];
+                               kf[10] = kf[4] ^ kf[ 9];
+                               kf[11] = kf[5] ^ kf[10];
+                               kf += 6;
+                       }
+                       while(kf < kt);
+                       break;
+
+       case 8: this->aes_e_key[4] = const_word_in(in_key + 16);
+                       this->aes_e_key[5] = const_word_in(in_key + 20);
+                       this->aes_e_key[6] = const_word_in(in_key + 24);
+                       this->aes_e_key[7] = const_word_in(in_key + 28);
+                       do
+                       {   kf[ 8] = kf[0] ^ ls_box(kf[7],3) ^ rcon_tab[rci++];
+                               kf[ 9] = kf[1] ^ kf[ 8];
+                               kf[10] = kf[2] ^ kf[ 9];
+                               kf[11] = kf[3] ^ kf[10];
+                               kf[12] = kf[4] ^ ls_box(kf[11],0);
+                               kf[13] = kf[5] ^ kf[12];
+                               kf[14] = kf[6] ^ kf[13];
+                               kf[15] = kf[7] ^ kf[14];
+                               kf += 8;
+                       }
+                       while (kf < kt);
+                       break;
+       }
+       
+       if(!f)
     {
-    case 4: do
-            {   kf[4] = kf[0] ^ ls_box(kf[3],3) ^ rcon_tab[rci++];
-                kf[5] = kf[1] ^ kf[4];
-                kf[6] = kf[2] ^ kf[5];
-                kf[7] = kf[3] ^ kf[6];
-                kf += 4;
-            }
-            while(kf < kt);
-            break;
-
-    case 6: this->aes_e_key[4] = const_word_in(in_key + 16);
-            this->aes_e_key[5] = const_word_in(in_key + 20);
-            do
-            {   kf[ 6] = kf[0] ^ ls_box(kf[5],3) ^ rcon_tab[rci++];
-                kf[ 7] = kf[1] ^ kf[ 6];
-                kf[ 8] = kf[2] ^ kf[ 7];
-                kf[ 9] = kf[3] ^ kf[ 8];
-                kf[10] = kf[4] ^ kf[ 9];
-                kf[11] = kf[5] ^ kf[10];
-                kf += 6;
-            }
-            while(kf < kt);
-            break;
-
-    case 8: this->aes_e_key[4] = const_word_in(in_key + 16);
-            this->aes_e_key[5] = const_word_in(in_key + 20);
-            this->aes_e_key[6] = const_word_in(in_key + 24);
-            this->aes_e_key[7] = const_word_in(in_key + 28);
-            do
-            {   kf[ 8] = kf[0] ^ ls_box(kf[7],3) ^ rcon_tab[rci++];
-                kf[ 9] = kf[1] ^ kf[ 8];
-                kf[10] = kf[2] ^ kf[ 9];
-                kf[11] = kf[3] ^ kf[10];
-                kf[12] = kf[4] ^ ls_box(kf[11],0);
-                kf[13] = kf[5] ^ kf[12];
-                kf[14] = kf[6] ^ kf[13];
-                kf[15] = kf[7] ^ kf[14];
-                kf += 8;
-            }
-            while (kf < kt);
-            break;
-    }
-
-    if(!f)
-    {   u_int32_t    i;
-        
-        kt = this->aes_d_key + nc * this->aes_Nrnd;
-        kf = this->aes_e_key;
-        
-        cpy(kt, kf); kt -= 2 * nc;
-
-        for(i = 1; i < this->aes_Nrnd; ++i)
-        { 
+               u_int32_t    i;
+
+               kt = this->aes_d_key + nc * this->aes_Nrnd;
+               kf = this->aes_e_key;
+               
+               cpy(kt, kf); kt -= 2 * nc;
+               
+               for(i = 1; i < this->aes_Nrnd; ++i)
+               { 
 #if defined(ONE_TABLE) || defined(FOUR_TABLES)
 #if !defined(ONE_IM_TABLE) && !defined(FOUR_IM_TABLES)
-            u_int32_t    f2, f4, f8, f9;
+                       u_int32_t    f2, f4, f8, f9;
 #endif
-            mix(kt, kf);
+                       mix(kt, kf);
 #else
-            cpy(kt, kf);
+                       cpy(kt, kf);
 #endif
-            kt -= 2 * nc;
+                       kt -= 2 * nc;
         }
-        
-        cpy(kt, kf);
+               cpy(kt, kf);
     }
 
        return SUCCESS;
@@ -1566,10 +1566,9 @@ static status_t set_key (private_aes_cbc_crypter_t *this, chunk_t key)
 /**
  * Implementation of crypter_t.destroy and aes_cbc_crypter_t.destroy.
  */
-static status_t destroy (private_aes_cbc_crypter_t *this)
+static void destroy (private_aes_cbc_crypter_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -1578,10 +1577,7 @@ static status_t destroy (private_aes_cbc_crypter_t *this)
 aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize)
 {
        private_aes_cbc_crypter_t *this = allocator_alloc_thing(private_aes_cbc_crypter_t);
-       if (this == NULL)
-       {
-               return NULL;    
-       }
+
        #if !defined(FIXED_TABLES)
     if(!tab_gen) { gen_tabs(); tab_gen = 1; }
        #endif
@@ -1610,10 +1606,7 @@ aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize)
        this->public.crypter_interface.decrypt = (status_t (*) (crypter_t *, chunk_t , chunk_t, chunk_t *)) decrypt;
        this->public.crypter_interface.get_block_size = (size_t (*) (crypter_t *)) get_block_size;
        this->public.crypter_interface.set_key = (status_t (*) (crypter_t *,chunk_t)) set_key;
-       this->public.crypter_interface.destroy = (status_t (*) (crypter_t *)) destroy;
-
-       /* public functions */
-       this->public.destroy = (status_t (*) (aes_cbc_crypter_t *)) destroy;
+       this->public.crypter_interface.destroy = (void (*) (crypter_t *)) destroy;
        
        /* private functions */
        this->decrypt_block = decrypt_block;
index 4a8e935..1e5fd17 100644 (file)
@@ -40,26 +40,15 @@ struct aes_cbc_crypter_t {
         * crypter_t interface.
         */
        crypter_t crypter_interface;
-       
-       /**
-        * @brief Destroys a aes_cbc_crypter_t object.
-        *
-        * @param this                          crypter_t object to destroy
-        * @return              
-        *                                                      - SUCCESS in any case
-        */
-       status_t (*destroy) (aes_cbc_crypter_t *this);
 };
 
 /**
  * @brief Constructor to create aes_cbc_crypter_t objects.
  * 
- * @param blocksize                            block size of AES crypter
- *                                                             (16, 24 or 32 are supported)
- *                                                             Default size is set to 16.
- * @return
- *                                                             - aes_cbc_crypter_t if successfully
- *                                                             - NULL if out of ressources
+ * @param blocksize            block size of AES crypter
+ *                                             (16, 24 or 32 are supported)
+ *                                             Default size is set to 16.
+ * @return                             aes_cbc_crypter_t if successfully
  */
 aes_cbc_crypter_t *aes_cbc_crypter_create(size_t blocksize);
 
index 1a0f859..a72e5a5 100644 (file)
@@ -56,7 +56,6 @@ crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm,size_t blo
                case ENCR_AES_CBC:
                {
                        return (crypter_t*)aes_cbc_crypter_create(blocksize);
-                       
                }
                default:
                        return NULL;
index 878ea5e..cd96747 100644 (file)
@@ -68,8 +68,9 @@ struct crypter_t {
         * @param data                          data to encrypt
         * @param iv                                    iv
         * @param [out]encrypted        pointer where the encrypted bytes will be written
-        * @return                              
-        *                                                      - SUCCESS in any case
+        * @return
+        *                                                      - SUCCESS, or
+        *                                                      - INVALID_ARG if data size not a multiple of  block size
         */
        status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
        
@@ -81,8 +82,9 @@ struct crypter_t {
         * @param data                          data to decrypt
         * @param iv                                    iv
         * @param [out]encrypted        pointer where the decrypted bytes will be written
-        * @return                              
-        *                                                      - SUCCESS in any case
+        * @return
+        *                                                      - SUCCESS, or
+        *                                                      - INVALID_ARG if data size not a multiple of  block size
         */
        status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
 
@@ -100,7 +102,8 @@ struct crypter_t {
         * @param this                          calling crypter
         * @param key                           key to set
         * @return
-        *                                                      - SUCCESS in any case
+        *                                                      - SUCCESS, or
+        *                                                      - INVALID_ARG if key size != block size
         */
        status_t (*set_key) (crypter_t *this, chunk_t key);
        
@@ -108,10 +111,8 @@ struct crypter_t {
         * @brief Destroys a crypter_t object.
         *
         * @param this                          crypter_t object to destroy
-        * @return              
-        *                                                      - SUCCESS in any case
         */
-       status_t (*destroy) (crypter_t *this);
+       void (*destroy) (crypter_t *this);
 };
 
 /**
@@ -121,7 +122,7 @@ struct crypter_t {
  * @param blocksize                            block size in bytes
  * @return
  *                                                             - crypter_t if successfully
- *                                                             - NULL if out of ressources or crypter not supported
+ *                                                             - NULL if crypter not supported
  */
 crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t blocksize);
 
index 1992e57..2ec3769 100644 (file)
@@ -438,8 +438,7 @@ struct private_diffie_hellman_t {
 };
 
 /**
- * Implements private_diffie_hellman_t's set_modulus function.
- * See #private_diffie_hellman_t.set_modulus for description.
+ * Implements private_diffie_hellman_tset_modulus.
  */
 static status_t set_modulus(private_diffie_hellman_t *this)
 {
@@ -464,19 +463,16 @@ static status_t set_modulus(private_diffie_hellman_t *this)
 }
 
 /**
- * Implements diffie_hellman_t's set_other_public_value function.
- * See #diffie_hellman_t.set_other_public_value for description.
+ * Implementation of diffie_hellman_t.set_other_public_value.
  */
-static status_t set_other_public_value(private_diffie_hellman_t *this,chunk_t public_value)
+static void set_other_public_value(private_diffie_hellman_t *this,chunk_t public_value)
 {
        this->gmp_helper->chunk_to_mpz(this->gmp_helper,&(this->other_public_value),public_value);
-       this->compute_shared_secret(this);              
-       return SUCCESS;
+       this->compute_shared_secret(this);
 }
 
 /**
- * Implements diffie_hellman_t's get_other_public_value function.
- * See #diffie_hellman_t.get_other_public_value for description.
+ * Implements diffie_hellman_t.get_other_public_value.
  */
 static status_t get_other_public_value(private_diffie_hellman_t *this,chunk_t *public_value)
 {
@@ -484,12 +480,12 @@ static status_t get_other_public_value(private_diffie_hellman_t *this,chunk_t *p
        {
                return FAILED;
        }
-       return (this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->other_public_value), public_value,this->modulus_length));
+       this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->other_public_value), public_value,this->modulus_length);
+       return SUCCESS;
 }
 
 /**
- * Implements private_diffie_hellman_t's compute_shared_secret function.
- * See #private_diffie_hellman_t.compute_shared_secret for description.
+ * Implements private_diffie_hellman_t.compute_shared_secret.
  */
 static void compute_shared_secret (private_diffie_hellman_t *this)
 {
@@ -497,14 +493,13 @@ static void compute_shared_secret (private_diffie_hellman_t *this)
        mpz_init(this->shared_secret);
        /* calculate my public value */
        mpz_powm(this->shared_secret,this->other_public_value,this->my_prime,this->modulus);
-
+       
        this->shared_secret_is_computed = TRUE;
 }
 
 
 /**
- * Implements private_diffie_hellman_t's compute_public_value function.
- * See #private_diffie_hellman_t.compute_public_value for description.
+ * Implements private_diffie_hellman_t.compute_public_value.
  */
 static void compute_public_value (private_diffie_hellman_t *this)
 {
@@ -521,8 +516,7 @@ static void compute_public_value (private_diffie_hellman_t *this)
 }
 
 /**
- * Implements diffie_hellman_t's get_my_public_value function.
- * See #diffie_hellman_t.get_my_public_value for description.
+ * Implements diffie_hellman_t.get_my_public_value.
  */
 static status_t get_my_public_value(private_diffie_hellman_t *this,chunk_t *public_value)
 {
@@ -530,12 +524,12 @@ static status_t get_my_public_value(private_diffie_hellman_t *this,chunk_t *publ
        {
                this->compute_public_value(this);
        }
-       return (this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->my_public_value), public_value,this->modulus_length));
+       this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->my_public_value), public_value,this->modulus_length);
+       return SUCCESS;
 }
 
 /**
- * Implements diffie_hellman_t's get_shared_secret function.
- * See #diffie_hellman_t.get_shared_secret for description.
+ * Implements diffie_hellman_t.get_shared_secret.
  */
 static status_t get_shared_secret(private_diffie_hellman_t *this,chunk_t *secret)
 {
@@ -543,14 +537,14 @@ static status_t get_shared_secret(private_diffie_hellman_t *this,chunk_t *secret
        {
                return FAILED;
        }
-       return (this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->shared_secret), secret,this->modulus_length));
+       this->gmp_helper->mpz_to_chunk(this->gmp_helper,&(this->shared_secret), secret,this->modulus_length);
+       return SUCCESS;
 }
 
 /**
- * Implements diffie_hellman_t's destroy function.
- * See #diffie_hellman_t.destroy for description.
+ * Implements diffie_hellman_t.destroy.
  */
-static status_t destroy(private_diffie_hellman_t *this)
+static void destroy(private_diffie_hellman_t *this)
 {
        this->gmp_helper->destroy(this->gmp_helper);
        mpz_clear(this->modulus);
@@ -565,9 +559,7 @@ static status_t destroy(private_diffie_hellman_t *this)
                mpz_clear(this->other_public_value);
                mpz_clear(this->shared_secret);
        }
-
        allocator_free(this);
-       return SUCCESS;
 }
 
 
@@ -577,17 +569,13 @@ static status_t destroy(private_diffie_hellman_t *this)
 diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
 {
        private_diffie_hellman_t *this = allocator_alloc_thing(private_diffie_hellman_t);
-       if ((this == NULL))
-       {
-               return NULL;
-       }
-       
+
        /* public functions */
        this->public.get_shared_secret = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_shared_secret;
-       this->public.set_other_public_value = (status_t (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
+       this->public.set_other_public_value = (void (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
        this->public.get_other_public_value = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_other_public_value;
        this->public.get_my_public_value = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_my_public_value;
-       this->public.destroy = (status_t (*)(diffie_hellman_t *)) destroy;
+       this->public.destroy = (void (*)(diffie_hellman_t *)) destroy;
        
        /* private functions */
        this->set_modulus = set_modulus;
@@ -599,12 +587,6 @@ diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
        
        this->gmp_helper = gmp_helper_create();
        
-       if (this->gmp_helper == NULL)
-       {
-               allocator_free(this);
-               return NULL;
-       }
-
        /* set this->modulus */ 
        if (this->set_modulus(this) != SUCCESS)
        {
@@ -612,13 +594,9 @@ diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
                allocator_free(this);
                return NULL;
        }
-           
-       if (this->gmp_helper->init_prime(this->gmp_helper,&(this->my_prime),this->modulus_length) != SUCCESS)
-       {
-               this->gmp_helper->destroy(this->gmp_helper);
-               allocator_free(this);
-               return NULL;
-       }
+       
+       this->gmp_helper->init_prime(this->gmp_helper,&(this->my_prime),this->modulus_length);
+       
        this->my_public_value_is_computed = FALSE;
        this->shared_secret_is_computed = FALSE;
        
index 04cfb98..c3ca325 100644 (file)
@@ -73,7 +73,6 @@ struct diffie_hellman_t {
         * @return                              
         *                                              - SUCCESS, or
         *                                              - FAILED if not both DH values are set
-        *                                              - OUT_OF_RES if out of ressources
         */
        status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
        
@@ -84,11 +83,8 @@ struct diffie_hellman_t {
         * 
         * @param this                  calling diffie_hellman_t object
         * @param public_value  public value of partner
-        * @return                              
-        *                                              - SUCCESS, or
-        *                                              - OUT_OF_RES if out of ressources
         */
-       status_t (*set_other_public_value) (diffie_hellman_t *this, chunk_t public_value);
+       void (*set_other_public_value) (diffie_hellman_t *this, chunk_t public_value);
        
        /**
         * @brief Gets the public value of partner.
@@ -99,7 +95,6 @@ struct diffie_hellman_t {
         * @param[out] public_value public value of partner is stored at this location
         * @return                              
         *                                                      - SUCCESS, or
-        *                                                      - OUT_OF_RES if out of ressources
         *                                                      - FAILED if other public value not set
         */
        status_t (*get_other_public_value) (diffie_hellman_t *this, chunk_t *public_value);
@@ -110,10 +105,10 @@ struct diffie_hellman_t {
         * @warning chunk gets copied
         * 
         * @param this                          calling diffie_hellman_t object
-        * @param[out] public_value public value of caller is stored at this location
+        * @param[out]                          public_value public value of caller is stored at this location
         * @return                              
         *                                                      - SUCCESS, or
-        *                                                      - OUT_OF_RES if out of ressources
+        *                                                      - FAILED if not computed
         */
        status_t (*get_my_public_value) (diffie_hellman_t *this, chunk_t *public_value);
 
@@ -121,10 +116,8 @@ struct diffie_hellman_t {
         * @brief Destroys an diffie_hellman_t object.
         *
         * @param this                          diffie_hellman_t object to destroy
-        * @return              
-        *                                                      - SUCCESS in any case
         */
-       status_t (*destroy) (diffie_hellman_t *this);
+       void (*destroy) (diffie_hellman_t *this);
 };
 
 /**
@@ -134,8 +127,8 @@ struct diffie_hellman_t {
  * 
  * @param dh_group_number      Diffie Hellman group number to use
  * @return
- *                                                     - diffie_hellman_t if successfully
- *                                                     - NULL if out of ressources or dh_group not supported
+ *                                                     - diffie_hellman_t object
+ *                                                     - NULL if dh group not supported
  * 
  * @ingroup transforms
  */
index dfc654e..170dfe8 100644 (file)
@@ -54,8 +54,3 @@ hasher_t *hasher_create(hash_algorithm_t hash_algorithm)
                        return NULL;
        }
 }
-
-
-
-
-
index ed4e0ee..eda6fe1 100644 (file)
@@ -63,10 +63,8 @@ struct hasher_t {
         * @param this                  calling hasher
         * @param data                  data to hash
         * @param [out]buffer   pointer where the hash will be written
-        * @return                              
-        *                                              - SUCCESS in any case
         */
-       status_t (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
+       void (*get_hash) (hasher_t *this, chunk_t data, u_int8_t *hash);
        
        /**
         * @brief hash data and allocate space for the hash
@@ -78,11 +76,8 @@ struct hasher_t {
         * @param this                  calling hasher
         * @param data                  chunk with data to hash
         * @param [out]hash             chunk which will hold allocated hash
-        * @return                              
-        *                                              - SUCCESS in any case
-        *                                              - OUT_OF_RES if space could not be allocated
         */
-       status_t (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
+       void (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
        
        /**
         * @brief Get the block size of this hashing function.
@@ -97,18 +92,15 @@ struct hasher_t {
         * computation of a completly new hash.
         * 
         * @param this                  calling hasher
-        * @return                              - SUCCESS in any case
         */
-       status_t (*reset) (hasher_t *this);
+       void (*reset) (hasher_t *this);
        
        /**
         * @brief Destroys a hasher object.
         *
         * @param this  hasher_t object to destroy
-        * @return              
-        *                              SUCCESS in any case
         */
-       status_t (*destroy) (hasher_t *this);
+       void (*destroy) (hasher_t *this);
 };
 
 /**
@@ -117,7 +109,7 @@ struct hasher_t {
  * @param hash_algorithm       Algorithm to use for hashing
  * @return
  *                                                     - hasher_t if successfully
- *                                                     - NULL if out of ressources 
+ *                                                     - NULL if algorithm not supported
  * 
  * @ingroup hashers
  */
index 3671001..bdb0b9e 100644 (file)
@@ -244,7 +244,7 @@ static void MD5Transform(u_int32_t state[4], u_int8_t block[64])
  * operation, processing another message block, and updating the
  * context.
  */
-void MD5Update(private_md5_hasher_t *this, u_int8_t *input, size_t inputLen)
+static void MD5Update(private_md5_hasher_t *this, u_int8_t *input, size_t inputLen)
 {
        u_int32_t i;
        size_t index, partLen;
@@ -285,7 +285,7 @@ void MD5Update(private_md5_hasher_t *this, u_int8_t *input, size_t inputLen)
 /* MD5 finalization. Ends an MD5 message-digest operation, writing the
  * the message digest and zeroizing the context.
  */
-void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
+static void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
 {
        u_int8_t bits[8];
        size_t index, padLen;
@@ -313,7 +313,7 @@ void MD5Final (private_md5_hasher_t *this, u_int8_t digest[16])
 /**
  * implementation of hasher_t.get_hash for md5
  */
-static status_t get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
+static void get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
 {
        MD5Update(this, chunk.ptr, chunk.len);
        if (buffer != NULL)
@@ -321,14 +321,13 @@ static status_t get_hash(private_md5_hasher_t *this, chunk_t chunk, u_int8_t *bu
                MD5Final(this, buffer);
                this->public.hasher_interface.reset(&(this->public.hasher_interface));
        }
-       return SUCCESS;
 }
 
 
 /**
  * implementation of hasher_t.allocate_hash for md5
  */
-static status_t allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
+static void allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *hash)
 {
        chunk_t allocated_hash;
        
@@ -337,17 +336,12 @@ static status_t allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t
        {       
                allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_MD5);
                allocated_hash.len = BLOCK_SIZE_MD5;
-               if (allocated_hash.ptr == NULL)
-               {
-                       return OUT_OF_RES;
-               }
+
                MD5Final(this, allocated_hash.ptr);
                this->public.hasher_interface.reset(&(this->public.hasher_interface));
                
                *hash = allocated_hash;
        }
-       
-       return SUCCESS;
 }
        
 /**
@@ -357,11 +351,11 @@ static size_t get_block_size(private_md5_hasher_t *this)
 {
        return BLOCK_SIZE_MD5;
 }
-       
+
 /**
  * implementation of hasher_t.reset for md5
  */
-static status_t reset(private_md5_hasher_t *this)
+static void reset(private_md5_hasher_t *this)
 {
        this->state[0] = 0x67452301;
        this->state[1] = 0xefcdab89;
@@ -369,34 +363,28 @@ static status_t reset(private_md5_hasher_t *this)
        this->state[3] = 0x10325476;
        this->count[0] = 0;
        this->count[1] = 0;
-    return SUCCESS;
 }
+
 /**
  * implementation of hasher_t.destroy for md5
  */
-static status_t destroy(private_md5_hasher_t *this)
+static void destroy(private_md5_hasher_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
-
 /*
  * Described in header
  */
 md5_hasher_t *md5_hasher_create()
 {
        private_md5_hasher_t *this = allocator_alloc_thing(private_md5_hasher_t);
-       if (this == NULL)
-       {
-               return NULL;    
-       }
-       
-       this->public.hasher_interface.get_hash = (status_t (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
-       this->public.hasher_interface.allocate_hash = (status_t (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
+
+       this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
+       this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
        this->public.hasher_interface.get_block_size = (size_t (*) (hasher_t*))get_block_size;
-       this->public.hasher_interface.reset = (size_t (*) (hasher_t*))reset;
-       this->public.hasher_interface.destroy = (size_t (*) (hasher_t*))destroy;
+       this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
+       this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
        
        /* initialize */
        this->public.hasher_interface.reset(&(this->public.hasher_interface));
index d2dcb0a..f73fdb5 100644 (file)
@@ -45,9 +45,7 @@ struct md5_hasher_t {
 /**
  * @brief Creates a new md5_hasher_t.
  * 
- * @return
- *                             - md5_hasher_t if successfully
- *                             - NULL if out of ressources
+ * @return     md5_hasher_t object
  * 
  * @ingroup hashers
  */
index 115a6e8..609571b 100644 (file)
@@ -74,7 +74,7 @@ struct private_sha1_hasher_t {
 /* 
  * Hash a single 512-bit block. This is the core of the algorithm. *
  */
-void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
+static void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
 {
        u_int32_t a, b, c, d, e;
        typedef union {
@@ -125,7 +125,7 @@ void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
 /* 
  * Run your data through this. 
  */
-void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
+static void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
 {
        u_int32_t i;
        u_int32_t j;
@@ -158,7 +158,7 @@ void SHA1Update(private_sha1_hasher_t* this, u_int8_t *data, u_int32_t len)
 /* 
  * Add padding and return the message digest. 
  */
-void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
+static void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
 {
        u_int32_t i;
        u_int8_t finalcount[8];
@@ -187,7 +187,7 @@ void SHA1Final(private_sha1_hasher_t *this, u_int8_t *digest)
 /**
  * implementation of hasher_t.get_hash for sha1
  */
-static status_t get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
+static void get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *buffer)
 {
        SHA1Update(this, chunk.ptr, chunk.len);
        if (buffer != NULL)
@@ -195,14 +195,13 @@ static status_t get_hash(private_sha1_hasher_t *this, chunk_t chunk, u_int8_t *b
                SHA1Final(this, buffer);
                this->public.hasher_interface.reset(&(this->public.hasher_interface));
        }
-       return SUCCESS;
 }
 
 
 /**
  * implementation of hasher_t.allocate_hash for sha1
  */
-static status_t allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
+static void allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
 {
        chunk_t allocated_hash;
        
@@ -211,17 +210,12 @@ static status_t allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_
        {       
                allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_SHA1);
                allocated_hash.len = BLOCK_SIZE_SHA1;
-               if (allocated_hash.ptr == NULL)
-               {
-                       return OUT_OF_RES;
-               }
+               
                SHA1Final(this, allocated_hash.ptr);
                this->public.hasher_interface.reset(&(this->public.hasher_interface));
                
                *hash = allocated_hash;
        }
-       
-       return SUCCESS;
 }
        
 /**
@@ -235,7 +229,7 @@ static size_t get_block_size(private_sha1_hasher_t *this)
 /**
  * implementation of hasher_t.reset for sha1
  */
-static status_t reset(private_sha1_hasher_t *this)
+static void reset(private_sha1_hasher_t *this)
 {
        this->state[0] = 0x67452301;
     this->state[1] = 0xEFCDAB89;
@@ -244,15 +238,13 @@ static status_t reset(private_sha1_hasher_t *this)
     this->state[4] = 0xC3D2E1F0;
     this->count[0] = 0;
     this->count[1] = 0;
-    return SUCCESS;
 }
 /**
  * implementation of hasher_t.destroy for sha1
  */
-static status_t destroy(private_sha1_hasher_t *this)
+static void destroy(private_sha1_hasher_t *this)
 {
        allocator_free(this);
-       return SUCCESS;
 }
 
 
@@ -267,11 +259,11 @@ sha1_hasher_t *sha1_hasher_create()
                return NULL;    
        }
        
-       this->public.hasher_interface.get_hash = (status_t (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
-       this->public.hasher_interface.allocate_hash = (status_t (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
+       this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
+       this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
        this->public.hasher_interface.get_block_size = (size_t (*) (hasher_t*))get_block_size;
-       this->public.hasher_interface.reset = (size_t (*) (hasher_t*))reset;
-       this->public.hasher_interface.destroy = (size_t (*) (hasher_t*))destroy;
+       this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
+       this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
        
        /* initialize */
        this->public.hasher_interface.reset(&(this->public.hasher_interface));
index ed1780d..c712e4b 100644 (file)
@@ -45,9 +45,7 @@ struct sha1_hasher_t {
 /**
  * @brief Creates a new sha1_hasher_t.
  * 
- * @return
- *                             - sha1_hasher_t if successfully
- *                             - NULL if out of ressources
+ * @return     sha1_hasher_t object
  * 
  * @ingroup hashers
  */
index 4ecd61e..c7847ad 100644 (file)
@@ -59,7 +59,7 @@ struct private_hmac_t {
 /**
  * Implementation of hmac_t.get_mac.
  */
-static status_t get_mac(private_hmac_t *this, chunk_t data, u_int8_t *out)
+static void get_mac(private_hmac_t *this, chunk_t data, u_int8_t *out)
 {
        /* H(K XOR opad, H(K XOR ipad, text)) 
         * 
@@ -92,13 +92,12 @@ static status_t get_mac(private_hmac_t *this, chunk_t data, u_int8_t *out)
                /* reinit for next call */
                this->h->get_hash(this->h, this->ipaded_key, NULL);
        }
-       return SUCCESS;
 }
 
 /**
  * Implementation of hmac_t.allocate_mac.
  */
-static status_t allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
+static void allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
 {
        /* allocate space and use get_mac */
        if (out == NULL)
@@ -110,13 +109,8 @@ static status_t allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
        {
                out->len = this->h->get_block_size(this->h);
                out->ptr = allocator_alloc(out->len);
-               if (out->ptr == NULL)
-               {
-                       return OUT_OF_RES;      
-               }
                this->hmac.get_mac(&(this->hmac), data, out->ptr);
        }
-       return SUCCESS;
 }
        
 /**
@@ -130,7 +124,7 @@ static size_t get_block_size(private_hmac_t *this)
 /**
  * Implementation of hmac_t.set_key.
  */
-static status_t set_key(private_hmac_t *this, chunk_t key)
+static void set_key(private_hmac_t *this, chunk_t key)
 {
        int i;
        u_int8_t buffer[this->b];
@@ -158,20 +152,17 @@ static status_t set_key(private_hmac_t *this, chunk_t key)
        /* begin hashing of inner pad */
        this->h->reset(this->h);
        this->h->get_hash(this->h, this->ipaded_key, NULL);
-       
-       return SUCCESS;;
 }
 
 /**
  * Implementation of hmac_t.destroy.
  */
-static status_t destroy(private_hmac_t *this)
+static void destroy(private_hmac_t *this)
 {
        this->h->destroy(this->h);
        allocator_free(this->opaded_key.ptr);
        allocator_free(this->ipaded_key.ptr);
        allocator_free(this);
-       return SUCCESS;
 }
 
 /*
@@ -182,16 +173,13 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
        private_hmac_t *this;
        
        this = allocator_alloc_thing(private_hmac_t);
-       if (this == NULL)
-       {
-               return NULL;    
-       }
+
        /* set hmac_t methods */
-       this->hmac.get_mac = (size_t (*)(hmac_t *,chunk_t,u_int8_t*))get_mac;
-       this->hmac.allocate_mac = (size_t (*)(hmac_t *,chunk_t,chunk_t*))allocate_mac;
+       this->hmac.get_mac = (void (*)(hmac_t *,chunk_t,u_int8_t*))get_mac;
+       this->hmac.allocate_mac = (void (*)(hmac_t *,chunk_t,chunk_t*))allocate_mac;
        this->hmac.get_block_size = (size_t (*)(hmac_t *))get_block_size;
-       this->hmac.set_key = (status_t (*)(hmac_t *,chunk_t))set_key;
-       this->hmac.destroy = (status_t (*)(hmac_t *))destroy;
+       this->hmac.set_key = (void (*)(hmac_t *,chunk_t))set_key;
+       this->hmac.destroy = (void (*)(hmac_t *))destroy;
        
        /* set b, according to hasher */
        switch (hash_algorithm)
@@ -207,30 +195,13 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
                
        /* build the hasher */
        this->h = hasher_create(hash_algorithm);
-       if (this->h == NULL)
-       {
-               allocator_free(this);
-               return NULL;    
-       }
 
        /* build ipad and opad */
        this->opaded_key.ptr = allocator_alloc(this->b);
        this->opaded_key.len = this->b;
-       if (this->opaded_key.ptr == NULL)
-       {
-               this->h->destroy(this->h);
-               allocator_free(this);
-               return NULL;    
-       }
+
        this->ipaded_key.ptr = allocator_alloc(this->b);
        this->ipaded_key.len = this->b;
-       if (this->ipaded_key.ptr == NULL)
-       {
-               this->h->destroy(this->h);
-               allocator_free(this->opaded_key.ptr);
-               allocator_free(this);
-               return NULL;    
-       }
 
        return &(this->hmac);
 }
index 3df69e8..d415ace 100644 (file)
@@ -52,10 +52,8 @@ struct hmac_t {
         * @param this                  calling hmac
         * @param data                  chunk of data to authenticate
         * @param[out] buffer   pointer where the generated bytes will be written
-        * @return                              
-        *                                              - SUCCESS in any case
         */
-       status_t (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
+       void (*get_mac) (hmac_t *this, chunk_t data, u_int8_t *buffer);
        
        /**
         * @brief Generates message authentication code and 
@@ -69,11 +67,8 @@ struct hmac_t {
         * @param this                  calling hmac
         * @param data                  chunk of data to authenticate
         * @param[out] chunk    chunk which will hold generated bytes
-        * @return                              
-        *                                              - SUCCESS, or
-        *                                              - OUT_OF_RES if space could not be allocated
         */
-       status_t (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
+       void (*allocate_mac) (hmac_t *this, chunk_t data, chunk_t *chunk);
        
        /**
         * @brief Get the block size of this hmac.
@@ -90,19 +85,15 @@ struct hmac_t {
         * 
         * @param this                  calling hmac
         * @param key                   key to set
-        * @return                              
-        *                                              - SUCCESS in any case
         */
-       status_t (*set_key) (hmac_t *this, chunk_t key);
+       void (*set_key) (hmac_t *this, chunk_t key);
        
        /**
         * @brief Destroys a hmac object.
         *
         * @param this                  hmac_t object to destroy
-        * @return
-        *                                              - SUCCESS in any case
         */
-       status_t (*destroy) (hmac_t *this);
+       void (*des