diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-16 14:43:13 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-16 14:43:13 +0000 |
commit | df917df71c69cd4764c84c3888e25fd2f385fdcc (patch) | |
tree | 6c465a7e2a98f02f0a8da2a0cf3b859d77540aca /Source/charon | |
parent | 2b3183835a8ef52927be7e421dc5f87b8cbe9df2 (diff) | |
download | strongswan-df917df71c69cd4764c84c3888e25fd2f385fdcc.tar.bz2 strongswan-df917df71c69cd4764c84c3888e25fd2f385fdcc.tar.xz |
- defined interface for each job and implemented incoming packet job and
initiate ike sa job
Diffstat (limited to 'Source/charon')
-rw-r--r-- | Source/charon/jobs/incoming_packet_job.c | 102 | ||||
-rw-r--r-- | Source/charon/jobs/incoming_packet_job.h | 74 | ||||
-rw-r--r-- | Source/charon/jobs/initiate_ike_sa_job.c | 110 | ||||
-rw-r--r-- | Source/charon/jobs/initiate_ike_sa_job.h | 71 | ||||
-rw-r--r-- | Source/charon/jobs/job.c | 33 | ||||
-rw-r--r-- | Source/charon/jobs/job.h | 42 |
6 files changed, 379 insertions, 53 deletions
diff --git a/Source/charon/jobs/incoming_packet_job.c b/Source/charon/jobs/incoming_packet_job.c new file mode 100644 index 000000000..93508b7fe --- /dev/null +++ b/Source/charon/jobs/incoming_packet_job.c @@ -0,0 +1,102 @@ +/** + * @file incoming_packet_job.h + * + * @brief Job of type INCOMING_PACKET + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + + +#include "incoming_packet_job.h" + +#include "../utils/allocator.h" + +/** + * Private data of an incoming_packet_job_t Object + * + */ +typedef struct private_incoming_packet_job_s private_incoming_packet_job_t; + +struct private_incoming_packet_job_s { + /** + * public incoming_packet_job_t interface + */ + incoming_packet_job_t public; + + /** + * Assigned packet + */ + packet_t *packet; +}; + + +/** + * Implements incoming_packet_job_t's get_type function. + * See #incoming_packet_job_t.get_type for description. + */ +static job_type_t get_type(private_incoming_packet_job_t *this) +{ + return INCOMING_PACKET; +} + +/** + * Implements incoming_packet_job_t's get_configuration_name function. + * See #incoming_packet_job_t.get_configuration_name for description. + */ +static status_t get_packet(private_incoming_packet_job_t *this,packet_t **packet) +{ + *packet = this->packet; + return SUCCESS; +} + + +/** + * Implements job_t's and incoming_packet_job_t's destroy function. + * See #job_t.destroy or #incoming_packet_job_t.destroy for description. + */ +static status_t destroy(job_t *job) +{ + private_incoming_packet_job_t *this = (private_incoming_packet_job_t *) job; + allocator_free(this); + return SUCCESS; +} + + +/* + * Described in header + */ +incoming_packet_job_t *incoming_packet_job_create(packet_t *packet) +{ + private_incoming_packet_job_t *this = allocator_alloc_thing(private_incoming_packet_job_t); + if ((this == NULL)) + { + return NULL; + } + + /* interface functions */ + this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type; + this->public.job_interface.destroy = destroy; + + /* public functions */ + this->public.get_packet = (status_t (*)(incoming_packet_job_t *,packet_t **)) get_packet; + this->public.destroy = (status_t (*)(incoming_packet_job_t *)) destroy; + + /* private variables */ + this->packet = packet; + + return &(this->public); +} diff --git a/Source/charon/jobs/incoming_packet_job.h b/Source/charon/jobs/incoming_packet_job.h new file mode 100644 index 000000000..a984c6011 --- /dev/null +++ b/Source/charon/jobs/incoming_packet_job.h @@ -0,0 +1,74 @@ +/** + * @file incoming_packet_job.h + * + * @brief Job of type INCOMING_PACKET + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef INCOMING_PACKET_JOB_H_ +#define INCOMING_PACKET_JOB_H_ + +#include "job.h" +#include "../types.h" +#include "../packet.h" + +/** + * Object representing an INCOMING_PACKET Job + * + */ +typedef struct incoming_packet_job_s incoming_packet_job_t; + +struct incoming_packet_job_s { + /** + * implements job_t interface + */ + job_t job_interface; + + /** + * @brief Returns the assigned packet_t object + * + * @warning Returned packet is not cloned and has to get destroyed by the caller + * + * @param this calling incoming_packet_job_t object + * @param[out] packet assigned packet will be written into this location + * @return SUCCESS + */ + status_t (*get_packet) (incoming_packet_job_t *this, packet_t **packet); + + /** + * @brief Destroys an incoming_packet_job_t object. + * + * @param this incoming_packet_job_t object to destroy + * @return + * SUCCESS in any case + */ + status_t (*destroy) (incoming_packet_job_t *this); +}; + +/** + * Creates a job of type INCOMING_PACKET + * + * @param[in] packet packet to assign with this job + * @return + * - incoming_packet_job_t if successfully + * - NULL if out of ressources + */ +incoming_packet_job_t *incoming_packet_job_create(packet_t *packet); + + +#endif /*INCOMING_PACKET_JOB_H_*/ diff --git a/Source/charon/jobs/initiate_ike_sa_job.c b/Source/charon/jobs/initiate_ike_sa_job.c new file mode 100644 index 000000000..c5498f441 --- /dev/null +++ b/Source/charon/jobs/initiate_ike_sa_job.c @@ -0,0 +1,110 @@ +/** + * @file initiate_ike_sa_job.c + * + * @brief Job of type INITIATE_IKE_SA + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + + +#include <stdlib.h> + +#include "initiate_ike_sa_job.h" + +#include "../utils/allocator.h" + +/** + * Private data of an initiate_ike_sa_job_t Object + * + */ +typedef struct private_initiate_ike_sa_job_s private_initiate_ike_sa_job_t; + +struct private_initiate_ike_sa_job_s { + /** + * public initiate_ike_sa_job_t interface + */ + initiate_ike_sa_job_t public; + + /** + * Name of the assigned configuration + */ + char *configuration_name; +}; + + +/** + * Implements initiate_ike_sa_job_t's get_type function. + * See #initiate_ike_sa_job_t.get_type for description. + */ +static job_type_t get_type(private_initiate_ike_sa_job_t *this) +{ + return INITIATE_IKE_SA; +} + +/** + * Implements initiate_ike_sa_job_t's get_configuration_name function. + * See #initiate_ike_sa_job_t.get_configuration_name for description. + */ +static char * get_configuration_name(private_initiate_ike_sa_job_t *this) +{ + return this->configuration_name; +} + + +/** + * Implements job_t's and initiate_ike_sa_job_t's destroy function. + * See #job_t.destroy or #initiate_ike_sa_job_t.destroy for description. + */ +static status_t destroy(job_t *job) +{ + private_initiate_ike_sa_job_t *this = (private_initiate_ike_sa_job_t *) job; + allocator_free(this->configuration_name); + allocator_free(this); + return SUCCESS; +} + + +/* + * Described in header + */ +initiate_ike_sa_job_t *initiate_ike_sa_job_create(char *configuration_name) +{ + private_initiate_ike_sa_job_t *this = allocator_alloc_thing(private_initiate_ike_sa_job_t); + if ((this == NULL) || (configuration_name == NULL)) + { + return NULL; + } + + /* interface functions */ + this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type; + this->public.job_interface.destroy = destroy; + + /* public functions */ + this->public.get_configuration_name = (char * (*)(initiate_ike_sa_job_t *)) get_configuration_name; + this->public.destroy = (status_t (*)(initiate_ike_sa_job_t *)) destroy; + + /* private variables */ + this->configuration_name = allocator_alloc(sizeof(configuration_name) + 1); + if (this->configuration_name == NULL) + { + allocator_free(this); + return NULL; + } + strcpy(this->configuration_name,configuration_name); + + return &(this->public); +} diff --git a/Source/charon/jobs/initiate_ike_sa_job.h b/Source/charon/jobs/initiate_ike_sa_job.h new file mode 100644 index 000000000..ce82d99a7 --- /dev/null +++ b/Source/charon/jobs/initiate_ike_sa_job.h @@ -0,0 +1,71 @@ +/** + * @file initiate_ike_sa_job.h + * + * @brief Job of type INITIATE_IKE_SA + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef INITIATE_IKE_SA_JOB_H_ +#define INITIATE_IKE_SA_JOB_H_ + +#include "../types.h" +#include "job.h" + +/** + * Object representing an INITIATE_IKE_SA Job + * + */ +typedef struct initiate_ike_sa_job_s initiate_ike_sa_job_t; + +struct initiate_ike_sa_job_s { + /** + * implements job_t interface + */ + job_t job_interface; + + /** + * @brief Returns the currently set configuration name for this job + * + * @warning Returned name is not copied. + * + * @param this calling initiate_ike_sa_job_t object + * @return name of the configuration + */ + char * (*get_configuration_name) (initiate_ike_sa_job_t *this); + + /** + * @brief Destroys an initiate_ike_sa_job_t object. + * + * @param this initiate_ike_sa_job_t object to destroy + * @return + * SUCCESS in any case + */ + status_t (*destroy) (initiate_ike_sa_job_t *this); +}; + +/** + * Creates a job of type INITIATE_IKE_SA + * + * @param configuration_name name of the configuration to initiate IKE_SA with + * @return + * - initiate_ike_sa_job_t if successfully + * - NULL if out of ressources or no configuration_name given + */ +initiate_ike_sa_job_t *initiate_ike_sa_job_create(char *configuration_name); + +#endif /*INITIATE_IKE_SA_JOB_H_*/ diff --git a/Source/charon/jobs/job.c b/Source/charon/jobs/job.c index bb125a10e..218800352 100644 --- a/Source/charon/jobs/job.c +++ b/Source/charon/jobs/job.c @@ -1,8 +1,8 @@ /** * @file job.c - * - * @brief Job-Class representing a job e.g. in job_queue - * + * + * @brief Job-Interface representing a job e.g. in job_queue + * */ /* @@ -20,11 +20,8 @@ * for more details. */ -#include <stdlib.h> - #include "job.h" -#include "../utils/allocator.h" mapping_t job_type_m[] = { {INCOMING_PACKET, "INCOMING_PACKET"}, @@ -32,27 +29,3 @@ mapping_t job_type_m[] = { {INITIATE_IKE_SA, "INITIATE_IKE_SA"}, {MAPPING_END, NULL} }; - - /** - * @brief implements function destroy of job_t - */ -static status_t job_destroy(job_t *job) -{ - allocator_free(job); - return SUCCESS; -} - -/* - * Creates a job (documented in header-file) - */ -job_t *job_create(job_type_t type, void *assigned_data) -{ - job_t *this = allocator_alloc_thing(job_t); - - this->destroy = job_destroy; - - this->type = type; - this->assigned_data = assigned_data; - - return this; -} diff --git a/Source/charon/jobs/job.h b/Source/charon/jobs/job.h index f576cba66..ae2d27170 100644 --- a/Source/charon/jobs/job.h +++ b/Source/charon/jobs/job.h @@ -1,7 +1,7 @@ /** * @file job.h * - * @brief Job-Class representing a job e.g. in job_queue + * @brief Job-Interface representing a job e.g. in job_queue * */ @@ -33,40 +33,43 @@ typedef enum job_type_e job_type_t; enum job_type_e { /** - * process an incoming IKEv2-Message + * Process an incoming IKEv2-Message + * + * Job is implemented in class type incoming_packet_job_t */ INCOMING_PACKET, /** - * retransmit an IKEv2-Message + * Retransmit an IKEv2-Message */ RETRANSMIT_REQUEST, /** - * establish an ike sa as initiator + * Establish an ike sa as initiator + * + * Job is implemented in class type initiate_ike_sa_job_t */ INITIATE_IKE_SA + /* more job types have to be inserted here */ }; extern mapping_t job_type_m[]; /** - * @brief Job as it is stored in the job queue - * - * A job consists of a job-type and an assigned value + * @brief Job-Interface as it is stored in the job queue * - * The value-type for a specific job is not discussed here + * A job consists of a job-type and one or more assigned values */ typedef struct job_s job_t; struct job_s{ + /** - * Type of job - */ - job_type_t type; - /** - * Every job has its assigned_data based on the job type + * @brief get type of job + * + * @param this calling object + * @return type of this job */ - void * assigned_data; + job_type_t (*get_type) (job_t *this); /** * @brief Destroys a job_t object @@ -77,14 +80,7 @@ struct job_s{ status_t (*destroy) (job_t *job); }; -/** - * @brief Creates a job of specific type - * - * @param type type of the job - * @param assigned_data value to assign to the job - * - * @return job_t job object - */ -job_t *job_create(job_type_t type, void *assigned_data); +#include "initiate_ike_sa_job.h" +#include "incoming_packet_job.h" #endif /*JOB_H_*/ |