--- /dev/null
+/**
+ * @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);
+}
--- /dev/null
+/**
+ * @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_*/
--- /dev/null
+/**
+ * @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);
+}
--- /dev/null
+/**
+ * @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_*/
/**
* @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
+ *
*/
/*
* for more details.
*/
-#include <stdlib.h>
-
#include "job.h"
-#include "../utils/allocator.h"
mapping_t job_type_m[] = {
{INCOMING_PACKET, "INCOMING_PACKET"},
{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;
-}
/**
* @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
*
*/
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
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_*/