aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/utils
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-28 20:29:47 +0000
committerMartin Willi <martin@strongswan.org>2005-11-28 20:29:47 +0000
commitd048df5cabd2d17713230f260bccebb205740498 (patch)
tree5c08427945e6a94421e84deada90aac2065fde18 /Source/charon/utils
parent3fe058703ffe537dfdf68b9ad4d9143644230321 (diff)
downloadstrongswan-d048df5cabd2d17713230f260bccebb205740498.tar.bz2
strongswan-d048df5cabd2d17713230f260bccebb205740498.tar.xz
- return value cleanup
Diffstat (limited to 'Source/charon/utils')
-rw-r--r--Source/charon/utils/gmp_helper.c213
-rw-r--r--Source/charon/utils/gmp_helper.h37
-rw-r--r--Source/charon/utils/iterator.h20
-rw-r--r--Source/charon/utils/linked_list.c145
-rw-r--r--Source/charon/utils/linked_list.h29
-rw-r--r--Source/charon/utils/logger.c45
-rw-r--r--Source/charon/utils/logger.h22
-rw-r--r--Source/charon/utils/logger_manager.c161
-rw-r--r--Source/charon/utils/logger_manager.h29
-rw-r--r--Source/charon/utils/randomizer.c27
-rw-r--r--Source/charon/utils/randomizer.h9
-rw-r--r--Source/charon/utils/tester.c8
-rw-r--r--Source/charon/utils/tester.h13
13 files changed, 186 insertions, 572 deletions
diff --git a/Source/charon/utils/gmp_helper.c b/Source/charon/utils/gmp_helper.c
index dee334aa0..33050129a 100644
--- a/Source/charon/utils/gmp_helper.c
+++ b/Source/charon/utils/gmp_helper.c
@@ -44,7 +44,6 @@ struct private_gmp_helper_t {
* Public gmp_helper_t interface.
*/
gmp_helper_t public;
-
};
@@ -53,186 +52,83 @@ struct private_gmp_helper_t {
*/
static void chunk_to_mpz(private_gmp_helper_t *this, mpz_t *mpz_value, chunk_t data)
{
- size_t i;
-
- mpz_init_set_ui(*(mpz_value), 0);
-
- for (i = 0; i < data.len; i++)
- {
+ size_t i;
+
+ mpz_init_set_ui(*(mpz_value), 0);
+
+ for (i = 0; i < data.len; i++)
+ {
mpz_mul_ui(*(mpz_value),*(mpz_value), 1 << 8);
mpz_add_ui(*(mpz_value),*(mpz_value), data.ptr[i]);
- }
+ }
}
/**
* Implementation of gmp_helper_t.mpz_to_chunk.
*/
-static status_t mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes)
+static void mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes)
{
- mpz_t temp1, temp2;
- status_t status = SUCCESS;
- int i;
- chunk_t tmp_chunk;
-
- tmp_chunk.len = bytes;
- tmp_chunk.ptr = allocator_alloc(tmp_chunk.len);
-
- if (tmp_chunk.ptr == NULL)
- {
- allocator_free_chunk(&tmp_chunk);
- return OUT_OF_RES;
- }
-
- /* free memory */
- memset(tmp_chunk.ptr,0,tmp_chunk.len);
-
- mpz_init(temp1);
- mpz_init(temp2);
-
- mpz_set(temp1, *mpz_value);
-
- for (i = tmp_chunk.len-1; i >= 0; i--)
- {
+ mpz_t temp1, temp2;
+ int i;
+ chunk_t tmp_chunk;
+
+ tmp_chunk.len = bytes;
+ tmp_chunk.ptr = allocator_alloc(tmp_chunk.len);
+
+ memset(tmp_chunk.ptr,0,tmp_chunk.len);
+
+ mpz_init(temp1);
+ mpz_init(temp2);
+
+ mpz_set(temp1, *mpz_value);
+
+ for (i = tmp_chunk.len-1; i >= 0; i--)
+ {
tmp_chunk.ptr[i] = mpz_mdivmod_ui(temp2, NULL, temp1, 1 << 8);
mpz_set(temp1, temp2);
-
- }
-
- if (mpz_sgn(temp1) != 0)
- {
- fprintf (stderr,"value %d\n",mpz_sgn(temp1));
- status = FAILED;
- }
- mpz_clear(temp1);
- mpz_clear(temp2);
- *data = tmp_chunk;
- if (status != SUCCESS)
- {
- allocator_free_chunk(&tmp_chunk);
}
- return status;
+
+ mpz_clear(temp1);
+ mpz_clear(temp2);
+ *data = tmp_chunk;
}
/**
* Implementation of gmp_helper_t.init_prime.
*/
-static status_t init_prime (private_gmp_helper_t *this, mpz_t *prime, int bytes)
+static void init_prime (private_gmp_helper_t *this, mpz_t *prime, int bytes)
{
- randomizer_t *randomizer;
- chunk_t random_bytes;
- status_t status;
- randomizer = randomizer_create();
-
- if (randomizer == NULL)
- {
- return OUT_OF_RES;
- }
-
- /* TODO change to true random device ? */
- //status = randomizer->allocate_random_bytes(randomizer,bytes, &random_bytes);
- status = randomizer->allocate_pseudo_random_bytes(randomizer,bytes, &random_bytes);
-
- /* make sure most significant bit is set */
- random_bytes.ptr[0] = random_bytes.ptr[0] | 0x80;
-
-
- /* not needed anymore */
- randomizer->destroy(randomizer);
-
- /* convert chunk to mpz value */
- this->public.chunk_to_mpz(&(this->public),prime, random_bytes);
-
- /* chunk is not used anymore */
- allocator_free(random_bytes.ptr);
- random_bytes.ptr = NULL;
-
- /* composites are possible but should never occur */
- mpz_nextprime (*(prime),*(prime));
-
- return SUCCESS;
-}
-
-/**
- * Implementation of gmp_helper_t.init_prime_fast.
- */
-static status_t init_prime_fast (private_gmp_helper_t *this, mpz_t *prime, int bytes){
randomizer_t *randomizer;
- chunk_t random_bytes;
- status_t status;
- unsigned long tries;
- size_t length;
-
-
- randomizer = randomizer_create();
-
- if (randomizer == NULL)
- {
- return OUT_OF_RES;
- }
-
- /* TODO change to true random device ? */
- //status = randomizer->allocate_random_bytes(randomizer,bytes, &random_bytes);
- status = randomizer->allocate_pseudo_random_bytes(randomizer,bytes, &random_bytes);
-
- /* make sure most significant bit is set */
- random_bytes.ptr[0] = random_bytes.ptr[0] | 0x80;
- /* not needed anymore */
- randomizer->destroy(randomizer);
-
- /* convert chunk to mpz value */
- this->public.chunk_to_mpz(&(this->public),prime, random_bytes);
-
- /* chunk is not used anymore */
- allocator_free(random_bytes.ptr);
- random_bytes.ptr = NULL;
+ chunk_t random_bytes;
+ randomizer = randomizer_create();
- /* make value odd */
- if (mpz_fdiv_ui(*prime, 2) != 1)
- {
- /* make value odd */
- mpz_add_ui(*prime,*prime,1);
- }
+ /* TODO change to true random device ? */
+ //randomizer->allocate_random_bytes(randomizer,bytes, &random_bytes);
+ randomizer->allocate_pseudo_random_bytes(randomizer,bytes, &random_bytes);
- tries = 1;
+ /* make sure most significant bit is set */
+ random_bytes.ptr[0] = random_bytes.ptr[0] | 0x80;
- /* starting find a prime */
- while (!mpz_probab_prime_p(*prime, PRIMECHECK_ROUNDS))
- {
- /* not a prime, increase by 2 */
- mpz_add_ui(*prime, *prime, 2);
- tries++;
- }
-
- length = mpz_sizeinbase(*prime, 2);
-
-
- /* check bit length of prime */
- if ((length < (bytes * 8)) || (length > ((bytes * 8) + 1)))
- {
- return FAILED;
- }
+ /* not needed anymore */
+ randomizer->destroy(randomizer);
-
- if (length == ((bytes * 8) + 1))
- {
- /* carry out occured! retry */
- mpz_clear(*prime);
-
- /* recursive call */
- return this->public.init_prime_fast(&(this->public),prime, bytes);
- }
-
- return SUCCESS;
+ /* convert chunk to mpz value */
+ this->public.chunk_to_mpz(&(this->public),prime, random_bytes);
+
+ /* chunk is not used anymore */
+ allocator_free(random_bytes.ptr);
+ random_bytes.ptr = NULL;
+
+ /* composites are possible but should never occur */
+ mpz_nextprime (*(prime),*(prime));
}
-
/**
* Implementation of gmp_helper_t.destroy.
*/
-static status_t destroy(private_gmp_helper_t *this)
+static void destroy(private_gmp_helper_t *this)
{
allocator_free(this);
- return SUCCESS;
}
/*
@@ -241,19 +137,14 @@ static status_t destroy(private_gmp_helper_t *this)
gmp_helper_t *gmp_helper_create()
{
private_gmp_helper_t *this = allocator_alloc_thing(private_gmp_helper_t);
- if ((this == NULL))
- {
- return NULL;
- }
/* public functions */
- this->public.destroy = (status_t (*)(gmp_helper_t *)) destroy;
- this->public.init_prime = (status_t (*) (gmp_helper_t *, mpz_t *, int)) init_prime;
- this->public.init_prime_fast = (status_t (*) (gmp_helper_t *, mpz_t *, int)) init_prime_fast;
+ this->public.destroy = (void (*)(gmp_helper_t *)) destroy;
+ this->public.init_prime = (void (*) (gmp_helper_t *, mpz_t *, int)) init_prime;
- /* private functions */
+ /* private functions */
this->public.chunk_to_mpz = (void (*) (gmp_helper_t *,mpz_t *, chunk_t )) chunk_to_mpz;
- this->public.mpz_to_chunk = (status_t (*) (gmp_helper_t *,mpz_t *, chunk_t *,size_t )) mpz_to_chunk;
+ this->public.mpz_to_chunk = (void (*) (gmp_helper_t *,mpz_t *, chunk_t *,size_t )) mpz_to_chunk;
return &(this->public);
}
diff --git a/Source/charon/utils/gmp_helper.h b/Source/charon/utils/gmp_helper.h
index 1987658da..3b274cf05 100644
--- a/Source/charon/utils/gmp_helper.h
+++ b/Source/charon/utils/gmp_helper.h
@@ -47,26 +47,8 @@ struct gmp_helper_t {
* @param this calling object
* @param[out] var pointer to mpz_t variable to initialize
* @param[in] bytes length of given prime in bytes
- * @return
- * - SUCCCESS
- * - OUT_OF_RES
*/
- status_t (*init_prime) (gmp_helper_t *this, mpz_t *var, int bytes);
-
- /**
- * Initialize an mpz_t to a random prime of specified size without using gmp
- * next prime function.
- *
- *
- * @param this calling object
- * @param[out] var mpz_t variable to initialize
- * @param[in] bytes length of given prime in bytes
- * @return
- * - SUCCCESS
- * - FAILED if length of prime not as asked. Try again.
- * - OUT_OF_RES
- */
- status_t (*init_prime_fast) (gmp_helper_t *this, mpz_t *prime, int bytes);
+ void (*init_prime) (gmp_helper_t *this, mpz_t *var, int bytes);
/**
* Convert network form (binary bytes, big-endian) to mpz_t of gmp library.
@@ -74,7 +56,7 @@ struct gmp_helper_t {
* The given mpz_t gets initialized in this function.
*
* @param this calling private_gmp_helper_t object
- * @param mpz_value pointer to a mpz_t value
+ * @param mpz_value pointer to a mpz_t value
* @param data chunk_t containing the network form of data
*/
void (*chunk_to_mpz) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t data);
@@ -83,16 +65,11 @@ struct gmp_helper_t {
* Convert mpz_t to network form (binary bytes, big-endian).
*
* @param this calling private_gmp_helper_t object
- * @param mpz_value mpz_value to convert
+ * @param mpz_value mpz_value to convert
* @param data chunk_t where the data are written to
* @param bytes number of bytes to copy
- *
- * @return
- * - SUCCESS
- * - OUT_OF_RES
- * - FAILED if mpz_t value was longer then given bytes count
*/
- status_t (*mpz_to_chunk) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes);
+ void (*mpz_to_chunk) (gmp_helper_t *this, mpz_t *mpz_value, chunk_t *data, size_t bytes);
/**
* @brief Destroys an gmp_helper_t object.
@@ -100,15 +77,13 @@ struct gmp_helper_t {
* @param this gmp_helper_t object to destroy
* @return SUCCESS in any case
*/
- status_t (*destroy) (gmp_helper_t *this);
+ void (*destroy) (gmp_helper_t *this);
};
/**
* Creates a new gmp_helper_t object
*
- * @return
- * - gmp_helper_t object
- * - NULL if out of ressources
+ * @return gmp_helper_t object
*
* @ingroup utils
*/
diff --git a/Source/charon/utils/iterator.h b/Source/charon/utils/iterator.h
index 31964e03a..f644b90c3 100644
--- a/Source/charon/utils/iterator.h
+++ b/Source/charon/utils/iterator.h
@@ -52,7 +52,7 @@ struct iterator_t {
* @param[out] value value is set to the current value at iterator position
* @return
* - SUCCESS
- * - FAILED if list is empty
+ * - FAILED if iterator on an invalid position
*/
status_t (*current) (iterator_t *this, void **value);
@@ -63,24 +63,18 @@ struct iterator_t {
*
* @param this calling iterator
* @param[in] item value to insert in list
- * @return
- * - SUCCESS
- * - FAILED
*/
- status_t (*insert_before) (iterator_t *this, void *item);
+ void (*insert_before) (iterator_t *this, void *item);
/**
- * Inserts a new item after the given iterator position.
+ * @brief Inserts a new item after the given iterator position.
*
* The iterator position is not changed after inserting.
*
* @param this calling iterator
* @param[in] item value to insert in list
- * @return
- * - SUCCESS
- * - FAILED
*/
- status_t (*insert_after) (iterator_t *this, void *item);
+ void (*insert_after) (iterator_t *this, void *item);
/**
* @brief removes an element from list at the given iterator position.
@@ -93,7 +87,7 @@ struct iterator_t {
* @param linked_list calling object
* @return
* - SUCCESS
- * - FAILED
+ * - FAILED if iterator is on an invalid position
*/
status_t (*remove) (iterator_t *iterator);
@@ -107,7 +101,7 @@ struct iterator_t {
* @param this calling object
* @return SUCCESS in any case
*/
- status_t (*reset) (iterator_t *this);
+ void (*reset) (iterator_t *this);
/**
* @brief Destroys an iterator.
@@ -116,7 +110,7 @@ struct iterator_t {
* @return SUCCESS in any case
*
*/
- status_t (*destroy) (iterator_t *this);
+ void (*destroy) (iterator_t *this);
};
#endif /*ITERATOR_H_*/
diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c
index 5844c1b8a..27d9db64b 100644
--- a/Source/charon/utils/linked_list.c
+++ b/Source/charon/utils/linked_list.c
@@ -41,32 +41,31 @@ struct linked_list_element_t {
void *value;
/**
- * Destroys a linked_list_element object.
- *
- * @param linked_list_element_t calling object
- * @returns SUCCESS in any case
- */
- status_t (*destroy) (linked_list_element_t *this);
-
- /**
* previous list element
* NULL if first element in list
*/
linked_list_element_t *previous;
+
/**
* next list element
* NULL if last element in list
*/
linked_list_element_t *next;
+
+ /**
+ * Destroys a linked_list_element object.
+ *
+ * @param linked_list_element_t calling object
+ */
+ void (*destroy) (linked_list_element_t *this);
};
/**
* Implementation of linked_list_element_t.destroy.
*/
-static status_t linked_list_element_destroy(linked_list_element_t *this)
+static void linked_list_element_destroy(linked_list_element_t *this)
{
allocator_free(this);
- return SUCCESS;
}
/**
@@ -74,21 +73,14 @@ static status_t linked_list_element_destroy(linked_list_element_t *this)
*
* @warning Only the pointer to the value is stored.
*
- * @param[in] value value of item to be set
- * @return
- * - linked_list_element_t object
- * - NULL if out of ressources
+ * @param[in] value value of item to be set
+ * @return linked_list_element_t object
*/
linked_list_element_t *linked_list_element_create(void *value)
{
linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t);
- if (this == NULL)
- {
- return NULL;
- }
-
this->destroy = linked_list_element_destroy;
this->previous=NULL;
@@ -120,6 +112,7 @@ struct private_linked_list_t {
* NULL if no elements in list.
*/
linked_list_element_t *first;
+
/**
* Last element in list.
* NULL if no elements in list.
@@ -132,7 +125,6 @@ typedef struct private_iterator_t private_iterator_t;
/**
* Private variables and functions of linked list iterator.
- *
*/
struct private_iterator_t {
/**
@@ -204,10 +196,9 @@ static status_t iterator_current(private_iterator_t *this, void **value)
/**
* Implementation of iterator_t.reset.
*/
-static status_t iterator_reset(private_iterator_t *this)
+static void iterator_reset(private_iterator_t *this)
{
this->current = NULL;
- return SUCCESS;
}
/**
@@ -275,28 +266,17 @@ static status_t remove(private_iterator_t *this)
/**
* Implementation of iterator_t.insert_before.
*/
-static status_t insert_before(private_iterator_t * iterator, void *item)
+static void insert_before(private_iterator_t * iterator, void *item)
{
if (iterator->current == NULL)
{
- return (iterator->list->public.insert_first(&(iterator->list->public), item));
+ iterator->list->public.insert_first(&(iterator->list->public), item);
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
- if (element == NULL)
- {
- return OUT_OF_RES;
- }
-
if (iterator->current->previous == NULL)
{
- if (iterator->list->first != iterator->current)
- {
- element->destroy(element);
- return FAILED;
- }
-
iterator->current->previous = element;
element->next = iterator->current;
iterator->list->first = element;
@@ -310,35 +290,22 @@ static status_t insert_before(private_iterator_t * iterator, void *item)
}
iterator->list->count++;
-
- return SUCCESS;
}
/**
* Implementation of iterator_t.insert_after.
*/
-static status_t insert_after(private_iterator_t * iterator, void *item)
+static void insert_after(private_iterator_t * iterator, void *item)
{
if (iterator->current == NULL)
{
- return (iterator->list->public.insert_first(&(iterator->list->public),item));
+ iterator->list->public.insert_first(&(iterator->list->public),item);
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
- if (element == NULL)
- {
- return OUT_OF_RES;
- }
-
if (iterator->current->next == NULL)
{
- if (iterator->list->last != iterator->current)
- {
- element->destroy(element);
- return FAILED;
- }
-
iterator->current->next = element;
element->previous = iterator->current;
iterator->list->last = element;
@@ -350,18 +317,15 @@ static status_t insert_after(private_iterator_t * iterator, void *item)
iterator->current->next = element;
element->previous = iterator->current;
}
-
iterator->list->count++;
- return SUCCESS;
}
/**
* Implementation of iterator_t.destroy.
*/
-static status_t iterator_destroy(private_iterator_t *this)
+static void iterator_destroy(private_iterator_t *this)
{
allocator_free(this);
- return SUCCESS;
}
/**
@@ -376,17 +340,12 @@ static int get_count(private_linked_list_t *this)
/**
* Implementation of linked_list_t.insert_first.
*/
-static status_t insert_first(private_linked_list_t *this, void *item)
+static void insert_first(private_linked_list_t *this, void *item)
{
linked_list_element_t *element;
element =(linked_list_element_t *) linked_list_element_create(item);
- if (element == NULL)
- {
- return OUT_OF_RES;
- }
-
if (this->count == 0)
{
/* first entry in list */
@@ -397,12 +356,6 @@ static status_t insert_first(private_linked_list_t *this, void *item)
}
else
{
- if ((this->first == NULL) || (this->last == NULL))
- {
- /* should never happen */
- element->destroy(element);
- return FAILED;
- }
linked_list_element_t *old_first_element = this->first;
element->next = old_first_element;
element->previous = NULL;
@@ -411,8 +364,6 @@ static status_t insert_first(private_linked_list_t *this, void *item)
}
this->count++;
-
- return SUCCESS;
}
/**
@@ -437,7 +388,9 @@ static status_t remove_first(private_linked_list_t *this, void **item)
this->count--;
- return (element->destroy(element));
+ element->destroy(element);
+
+ return SUCCESS;
}
/**
@@ -458,15 +411,10 @@ static status_t get_first(private_linked_list_t *this, void **item)
/**
* Implementation of linked_list_t.insert_last.
*/
-static status_t insert_last(private_linked_list_t *this, void *item)
+static void insert_last(private_linked_list_t *this, void *item)
{
linked_list_element_t *element = (linked_list_element_t *) linked_list_element_create(item);
- if (element == NULL)
- {
- return OUT_OF_RES;
- }
-
if (this->count == 0)
{
/* first entry in list */
@@ -474,14 +422,10 @@ static status_t insert_last(private_linked_list_t *this, void *item)
this->last = element;
element->previous = NULL;
element->next = NULL;
- }else
+ }
+ else
{
- if ((this->first == NULL) || (this->last == NULL))
- {
- /* should never happen */
- element->destroy(element);
- return FAILED;
- }
+
linked_list_element_t *old_last_element = this->last;
element->previous = old_last_element;
element->next = NULL;
@@ -490,8 +434,6 @@ static status_t insert_last(private_linked_list_t *this, void *item)
}
this->count++;
-
- return SUCCESS;
}
/**
@@ -516,7 +458,9 @@ static status_t remove_last(private_linked_list_t *this, void **item)
this->count--;
- return (element->destroy(element));
+ element->destroy(element);
+
+ return SUCCESS;
}
/**
@@ -537,48 +481,39 @@ static status_t get_last(private_linked_list_t *this, void **item)
/**
* Implementation of linked_list_t.create_iterator.
*/
-static status_t create_iterator (private_linked_list_t *linked_list, iterator_t **iterator,bool forward)
+static void create_iterator (private_linked_list_t *linked_list, iterator_t **iterator,bool forward)
{
private_iterator_t *this = allocator_alloc_thing(private_iterator_t);
- if (this == NULL)
- {
- return OUT_OF_RES;
- }
-
this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next;
this->public.current = (status_t (*) (iterator_t *this, void **value)) iterator_current;
- this->public.insert_before = (status_t (*) (iterator_t *this, void *item)) insert_before;
- this->public.insert_after = (status_t (*) (iterator_t *this, void *item)) insert_after;
+ this->public.insert_before = (void (*) (iterator_t *this, void *item)) insert_before;
+ this->public.insert_after = (void (*) (iterator_t *this, void *item)) insert_after;
this->public.remove = (status_t (*) (iterator_t *this)) remove;
- this->public.reset = (status_t (*) (iterator_t *this)) iterator_reset;
- this->public.destroy = (status_t (*) (iterator_t *this)) iterator_destroy;
-
+ this->public.reset = (void (*) (iterator_t *this)) iterator_reset;
+ this->public.destroy = (void (*) (iterator_t *this)) iterator_destroy;
this->forward = forward;
this->current = NULL;
this->list = linked_list;
*iterator = &(this->public);
-
- return (SUCCESS);
}
/**
* Implementation of linked_list_t.destroy.
*/
-static status_t linked_list_destroy(private_linked_list_t *this)
+static void linked_list_destroy(private_linked_list_t *this)
{
void * value;
/* Remove all list items before destroying list */
+
while (this->public.remove_first(&(this->public),&value) != NOT_FOUND)
{
-
/* values are not destroyed so memory leaks are possible
* if list is not empty when deleting */
}
allocator_free(this);
- return SUCCESS;
}
/*
@@ -589,14 +524,14 @@ linked_list_t *linked_list_create()
private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
this->public.get_count = (int (*) (linked_list_t *linked_list)) get_count;
- this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, iterator_t **iterator,bool forward)) create_iterator;
+ this->public.create_iterator = (void (*) (linked_list_t *linked_list, iterator_t **iterator,bool forward)) create_iterator;
this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
this->public.get_last = (status_t (*) (linked_list_t *linked_list, void **item)) get_last;
- this->public.insert_first = (status_t (*) (linked_list_t *linked_list, void *item)) insert_first;
- this->public.insert_last = (status_t (*) (linked_list_t *linked_list, void *item)) insert_last;
+ this->public.insert_first = (void (*) (linked_list_t *linked_list, void *item)) insert_first;
+ this->public.insert_last = (void (*) (linked_list_t *linked_list, void *item)) insert_last;
this->public.remove_first = (status_t (*) (linked_list_t *linked_list, void **item)) remove_first;
this->public.remove_last = (status_t (*) (linked_list_t *linked_list, void **item)) remove_last;
- this->public.destroy = (status_t (*) (linked_list_t *linked_list)) linked_list_destroy;
+ this->public.destroy = (void (*) (linked_list_t *linked_list)) linked_list_destroy;
this->count = 0;
this->first = NULL;
diff --git a/Source/charon/utils/linked_list.h b/Source/charon/utils/linked_list.h
index 88cf8ba07..e1b08511a 100644
--- a/Source/charon/utils/linked_list.h
+++ b/Source/charon/utils/linked_list.h
@@ -43,8 +43,8 @@ struct linked_list_t {
/**
* @brief Gets the count of items in the list.
*
- * @param linked_list calling object
- * @return number of items in list
+ * @param linked_list calling object
+ * @return number of items in list
*/
int (*get_count) (linked_list_t *linked_list);
@@ -53,26 +53,19 @@ struct linked_list_t {
*
* @warning Created iterator has to get destroyed by the caller.
*
- * @param linked_list calling object
+ * @param linked_list calling object
* @param[out] iterator place where the iterator is written
- * @param[in] forward iterator direction (TRUE: front to end)
- * @return
- * - SUCCESS
- * - OUT_OF_RES
+ * @param[in] forward iterator direction (TRUE: front to end)
*/
- status_t (*create_iterator) (linked_list_t *linked_list, iterator_t **iterator,bool forward);
+ void (*create_iterator) (linked_list_t *linked_list, iterator_t **iterator, bool forward);
/**
* @brief Inserts a new item at the beginning of the list.
*
* @param linked_list calling object
* @param[in] item value to insert in list
- * @return
- * - SUCCESS
- * - FAILED if internal list is corrupted.
- * - OUT_OF_RES
*/
- status_t (*insert_first) (linked_list_t *linked_list, void *item);
+ void (*insert_first) (linked_list_t *linked_list, void *item);
/**
* @brief Removes the first item in the list and returns its value.
@@ -101,12 +94,8 @@ struct linked_list_t {
*
* @param linked_list calling object
* @param[in] item value to insert into list
- * @return
- * - SUCCESS
- * - FAILED if internal list is corrupted.
- * - OUT_OF_RES
*/
- status_t (*insert_last) (linked_list_t *linked_list, void *item);
+ void (*insert_last) (linked_list_t *linked_list, void *item);
/**
* @brief Removes the last item in the list and returns its value.
@@ -142,12 +131,14 @@ struct linked_list_t {
* @return
* - SUCCESS
*/
- status_t (*destroy) (linked_list_t *linked_list);
+ void (*destroy) (linked_list_t *linked_list);
};
/**
* @brief Creates an empty linked list object.
*
+ * @return the created linked list.
+ *
* @ingroup utils
*/
linked_list_t *linked_list_create();
diff --git a/Source/charon/utils/logger.c b/Source/charon/utils/logger.c
index 9dfdd9496..6f5c51582 100644
--- a/Source/charon/utils/logger.c
+++ b/Source/charon/utils/logger.c
@@ -41,7 +41,7 @@
typedef struct private_logger_t private_logger_t;
/**
- * @brief The logger object.
+ * @brief The logger object's private data.
*/
struct private_logger_t {
/**
@@ -119,7 +119,6 @@ static void prepend_prefix(private_logger_t *this, logger_level_t loglevel, char
log_details = '0';
}
-
if (this->log_pid)
{
snprintf(buffer, MAX_LOG, "[%c%c] [%s] @%d %s", log_type, log_details, this->name, getpid(), string);
@@ -128,7 +127,6 @@ static void prepend_prefix(private_logger_t *this, logger_level_t loglevel, char
{
snprintf(buffer, MAX_LOG, "[%c%c] [%s] %s", log_type, log_details, this->name, string);
}
-
}
/**
@@ -136,7 +134,7 @@ static void prepend_prefix(private_logger_t *this, logger_level_t loglevel, char
*
* Yes, logg is wrong written :-).
*/
-static status_t logg(private_logger_t *this, logger_level_t loglevel, char *format, ...)
+static void logg(private_logger_t *this, logger_level_t loglevel, char *format, ...)
{
if ((this->level & loglevel) == loglevel)
{
@@ -163,13 +161,12 @@ static status_t logg(private_logger_t *this, logger_level_t loglevel, char *form
}
}
- return SUCCESS;
}
/**
* Implementation of logger_t.log_bytes.
*/
-static status_t log_bytes(private_logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len)
+static void log_bytes(private_logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len)
{
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -256,48 +253,42 @@ static status_t log_bytes(private_logger_t *this, logger_level_t loglevel, char
}
}
}
-
pthread_mutex_unlock(&mutex);
- return SUCCESS;
}
/**
* Implementation of logger_t.log_chunk.
*/
-static status_t log_chunk(logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk)
+static void log_chunk(logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk)
{
this->log_bytes(this, loglevel, label, chunk->ptr, chunk->len);
- return SUCCESS;
}
/**
* Implementation of logger_t.enable_level.
*/
-static status_t enable_level(private_logger_t *this, logger_level_t log_level)
+static void enable_level(private_logger_t *this, logger_level_t log_level)
{
this->level |= log_level;
- return SUCCESS;
}
/**
* Implementation of logger_t.disable_level.
*/
-static status_t disable_level(private_logger_t *this, logger_level_t log_level)
+static void disable_level(private_logger_t *this, logger_level_t log_level)
{
this->level &= ~log_level;
- return SUCCESS;
}
/**
* Implementation of logger_t.destroy.
*/
-static status_t destroy(private_logger_t *this)
+static void destroy(private_logger_t *this)
{
allocator_free(this->name);
allocator_free(this);
- return SUCCESS;
}
/*
@@ -306,23 +297,18 @@ static status_t destroy(private_logger_t *this)
logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_pid, FILE * output)
{
private_logger_t *this = allocator_alloc_thing(private_logger_t);
-
- if (this == NULL)
- {
- return NULL;
- }
if (logger_name == NULL)
{
logger_name = "";
}
- this->public.log = (status_t(*)(logger_t*,logger_level_t,char*,...))logg;
- this->public.log_bytes = (status_t(*)(logger_t*, logger_level_t, char*,char*,size_t))log_bytes;
+ this->public.log = (void(*)(logger_t*,logger_level_t,char*,...))logg;
+ this->public.log_bytes = (void(*)(logger_t*, logger_level_t, char*,char*,size_t))log_bytes;
this->public.log_chunk = log_chunk;
- this->public.enable_level = (status_t(*)(logger_t*,logger_level_t))enable_level;
- this->public.disable_level = (status_t(*)(logger_t*,logger_level_t))disable_level;
- this->public.destroy = (status_t(*)(logger_t*))destroy;
+ this->public.enable_level = (void(*)(logger_t*,logger_level_t))enable_level;
+ this->public.disable_level = (void(*)(logger_t*,logger_level_t))disable_level;
+ this->public.destroy = (void(*)(logger_t*))destroy;
this->prepend_prefix = prepend_prefix;
@@ -330,14 +316,9 @@ logger_t *logger_create(char *logger_name, logger_level_t log_level, bool log_pi
this->level = log_level;
this->log_pid = log_pid;
this->name = allocator_alloc(strlen(logger_name) + 1);
- if (this->name == NULL)
- {
- allocator_free(this);
- return NULL;
- }
+
strcpy(this->name,logger_name);
this->output = output;
-
if (output == NULL)
{
diff --git a/Source/charon/utils/logger.h b/Source/charon/utils/logger.h
index 34673e50d..c52211c31 100644
--- a/Source/charon/utils/logger.h
+++ b/Source/charon/utils/logger.h
@@ -99,9 +99,8 @@ struct logger_t {
* @param loglevel or'ed set of loglevels
* @param format printf like format string
* @param ... printf like parameters
- * @return SUCCESS in any case
*/
- status_t (*log) (logger_t *this, logger_level_t log_level, char *format, ...);
+ void (*log) (logger_t *this, logger_level_t log_level, char *format, ...);
/**
* @brief Log some bytes, useful for debugging.
@@ -114,9 +113,8 @@ struct logger_t {
* @param label a labeling name, logged with the bytes
* @param bytes pointer to the bytes to dump
* @param len number of bytes to dump
- * @return SUCCESS in any case
*/
- status_t (*log_bytes) (logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len);
+ void (*log_bytes) (logger_t *this, logger_level_t loglevel, char *label, char *bytes, size_t len);
/**
* @brief Log a chunk, useful for debugging.
@@ -128,35 +126,31 @@ struct logger_t {
* @param loglevel or'ed set of loglevels
* @param label a labeling name, logged with the bytes
* @param chunk pointer to a chunk to log
- * @return SUCCESS in any case
*/
- status_t (*log_chunk) (logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk);
+ void (*log_chunk) (logger_t *this, logger_level_t loglevel, char *label, chunk_t *chunk);
/**
* @brief Enables a loglevel for the current logger_t object.
*
* @param this logger_t object
* @param log_level loglevel to enable
- * @return SUCCESS in any case
*/
- status_t (*enable_level) (logger_t *this, logger_level_t log_level);
+ void (*enable_level) (logger_t *this, logger_level_t log_level);
/**
* @brief Disables a loglevel for the current logger_t object.
*
* @param this logger_t object
* @param log_level loglevel to enable
- * @return UCCESS in any case
*/
- status_t (*disable_level) (logger_t *this, logger_level_t log_level);
+ void (*disable_level) (logger_t *this, logger_level_t log_level);
/**
* @brief Destroys a logger_t object.
*
* @param this logger_t object
- * @return SUCCESS in any case
*/
- status_t (*destroy) (logger_t *this);
+ void (*destroy) (logger_t *this);
};
/**
@@ -166,9 +160,7 @@ struct logger_t {
* @param log_level or'ed set of log_levels to assign to the new logger_t object
* @param log_pid TRUE if thread id should also be logged
* @param output FILE * if log has to go on a file output, NULL for syslog
- * @return
- * - logger_t object
- * - NULL if out of ressources
+ * @return logger_t object
*
* @ingroup utils
*/
diff --git a/Source/charon/utils/logger_manager.c b/Source/charon/utils/logger_manager.c
index 0207eab24..5c3a69547 100644
--- a/Source/charon/utils/logger_manager.c
+++ b/Source/charon/utils/logger_manager.c
@@ -89,11 +89,8 @@ struct private_logger_manager_t {
* @param context context to set level
* @param logger_level logger_level to set
* @param enable enable specific level or disable it
- * @return
- * - SUCCESS
- * - OUT_OF_RES
*/
- status_t (*set_logger_level) (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable);
+ void (*set_logger_level) (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable);
};
@@ -184,32 +181,13 @@ static logger_t *create_logger(private_logger_manager_t *this, logger_context_t
logger = logger_create(context_name,logger_level,log_thread_ids,output);
}
-
- if (logger == NULL)
- {
- pthread_mutex_unlock(&(this->mutex));
- return NULL;
- }
entry = allocator_alloc_thing(loggers_entry_t);
-
- if (entry == NULL)
- {
- logger->destroy(logger);
- pthread_mutex_unlock(&(this->mutex));
- return NULL;
- }
entry->context = context;
entry->logger = logger;
- if (this->loggers->insert_last(this->loggers,entry) != SUCCESS)
- {
- allocator_free(entry);
- logger->destroy(logger);
- pthread_mutex_unlock(&(this->mutex));
- return NULL;
- }
+ this->loggers->insert_last(this->loggers,entry);
pthread_mutex_unlock(&(this->mutex));
return logger;
@@ -227,28 +205,18 @@ static logger_level_t get_logger_level (private_logger_manager_t *this, logger_c
pthread_mutex_lock(&(this->mutex));
- if (this->logger_levels->create_iterator(this->logger_levels,&iterator,TRUE) != SUCCESS)
- {
- pthread_mutex_unlock(&(this->mutex));
- return logger_level;
- }
-
+ this->logger_levels->create_iterator(this->logger_levels, &iterator,TRUE);
/* check for existing logger_level entry */
while (iterator->has_next(iterator))
{
-
logger_levels_entry_t * entry;
- if (iterator->current(iterator,(void **)&entry) != SUCCESS)
- {
- break;
- }
+ iterator->current(iterator,(void **)&entry);
if (entry->context == context)
{
logger_level = entry->level;
break;
}
}
-
iterator->destroy(iterator);
pthread_mutex_unlock(&(this->mutex));
@@ -258,71 +226,45 @@ static logger_level_t get_logger_level (private_logger_manager_t *this, logger_c
/**
* Implementation of logger_manager_t.destroy_logger.
*/
-static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
+static void destroy_logger(private_logger_manager_t *this,logger_t *logger)
{
-
iterator_t *iterator;
- status_t status = NOT_FOUND;
pthread_mutex_lock(&(this->mutex));
- if (this->loggers->create_iterator(this->loggers,&iterator,TRUE) != SUCCESS)
- {
- pthread_mutex_unlock(&(this->mutex));
- return OUT_OF_RES;
- }
-
+
+ this->loggers->create_iterator(this->loggers,&iterator,TRUE);
while (iterator->has_next(iterator))
{
-
loggers_entry_t * entry;
- status = iterator->current(iterator,(void **)&entry);
- if (status != SUCCESS)
- {
- break;
- }
- status = NOT_FOUND;
+ iterator->current(iterator,(void **)&entry);
if (entry->logger == logger)
{
iterator->remove(iterator);
allocator_free(entry);
logger->destroy(logger);
- status = SUCCESS;
break;
}
}
iterator->destroy(iterator);
pthread_mutex_unlock(&(this->mutex));
- return status;
}
/**
* Implementation of private_logger_manager_t.set_logger_level.
*/
-static status_t set_logger_level (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable)
+static void set_logger_level(private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable)
{
iterator_t *iterator;
- status_t status;
+ bool found = FALSE;
pthread_mutex_lock(&(this->mutex));
- if (this->logger_levels->create_iterator(this->logger_levels,&iterator,TRUE) != SUCCESS)
- {
- pthread_mutex_unlock(&(this->mutex));
- return OUT_OF_RES;
- }
+ this->logger_levels->create_iterator(this->logger_levels,&iterator,TRUE);
- status = NOT_FOUND;
/* find existing logger_level entry */
while (iterator->has_next(iterator))
{
logger_levels_entry_t * entry;
- status = iterator->current(iterator,(void **)&entry);
- if (status != SUCCESS)
- {
- iterator->destroy(iterator);
- pthread_mutex_unlock(&(this->mutex));
- return status;
- }
- status = NOT_FOUND;
+ iterator->current(iterator,(void **)&entry);
if (entry->context == context)
{
if (enable)
@@ -333,74 +275,51 @@ static status_t set_logger_level (private_logger_manager_t *this, logger_context
{
entry->level &= ~logger_level;
}
-
- status = SUCCESS;
+ found = TRUE;
break;
}
}
iterator->destroy(iterator);
- if (status == NOT_FOUND)
+ if (!found)
{
/* logger_levels entry not existing for current context */
logger_levels_entry_t *entry = allocator_alloc_thing(logger_levels_entry_t);
- if (entry == NULL)
- {
- pthread_mutex_unlock(&(this->mutex));
- return OUT_OF_RES;
- }
+
entry->context = context;
entry->level = (enable) ? logger_level : (this->default_log_level & (~logger_level));
- status = this->logger_levels->insert_last(this->logger_levels,entry);
- if (status != SUCCESS)
- {
- allocator_free(entry);
- pthread_mutex_unlock(&(this->mutex));
- return status;
- }
+ this->logger_levels->insert_last(this->logger_levels,entry);
}
- if (this->loggers->create_iterator(this->loggers,&iterator,TRUE) != SUCCESS)
- {
- pthread_mutex_unlock(&(this->mutex));
- return OUT_OF_RES;
- }
-
+ this->loggers->create_iterator(this->loggers,&iterator,TRUE);
while (iterator->has_next(iterator))
{
-
loggers_entry_t * entry;
- status = iterator->current(iterator,(void **)&entry);
- if (status != SUCCESS)
- {
- iterator->destroy(iterator);
- pthread_mutex_unlock(&(this->mutex));
- return status;
- }
+ iterator->current(iterator,(void **)&entry);
+
if (entry->context == context)
{
if (enable)
{
- status = entry->logger->enable_level(entry->logger,logger_level);
+ entry->logger->enable_level(entry->logger,logger_level);
}
else
{
- status = entry->logger->disable_level(entry->logger,logger_level);
+ entry->logger->disable_level(entry->logger,logger_level);
}
}
}
-
iterator->destroy(iterator);
+
pthread_mutex_unlock(&(this->mutex));
- return SUCCESS;
}
/**
* Implementation of logger_manager_t.enable_logger_level.
*/
-static status_t enable_logger_level (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level)
+static void enable_logger_level(private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level)
{
return set_logger_level(this,context,logger_level,TRUE);
}
@@ -408,7 +327,7 @@ static status_t enable_logger_level (private_logger_manager_t *this, logger_cont
/**
* Implementation of logger_manager_t.disable_logger_level.
*/
-static status_t disable_logger_level (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level)
+static void disable_logger_level(private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level)
{
return set_logger_level(this,context,logger_level,FALSE);
}
@@ -416,7 +335,7 @@ static status_t disable_logger_level (private_logger_manager_t *this, logger_con
/**
* Implementation of logger_manager_t.destroy.
*/
-static status_t destroy(private_logger_manager_t *this)
+static void destroy(private_logger_manager_t *this)
{
while (this->loggers->get_count(this->loggers) > 0)
@@ -447,7 +366,6 @@ static status_t destroy(private_logger_manager_t *this)
pthread_mutex_destroy(&(this->mutex));
allocator_free(this);
- return SUCCESS;
}
/*
@@ -456,35 +374,18 @@ static status_t destroy(private_logger_manager_t *this)
logger_manager_t *logger_manager_create(logger_level_t default_log_level)
{
private_logger_manager_t *this = allocator_alloc_thing(private_logger_manager_t);
-
- if (this == NULL)
- {
- return NULL;
- }
-
+
this->public.create_logger = (logger_t *(*)(logger_manager_t*,logger_context_t context, char *))create_logger;
- this->public.destroy_logger = (status_t(*)(logger_manager_t*,logger_t *logger))destroy_logger;
- this->public.destroy = (status_t(*)(logger_manager_t*))destroy;
+ this->public.destroy_logger = (void(*)(logger_manager_t*,logger_t *logger))destroy_logger;
+ this->public.destroy = (void(*)(logger_manager_t*))destroy;
this->public.get_logger_level = (logger_level_t (*)(logger_manager_t *, logger_context_t)) get_logger_level;
- this->public.enable_logger_level = (status_t (*)(logger_manager_t *, logger_context_t,logger_level_t)) enable_logger_level;
- this->public.disable_logger_level = (status_t (*)(logger_manager_t *, logger_context_t,logger_level_t)) disable_logger_level;
- this->set_logger_level = (status_t (*)(private_logger_manager_t *, logger_context_t,logger_level_t,bool)) set_logger_level;
+ this->public.enable_logger_level = (void (*)(logger_manager_t *, logger_context_t,logger_level_t)) enable_logger_level;
+ this->public.disable_logger_level = (void (*)(logger_manager_t *, logger_context_t,logger_level_t)) disable_logger_level;
+ this->set_logger_level = (void (*)(private_logger_manager_t *, logger_context_t,logger_level_t,bool)) set_logger_level;
/* private variables */
this->loggers = linked_list_create();
-
- if (this->loggers == NULL)
- {
- allocator_free(this);
- return NULL;
- }
this->logger_levels = linked_list_create();
- if (this->logger_levels == NULL)
- {
- this->loggers->destroy(this->loggers);
- allocator_free(this);
- return NULL;
- }
this->default_log_level = default_log_level;
pthread_mutex_init(&(this->mutex), NULL);
diff --git a/Source/charon/utils/logger_manager.h b/Source/charon/utils/logger_manager.h
index afc199ca7..c663bd7de 100644
--- a/Source/charon/utils/logger_manager.h
+++ b/Source/charon/utils/logger_manager.h
@@ -73,9 +73,7 @@ struct logger_manager_t {
* @param[out] logger pointer to a a place where the new logger is stored
* @param name name for the new logger. Context name is already included
* and has not to be specified (so NULL is allowed)
- * @return
- * - logger_t object
- * - NULL if out of ressources
+ * @return logger_t object
*/
logger_t *(*create_logger) (logger_manager_t *this, logger_context_t context, char *name);
@@ -88,12 +86,9 @@ struct logger_manager_t {
* destroy function.
*
* @param this logger_manager_t object
- * @param logger pointer to the logger which has to be destroyed
- * @return - SUCCESS
- * - OUT_OF_RES (when searching the specific logger_t object)
- * - NOT_FOUND
+ * @param logger pointer to the logger which has to be destroyed
*/
- status_t (*destroy_logger) (logger_manager_t *this,logger_t *logger);
+ void (*destroy_logger) (logger_manager_t *this,logger_t *logger);
/**
* Returns the set logger_level of a specific context or 0.
@@ -110,11 +105,8 @@ struct logger_manager_t {
* @param this calling object
* @param context context to set level
* @param logger_level logger_level to eanble
- * @return
- * - SUCCESS
- * - OUT_OF_RES
*/
- status_t (*enable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
+ void (*enable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
/**
@@ -123,11 +115,8 @@ struct logger_manager_t {
* @param this calling object
* @param context context to set level
* @param logger_level logger_level to disable
- * @return
- * - SUCCESS
- * - OUT_OF_RES
*/
- status_t (*disable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
+ void (*disable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
/**
@@ -136,19 +125,15 @@ struct logger_manager_t {
* All remaining managed logger_t objects are also destroyed.
*
* @param this logger_manager_t object
- * @return
- * - SUCCESS in any case
*/
- status_t (*destroy) (logger_manager_t *this);
+ void (*destroy) (logger_manager_t *this);
};
/**
* @brief Constructor to create a logger_manager_t object.
*
* @param default_log_level default log level for a context
- * @return
- * - logger_manager_t object
- * - NULL if out of ressources
+ * @return logger_manager_t object
*
* @ingroup utils
*/
diff --git a/Source/charon/utils/randomizer.c b/Source/charon/utils/randomizer.c
index 88c9e827a..7d0c0bb6b 100644
--- a/Source/charon/utils/randomizer.c
+++ b/Source/charon/utils/randomizer.c
@@ -155,13 +155,11 @@ static status_t allocate_pseudo_random_bytes(private_randomizer_t *this, size_t
/**
* Implementation of randomizer_t.destroy.
*/
-static status_t destroy(private_randomizer_t *this)
+static void destroy(private_randomizer_t *this)
{
allocator_free(this->random_dev_name);
allocator_free(this->pseudo_random_dev_name);
allocator_free(this);
-
- return SUCCESS;
}
/*
@@ -178,41 +176,22 @@ randomizer_t *randomizer_create(void)
randomizer_t *randomizer_create_on_devices(char * random_dev_name,char * prandom_dev_name)
{
private_randomizer_t *this = allocator_alloc_thing(private_randomizer_t);
- if (this == NULL)
- {
- return NULL;
- }
- if ((random_dev_name == NULL) || (prandom_dev_name == NULL))
- {
- return NULL;
- }
-
+
/* public functions */
this->public.get_random_bytes = (status_t (*) (randomizer_t *,size_t, u_int8_t *)) get_random_bytes;
this->public.allocate_random_bytes = (status_t (*) (randomizer_t *,size_t, chunk_t *)) allocate_random_bytes;
this->public.get_pseudo_random_bytes = (status_t (*) (randomizer_t *,size_t, u_int8_t *)) get_pseudo_random_bytes;
this->public.allocate_pseudo_random_bytes = (status_t (*) (randomizer_t *,size_t, chunk_t *)) allocate_pseudo_random_bytes;
- this->public.destroy = (status_t (*) (randomizer_t *))destroy;
+ this->public.destroy = (void (*) (randomizer_t *))destroy;
/* private functions */
this->get_bytes_from_device = get_bytes_from_device;
/* private fields */
this->random_dev_name = allocator_alloc(strlen(random_dev_name) + 1);
- if (this->random_dev_name == NULL)
- {
- allocator_free(this);
- return NULL;
- }
strcpy(this->random_dev_name,random_dev_name);
this->pseudo_random_dev_name = allocator_alloc(strlen(prandom_dev_name) + 1);
- if (this->pseudo_random_dev_name == NULL)
- {
- allocator_free(this->random_dev_name);
- allocator_free(this);
- return NULL;
- }
strcpy(this->pseudo_random_dev_name,prandom_dev_name);
return &(this->public);
diff --git a/Source/charon/utils/randomizer.h b/Source/charon/utils/randomizer.h
index a18a37745..b5dc3780a 100644
--- a/Source/charon/utils/randomizer.h
+++ b/Source/charon/utils/randomizer.h
@@ -54,10 +54,9 @@ struct randomizer_t {
*
* @param this calling randomizer_t object
* @param bytes number of bytes to allocate
- * @param[out] chunk chunk which will hold the allocated random bytes
+ * @param[out] chunk chunk which will hold the allocated random bytes
* @return
* - SUCCESS
- * - OUT_OF_RES
* - FAILED if random device could not be opened
*/
status_t (*allocate_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
@@ -83,7 +82,6 @@ struct randomizer_t {
* @param[out] chunk chunk which will hold the allocated random bytes
* @return
* - SUCCESS
- * - OUT_OF_RES
* - FAILED if random device could not be opened
*/
status_t (*allocate_pseudo_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
@@ -92,9 +90,8 @@ struct randomizer_t {
* @brief Destroys a randomizer_t object.
*
* @param this randomizer_t object to destroy
- * @return SUCCESS in any case
*/
- status_t (*destroy) (randomizer_t *this);
+ void (*destroy) (randomizer_t *this);
};
/**
@@ -115,7 +112,7 @@ randomizer_t *randomizer_create();
* @param prandom_dev_name device name for pseudo random values, etc /dev/urandom
* @return
* - created randomizer_t
- * - NULL if out of ressources
+ * - NULL if failed
*
* @ingroup utils
*/
diff --git a/Source/charon/utils/tester.c b/Source/charon/utils/tester.c
index 3f278cbe0..58dd555a6 100644
--- a/Source/charon/utils/tester.c
+++ b/Source/charon/utils/tester.c
@@ -93,7 +93,7 @@ struct private_tester_t {
/**
* Implementation of tester_t.perform_tests.
*/
-static status_t perform_tests(tester_t *tester,test_t **tests)
+static void perform_tests(tester_t *tester,test_t **tests)
{
private_tester_t *this =(private_tester_t*) tester;
int current_test = 0;
@@ -110,13 +110,12 @@ static status_t perform_tests(tester_t *tester,test_t **tests)
fprintf(this->output,"=====================================================================\n");
fprintf(this->output,"End testing. %d of %d tests succeeded\n",this->tests_count - this->failed_tests_count,this->tests_count);
fprintf(this->output,"=====================================================================\n");
- return SUCCESS;
}
/**
* Implementation of tester_t.perform_test.
*/
-static status_t perform_test(tester_t *tester, test_t *test)
+static void perform_test(tester_t *tester, test_t *test)
{
test_t *tests[] = {test, NULL};
return (perform_tests(tester,tests));
@@ -214,12 +213,11 @@ static void assert_false(tester_t *tester, bool to_be_false,char * assert_name)
/**
* Implementation of tester_t.destroy.
*/
-static status_t destroy(tester_t *tester)
+static void destroy(tester_t *tester)
{
private_tester_t *this = (private_tester_t*) tester;
pthread_mutex_destroy(&(this->mutex));
allocator_free(this);
- return SUCCESS;
}
/*
diff --git a/Source/charon/utils/tester.h b/Source/charon/utils/tester.h
index 4352b4551..729152101 100644
--- a/Source/charon/utils/tester.h
+++ b/Source/charon/utils/tester.h
@@ -63,18 +63,16 @@ struct tester_t {
* @param tester tester_t object
* @param tests pointer to an array of test_t-pointers.
* The last item has to be NULL.
- * @return SUCCESS in any case
*/
- status_t (*perform_tests) (tester_t *tester,test_t **tests);
+ void (*perform_tests) (tester_t *tester,test_t **tests);
/**
* @brief Run a specific test case.
*
* @param this tester_t object
* @param test pointer to a test_t object which will be performed
- * @return SUCCESS in any case
*/
- status_t (*perform_test) (tester_t *tester, test_t *test);
+ void (*perform_test) (tester_t *tester, test_t *test);
/**
* Is called in a testcase to check a specific situation for TRUE.
@@ -106,9 +104,8 @@ struct tester_t {
* @brief Destroys a tester_t object
*
* @param tester tester_t object
- * @return SUCCESS in any case
*/
- status_t (*destroy) (tester_t *tester);
+ void (*destroy) (tester_t *tester);
};
/**
@@ -118,9 +115,7 @@ struct tester_t {
* @param display_succeeded_asserts has to be TRUE, if all asserts should be displayed,
* FALSE otherwise
*
- * @return
- * - tester_t object
- * - NULL if out of ressources
+ * @return - tester_t object
*
* @ingroup utils
*/