- jobs moved into queues

This commit is contained in:
Martin Willi
2005-11-23 09:34:31 +00:00
parent 021c232232
commit 7cf14676db
11 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -26,7 +26,7 @@
#include <sys/time.h>
#include <types.h>
#include <jobs/job.h>
#include <queues/jobs/job.h>
/**
* @brief Event-Queue used to store timed events.
+1 -1
View File
@@ -24,7 +24,7 @@
#define JOB_QUEUE_H_
#include <types.h>
#include <jobs/job.h>
#include <queues/jobs/job.h>
/**
* @brief Job-Queue
@@ -0,0 +1,105 @@
/**
* @file delete_ike_sa_job.h
*
* @brief Job of type DELETE_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 "delete_ike_sa_job.h"
#include <utils/allocator.h>
/**
* Private data of an delete_ike_sa_job_t Object
*
*/
typedef struct private_delete_ike_sa_job_s private_delete_ike_sa_job_t;
struct private_delete_ike_sa_job_s {
/**
* public delete_ike_sa_job_t interface
*/
delete_ike_sa_job_t public;
/**
* ID of the ike_sa to delete
*/
ike_sa_id_t *ike_sa_id;
};
/**
* Implements delete_ike_sa_job_t's get_type function.
* See #delete_ike_sa_job_t.get_type for description.
*/
static job_type_t get_type(private_delete_ike_sa_job_t *this)
{
return DELETE_IKE_SA;
}
/**
* Implements delete_ike_sa_job_t's get_ike_sa_id function.
* See #delete_ike_sa_job_t.get_ike_sa_id for description.
*/
static ike_sa_id_t * get_ike_sa_id(private_delete_ike_sa_job_t *this)
{
return this->ike_sa_id;
}
/**
* Implements job_t's and delete_ike_sa_job_t's destroy function.
* See #job_t.destroy or #delete_ike_sa_job_t.destroy for description.
*/
static status_t destroy(job_t *job)
{
private_delete_ike_sa_job_t *this = (private_delete_ike_sa_job_t *) job;
this->ike_sa_id->destroy(this->ike_sa_id);
allocator_free(this);
return SUCCESS;
}
/*
* Described in header
*/
delete_ike_sa_job_t *delete_ike_sa_job_create(ike_sa_id_t *ike_sa_id)
{
private_delete_ike_sa_job_t *this = allocator_alloc_thing(private_delete_ike_sa_job_t);
if (this == NULL)
{
return NULL;
}
/* interface functions */
this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
/* same as destroy */
this->public.job_interface.destroy_all = (status_t (*) (job_t *)) destroy;
this->public.job_interface.destroy = destroy;
/* public functions */
this->public.get_ike_sa_id = (ike_sa_id_t * (*)(delete_ike_sa_job_t *)) get_ike_sa_id;
this->public.destroy = (status_t (*)(delete_ike_sa_job_t *)) destroy;
/* private variables */
if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
{
allocator_free(this);
return NULL;
}
return &(this->public);
}
@@ -0,0 +1,74 @@
/**
* @file delete_ike_sa_job.h
*
* @brief Job of type DELETE_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 DELETE_IKE_SA_JOB_H_
#define DELETE_IKE_SA_JOB_H_
#include <types.h>
#include <ike_sa_id.h>
#include <queues/jobs/job.h>
/**
* Object representing an DELETE_IKE_SA Job
*
*/
typedef struct delete_ike_sa_job_s delete_ike_sa_job_t;
struct delete_ike_sa_job_s {
/**
* implements job_t interface
*/
job_t job_interface;
/**
* @brief Returns the currently set ike_sa_id
*
* @warning Returned object is not copied.
*
* @param this calling delete_ike_sa_job_t object
* @return ike_sa_id_t object
*/
ike_sa_id_t * (*get_ike_sa_id) (delete_ike_sa_job_t *this);
/**
* @brief Destroys an delete_ike_sa_job_t object (including assigned data)
*
* @param this delete_ike_sa_job_t object to destroy
* @return
* SUCCESS in any case
*/
status_t (*destroy) (delete_ike_sa_job_t *this);
};
/**
* Creates a job of type DELETE_IKE_SA
*
* @param ike_sa_id id of the IKE_SA to delete
* @return
* - delete_ike_sa_job_t if successfully
* - NULL if out of ressources
*/
delete_ike_sa_job_t *delete_ike_sa_job_create(ike_sa_id_t *ike_sa_id);
#endif /*DELETE_IKE_SA_JOB_H_*/
@@ -0,0 +1,122 @@
/**
* @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)
{
if (this->packet == NULL)
{
return FAILED;
}
*packet = this->packet;
return SUCCESS;
}
/**
* Implements job_t's and destroy_all function.
* See #job_t.destroy_all description.
*/
static status_t destroy_all(private_incoming_packet_job_t *this)
{
if (this->packet != NULL)
{
this->packet->destroy(this->packet);
}
allocator_free(this);
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_all = (status_t (*) (job_t *)) destroy_all;
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);
}
@@ -0,0 +1,76 @@
/**
* @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 <types.h>
#include <packet.h>
#include <queues/jobs/job.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
* - FAILED if no packet is assigned
*/
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_*/
@@ -0,0 +1,111 @@
/**
* @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;
/* same as destroy */
this->public.job_interface.destroy_all = (status_t (*) (job_t *)) destroy;
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(strlen(configuration_name) + 1);
if (this->configuration_name == NULL)
{
allocator_free(this);
return NULL;
}
strcpy(this->configuration_name,configuration_name);
return &(this->public);
}
@@ -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 <queues/jobs/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_*/
+33
View File
@@ -0,0 +1,33 @@
/**
* @file job.c
*
* @brief Job-Interface representing a job e.g. in job_queue
*
*/
/*
* 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 "job.h"
mapping_t job_type_m[] = {
{INCOMING_PACKET, "INCOMING_PACKET"},
{RETRANSMIT_REQUEST, "RETRANSMIT_REQUEST"},
{INITIATE_IKE_SA, "INITIATE_IKE_SA"},
{DELETE_IKE_SA, "DELETE_IKE_SA"},
{MAPPING_END, NULL}
};
+104
View File
@@ -0,0 +1,104 @@
/**
* @file job.h
*
* @brief Job-Interface representing a job e.g. in job_queue
*
*/
/*
* 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 JOB_H_
#define JOB_H_
#include <types.h>
#include <definitions.h>
/**
* Type of Jobs in Job-Queue
*/
typedef enum job_type_e job_type_t;
enum job_type_e {
/**
* Process an incoming IKEv2-Message
*
* Job is implemented in class type incoming_packet_job_t
*/
INCOMING_PACKET,
/**
* Retransmit an IKEv2-Message
*/
RETRANSMIT_REQUEST,
/**
* Establish an ike sa as initiator
*
* Job is implemented in class type initiate_ike_sa_job_t
*/
INITIATE_IKE_SA,
/**
* Delete an ike sa
*
* Job is implemented in class type delete_ike_sa_job_t
*/
DELETE_IKE_SA
/* more job types have to be inserted here */
};
extern mapping_t job_type_m[];
/**
* @brief Job-Interface as it is stored in the job queue
*
* A job consists of a job-type and one or more assigned values
*/
typedef struct job_s job_t;
struct job_s{
/**
* @brief get type of job
*
* @param this calling object
* @return type of this job
*/
job_type_t (*get_type) (job_t *this);
/**
* @brief Destroys a job_t object and all assigned data!
*
* @param job_t calling object
* @returns SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy_all) (job_t *job);
/**
* @brief Destroys a job_t object
*
* @param job_t calling object
* @returns SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy) (job_t *job);
};
#include "initiate_ike_sa_job.h"
#include "delete_ike_sa_job.h"
#include "incoming_packet_job.h"
#endif /*JOB_H_*/