- changed memory allocator functions to own allocator calls

This commit is contained in:
Jan Hutter 2005-11-09 09:11:06 +00:00
parent c1ca1ee042
commit 7953866962
22 changed files with 606 additions and 606 deletions

View file

@ -1,9 +1,9 @@
/**
* @file configuration.c
*
* @brief Class configuration_t.
*
* @brief Class configuration_t.
* Object of this type represents a configuration for an IKE_SA
*
*
*/
/*
@ -33,15 +33,15 @@
* Private data of an configuration_t object
*/
typedef struct private_configuration_s private_configuration_t;
struct private_configuration_s {
struct private_configuration_s {
/**
* Public part of a configuration_t object
*/
configuration_t public;
/* Private values */
};
@ -55,7 +55,7 @@ static status_t destroy (private_configuration_t *this)
{
return FAILED;
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -64,15 +64,15 @@ static status_t destroy (private_configuration_t *this)
*/
configuration_t * configuration_create()
{
private_configuration_t *this = alloc_thing(private_configuration_t, "private_configuration_t");
private_configuration_t *this = allocator_alloc_thing(private_configuration_t, "private_configuration_t");
if (this == NULL)
{
return NULL;
}
/* Public functions */
this->public.destroy = (status_t(*)(configuration_t*))destroy;
return (&this->public);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file event_queue.c
*
*
* @brief Event-Queue based on linked_list_t
*
*
*/
/*
@ -25,8 +25,8 @@
#include <pluto/defs.h>
#include <pthread.h>
#include <stdlib.h>
#include "types.h"
#include "event_queue.h"
#include "linked_list.h"
@ -35,9 +35,9 @@
/**
* @brief represents an event as it is stored in the event queue
*
*
* A event consists of a event time and an assigned job object
*
*
*/
typedef struct event_s event_t;
@ -54,14 +54,14 @@ struct event_s{
/**
* @brief Destroys a event_t object
*
*
* @param event_t calling object
* @returns SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy) (event_t *event);
};
/**
* @brief implements function destroy of event_t
*/
@ -71,7 +71,7 @@ static status_t event_destroy(event_t *event)
{
return FAILED;
}
pfree(event);
allocator_free(event);
return SUCCESS;
}
@ -80,66 +80,66 @@ static status_t event_destroy(event_t *event)
*
* @param time to fire the event
* @param job job to add to job-queue at specific time
*
*
* @return event_t event object
*/
static event_t *event_create(timeval_t time, job_t *job)
{
event_t *this = alloc_thing(event_t, "event_t");
event_t *this = allocator_alloc_thing(event_t, "event_t");
this->destroy = event_destroy;
this->time = time;
this->job = job;
return this;
}
/**
* @brief Private Variables and Functions of event_queue class
*
*
*/
typedef struct private_event_queue_s private_event_queue_t;
struct private_event_queue_s {
event_queue_t public;
/**
* The events are stored in a linked list
*/
linked_list_t *list;
/**
* access to linked_list is locked through this mutex
*/
pthread_mutex_t mutex;
/**
* If the queue is empty or an event has not to be fired
* a thread has to wait
* This condvar is used to wake up such a thread
*/
pthread_cond_t condvar;
pthread_cond_t condvar;
};
/**
* Returns the difference of to timeval structs in microseconds
*
*
* @param end_time end time
* @param start_time start time
*
*
* @warning this function is also defined in the tester class
* In later improvements, this function can be added to a general
* class type!
*
*
* @return difference in microseconds
*/
static long time_difference(struct timeval *end_time, struct timeval *start_time)
{
long seconds, microseconds;
seconds = (end_time->tv_sec - start_time->tv_sec);
microseconds = (end_time->tv_usec - start_time->tv_usec);
return ((seconds * 1000000) + microseconds);
@ -167,9 +167,9 @@ static status_t get(private_event_queue_t *this, job_t **job)
event_t * next_event;
int count;
int oldstate;
pthread_mutex_lock(&(this->mutex));
while (1)
{
this->list->get_count(this->list,&count);
@ -178,18 +178,18 @@ static status_t get(private_event_queue_t *this, job_t **job)
/* add mutex unlock handler for cancellation, enable cancellation */
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
pthread_cond_wait( &(this->condvar), &(this->mutex));
/* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
this->list->get_count(this->list,&count);
}
this->list->get_first(this->list,(void **) &next_event);
gettimeofday(&current_time,NULL);
long difference = time_difference(&current_time,&(next_event->time));
if (difference <= 0)
@ -203,18 +203,18 @@ 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;
next_event->destroy(next_event);
break;
}
}
pthread_cond_signal( &(this->condvar));
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
@ -227,7 +227,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
event_t *current_event;
status_t status;
int count;
if (event == NULL)
{
return FAILED;
@ -243,7 +243,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
status = this->list->insert_first(this->list,event);
break;
}
/* check last entry */
this->list->get_last(this->list,(void **) &current_event);
@ -253,7 +253,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
status = this->list->insert_last(this->list,event);
break;
}
/* check first entry */
this->list->get_first(this->list,(void **) &current_event);
@ -263,27 +263,27 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
status = this->list->insert_first(this->list,event);
break;
}
linked_list_iterator_t * iterator;
status = this->list->create_iterator(this->list,&iterator,TRUE);
if (status != SUCCESS)
{
break;
}
iterator->has_next(iterator);
/* first element has not to be checked (already done) */
/* first element has not to be checked (already done) */
while(iterator->has_next(iterator))
{
status = iterator->current(iterator,(void **) &current_event);
if (time_difference(&(event->time), &(current_event->time)) <= 0)
{
/* my event has to be fired before the current event in list */
status = this->list->insert_before(this->list,iterator,event);
status = this->list->insert_before(this->list,iterator,event);
break;
}
}
@ -298,7 +298,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
{
event->destroy(event);
}
return status;
return status;
}
/**
@ -309,12 +309,12 @@ static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
timeval_t current_time;
timeval_t time;
int micros = ms * 1000;
gettimeofday(&current_time, NULL);
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);
}
@ -323,13 +323,13 @@ static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
* @brief implements function destroy of event_queue_t
*/
static status_t event_queue_destroy(private_event_queue_t *this)
{
{
int count;
this->list->get_count(this->list,&count);
while (count > 0)
{
event_t *event;
event_t *event;
if (this->list->remove_first(this->list,(void *) &event) != SUCCESS)
{
this->list->destroy(this->list);
@ -340,17 +340,17 @@ static status_t event_queue_destroy(private_event_queue_t *this)
this->list->get_count(this->list,&count);
}
this->list->destroy(this->list);
pthread_mutex_destroy(&(this->mutex));
pthread_cond_destroy(&(this->condvar));
pfree(this);
allocator_free(this);
return SUCCESS;
}
/*
*
*
* Documented in header
*/
event_queue_t *event_queue_create()
@ -360,23 +360,23 @@ event_queue_t *event_queue_create()
{
return NULL;
}
private_event_queue_t *this = alloc_thing(private_event_queue_t, "private_event_queue_t");
private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t, "private_event_queue_t");
if (this == NULL)
{
linked_list->destroy(linked_list);
return NULL;
}
this->public.get_count = (status_t (*) (event_queue_t *event_queue, int *count)) 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->list = linked_list;
pthread_mutex_init(&(this->mutex), NULL);
pthread_cond_init(&(this->condvar), NULL);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file generator.c
*
*
* @brief Generic generator class used to generate IKEv2-Header and Payload
*
*
*/
/*
@ -32,18 +32,18 @@
* Private data of a generator_t object
*/
typedef struct private_generator_s private_generator_t;
struct private_generator_s {
struct private_generator_s {
/**
* Public part of a generator object
*/
generator_t public;
/* private functions and fields */
/**
* Generates a chunk_t with specific encoding rules
*
*
* items are bytewhise written
*
* @param this private_generator_t-object
@ -51,17 +51,17 @@ struct private_generator_s {
* @param encoding_rules pointer to first encoding_rule of encoding rules array
* @param encoding_rules_count number of encoding rules in encoding rules array
* @param data pointer to chunk where to write the data in
*
*
* @return SUCCESS if succeeded,
* OUT_OF_RES if out of ressources
*/
status_t (*generate) (private_generator_t *this,void * data_struct,encoding_rule_t *encoding_rules, size_t encoding_rules_count, chunk_t *data);
/**
* TODO
*/
status_t (*generate_u_int_type) (private_generator_t *this,encoding_type_t int_type,u_int8_t **buffer,u_int8_t **out_position,u_int8_t **roof_position,size_t *current_bit);
/**
* Pointer to the payload informations needed to automatic
* generate a specific payload type
@ -76,8 +76,8 @@ struct private_generator_s {
static status_t generate_u_int_type (private_generator_t *this,encoding_type_t int_type,u_int8_t **buffer,u_int8_t **out_position,u_int8_t **roof_position,size_t *current_bit)
{
size_t number_of_bits = 0;
size_t number_of_bits = 0;
switch (int_type)
{
case U_INT_4:
@ -106,7 +106,7 @@ static status_t generate_u_int_type (private_generator_t *this,encoding_type_t i
*/
static status_t generate (private_generator_t *this,void * data_struct,encoding_rule_t *encoding_rules, size_t encoding_rules_count, chunk_t *data)
{
u_int8_t * buffer = alloc_bytes(GENERATOR_DATA_BUFFER_SIZE, "generator buffer");
u_int8_t * buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE, "generator buffer");
u_int8_t * out_position = buffer;
u_int8_t * roof_position = buffer + GENERATOR_DATA_BUFFER_SIZE;
size_t current_bit = 0;
@ -138,18 +138,18 @@ static status_t generate (private_generator_t *this,void * data_struct,encoding_
}
if (status != SUCCESS)
{
pfree(buffer);
allocator_free(buffer);
return status;
}
}
return SUCCESS;
}
static status_t generate_payload (private_generator_t *this,payload_type_t payload_type,void * data_struct, chunk_t *data)
{
int i;
/* check every payload info for specific type */
for (i = 0; this->payload_infos[i] != NULL; i++)
{
@ -172,7 +172,7 @@ static status_t destroy(private_generator_t *this)
return FAILED;
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -182,26 +182,26 @@ static status_t destroy(private_generator_t *this)
generator_t * generator_create(payload_info_t ** payload_infos)
{
private_generator_t *this;
if (payload_infos == NULL)
{
return NULL;
}
this = alloc_thing(private_generator_t,"private_generator_t");
this = allocator_alloc_thing(private_generator_t,"private_generator_t");
if (this == NULL)
{
return NULL;
}
this->public.generate_payload = (status_t(*)(generator_t*, payload_type_t, void *, chunk_t *)) generate_payload;
this->public.destroy = (status_t(*)(generator_t*)) destroy;
/* initiate private fields */
this->generate = generate;
this->generate_u_int_type = generate_u_int_type;
this->payload_infos = payload_infos;
return &(this->public);
}

View file

@ -1,9 +1,9 @@
/**
* @file ike_sa.c
*
*
* @brief Class ike_sa_t. An object of this type is managed by an
* ike_sa_manager_t-object and represents an IKE_SA
*
*
*/
/*
@ -37,26 +37,26 @@ enum ike_sa_state_e{
* IKE_SA is is not in a state
*/
NO_STATE,
/**
* A IKE_SA_INIT-message was sent: role initiator
*/
IKE_SA_INIT_REQUESTED,
/**
* A IKE_SA_INIT-message was replied: role responder
*/
IKE_SA_INIT_RESPONDED,
/**
* An IKE_AUTH-message was sent after a successful
* An IKE_AUTH-message was sent after a successful
* IKE_SA_INIT-exchange: role initiator
*/
IKE_AUTH_REQUESTED,
/**
* An IKE_AUTH-message was replied: role responder.
* In this state, all the informations for an IKE_SA
* In this state, all the informations for an IKE_SA
* and one CHILD_SA are known.
*/
IKE_SA_INITIALIZED
@ -67,26 +67,26 @@ enum ike_sa_state_e{
* Private data of an message_t object
*/
typedef struct private_ike_sa_s private_ike_sa_t;
struct private_ike_sa_s {
struct private_ike_sa_s {
/**
* Public part of a ike_sa_t object
*/
ike_sa_t public;
/* Private values */
/**
* Identifier for the current IKE_SA
*/
ike_sa_id_t *ike_sa_id;
/**
* Linked List containing the child sa's of the current IKE_SA
*/
linked_list_t *child_sas;
/**
* Current state of the IKE_SA
*/
@ -108,7 +108,7 @@ static status_t process_message (private_ike_sa_t *this, message_t *message)
static status_t process_configuration (private_ike_sa_t *this,configuration_t *configuration)
{
/*
* @TODO Add configuration processing here
* @TODO Add configuration processing here
*/
return SUCCESS;
}
@ -130,13 +130,13 @@ static status_t destroy (private_ike_sa_t *this)
{
return FAILED;
}
this->ike_sa_id->destroy(this->ike_sa_id);
this->child_sas->destroy(this->child_sas);
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -145,37 +145,37 @@ 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 = alloc_thing(private_ike_sa_t, "private_ike_sa_t");
private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t, "private_ike_sa_t");
if (this == NULL)
{
return NULL;
}
/* Public functions */
this->public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
this->public.process_configuration = (status_t(*)(ike_sa_t*, configuration_t*)) process_configuration;
this->public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
this->public.process_configuration = (status_t(*)(ike_sa_t*, configuration_t*)) process_configuration;
this->public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
this->public.destroy = (status_t(*)(ike_sa_t*))destroy;
/* initialize private fields */
if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
{
pfree(this);
allocator_free(this);
return NULL;
}
this->child_sas = linked_list_create();
if (this->child_sas == NULL)
{
this->ike_sa_id->destroy(this->ike_sa_id);
pfree(this);
allocator_free(this);
return NULL;
}
/* at creation time, IKE_SA isn't in a specific state */
this->current_state = NO_STATE;
return (&this->public);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file ike_sa_id.c
*
*
* @brief Class for identification of an IKE_SA
*
*
*/
/*
@ -19,7 +19,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <string.h>
#include <freeswan.h>
@ -33,31 +33,31 @@
* Private data of an ike_sa_id object
*/
typedef struct private_ike_sa_id_s private_ike_sa_id_t;
struct private_ike_sa_id_s {
struct private_ike_sa_id_s {
/**
* Public part of a ike_sa_id object
*/
ike_sa_id_t public;
/* Private values */
/**
* SPI of Initiator
*/
spi_t initiator_spi;
/**
* SPI of Responder
*/
spi_t responder_spi;
/**
* Role for specific IKE_SA
*/
ike_sa_role_t role;
};
@ -101,7 +101,7 @@ static status_t equals (private_ike_sa_id_t *this,private_ike_sa_id_t *other, bo
{
return FAILED;
}
if ( (this->role == other->role) &&
if ( (this->role == other->role) &&
(this->initiator_spi.high == other->initiator_spi.high) &&
(this->initiator_spi.low == other->initiator_spi.low) &&
(this->responder_spi.high == other->responder_spi.high) &&
@ -115,7 +115,7 @@ static status_t equals (private_ike_sa_id_t *this,private_ike_sa_id_t *other, bo
/* private_ike_sa_id's are not equal */
*are_equal = FALSE;
}
return SUCCESS;
}
@ -128,11 +128,11 @@ status_t replace_values (private_ike_sa_id_t *this, private_ike_sa_id_t *other)
{
return FAILED;
}
this->initiator_spi = other->initiator_spi;
this->responder_spi = other->responder_spi;
this->role = other->role;
return SUCCESS;
}
@ -144,7 +144,7 @@ static status_t get_values(private_ike_sa_id_t *this, spi_t *initiator, spi_t *r
memcpy(initiator, &(this->initiator_spi), sizeof(initiator));
memcpy(responder, &(this->responder_spi), sizeof(responder));
*role = this->role;
return SUCCESS;
}
@ -158,9 +158,9 @@ static status_t clone (private_ike_sa_id_t *this, ike_sa_id_t **clone_of_this)
{
return FAILED;
}
*clone_of_this = ike_sa_id_create(this->initiator_spi, this->responder_spi, this->role);
return (*clone_of_this == NULL) ? FAILED : SUCCESS;
}
@ -173,7 +173,7 @@ static status_t destroy (private_ike_sa_id_t *this)
{
return FAILED;
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -182,12 +182,12 @@ static status_t destroy (private_ike_sa_id_t *this)
*/
ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, ike_sa_role_t role)
{
private_ike_sa_id_t *this = alloc_thing(private_ike_sa_id_t, "private_ike_sa_id_t");
private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t, "private_ike_sa_id_t");
if (this == NULL)
{
return NULL;
}
/* Public functions */
this->public.set_responder_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_responder_spi;
this->public.set_initiator_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_initiator_spi;
@ -203,6 +203,6 @@ ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, ike_sa_
this->initiator_spi = initiator_spi;
this->responder_spi = responder_spi;
this->role = role;
return (&this->public);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file ike_sa_manager.c
*
*
* @brief Central point for managing IKE-SAs (creation, locking, deleting...)
*
*
*/
/*
@ -51,7 +51,7 @@ struct ike_sa_entry_s {
/**
* identifiaction of ike_sa (SPIs)
*/
ike_sa_id_t *ike_sa_id;
ike_sa_id_t *ike_sa_id;
/**
* the contained ike_sa
*/
@ -62,29 +62,29 @@ static status_t ike_sa_entry_destroy(ike_sa_entry_t *this)
{
this->ike_sa->destroy(this->ike_sa);
this->ike_sa_id->destroy(this->ike_sa_id);
pfree(this);
allocator_free(this);
return SUCCESS;
}
/**
* @brief creates a new entry for the ike_sa list
*
*
* This constructor additionaly creates a new and empty SA
*
*
* @param ike_sa_id the associated ike_sa_id_t, NOT cloned
* @return created entry, with ike_sa and ike_sa_id
*/
ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
{
ike_sa_entry_t *this = alloc_thing(ike_sa_entry_t, "ike_sa_entry_t");
ike_sa_entry_t *this = allocator_alloc_thing(ike_sa_entry_t, "ike_sa_entry_t");
this->destroy = ike_sa_entry_destroy;
this->waiting_threads = 0;
pthread_cond_init(&(this->condvar), NULL);
/* we set checkout flag when we really give it out */
this->checked_out = FALSE;
this->checked_out = FALSE;
this->ike_sa_id = ike_sa_id;
this->ike_sa = ike_sa_create(ike_sa_id);
return this;
@ -99,12 +99,12 @@ struct private_ike_sa_manager_s {
* Public members
*/
ike_sa_manager_t public;
/**
* @brief get next spi
*
*
* we give out SPIs incremental
*
*
* @param this the ike_sa_manager
* @param spi[out] spi will be written here
* @return SUCCESS or,
@ -113,10 +113,10 @@ struct private_ike_sa_manager_s {
status_t (*get_next_spi) (private_ike_sa_manager_t *this, spi_t *spi);
/**
* @brief find the ike_sa_entry in the list by SPIs
*
*
* This function simply iterates over the linked list. A hash-table
* would be more efficient when storing a lot of IKE_SAs...
*
*
* @param this the ike_sa_manager containing the list
* @param ike_sa_id id of the ike_sa, containing SPIs
* @param entry[out] pointer to set to the found entry
@ -126,10 +126,10 @@ struct private_ike_sa_manager_s {
status_t (*get_entry_by_id) (private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, ike_sa_entry_t **entry);
/**
* @brief find the ike_sa_entry in the list by pointer to SA.
*
*
* This function simply iterates over the linked list. A hash-table
* would be more efficient when storing a lot of IKE_SAs...
*
*
* @param this the ike_sa_manager containing the list
* @param ike_sad pointer to the ike_sa
* @param entry[out] pointer to set to the found entry
@ -138,14 +138,14 @@ struct private_ike_sa_manager_s {
*/
status_t (*get_entry_by_sa) (private_ike_sa_manager_t *this, ike_sa_t *ike_sa, ike_sa_entry_t **entry);
/**
* @brief
* @brief
*/
status_t (*delete_entry) (private_ike_sa_manager_t *this, ike_sa_entry_t *entry);
/**
* lock for exclusivly accessing the manager
*/
pthread_mutex_t mutex;
/**
* Linked list with entries for the ike_sa
*/
@ -153,7 +153,7 @@ struct private_ike_sa_manager_s {
/**
* Next SPI, needed for incremental creation of SPIs
*/
spi_t next_spi;
spi_t next_spi;
};
@ -194,7 +194,7 @@ static status_t get_ike_sa_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t
{
ike_sa_entry_t *current;
iterator->current(iterator, (void**)&current);
if (current->ike_sa == ike_sa)
if (current->ike_sa == ike_sa)
{
*entry = current;
iterator->destroy(iterator);
@ -234,24 +234,24 @@ static status_t checkout_ike_sa(private_ike_sa_manager_t *this, ike_sa_id_t *ike
bool responder_spi_set;
bool initiator_spi_set;
status_t retval;
pthread_mutex_lock(&(this->mutex));
responder_spi_set = ike_sa_id->responder_spi_is_set(ike_sa_id);
initiator_spi_set = ike_sa_id->initiator_spi_is_set(ike_sa_id);
if (initiator_spi_set && responder_spi_set)
if (initiator_spi_set && responder_spi_set)
{
/* we SHOULD have an IKE_SA for these SPIs in the list,
* if not, we cant handle the request...
*/
ike_sa_entry_t *entry;
/* look for the entry */
if (this->get_entry_by_id(this, ike_sa_id, &entry) == SUCCESS)
if (this->get_entry_by_id(this, ike_sa_id, &entry) == SUCCESS)
{
/* is this IKE_SA already checked out ?? */
while (entry->checked_out)
{
while (entry->checked_out)
{
/* so wait until we can get it for us.
* we register us as waiting.
*/
@ -263,13 +263,13 @@ static status_t checkout_ike_sa(private_ike_sa_manager_t *this, ike_sa_id_t *ike
entry->checked_out = TRUE;
*ike_sa = entry->ike_sa;
/* DON'T use return, we must unlock the mutex! */
retval = SUCCESS;
retval = SUCCESS;
}
else
{
/* looks like there is no such IKE_SA, better luck next time... */
/* DON'T use return, we must unlock the mutex! */
retval = NOT_FOUND;
}
@ -286,22 +286,22 @@ static status_t checkout_ike_sa(private_ike_sa_manager_t *this, ike_sa_id_t *ike
spi_t responder_spi;
ike_sa_id_t *new_ike_sa_id;
ike_sa_entry_t *new_ike_sa_entry;
/* set SPIs, we are the responder */
ike_sa_id->clone(ike_sa_id, &new_ike_sa_id);
this->get_next_spi(this, &responder_spi);
new_ike_sa_id->set_responder_spi(new_ike_sa_id, responder_spi);
/* 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(new_ike_sa_id);
this->list->insert_last(this->list, new_ike_sa_entry);
/* check ike_sa out */
new_ike_sa_entry->checked_out = TRUE;
*ike_sa = new_ike_sa_entry->ike_sa;
/* DON'T use return, we must unlock the mutex! */
retval = SUCCESS;
}
@ -309,34 +309,34 @@ static status_t checkout_ike_sa(private_ike_sa_manager_t *this, ike_sa_id_t *ike
{
/* creation of an IKE_SA from local site,
* we are the initiator!
*/
*/
spi_t initiator_spi, responder_spi;
ike_sa_id_t *new_ike_sa_id;
ike_sa_entry_t *new_ike_sa_entry;
/* set SPIs */
memset(&responder_spi, 0, sizeof(spi_t));
this->get_next_spi(this, &initiator_spi);
/* we also set arguments SPI, so its still valid */
ike_sa_id->set_initiator_spi(ike_sa_id, initiator_spi);
/* create entry */
new_ike_sa_id = ike_sa_id_create(initiator_spi, responder_spi, INITIATOR);
new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
this->list->insert_last(this->list, new_ike_sa_entry);
/* check ike_sa out */
new_ike_sa_entry->checked_out = TRUE;
*ike_sa = new_ike_sa_entry->ike_sa;
/* DON'T use return, we must unlock the mutex! */
retval = SUCCESS;
}
else
else
{
/* responder set, initiator not: here is something seriously wrong! */
/* DON'T use return, we must unlock the mutex! */
retval = INVALID_ARG;
}
@ -347,31 +347,31 @@ static status_t checkout_ike_sa(private_ike_sa_manager_t *this, ike_sa_id_t *ike
}
static status_t checkin_ike_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
{
/* to check the SA back in, we look for the pointer of the ike_sa
{
/* to check the SA back in, we look for the pointer of the ike_sa
* in all entries.
* We can't search by SPI's since the MAY have changed (e.g. on reception
* of a IKE_SA_INIT response). Updating of the SPI MAY be necessary...
*/
status_t retval;
ike_sa_entry_t *entry;
pthread_mutex_lock(&(this->mutex));
/* look for the entry */
if (this->get_entry_by_sa(this, ike_sa, &entry) == SUCCESS)
if (this->get_entry_by_sa(this, ike_sa, &entry) == SUCCESS)
{
/* ike_sa_id must be updated */
entry->ike_sa_id->replace_values(entry->ike_sa_id, ike_sa->get_id(ike_sa));
/* signal waiting threads */
entry->checked_out = FALSE;
pthread_cond_signal(&(entry->condvar));
retval = SUCCESS;
retval = SUCCESS;
}
else
{
/* this SA is no more, this REALLY should not happen */
/* this SA is no more, this REALLY should not happen */
retval = NOT_FOUND;
}
pthread_mutex_unlock(&(this->mutex));
@ -381,20 +381,20 @@ static status_t checkin_ike_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
static status_t delete_ike_sa_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
{
/* deletion is a bit complex, we must garant that no thread is waiting for
* this SA.
{
/* deletion is a bit complex, we must garant that no thread is waiting for
* this SA.
* We take this SA from the list, and start signaling while threads
* are in the condvar.
* are in the condvar.
*/
linked_list_t *list = this->list;
linked_list_iterator_t *iterator;
ike_sa_entry_t *entry;
bool found = FALSE;
status_t retval;
pthread_mutex_lock(&(this->mutex));
/* remove SA from list */
list->create_iterator(list, &iterator, TRUE);
while (iterator->has_next(iterator))
@ -408,8 +408,8 @@ static status_t delete_ike_sa_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ik
}
}
iterator->destroy(iterator);
if (found)
if (found)
{
/* wait until all workers have done their work */
while (entry->waiting_threads)
@ -417,9 +417,9 @@ static status_t delete_ike_sa_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ik
/* wake up all */
pthread_cond_signal(&(entry->condvar));
/* and the nice thing, they will wake us again when their work is done */
pthread_cond_wait(&(entry->condvar), &(this->mutex));
pthread_cond_wait(&(entry->condvar), &(this->mutex));
}
/* ok, we are alone now, no threads waiting in the entry's condvar */
entry->destroy(entry);
retval = SUCCESS;
@ -428,26 +428,26 @@ static status_t delete_ike_sa_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ik
{
retval = NOT_FOUND;
}
pthread_mutex_unlock(&(this->mutex));
return retval;
}
static status_t delete_ike_sa_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id)
{
/* deletion is a bit complex, we must garant that no thread is waiting for
* this SA.
{
/* deletion is a bit complex, we must garant that no thread is waiting for
* this SA.
* We take this SA from the list, and start signaling while threads
* are in the condvar.
* are in the condvar.
*/
linked_list_t *list = this->list;
linked_list_iterator_t *iterator;
ike_sa_entry_t *entry;
bool found = FALSE;
status_t retval;
pthread_mutex_lock(&(this->mutex));
/* remove SA from list */
list->create_iterator(list, &iterator, TRUE);
while (iterator->has_next(iterator))
@ -463,8 +463,8 @@ static status_t delete_ike_sa_by_id(private_ike_sa_manager_t *this, ike_sa_id_t
}
}
iterator->destroy(iterator);
if (found)
if (found)
{
/* wait until all workers have done their work */
while (entry->waiting_threads)
@ -472,9 +472,9 @@ static status_t delete_ike_sa_by_id(private_ike_sa_manager_t *this, ike_sa_id_t
/* wake up all */
pthread_cond_signal(&(entry->condvar));
/* and the nice thing, they will wake us again when their work is done */
pthread_cond_wait(&(entry->condvar), &(this->mutex));
pthread_cond_wait(&(entry->condvar), &(this->mutex));
}
/* ok, we are alone now, no threads waiting in the entry's condvar */
entry->destroy(entry);
retval = SUCCESS;
@ -483,7 +483,7 @@ static status_t delete_ike_sa_by_id(private_ike_sa_manager_t *this, ike_sa_id_t
{
retval = NOT_FOUND;
}
pthread_mutex_unlock(&(this->mutex));
return retval;
}
@ -501,10 +501,10 @@ static status_t destroy(private_ike_sa_manager_t *this)
entry->destroy(entry);
}
iterator->destroy(iterator);
list->destroy(list);
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -512,31 +512,31 @@ static status_t destroy(private_ike_sa_manager_t *this)
ike_sa_manager_t *ike_sa_manager_create()
{
private_ike_sa_manager_t *this = alloc_thing(private_ike_sa_manager_t, "private_ike_sa_manager_t");
private_ike_sa_manager_t *this = allocator_alloc_thing(private_ike_sa_manager_t, "private_ike_sa_manager_t");
/* assign public functions */
this->public.destroy = (status_t(*)(ike_sa_manager_t*))destroy;
this->public.checkout_ike_sa = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t *sa_id, ike_sa_t **sa))checkout_ike_sa;
this->public.checkin_ike_sa = (status_t(*)(ike_sa_manager_t*, ike_sa_t *sa))checkin_ike_sa;
this->public.delete_ike_sa_by_id = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t *sa_id))delete_ike_sa_by_id;
this->public.delete_ike_sa_by_sa = (status_t(*)(ike_sa_manager_t*, ike_sa_t *ike_sa))delete_ike_sa_by_sa;
/* initialize private data */
this->get_next_spi = get_next_spi;
this->get_entry_by_sa = get_ike_sa_entry_by_sa;
this->get_entry_by_id = get_ike_sa_entry_by_id;
this->list = linked_list_create();
if (this->list == NULL)
{
pfree(this);
return NULL;
allocator_free(this);
return NULL;
}
pthread_mutex_init(&(this->mutex), NULL);
this->next_spi.low = 1;
this->next_spi.high = 0;
return (ike_sa_manager_t*)this;
}

View file

@ -1,8 +1,8 @@
/**
* @file job.c
*
*
* @brief Job-Class representing a job e.g. in job_queue
*
*
*/
/*
@ -24,15 +24,15 @@
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include "job.h"
/**
* @brief implements function destroy of job_t
*/
static status_t job_destroy(job_t *job)
{
pfree(job);
allocator_free(job);
return SUCCESS;
}
@ -41,12 +41,12 @@ static status_t job_destroy(job_t *job)
*/
job_t *job_create(job_type_t type, void *assigned_data)
{
job_t *this = alloc_thing(job_t, "job_t");
job_t *this = allocator_alloc_thing(job_t, "job_t");
this->destroy = job_destroy;
this->type = type;
this->assigned_data = assigned_data;
return this;
}

View file

@ -1,8 +1,8 @@
/**
* @file job_queue.c
*
*
* @brief Job-Queue based on linked_list_t
*
*
*/
/*
@ -25,20 +25,20 @@
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include "job_queue.h"
#include "linked_list.h"
/**
* @brief Private Variables and Functions of job_queue class
*
*
*/
typedef struct private_job_queue_s private_job_queue_t;
struct private_job_queue_s {
job_queue_t public;
/**
* The jobs are stored in a linked list
*/
@ -47,12 +47,12 @@ struct private_job_queue_s {
* access to linked_list is locked through this mutex
*/
pthread_mutex_t mutex;
/**
* If the queue is empty a thread has to wait
* This condvar is used to wake up such a thread
*/
pthread_cond_t condvar;
pthread_cond_t condvar;
};
@ -82,9 +82,9 @@ static status_t get(private_job_queue_t *this, job_t **job)
/* add mutex unlock handler for cancellation, enable cancellation */
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
pthread_cond_wait( &(this->condvar), &(this->mutex));
/* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
@ -109,14 +109,14 @@ static status_t add(private_job_queue_t *this, job_t *job)
/**
* @brief implements function destroy of job_queue_t
*
*
*/
static status_t job_queue_destroy (private_job_queue_t *this)
{
{
int count;
this->list->get_count(this->list,&count);
while (count > 0)
while (count > 0)
{
job_t *job;
if (this->list->remove_first(this->list,(void *) &job) != SUCCESS)
@ -128,17 +128,17 @@ static status_t job_queue_destroy (private_job_queue_t *this)
this->list->get_count(this->list,&count);
}
this->list->destroy(this->list);
pthread_mutex_destroy(&(this->mutex));
pthread_cond_destroy(&(this->condvar));
pfree(this);
allocator_free(this);
return SUCCESS;
}
/*
*
*
* Documented in header
*/
job_queue_t *job_queue_create()
@ -148,22 +148,22 @@ job_queue_t *job_queue_create()
{
return NULL;
}
private_job_queue_t *this = alloc_thing(private_job_queue_t, "private_job_queue_t");
private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t, "private_job_queue_t");
if (this == NULL)
{
linked_list->destroy(linked_list);
return NULL;
}
this->public.get_count = (status_t(*)(job_queue_t*, int*))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->list = linked_list;
pthread_mutex_init(&(this->mutex), NULL);
pthread_cond_init(&(this->condvar), NULL);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file linked_list.c
*
*
* @brief Generic Double Linked List
*
*
*/
/*
@ -26,14 +26,14 @@
#include <pluto/defs.h>
#include "linked_list.h"
typedef struct linked_list_element_s linked_list_element_t;
/**
* @brief Element of the linked_list.
*
*
* This element holds a pointer to the value of the list item itself.
*/
struct linked_list_element_s{
@ -41,17 +41,17 @@ struct linked_list_element_s{
* value of a list item
*/
void *value;
/**
* @brief Destroys a linked_list_element object
*
*
* @param linked_list_element_t calling object
* @returns SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy) (linked_list_element_t *this);
/**
* previous list element
* previous list element
* NULL if first element in list
*/
linked_list_element_t *previous;
@ -71,7 +71,7 @@ static status_t linked_list_element_destroy(linked_list_element_t *this)
{
return FAILED;
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -79,33 +79,33 @@ static status_t linked_list_element_destroy(linked_list_element_t *this)
* @brief Creates an empty linked list object
*
* @param[in] value value of item to be set
*
*
* @warning only the pointer to the value is stored
*
*
* @return linked_list_element object
*/
linked_list_element_t *linked_list_element_create(void *value)
{
linked_list_element_t *this = alloc_thing(linked_list_element_t, "linked_list_element_t");
linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t, "linked_list_element_t");
if (this == NULL)
{
return NULL;
}
this->destroy = linked_list_element_destroy;
this->previous=NULL;
this->next=NULL;
this->value = value;
return (this);
}
/**
* Private variables and functions of linked list
*
*
*/
typedef struct private_linked_list_s private_linked_list_t;
@ -114,12 +114,12 @@ struct private_linked_list_s{
* Public part of linked list
*/
linked_list_t public;
/**
* number of items in the list
*/
int count;
/**
* First element in list
* NULL if no elements in list
@ -135,7 +135,7 @@ struct private_linked_list_s{
/**
* Private variables and functions of linked list iterator
*
*
*/
typedef struct private_linked_list_iterator_s private_linked_list_iterator_t;
@ -144,12 +144,12 @@ struct private_linked_list_iterator_s{
* Public part of linked list iterator
*/
linked_list_iterator_t public;
/**
* associated linked list
*/
private_linked_list_t * list;
/**
* current element of the iterator
*/
@ -173,7 +173,7 @@ bool iterator_has_next(private_linked_list_iterator_t *this)
if (this->current == NULL)
{
this->current = (this->forward) ? this->list->first : this->list->last;
return TRUE;
return TRUE;
}
if (this->forward)
{
@ -182,15 +182,15 @@ bool iterator_has_next(private_linked_list_iterator_t *this)
return FALSE;
}
this->current = this->current->next;
return TRUE;
return TRUE;
}
/* backward */
/* backward */
if (this->current->previous == NULL)
{
return FALSE;
}
this->current = this->current->previous;
return TRUE;
return TRUE;
}
/**
@ -232,7 +232,7 @@ static status_t iterator_destroy(private_linked_list_iterator_t *this)
{
return FAILED;
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -252,48 +252,48 @@ static status_t get_count(private_linked_list_t *this, int *count)
static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
{
private_linked_list_iterator_t *this = alloc_thing(private_linked_list_iterator_t, "private_linked_list_iterator_t");
private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t, "private_linked_list_iterator_t");
if (this == NULL)
{
return FAILED;
}
this->public.has_next = (bool (*) (linked_list_iterator_t *this)) iterator_has_next;
this->public.current = (status_t (*) (linked_list_iterator_t *this, void **value)) iterator_current;
this->public.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
this->forward = forward;
this->current = NULL;
this->list = linked_list;
*iterator = &(this->public);
return (SUCCESS);
return (SUCCESS);
}
/**
* @brief implements function insert_first of linked_list_t
*/
static status_t insert_first(private_linked_list_t *this, void *item)
{
linked_list_element_t *element;
if (this == NULL)
{
return FAILED;
}
element =(linked_list_element_t *) linked_list_element_create(item);
if (element == NULL)
{
return FAILED;
}
if (this->count == 0)
{
/* first entry in list */
@ -316,7 +316,7 @@ static status_t insert_first(private_linked_list_t *this, void *item)
old_first_element->previous = element;
this->first = element;
}
this->count++;
return SUCCESS;
@ -326,7 +326,7 @@ static status_t insert_first(private_linked_list_t *this, void *item)
* @brief implements function remove_first of linked_list_t
*/
static status_t remove_first(private_linked_list_t *this, void **item)
{
{
if (this == NULL)
{
return FAILED;
@ -336,14 +336,14 @@ static status_t remove_first(private_linked_list_t *this, void **item)
{
return FAILED;
}
if (this->first == NULL)
{
return FAILED;
}
linked_list_element_t *element = this->first;
if (element->next != NULL)
{
element->next->previous = NULL;
@ -353,7 +353,7 @@ static status_t remove_first(private_linked_list_t *this, void **item)
*item = element->value;
this->count--;
return (element->destroy(element));
}
@ -361,7 +361,7 @@ static status_t remove_first(private_linked_list_t *this, void **item)
* @brief implements function get_first of linked_list_t
*/
static status_t get_first(private_linked_list_t *this, void **item)
{
{
if (this == NULL)
{
return FAILED;
@ -371,12 +371,12 @@ static status_t get_first(private_linked_list_t *this, void **item)
{
return FAILED;
}
if (this->first == NULL)
{
return FAILED;
}
*item = this->first->value;
return SUCCESS;
@ -393,12 +393,12 @@ static status_t 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 FAILED;
}
if (this->count == 0)
{
/* first entry in list */
@ -420,9 +420,9 @@ static status_t insert_last(private_linked_list_t *this, void *item)
old_last_element->next = element;
this->last = element;
}
this->count++;
return SUCCESS;
}
@ -430,7 +430,7 @@ static status_t insert_last(private_linked_list_t *this, void *item)
* @brief implements function remove_last of linked_list_t
*/
static status_t remove_last(private_linked_list_t *this, void **item)
{
{
if (this == NULL)
{
return FAILED;
@ -440,14 +440,14 @@ static status_t remove_last(private_linked_list_t *this, void **item)
{
return FAILED;
}
if (this->last == NULL)
{
return FAILED;
}
linked_list_element_t *element = this->last;
if (element->previous != NULL)
{
element->previous->next = NULL;
@ -457,7 +457,7 @@ static status_t remove_last(private_linked_list_t *this, void **item)
*item = element->value;
this->count--;
return (element->destroy(element));
}
@ -470,17 +470,17 @@ static status_t get_last(private_linked_list_t *this, void **item)
{
return FAILED;
}
if (this->count == 0)
{
return FAILED;
}
if (this->last == NULL)
{
return FAILED;
}
*item = this->last->value;
return SUCCESS;
@ -495,7 +495,7 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
{
return FAILED;
}
if (this->count == 0)
{
return FAILED;
@ -507,12 +507,12 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
if (element == NULL)
{
return FAILED;
}
if (iterator->current->previous == NULL)
{
if (this->first != iterator->current)
@ -520,7 +520,7 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
element->destroy(element);
return FAILED;
}
iterator->current->previous = element;
element->next = iterator->current;
this->first = element;
@ -532,7 +532,7 @@ static status_t insert_before(private_linked_list_t *this, private_linked_list_i
iterator->current->previous = element;
element->next = iterator->current;
}
this->count++;
return SUCCESS;
@ -547,7 +547,7 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
{
return FAILED;
}
if (this->count == 0)
{
return FAILED;
@ -559,12 +559,12 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
if (element == NULL)
{
return FAILED;
}
if (iterator->current->next == NULL)
{
if (this->last != iterator->current)
@ -572,7 +572,7 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
element->destroy(element);
return FAILED;
}
iterator->current->next = element;
element->previous = iterator->current;
this->last = element;
@ -584,7 +584,7 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
iterator->current->next = element;
element->previous = iterator->current;
}
this->count++;
return SUCCESS;
}
@ -595,12 +595,12 @@ static status_t insert_after(private_linked_list_t *this, private_linked_list_it
static status_t linked_list_remove(private_linked_list_t *this, private_linked_list_iterator_t * iterator)
{
linked_list_element_t *new_current;
if ((this == NULL) || (iterator == NULL) || (iterator->current == NULL))
{
return FAILED;
}
if (this->count == 0)
{
return FAILED;
@ -618,13 +618,13 @@ static status_t linked_list_remove(private_linked_list_t *this, private_linked_l
{
new_current = NULL;
}
/* now delete the entry :-) */
if (iterator->current->previous == NULL)
{
{
if (iterator->current->next == NULL)
{
this->first = NULL;
this->first = NULL;
this->last = NULL;
}
else
@ -643,7 +643,7 @@ static status_t linked_list_remove(private_linked_list_t *this, private_linked_l
iterator->current->previous->next = iterator->current->next;
iterator->current->next->previous = iterator->current->previous;
}
this->count--;
iterator->current->destroy(iterator->current);
/* set the new iterator position */
@ -660,7 +660,7 @@ static status_t linked_list_destroy(private_linked_list_t *this)
{
return FAILED;
}
/* Remove all list items before destroying list */
while (this->count > 0)
{
@ -669,21 +669,21 @@ static status_t linked_list_destroy(private_linked_list_t *this)
* if list is not empty when deleting */
if (this->public.remove_first(&(this->public),&value) != SUCCESS)
{
pfree(this);
allocator_free(this);
return FAILED;
}
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
/*
* Described in header
*/
linked_list_t *linked_list_create()
linked_list_t *linked_list_create()
{
private_linked_list_t *this = alloc_thing(private_linked_list_t, "private_linked_list_t");
private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t, "private_linked_list_t");
this->public.get_count = (status_t (*) (linked_list_t *linked_list, int *count)) get_count;
this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
@ -696,10 +696,10 @@ linked_list_t *linked_list_create()
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->count = 0;
this->first = NULL;
this->last = NULL;
return (&(this->public));
}

View file

@ -1,8 +1,8 @@
/**
* @file message.c
*
*
* @brief Class message_t. Object of this type represents an IKEv2-Message
*
*
*/
/*
@ -32,15 +32,15 @@
* Private data of an message_t object
*/
typedef struct private_message_s private_message_t;
struct private_message_s {
struct private_message_s {
/**
* Public part of a message_t object
*/
message_t public;
/* Private values */
};
@ -54,7 +54,7 @@ static status_t destroy (private_message_t *this)
{
return FAILED;
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -63,15 +63,15 @@ static status_t destroy (private_message_t *this)
*/
message_t * message_create()
{
private_message_t *this = alloc_thing(private_message_t, "private_message_t");
private_message_t *this = allocator_alloc_thing(private_message_t, "private_message_t");
if (this == NULL)
{
return NULL;
}
/* Public functions */
this->public.destroy = (status_t(*)(message_t*))destroy;
return (&this->public);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file packet.h
*
*
* @brief UDP-Packet, contains data, sender and receiver
*
*
*/
/*
@ -27,9 +27,9 @@ static status_t destroy(packet_t *this)
{
if (this->data.ptr != NULL)
{
pfree(this->data.ptr);
allocator_free(this->data.ptr);
}
pfree(this);
allocator_free(this);
return SUCCESS;
}
@ -68,12 +68,12 @@ status_t set_source(packet_t *this, char *address, u_int16_t port)
packet_t *packet_create(int family)
{
packet_t *this = alloc_thing(packet_t, "packet_t");
packet_t *this = allocator_alloc_thing(packet_t, "packet_t");
this->destroy = destroy;
this->set_destination = set_destination;
this->set_source = set_source;
this->family = family;
switch (family)
{
@ -81,11 +81,11 @@ packet_t *packet_create(int family)
this->sockaddr_len = sizeof(struct sockaddr_in);
break;
default: /* not supported */
pfree(this);
return NULL;
allocator_free(this);
return NULL;
}
this->data.len = 0;
this->data.ptr = NULL;
this->data.ptr = NULL;
return this;
}

View file

@ -1,8 +1,8 @@
/**
* @file receiver.c
*
*
* @brief Implements the Receiver Thread encapsulated in the receiver_t-object
*
*
*/
/*
@ -19,7 +19,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <pthread.h>
#include <freeswan.h>
@ -37,13 +37,13 @@
* Private data of a receiver object
*/
typedef struct private_receiver_s private_receiver_t;
struct private_receiver_s {
struct private_receiver_s {
/**
* Public part of a receiver object
*/
receiver_t public;
/**
* Assigned thread to the receiver_t-object
*/
@ -53,7 +53,7 @@ struct private_receiver_s {
/**
* Thread function started at creation of the receiver object
*
*
* @param this assigned receiver object
* @return SUCCESS if thread_function ended successfully, FAILED otherwise
*/
@ -63,7 +63,7 @@ static void receiver_thread_function(private_receiver_t * this)
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
packet_t * current_packet;
job_t * current_job;
while (1)
{
while (global_socket->receive(global_socket,&current_packet) == SUCCESS)
@ -78,15 +78,15 @@ static void receiver_thread_function(private_receiver_t * this)
if ( global_job_queue->add(global_job_queue,current_job) != SUCCESS)
{
/* Packet could not be sent */
/* TODO LOG it */
/* TODO LOG it */
}
}
/* NOT GOOD !!!!!! */
/* TODO LOG it */
/* TODO LOG it */
}
}
/**
@ -95,25 +95,25 @@ static void receiver_thread_function(private_receiver_t * this)
static status_t destroy(private_receiver_t *this)
{
pthread_cancel(this->assigned_thread);
pthread_join(this->assigned_thread, NULL);
pfree(this);
allocator_free(this);
return SUCCESS;
}
receiver_t * receiver_create()
{
private_receiver_t *this = alloc_thing(private_receiver_t,"private_receiver_t");
private_receiver_t *this = allocator_alloc_thing(private_receiver_t,"private_receiver_t");
this->public.destroy = (status_t(*)(receiver_t*)) destroy;
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))receiver_thread_function, this) != 0)
{
/* thread could not be created */
pfree(this);
allocator_free(this);
return NULL;
}
return &(this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file scheduler.c
*
*
* @brief implements the scheduler, looks for jobs in event-queue
*
*
*/
/*
@ -19,28 +19,28 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <pthread.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include "scheduler.h"
#include "job_queue.h"
#include "globals.h"
/**
* Private data of a scheduler object
*/
typedef struct private_scheduler_s private_scheduler_t;
struct private_scheduler_s {
struct private_scheduler_s {
/**
* Public part of a scheduler object
*/
scheduler_t public;
/**
* Assigned thread to the scheduler_t-object
*/
@ -50,7 +50,7 @@ struct private_scheduler_s {
/**
* Thread function started at creation of the scheduler object
*
*
* @param this assigned scheduler object
* @return SUCCESS if thread_function ended successfully, FAILED otherwise
*/
@ -59,7 +59,7 @@ static void scheduler_thread_function(private_scheduler_t * this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
job_t *current_job;
for (;;)
{
/* get a job, this block until one is available */
@ -75,25 +75,25 @@ static void scheduler_thread_function(private_scheduler_t * this)
static status_t destroy(private_scheduler_t *this)
{
pthread_cancel(this->assigned_thread);
pthread_join(this->assigned_thread, NULL);
pfree(this);
allocator_free(this);
return SUCCESS;
}
scheduler_t * scheduler_create()
{
private_scheduler_t *this = alloc_thing(private_scheduler_t,"private_scheduler_t");
private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t,"private_scheduler_t");
this->public.destroy = (status_t(*)(scheduler_t*)) destroy;
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))scheduler_thread_function, this) != 0)
{
/* thread could not be created */
pfree(this);
allocator_free(this);
return NULL;
}
return &(this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file send_queue.c
*
*
* @brief Send-Queue based on linked_list_t
*
*
*/
/*
@ -19,43 +19,43 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <pthread.h>
#include "send_queue.h"
#include "linked_list.h"
/**
* @brief Private Variables and Functions of send_queue class
*
*
*/
typedef struct private_send_queue_s private_send_queue_t;
struct private_send_queue_s {
/**
* Public part of the send_queue_t object
*/
send_queue_t public;
/**
* The packets are stored in a linked list
*/
linked_list_t *list;
/**
* access to linked_list is locked through this mutex
*/
pthread_mutex_t mutex;
/**
* If the queue is empty a thread has to wait
* This condvar is used to wake up such a thread
*/
pthread_cond_t condvar;
pthread_cond_t condvar;
};
/**
* @brief implements function get_count of send_queue_t
*/
@ -66,7 +66,7 @@ static status_t get_count(private_send_queue_t *this, int *count)
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
/**
* @brief implements function get of send_queue_t
*/
@ -83,7 +83,7 @@ static status_t get(private_send_queue_t *this, packet_t **packet)
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
pthread_cond_wait( &(this->condvar), &(this->mutex));
/* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
@ -93,7 +93,7 @@ static status_t get(private_send_queue_t *this, packet_t **packet)
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
/**
* @brief implements function add of send_queue_t
*/
@ -105,18 +105,18 @@ static status_t add(private_send_queue_t *this, packet_t *packet)
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
/**
* @brief implements function destroy of send_queue_t
*
*
*/
static status_t destroy (private_send_queue_t *this)
{
int count;
this->list->get_count(this->list,&count);
/* destroy all packets in list before destroying list */
while (count > 0)
while (count > 0)
{
packet_t *packet;
if (this->list->remove_first(this->list,(void *) &packet) != SUCCESS)
@ -128,17 +128,17 @@ static status_t destroy (private_send_queue_t *this)
this->list->get_count(this->list,&count);
}
this->list->destroy(this->list);
pthread_mutex_destroy(&(this->mutex));
pthread_cond_destroy(&(this->condvar));
pfree(this);
allocator_free(this);
return SUCCESS;
}
/*
*
*
* Documented in header
*/
send_queue_t *send_queue_create()
@ -148,22 +148,22 @@ send_queue_t *send_queue_create()
{
return NULL;
}
private_send_queue_t *this = alloc_thing(private_send_queue_t, "private_send_queue_t");
private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t, "private_send_queue_t");
if (this == NULL)
{
linked_list->destroy(linked_list);
return NULL;
}
this->public.get_count = (status_t(*)(send_queue_t*, int*)) 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->list = linked_list;
pthread_mutex_init(&(this->mutex), NULL);
pthread_cond_init(&(this->condvar), NULL);
return (&this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file sender.c
*
*
* @brief Implements the Sender Thread encapsulated in the sender_t-object
*
*
*/
/*
@ -19,30 +19,30 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <pthread.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include "sender.h"
#include "socket.h"
#include "packet.h"
#include "send_queue.h"
#include "globals.h"
/**
* Private data of a sender object
*/
typedef struct private_sender_s private_sender_t;
struct private_sender_s {
struct private_sender_s {
/**
* Public part of a sender object
*/
sender_t public;
/**
* Assigned thread to the sender_t-object
*/
@ -52,7 +52,7 @@ struct private_sender_s {
/**
* Thread function started at creation of the sender object
*
*
* @param this assigned sender object
* @return SUCCESS if thread_function ended successfully, FAILED otherwise
*/
@ -61,28 +61,28 @@ static void sender_thread_function(private_sender_t * this)
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
packet_t * current_packet;
while (1)
{
while (global_send_queue->get(global_send_queue,&current_packet) == SUCCESS)
{
if ( global_socket->send(global_socket,current_packet) == SUCCESS)
{
current_packet->destroy(current_packet);
current_packet->destroy(current_packet);
}
else
{
/* Packet could not be sent */
/* TODO LOG it */
/* TODO LOG it */
}
}
/* NOT GOOD !!!!!! */
/* TODO LOG it */
/* TODO LOG it */
}
}
/**
@ -91,25 +91,25 @@ static void sender_thread_function(private_sender_t * this)
static status_t destroy(private_sender_t *this)
{
pthread_cancel(this->assigned_thread);
pthread_join(this->assigned_thread, NULL);
pfree(this);
allocator_free(this);
return SUCCESS;
}
sender_t * sender_create()
{
private_sender_t *this = alloc_thing(private_sender_t,"private_sender_t");
private_sender_t *this = allocator_alloc_thing(private_sender_t,"private_sender_t");
this->public.destroy = (status_t(*)(sender_t*)) destroy;
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))sender_thread_function, this) != 0)
{
/* thread could not be created */
pfree(this);
allocator_free(this);
return NULL;
}
return &(this->public);
}

View file

@ -1,10 +1,10 @@
/**
* @file socket.c
*
*
* @brief management of sockets
*
*
* receiver reads from here, sender writes to here
*
*
*/
/*
@ -42,7 +42,7 @@ struct private_socket_s{
* public functions
*/
socket_t public;
/**
* currently we only have one socket, maybe more in the future ?
*/
@ -57,98 +57,98 @@ status_t receiver(private_socket_t *this, packet_t **packet)
char buffer[MAX_PACKET];
int oldstate;
packet_t *pkt = packet_create(AF_INET);
/* add packet destroy handler for cancellation, enable cancellation */
pthread_cleanup_push((void(*)(void*))pkt->destroy, (void*)pkt);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
/* do the read */
pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0,
pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0,
&(pkt->source), &(pkt->sockaddr_len));
/* reset cancellation, remove packet destroy handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
/* TODO: get senders destination address, using
/* TODO: get senders destination address, using
* IP_PKTINFO and recvmsg */
if (pkt->data.len < 0)
{
pkt->destroy(pkt);
/* TODO: log detailed error */
return FAILED;
}
/* fill in packet */
pkt->data.ptr = alloc_bytes(pkt->data.len, "data in packet_t");
pkt->data.ptr = allocator_alloc(pkt->data.len, "data in packet_t");
memcpy(pkt->data.ptr, buffer, pkt->data.len);
/* return packet */
*packet = pkt;
return SUCCESS;
return SUCCESS;
}
/**
* implementation of socket_t.send
*/
status_t sender(private_socket_t *this, packet_t *packet)
status_t sender(private_socket_t *this, packet_t *packet)
{
ssize_t bytes_sent;
/* send data */
bytes_sent = sendto(this->socket_fd, packet->data.ptr, packet->data.len,
bytes_sent = sendto(this->socket_fd, packet->data.ptr, packet->data.len,
0, &(packet->destination), packet->sockaddr_len);
if (bytes_sent != packet->data.len)
if (bytes_sent != packet->data.len)
{
/* TODO: log detailed error */
return FAILED;
}
return SUCCESS;
}
/**
* implementation of socket_t.destroy
*/
status_t destroy(private_socket_t *this)
{
close(this->socket_fd);
pfree(this);
allocator_free(this);
return SUCCESS;
}
socket_t *socket_create(u_int16_t port)
{
private_socket_t *this = alloc_thing(private_socket_t, "private_socket_t");
private_socket_t *this = allocator_alloc_thing(private_socket_t, "private_socket_t");
struct sockaddr_in addr;
/* public functions */
this->public.send = (status_t(*)(socket_t*, packet_t*))sender;
this->public.receive = (status_t(*)(socket_t*, packet_t**))receiver;
this->public.destroy = (status_t(*)(socket_t*))destroy;
/* create default ipv4 socket */
this->socket_fd = socket(PF_INET, SOCK_DGRAM, 0);
if (this->socket_fd < 0) {
pfree(this);
allocator_free(this);
/* TODO: log detailed error */
return NULL;
}
}
/* bind socket to all interfaces */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(port);
if (bind(this->socket_fd,(struct sockaddr*)&addr, sizeof(addr)) < 0) {
pfree(this);
allocator_free(this);
/* TODO: log detailed error */
return NULL;
}
return (socket_t*)this;
}

View file

@ -1,8 +1,8 @@
/**
* @file tester.c
*
*
* @brief Test module for automatic testing
*
*
*/
/*
@ -28,7 +28,7 @@
#include <string.h>
#include <pthread.h>
#include <sys/time.h>
#include "tester.h"
#include "linked_list.h"
#include "thread_pool.h"
@ -36,18 +36,18 @@
/**
* @brief Private Variables and Functions of tester class
*
*
*/
typedef struct private_tester_s private_tester_t;
struct private_tester_s {
tester_t public;
/* Private functions */
void (*run_test) (tester_t *tester, void (*test_function) (tester_t * tester), char * test_name);
/* Private values */
FILE* output;
int tests_count;
@ -56,11 +56,11 @@ struct private_tester_s {
bool display_succeeded_asserts;
pthread_mutex_t mutex;
};
/*
* Implementation of function perform_tests
*/
static status_t perform_tests(tester_t *tester,test_t **tests)
static status_t perform_tests(tester_t *tester,test_t **tests)
{
private_tester_t *this =(private_tester_t*) tester;
int current_test = 0;
@ -71,7 +71,7 @@ static status_t perform_tests(tester_t *tester,test_t **tests)
this->run_test(tester,tests[current_test]->test_function,tests[current_test]->test_name);
current_test++;
}
fprintf(this->output,"End testing. %d of %d tests succeeded\n",this->tests_count - this->failed_tests_count,this->tests_count);
return SUCCESS;
@ -80,7 +80,7 @@ static status_t perform_tests(tester_t *tester,test_t **tests)
/*
* Implementation of function perform_test
*/
static status_t perform_test(tester_t *tester, test_t *test)
static status_t perform_test(tester_t *tester, test_t *test)
{
test_t *tests[] = {test, NULL};
return (perform_tests(tester,tests));
@ -88,20 +88,20 @@ static status_t perform_test(tester_t *tester, test_t *test)
/**
* Returns the difference of to timeval structs in microseconds
*
*
* @param end_time end time
* @param start_time start time
*
*
* @warning this function is also defined in the event queue
* in later improvements, this function can be added to a general
* class type!
*
*
* @return difference in microseconds
*/
static long time_difference(struct timeval *end_time, struct timeval *start_time)
{
long seconds, microseconds;
seconds = (end_time->tv_sec - start_time->tv_sec);
microseconds = (end_time->tv_usec - start_time->tv_usec);
return ((seconds * 1000000) + microseconds);
@ -109,7 +109,7 @@ static long time_difference(struct timeval *end_time, struct timeval *start_time
/**
* Implementation of function run_test
* Implementation of function run_test
*/
static void run_test(tester_t *tester, void (*test_function) (tester_t * tester), char * test_name)
{
@ -123,7 +123,7 @@ static void run_test(tester_t *tester, void (*test_function) (tester_t * tester)
test_function(tester);
gettimeofday(&end_time,NULL);
timediff = time_difference(&end_time, &start_time);
fprintf(this->output,"End Test '%s' in %ld microseconds\n", test_name,timediff);
if (this->failed_asserts_count > 0)
{
@ -132,27 +132,27 @@ static void run_test(tester_t *tester, void (*test_function) (tester_t * tester)
}
/**
* Implementation of function assert_true
* Implementation of function assert_true
*/
static void assert_true(tester_t *tester, bool to_be_true,char * assert_name)
{
private_tester_t *this = (private_tester_t *) tester;
if (assert_name == NULL)
{
assert_name = "unknown";
}
pthread_mutex_lock(&(this->mutex));
if (!to_be_true)
{
this->failed_asserts_count++;
fprintf(this->output," Assert '%s' failed!\n", assert_name);
fprintf(this->output," Assert '%s' failed!\n", assert_name);
}else
{
if (this->display_succeeded_asserts)
{
fprintf(this->output," Assert '%s' succeeded\n", assert_name);
fprintf(this->output," Assert '%s' succeeded\n", assert_name);
}
}
pthread_mutex_unlock(&(this->mutex));
@ -169,31 +169,31 @@ static void assert_false(tester_t *tester, bool to_be_false,char * assert_name)
/**
* Implements the destroy function
*/
static status_t destroy(tester_t *tester)
static status_t destroy(tester_t *tester)
{
private_tester_t *this = (private_tester_t*) tester;
pthread_mutex_destroy(&(this->mutex));
pfree(this);
allocator_free(this);
return SUCCESS;
}
tester_t *tester_create(FILE *output, bool display_succeeded_asserts)
tester_t *tester_create(FILE *output, bool display_succeeded_asserts)
{
private_tester_t *this = alloc_thing(private_tester_t, "private_tester_t");
private_tester_t *this = allocator_alloc_thing(private_tester_t, "private_tester_t");
this->public.destroy = destroy;
this->public.perform_tests = perform_tests;
this->public.perform_test = perform_test;
this->public.assert_true = assert_true;
this->public.assert_false = assert_false;
this->run_test = run_test;
this->display_succeeded_asserts = display_succeeded_asserts;
this->display_succeeded_asserts = display_succeeded_asserts;
this->failed_tests_count = 0;
this->tests_count = 0;
this->output = output;
pthread_mutex_init(&(this->mutex),NULL);
return &(this->public);
}

View file

@ -1,8 +1,8 @@
/**
* @file event_queue_test.h
*
*
* @brief Tests to test the Event-Queue type event_queue_t
*
*
*/
/*
@ -19,10 +19,10 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <stdlib.h>
#include <pthread.h>
#include "event_queue_test.h"
#include "../tester.h"
#include "../event_queue.h"
@ -43,23 +43,23 @@
/**
* @brief Informations for the involved test-thread used in this test
*
*
*/
typedef struct event_queue_test_s event_queue_test_t;
struct event_queue_test_s{
tester_t *tester;
event_queue_t *event_queue;
/**
* number of different event times to be inserted in the event-queue by each thread
*/
int insert_times_count;
int insert_times_count;
/**
* number of event to insert at one time
*/
int entries_per_time;
int entries_per_time;
};
@ -70,21 +70,21 @@ static void event_queue_insert_thread(event_queue_test_t * testinfos)
timeval_t time;
job_t * job;
int i,j;
gettimeofday(&current_time,NULL);
for (i = 0; i < testinfos->insert_times_count;i++)
{
for (j = 0; j < testinfos->entries_per_time;j++)
{
int *value = alloc_thing(int, "value");
int *value = allocator_alloc_thing(int, "value");
*value = i;
job = job_create(INCOMING_PACKET,value);
time.tv_usec = 0;
time.tv_sec = current_time.tv_sec + i;
tester->assert_true(tester,(testinfos->event_queue->add_absolute(testinfos->event_queue,job,time) == SUCCESS), "add call check");
}
}
}
}
@ -96,22 +96,22 @@ void test_event_queue(tester_t *tester)
int i,j, number_of_total_events;
int count;
timeval_t current_time, start_time;
testinfos.tester = tester;
testinfos.event_queue = event_queue;
testinfos.insert_times_count = EVENT_QUEUE_TIMES;
testinfos.entries_per_time = EVENT_QUEUE_ENTRY_PER_TIME;
number_of_total_events = EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_TIMES * EVENT_QUEUE_INSERT_THREADS;
gettimeofday(&start_time,NULL);
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
pthread_create( &threads[i], NULL,(void*(*)(void*)) &event_queue_insert_thread, (void*) &testinfos);
}
/* wait for all threads */
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
@ -120,22 +120,22 @@ void test_event_queue(tester_t *tester)
}
tester->assert_true(tester,(event_queue->get_count(event_queue,&count) == SUCCESS), "get_count call check");
tester->assert_true(tester,(count == number_of_total_events), "event count check");
tester->assert_true(tester,(count == number_of_total_events), "event count check");
for (i = 0; i < EVENT_QUEUE_TIMES;i++)
{
for (j = 0; j < (EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_INSERT_THREADS);j++)
{
job_t *job;
tester->assert_true(tester,(event_queue->get(event_queue,&job) == SUCCESS), "get call check");
tester->assert_true(tester,(event_queue->get(event_queue,&job) == SUCCESS), "get call check");
gettimeofday(&current_time,NULL);
tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
pfree(job->assigned_data);
tester->assert_true(tester,(job->destroy(job) == SUCCESS), "job destroy call check");
tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
allocator_free(job->assigned_data);
tester->assert_true(tester,(job->destroy(job) == SUCCESS), "job destroy call check");
}
}
tester->assert_true(tester,(event_queue->destroy(event_queue) == SUCCESS), "destroy call check");
}

View file

@ -1,8 +1,8 @@
/**
* @file job_queue_test.c
*
*
* @brief Tests to test the Job-Queue type job_queue_t
*
*
*/
/*
@ -20,50 +20,50 @@
* for more details.
*/
#include <stdlib.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include <pthread.h>
#include <unistd.h>
#include "job_queue_test.h"
#include "../tester.h"
#include "../job_queue.h"
typedef struct job_queue_test_s job_queue_test_t;
/**
* @brief Informations for the involved test-thread used in this test
*
*
*/
struct job_queue_test_s{
tester_t *tester;
job_queue_t *job_queue;
/**
* number of items to be inserted in the job-queue
* number of items to be inserted in the job-queue
*/
int insert_item_count;
int insert_item_count;
/**
* number of items to be removed by each
* receiver thread from the job-queue
* number of items to be removed by each
* receiver thread from the job-queue
*/
int remove_item_count;
int remove_item_count;
};
/**
* @brief sender thread used in the the job_queue test function
*
*
* @param testinfo informations for the specific thread.
*/
static void test_job_queue_sender(job_queue_test_t * testinfo)
{
int i;
int i;
for (i = 0; i < testinfo->insert_item_count; i++)
{
int *value = alloc_thing(int,"int in test_job_queue_sender");
int *value = allocator_alloc_thing(int,"int in test_job_queue_sender");
*value = i;
job_t *job = job_create(INCOMING_PACKET,value);
testinfo->job_queue->add(testinfo->job_queue,job);
@ -72,7 +72,7 @@ static void test_job_queue_sender(job_queue_test_t * testinfo)
/**
* @brief receiver thread used in the the job_queue test function
*
*
* @param testinfo informations for the specific thread.
*/
static void test_job_queue_receiver(job_queue_test_t * testinfo)
@ -82,8 +82,8 @@ static void test_job_queue_receiver(job_queue_test_t * testinfo)
{
job_t *job;
testinfo->tester->assert_true(testinfo->tester,(testinfo->job_queue->get(testinfo->job_queue,&job) == SUCCESS), "get job call check");
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
pfree(job->assigned_data);
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
allocator_free(job->assigned_data);
testinfo->tester->assert_true(testinfo->tester,(job->destroy(job) == SUCCESS), "job destroy call check");
}
}
@ -105,11 +105,11 @@ void test_job_queue(tester_t *tester)
test_infos.job_queue = job_queue;
test_infos.insert_item_count = 10000;
test_infos.remove_item_count = 50000;
desired_value = test_infos.insert_item_count * sender_count -
desired_value = test_infos.insert_item_count * sender_count -
test_infos.remove_item_count * receiver_count;
for (i = 0; i < receiver_count;i++)
{
pthread_create( &receiver_threads[i], NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
@ -118,8 +118,8 @@ void test_job_queue(tester_t *tester)
{
pthread_create( &sender_threads[i], NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
}
/* Wait for all threads */
for (i = 0; i < sender_count;i++)
{
@ -129,10 +129,10 @@ void test_job_queue(tester_t *tester)
{
pthread_join(receiver_threads[i], NULL);
}
/* the job-queue has to have disered_value count entries! */
tester->assert_true(tester,(job_queue->get_count(job_queue,&value) == SUCCESS), "get count call check");
tester->assert_true(tester,(value == desired_value), "get count value check");
tester->assert_true(tester,(value == desired_value), "get count value check");
tester->assert_true(tester,(job_queue->destroy(job_queue) == SUCCESS), "destroy call check");
}

View file

@ -1,8 +1,8 @@
/**
* @file receiver_test.c
*
*
* @brief Tests to test the Receiver (type receiver_t)
*
*
*/
/*
@ -19,7 +19,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <string.h>
#include <unistd.h>
@ -45,7 +45,7 @@
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
void test_receiver(tester_t *tester)
{
int i;
@ -54,21 +54,21 @@ void test_receiver(tester_t *tester)
job_t *job;
packet_t *received_packet;
receiver = receiver_create();
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
packet->data.ptr = alloc_thing(int, "packet data");
packet->data.ptr = allocator_alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_socket->send(global_socket,packet);
packet->destroy(packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
global_job_queue->get(global_job_queue,&job);
global_job_queue->get(global_job_queue,&job);
tester->assert_true(tester, (job->type == INCOMING_PACKET), "job type check");
received_packet = (packet_t *) job->assigned_data;
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
@ -76,7 +76,7 @@ void test_receiver(tester_t *tester)
received_packet->destroy(received_packet);
job->destroy(job);
}
}
tester->assert_true(tester, (receiver->destroy(receiver) == SUCCESS), "destroy call check");
}

View file

@ -1,8 +1,8 @@
/**
* @file sender_test.h
*
*
* @brief Tests to test the Sender (type sender_t)
*
*
*/
/*
@ -44,7 +44,7 @@
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
void test_sender(tester_t *tester)
{
int i;
@ -52,24 +52,24 @@ void test_sender(tester_t *tester)
packet_t *packet;
packet_t *received_packet;
sender = sender_create();
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
packet->data.ptr = alloc_thing(int, "packet data");
packet->data.ptr = allocator_alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_send_queue->add(global_send_queue,packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
global_socket->receive(global_socket,&received_packet);
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
received_packet->destroy(received_packet);
}
}
tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
}

View file

@ -1,8 +1,8 @@
/**
* @file thread_pool_test.c
*
*
* @brief Tests to test the Socket (type socket_t)
*
*
*/
/*
@ -31,31 +31,31 @@
* Description in header file
*/
void test_socket(tester_t *tester)
{
{
int packet_count = 5;
int current;
socket_t *skt = socket_create(4500);
packet_t *pkt = packet_create(AF_INET);
char *test_string = "Testing functionality of socket_t";
pkt->data.ptr = alloc_bytes(strlen(test_string) + 1,"test_string");
pkt->data.ptr = allocator_alloc(strlen(test_string) + 1,"test_string");
memcpy(pkt->data.ptr,test_string,strlen(test_string) + 1);
pkt->data.len = strlen(test_string) + 1;
/* send to previously bound socket */
pkt->set_destination(pkt, "127.0.0.1", 4500);
/* send packet_count packets */
for (current = 0; current < packet_count; current++)
{
if (skt->send(skt, pkt) == FAILED)
if (skt->send(skt, pkt) == FAILED)
{
tester->assert_true(tester, 0, "packet send");
}
}
pkt->destroy(pkt);
/* receive packet_count packets */
for (current = 0; current < packet_count; current++)
{
@ -63,7 +63,7 @@ void test_socket(tester_t *tester)
tester->assert_false(tester, strcmp(test_string, pkt->data.ptr), "packet exchange");
pkt->destroy(pkt);
}
tester->assert_true(tester, (skt->destroy(skt) == SUCCESS), "socket destroy call check");
}