aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-29 10:25:07 +0000
committerMartin Willi <martin@strongswan.org>2005-11-29 10:25:07 +0000
commit0e96f7d8c3aefaa1717f4c30e66fdc459d3f2ecc (patch)
tree9482ca76a46e005757ac485007ad18c8fa38d794
parent79b9c1d6c5ebf296d29e11f4a5f25c0bf60f896c (diff)
downloadstrongswan-0e96f7d8c3aefaa1717f4c30e66fdc459d3f2ecc.tar.bz2
strongswan-0e96f7d8c3aefaa1717f4c30e66fdc459d3f2ecc.tar.xz
- globals packed in a daemon
-rw-r--r--Source/charon/config/configuration_manager.c8
-rw-r--r--Source/charon/daemon.c410
-rw-r--r--Source/charon/daemon.h104
-rw-r--r--Source/charon/encoding/generator.c6
-rw-r--r--Source/charon/encoding/message.c6
-rw-r--r--Source/charon/encoding/parser.c6
-rw-r--r--Source/charon/encoding/payloads/encryption_payload.c4
-rw-r--r--Source/charon/globals.h43
-rw-r--r--Source/charon/network/socket.c10
-rw-r--r--Source/charon/sa/ike_sa.c10
-rw-r--r--Source/charon/sa/ike_sa_manager.c6
-rw-r--r--Source/charon/sa/states/ike_sa_init_requested.c4
-rw-r--r--Source/charon/sa/states/initiator_init.c13
-rw-r--r--Source/charon/sa/states/responder_init.c8
-rw-r--r--Source/charon/testcases/aes_cbc_crypter_test.c6
-rw-r--r--Source/charon/testcases/diffie_hellman_test.c6
-rw-r--r--Source/charon/testcases/generator_test.c39
-rw-r--r--Source/charon/testcases/hmac_signer_test.c10
-rw-r--r--Source/charon/testcases/packet_test.c2
-rw-r--r--Source/charon/testcases/parser_test.c2
-rw-r--r--Source/charon/testcases/receiver_test.c6
-rw-r--r--Source/charon/testcases/scheduler_test.c14
-rw-r--r--Source/charon/testcases/sender_test.c6
-rw-r--r--Source/charon/testcases/testcases.c118
-rw-r--r--Source/charon/threads/receiver.c12
-rw-r--r--Source/charon/threads/scheduler.c12
-rw-r--r--Source/charon/threads/sender.c10
-rw-r--r--Source/charon/threads/thread_pool.c28
28 files changed, 432 insertions, 477 deletions
diff --git a/Source/charon/config/configuration_manager.c b/Source/charon/config/configuration_manager.c
index e39d7c8e8..0ab8129b4 100644
--- a/Source/charon/config/configuration_manager.c
+++ b/Source/charon/config/configuration_manager.c
@@ -27,7 +27,7 @@
#include "configuration_manager.h"
#include <types.h>
-#include <globals.h>
+#include <daemon.h>
#include <utils/allocator.h>
#include <encoding/payloads/nonce_payload.h>
#include <encoding/payloads/proposal_substructure.h>
@@ -76,7 +76,7 @@ static status_t get_remote_host(private_configuration_manager_t *this, char *nam
}
else if (strcmp(name, "localhost") == 0)
{
- remote = host_create(AF_INET, "127.0.0.1", 4500);
+ remote = host_create(AF_INET, "127.0.0.1", 500);
}
else
{
@@ -277,7 +277,7 @@ static status_t destroy(private_configuration_manager_t *this)
this->logger->log(this->logger,CONTROL | MORE, "Going to destroy configuration manager ");
this->logger->log(this->logger,CONTROL | MOST, "Destroy assigned logger");
- global_logger_manager->destroy_logger(global_logger_manager,this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
allocator_free(this);
return SUCCESS;
}
@@ -300,7 +300,7 @@ configuration_manager_t *configuration_manager_create()
this->public.is_dh_group_allowed_for_host = (status_t(*)(configuration_manager_t*,host_t*,diffie_hellman_group_t,bool*)) is_dh_group_allowed_for_host;
/* private variables */
- this->logger = global_logger_manager->create_logger(global_logger_manager,CONFIGURATION_MANAGER,NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager,CONFIGURATION_MANAGER,NULL);
return (&this->public);
}
diff --git a/Source/charon/daemon.c b/Source/charon/daemon.c
index a8d815ef1..a32948fe9 100644
--- a/Source/charon/daemon.c
+++ b/Source/charon/daemon.c
@@ -28,170 +28,84 @@
#include <types.h>
-#include <sa/ike_sa_manager.h>
-#include <threads/sender.h>
-#include <threads/receiver.h>
-#include <threads/scheduler.h>
-#include <threads/thread_pool.h>
-#include <network/socket.h>
#include <utils/allocator.h>
-#include <utils/logger_manager.h>
-#include <queues/event_queue.h>
-#include <queues/job_queue.h>
-#include <queues/send_queue.h>
#include <queues/jobs/initiate_ike_sa_job.h>
-/* function declaration (defined and described after main function) */
-static status_t initialize_globals();
-static void destroy_globals();
-static status_t start_threads();
-static void end_threads();
-static void main_loop();
-static void register_signals();
-static void destroy_and_exit(int);
-/** Global job-queue */
-job_queue_t *global_job_queue = NULL;
-/** Global event-queue */
-event_queue_t *global_event_queue = NULL;
- /** Global send-queue */
-send_queue_t *global_send_queue = NULL;
- /** Global socket */
-socket_t *global_socket = NULL;
-/** Global logger manager */
-logger_manager_t *global_logger_manager = NULL;
-/** Global ike_sa-manager */
-ike_sa_manager_t *global_ike_sa_manager = NULL;
-/** Global configuration-manager */
-configuration_manager_t *global_configuration_manager = NULL;
+typedef struct private_daemon_t private_daemon_t;
/**
- * logger_t object assigned for daemon things
+ * Private additions to daemon_t, contains
+ * threads and internal functions.
*/
-static logger_t *logger = NULL;
+struct private_daemon_t {
+ /**
+ * public members of daemon_t
+ */
+ daemon_t public;
+
+ /**
+ * logger_t object assigned for daemon things
+ */
+ logger_t *logger;
-/**
- * Sender-Thread
- */
-static sender_t *sender_thread = NULL;
-/**
- * Receiver-Thread
- */
-static receiver_t *receiver_thread = NULL;
-/**
- * Scheduler-Thread
- */
-static scheduler_t *scheduler_thread = NULL;
-/**
- * Thread pool holding the worker threads
- */
-static thread_pool_t *thread_pool = NULL;
+ /**
+ * Signal set used for signal handling
+ */
+ sigset_t signal_set;
+
+ void (*run) (private_daemon_t *this);
+ void (*destroy) (private_daemon_t *this, char *reason);
+ void (*build_test_jobs) (private_daemon_t *this);
+ void (*initialize) (private_daemon_t *this);
+ void (*cleanup) (private_daemon_t *this);
+};
-/**
- * Signal set used for signal handling
- */
-sigset_t signal_set;
-int main()
-{
- /* set signal handler */
- register_signals();
-
- /* logger_manager is created first */
- global_logger_manager = logger_manager_create(FULL);
- if (global_logger_manager == NULL)
- {
- printf("could not create logger manager");
- return -1;
- }
+/**
+ * instance of the daemon
+ */
+daemon_t *charon;
+
- /* a own logger for the daemon is created */
- logger = global_logger_manager->create_logger(global_logger_manager,DAEMON,NULL);
- if (logger == NULL)
- {
- printf("could not create logger object");
- destroy_globals();
- return -1;
- }
-
- /* initialize all global objects */
- if (initialize_globals() != SUCCESS)
- {
- destroy_globals();
- return -1;
- }
-
- logger->log(logger,CONTROL,"starting %s", DAEMON_NAME);
- /* now its time to create all the different threads :-) */
- if (start_threads() != SUCCESS)
- {
- /* ugh, not good */
- logger->log(logger,CONTROL,"Fatal error: Needed Threads could not be started");
- destroy_and_exit(-1);
- }
-
- int i;
- for(i = 0; i<1; i++)
- {
- initiate_ike_sa_job_t *initiate_job;
-
- initiate_job = initiate_ike_sa_job_create("localhost");
- global_job_queue->add(global_job_queue, (job_t*)initiate_job);
-
- }
-
- logger->log(logger,CONTROL|MORE,"going to wait for exit signal");
- /* go and handle signals*/
- main_loop();
-
- destroy_and_exit(0);
-
- /* never reached */
- return -1;
-}
/**
- * Main Loop.
- * Waits for registered signals and acts dependently
+ * Loop of the main thread, waits for signals
*/
-static void main_loop()
-{
- while(1)
+static void run(private_daemon_t *this)
+{
+ while(TRUE)
{
- int signal_number;
- int error;
-
- error = sigwait(&signal_set, &signal_number);
-
- if(error)
- {
- /* do error code */
- logger->log(logger,CONTROL,"Error %d when waiting for signal",error);
- return;
- }
- switch (signal_number)
- {
+ int signal_number;
+ int error;
+
+ error = sigwait(&(this->signal_set), &signal_number);
+ if(error)
+ {
+ this->logger->log(this->logger, ERROR, "Error %d when waiting for signal", error);
+ return;
+ }
+ switch (signal_number)
+ {
case SIGHUP:
{
- logger->log(logger,CONTROL,"Signal of type SIGHUP received. Do nothing");
+ this->logger->log(this->logger, CONTROL, "Signal of type SIGHUP received. Do nothing");
break;
}
case SIGINT:
{
- logger->log(logger,CONTROL,"Signal of type SIGINT received. Exit main loop.");
+ this->logger->log(this->logger, CONTROL, "Signal of type SIGINT received. Exit main loop.");
return;
}
case SIGTERM:
- {
- logger->log(logger,CONTROL,"Signal of type SIGTERM received. Exit main loop.");
+ this->logger->log(this->logger, CONTROL, "Signal of type SIGTERM received. Exit main loop.");
return;
- }
default:
{
- logger->log(logger,CONTROL,"Unknown signal %d received. Do nothing",signal_number);
+ this->logger->log(this->logger, CONTROL, "Unknown signal %d received. Do nothing", signal_number);
break;
}
}
@@ -199,169 +113,167 @@ static void main_loop()
}
/**
- * Registers signals SIGINT, SIGHUP and SIGTERM.
- * Signals are handled in main_loop()
+ * Initialize the destruction of the daemon
*/
-static void register_signals()
+static void destroy(private_daemon_t *this, char *reason)
{
- sigemptyset(&signal_set);
- sigaddset(&signal_set, SIGINT);
- sigaddset(&signal_set, SIGHUP);
- sigaddset(&signal_set, SIGTERM);
- pthread_sigmask(SIG_BLOCK, &signal_set, 0);
+ /* we send SIGTERM, so the daemon can cleanly shut down */
+ this->logger->log(this->logger, ERROR, "Killing daemon: %s", reason);
+ this->logger->log(this->logger, CONTROL, "sending SIGTERM to ourself", reason);
+ kill(0, SIGTERM);
+ /* thread must die, since he produced a ciritcal failure and can't continue */
+ pthread_exit(NULL);
+}
+/**
+ * build some jobs to test daemon functionality
+ */
+static void build_test_jobs(daemon_t *this)
+{
+ int i;
+ for(i = 0; i<1; i++)
+ {
+ initiate_ike_sa_job_t *initiate_job;
+ initiate_job = initiate_ike_sa_job_create("localhost");
+ this->job_queue->add(this->job_queue, (job_t*)initiate_job);
+ }
}
+
/**
- * Initializes global objects
- *
- * @return
- * - SUCCESS
- * - FAILED
+ * Initialize global objects and threads
*/
-static status_t initialize_globals()
+static void initialize(daemon_t *this)
{
- /* initialize global object */
- global_socket = socket_create(IKEV2_UDP_PORT);
- global_ike_sa_manager = ike_sa_manager_create();
- global_job_queue = job_queue_create();
- global_event_queue = event_queue_create();
- global_send_queue = send_queue_create();
- global_configuration_manager = configuration_manager_create();
-
- if ( (global_socket == NULL) ||
- (global_job_queue == NULL) ||
- (global_event_queue == NULL) ||
- (global_send_queue == NULL) ||
- (global_configuration_manager == NULL) ||
- (global_ike_sa_manager == NULL))
- {
- return FAILED;
- }
-
- return SUCCESS;
+ this->socket = socket_create(IKEV2_UDP_PORT);
+ this->ike_sa_manager = ike_sa_manager_create();
+ this->job_queue = job_queue_create();
+ this->event_queue = event_queue_create();
+ this->send_queue = send_queue_create();
+ this->configuration_manager = configuration_manager_create();
+
+ this->sender = sender_create();
+ this->receiver = receiver_create();
+ this->scheduler = scheduler_create();
+ this->thread_pool = thread_pool_create(NUMBER_OF_WORKING_THREADS);
}
/**
- * Destroy global objects
+ * Destory all initiated objects
*/
-static void destroy_globals()
+static void cleanup(daemon_t *this)
{
- if (global_job_queue != NULL)
+ if (this->receiver != NULL)
{
- logger->log(logger,CONTROL|MOST,"destroy global_job_queue");
- global_job_queue->destroy(global_job_queue);
+ this->receiver->destroy(this->receiver);
}
- if (global_event_queue != NULL)
+ if (this->scheduler != NULL)
{
- logger->log(logger,CONTROL|MOST,"destroy global_event_queue");
- global_event_queue->destroy(global_event_queue);
+ this->scheduler->destroy(this->scheduler);
}
- if (global_send_queue != NULL)
+ if (this->sender != NULL)
{
- logger->log(logger,CONTROL|MOST,"destroy global_send_queue");
- global_send_queue->destroy(global_send_queue);
+ this->sender->destroy(this->sender);
}
- if (global_socket != NULL)
+ if (this->thread_pool != NULL)
{
- logger->log(logger,CONTROL|MOST,"destroy global_socket");
- global_socket->destroy(global_socket);
+ this->thread_pool->destroy(this->thread_pool);
}
- if (global_ike_sa_manager != NULL)
+ if (this->job_queue != NULL)
{
- logger->log(logger,CONTROL|MOST,"destroy global_ike_sa_manager");
- global_ike_sa_manager->destroy(global_ike_sa_manager);
+ this->job_queue->destroy(this->job_queue);
}
- if (global_configuration_manager != NULL)
+ if (this->event_queue != NULL)
{
- logger->log(logger,CONTROL|MOST,"destroy global_configuration_manager");
- global_configuration_manager->destroy(global_configuration_manager);
+ this->event_queue->destroy(this->event_queue);
}
-}
-
-/**
- * Creates all needed Threads
- *
- * @return
- * - SUCCESS
- * - FAILED
- */
-static status_t start_threads()
-{
- sender_thread = sender_create();
- if (sender_thread == NULL)
+ if (this->send_queue != NULL)
{
- return FAILED;
+ this->send_queue->destroy(this->send_queue);
}
- receiver_thread = receiver_create();
- if (receiver_thread == NULL)
+ if (this->socket != NULL)
{
- return FAILED;
- }
- scheduler_thread = scheduler_create();
- if (scheduler_thread == NULL)
+ this->socket->destroy(this->socket);
+ }
+ if (this->ike_sa_manager != NULL)
{
- return FAILED;
+ this->ike_sa_manager->destroy(this->ike_sa_manager);
}
- thread_pool = thread_pool_create(NUMBER_OF_WORKING_THREADS);
- if (thread_pool == NULL)
+ if (this->configuration_manager != NULL)
{
- return FAILED;
+ this->configuration_manager->destroy(this->configuration_manager);
}
-
- return SUCCESS;
+
+ this->logger_manager->destroy(this->logger_manager);
+ allocator_free(this);
}
+
/**
- * Ends all Threads
+ * @brief Create the daemon.
*
+ * @return created daemon_t
*/
-static void end_threads()
+private_daemon_t *daemon_create()
{
- if (receiver_thread != NULL)
- {
- receiver_thread->destroy(receiver_thread);
- }
- if (scheduler_thread != NULL)
- {
- scheduler_thread->destroy(scheduler_thread);
- }
- if (sender_thread != NULL)
- {
- sender_thread->destroy(sender_thread);
- }
- if (thread_pool != NULL)
- {
- thread_pool->destroy(thread_pool);
- }
-
+ private_daemon_t *this = allocator_alloc_thing(private_daemon_t);
+
+ /* assign methods */
+ this->run = run;
+ this->public.destroy = (void (*) (daemon_t*,char*))destroy;
+ this->build_test_jobs = (void (*) (private_daemon_t*)) build_test_jobs;
+ this->initialize = (void (*) (private_daemon_t*))initialize;
+ this->cleanup = (void (*) (private_daemon_t*))cleanup;
+
+ /* first build a logger */
+ this->public.logger_manager = logger_manager_create(DEFAULT_LOGLEVEL);
+ this->logger = (this->public.logger_manager)->create_logger(this->public.logger_manager, DAEMON, NULL);
+
+ /* NULL members for clean destruction */
+ this->public.socket = NULL;
+ this->public.ike_sa_manager = NULL;
+ this->public.job_queue = NULL;
+ this->public.event_queue = NULL;
+ this->public.send_queue = NULL;
+ this->public.configuration_manager = NULL;
+ this->public.sender= NULL;
+ this->public.receiver = NULL;
+ this->public.scheduler = NULL;
+ this->public.thread_pool = NULL;
+
+ /* setup signal handling */
+ sigemptyset(&(this->signal_set));
+ sigaddset(&(this->signal_set), SIGINT);
+ sigaddset(&(this->signal_set), SIGHUP);
+ sigaddset(&(this->signal_set), SIGTERM);
+ pthread_sigmask(SIG_BLOCK, &(this->signal_set), 0);
+
+ return this;
}
/**
- * Destroys initialized objects, kills all threads and exits
- *
- * @param exit_code Code to exit with
+ * Main function, manages the daemon
*/
-static void destroy_and_exit(int exit_code)
+int main(int argc, char *argv[])
{
- logger->log(logger,CONTROL,"going to exit daemon");
-
- end_threads();
+ private_daemon_t *private_charon;
- /* all globals can be destroyed now */
- destroy_globals();
+ private_charon = daemon_create();
+ charon = (daemon_t*)private_charon;
+
+ private_charon->initialize(private_charon);
+
+ private_charon->build_test_jobs(private_charon);
+
+ private_charon->run(private_charon);
+
+ private_charon->cleanup(private_charon);
- /* logger is destroyed */
- logger->log(logger,CONTROL|MORE,"destroy logger");
- logger->log(logger,CONTROL|MORE,"destroy logger_manager");
- global_logger_manager->destroy_logger(global_logger_manager,logger);
- global_logger_manager->destroy(global_logger_manager);
-
#ifdef LEAK_DETECTIVE
- /* Leaks are reported in log file */
report_memory_leaks(void);
#endif
- exit(exit_code);
+ return 0;
}
+
diff --git a/Source/charon/daemon.h b/Source/charon/daemon.h
index c7193bb94..872c7fa27 100644
--- a/Source/charon/daemon.h
+++ b/Source/charon/daemon.h
@@ -23,13 +23,113 @@
#ifndef DAEMON_H_
#define DAEMON_H_
-#include <globals.h>
+
+#include <threads/sender.h>
+#include <threads/receiver.h>
+#include <threads/scheduler.h>
+#include <threads/thread_pool.h>
+#include <sa/ike_sa_manager.h>
+#include <queues/send_queue.h>
+#include <queues/job_queue.h>
+#include <network/socket.h>
+#include <queues/event_queue.h>
+#include <utils/logger_manager.h>
+#include <config/configuration_manager.h>
+
+/**
+ * Name of the daemon
+ */
#define DAEMON_NAME "charon"
+/**
+ * Number of threads in the thread pool
+ *
+ * There are several other threads, this defines
+ * only the number of threads in thread_pool_t.
+ */
#define NUMBER_OF_WORKING_THREADS 1
-#define IKEV2_UDP_PORT 4500
+/**
+ * Port on which the daemon will
+ * listen for incoming traffic
+ */
+#define IKEV2_UDP_PORT 500
+/**
+ * Default loglevel to use. This is the
+ * maximum allowed level for ever context, the definiton
+ * of the context may be less verbose.
+ */
+#define DEFAULT_LOGLEVEL FULL
+
+typedef struct daemon_t daemon_t;
+
+/**
+ * @brief Main class of daemon, contains some globals
+ */
+struct daemon_t {
+ /**
+ * socket_t instance
+ */
+ socket_t *socket;
+ /**
+ * send_queue_t instance
+ */
+ send_queue_t *send_queue;
+ /**
+ * job_queue_t instance
+ */
+ job_queue_t *job_queue;
+ /**
+ * event_queue_t instance
+ */
+ event_queue_t *event_queue;
+ /**
+ * logger_manager_t instance
+ */
+ logger_manager_t *logger_manager;
+ /**
+ * ike_sa_manager_t instance
+ */
+ ike_sa_manager_t *ike_sa_manager;
+ /**
+ * configuration_manager_t instance
+ */
+ configuration_manager_t *configuration_manager;
+
+ /**
+ * Sender-Thread
+ */
+ sender_t *sender;
+
+ /**
+ * Receiver-Thread
+ */
+ receiver_t *receiver;
+
+ /**
+ * Scheduler-Thread
+ */
+ scheduler_t *scheduler;
+
+ /**
+ * Thread pool holding the worker threads
+ */
+ thread_pool_t *thread_pool;
+
+ /**
+ * @brief shut down the daemon
+ *
+ * @param this the daemon to kill
+ * @param reason describition why it will be killed
+ */
+ void (*destroy) (daemon_t *this, char *reason);
+};
+
+/**
+ * one and only instance of the daemon
+ */
+extern daemon_t *charon;
#endif /*DAEMON_H_*/
diff --git a/Source/charon/encoding/generator.c b/Source/charon/encoding/generator.c
index c239cf697..cfe8b815f 100644
--- a/Source/charon/encoding/generator.c
+++ b/Source/charon/encoding/generator.c
@@ -29,7 +29,7 @@
#include "generator.h"
#include <types.h>
-#include <globals.h>
+#include <daemon.h>
#include <utils/allocator.h>
#include <utils/linked_list.h>
#include <utils/logger_manager.h>
@@ -933,7 +933,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
static status_t destroy(private_generator_t *this)
{
allocator_free(this->buffer);
- global_logger_manager->destroy_logger(global_logger_manager,this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
allocator_free(this);
return SUCCESS;
}
@@ -977,7 +977,7 @@ generator_t * generator_create()
this->current_bit = 0;
this->last_payload_length_position_offset = 0;
this->header_length_position_offset = 0;
- this->logger = global_logger_manager->create_logger(global_logger_manager,GENERATOR,NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager,GENERATOR,NULL);
return &(this->public);
}
diff --git a/Source/charon/encoding/message.c b/Source/charon/encoding/message.c
index 37e9a55f1..82572e5a8 100644
--- a/Source/charon/encoding/message.c
+++ b/Source/charon/encoding/message.c
@@ -25,7 +25,7 @@
#include "message.h"
#include <types.h>
-#include <globals.h>
+#include <daemon.h>
#include <sa/ike_sa_id.h>
#include <encoding/generator.h>
#include <encoding/parser.h>
@@ -736,7 +736,7 @@ static void destroy (private_message_t *this)
iterator->destroy(iterator);
this->payloads->destroy(this->payloads);
this->parser->destroy(this->parser);
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -795,7 +795,7 @@ message_t *message_create_from_packet(packet_t *packet)
/* parser is created from data of packet */
this->parser = parser_create(this->packet->data);
- this->logger = global_logger_manager->create_logger(global_logger_manager, MESSAGE, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, MESSAGE, NULL);
return (&this->public);
}
diff --git a/Source/charon/encoding/parser.c b/Source/charon/encoding/parser.c
index 55ad56462..1bfb98d1e 100644
--- a/Source/charon/encoding/parser.c
+++ b/Source/charon/encoding/parser.c
@@ -27,7 +27,7 @@
#include <types.h>
#include <definitions.h>
-#include <globals.h>
+#include <daemon.h>
#include <utils/allocator.h>
#include <utils/logger.h>
#include <utils/linked_list.h>
@@ -875,7 +875,7 @@ static void reset_context (private_parser_t *this)
*/
static void destroy(private_parser_t *this)
{
- global_logger_manager->destroy_logger(global_logger_manager,this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
allocator_free(this);
}
@@ -886,7 +886,7 @@ parser_t *parser_create(chunk_t data)
{
private_parser_t *this = allocator_alloc_thing(private_parser_t);
- this->logger = global_logger_manager->create_logger(global_logger_manager, PARSER, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, PARSER, NULL);
this->public.parse_payload = (status_t(*)(parser_t*,payload_type_t,payload_t**)) parse_payload;
this->public.reset_context = (void(*)(parser_t*)) reset_context;
diff --git a/Source/charon/encoding/payloads/encryption_payload.c b/Source/charon/encoding/payloads/encryption_payload.c
index 08722f83f..db4b441e5 100644
--- a/Source/charon/encoding/payloads/encryption_payload.c
+++ b/Source/charon/encoding/payloads/encryption_payload.c
@@ -360,7 +360,7 @@ static status_t encrypt(private_encryption_payload_t *this, crypter_t *crypter)
/* encrypt concatenated chunk */
allocator_free(this->encrypted.ptr);
- status = crypter->encrypt(crypter, iv, concatenated, &(this->encrypted));
+ status = crypter->encrypt(crypter, concatenated, iv, &(this->encrypted));
allocator_free(padding.ptr);
allocator_free(concatenated.ptr);
allocator_free(iv.ptr);
@@ -408,7 +408,7 @@ static status_t decrypt(private_encryption_payload_t *this, crypter_t *crypter)
/* free previus data, if any */
allocator_free(this->decrypted.ptr);
- status = crypter->decrypt(crypter, iv, concatenated, &(this->decrypted));
+ status = crypter->decrypt(crypter, concatenated, iv, &(this->decrypted));
if (status != SUCCESS)
{
return FAILED;
diff --git a/Source/charon/globals.h b/Source/charon/globals.h
deleted file mode 100644
index 39dc841c6..000000000
--- a/Source/charon/globals.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * @file globals.h
- *
- * @brief Global used objects
- *
- */
-
-/*
- * 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 GLOBALS_H_
-#define GLOBALS_H_
-
-#include <sa/ike_sa_manager.h>
-#include <queues/send_queue.h>
-#include <queues/job_queue.h>
-#include <network/socket.h>
-#include <queues/event_queue.h>
-#include <utils/logger_manager.h>
-#include <config/configuration_manager.h>
-
-
-extern socket_t *global_socket;
-extern send_queue_t *global_send_queue;
-extern job_queue_t *global_job_queue;
-extern event_queue_t *global_event_queue;
-extern logger_manager_t *global_logger_manager;
-extern ike_sa_manager_t *global_ike_sa_manager;
-extern configuration_manager_t *global_configuration_manager;
-
-#endif /*GLOBALS_H_*/
diff --git a/Source/charon/network/socket.c b/Source/charon/network/socket.c
index 41a2224b8..c1c66a08f 100644
--- a/Source/charon/network/socket.c
+++ b/Source/charon/network/socket.c
@@ -30,7 +30,7 @@
#include "socket.h"
-#include <globals.h>
+#include <daemon.h>
#include <utils/allocator.h>
#include <utils/logger_manager.h>
@@ -139,7 +139,7 @@ status_t sender(private_socket_t *this, packet_t *packet)
void destroy(private_socket_t *this)
{
close(this->socket_fd);
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -153,14 +153,14 @@ socket_t *socket_create(u_int16_t port)
this->public.receive = (status_t(*)(socket_t*, packet_t**))receiver;
this->public.destroy = (void(*)(socket_t*))destroy;
- this->logger = global_logger_manager->create_logger(global_logger_manager, SOCKET, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, SOCKET, NULL);
/* create default ipv4 socket */
this->socket_fd = socket(PF_INET, SOCK_DGRAM, 0);
if (this->socket_fd < 0)
{
this->logger->log(this->logger, ERROR, "unable to open socket: %s", strerror(errno));
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
return NULL;
}
@@ -172,7 +172,7 @@ socket_t *socket_create(u_int16_t port)
if (bind(this->socket_fd,(struct sockaddr*)&addr, sizeof(addr)) < 0)
{
this->logger->log(this->logger, ERROR, "unable to bind socket to port %d: %s", port, strerror(errno));
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
return NULL;
}
diff --git a/Source/charon/sa/ike_sa.c b/Source/charon/sa/ike_sa.c
index 91ab32390..7d6fcef20 100644
--- a/Source/charon/sa/ike_sa.c
+++ b/Source/charon/sa/ike_sa.c
@@ -23,7 +23,7 @@
#include "ike_sa.h"
#include <types.h>
-#include <globals.h>
+#include <daemon.h>
#include <definitions.h>
#include <utils/allocator.h>
#include <utils/linked_list.h>
@@ -414,7 +414,7 @@ static status_t resend_last_reply(private_ike_sa_t *this)
return status;
}
- global_send_queue->add(global_send_queue, packet);
+ charon->send_queue->add(charon->send_queue, packet);
return SUCCESS;
}
@@ -428,7 +428,7 @@ static status_t create_delete_job(private_ike_sa_t *this)
this->logger->log(this->logger, CONTROL | MORE, "Going to create job to delete this IKE_SA");
delete_job = (job_t *) delete_ike_sa_job_create(this->ike_sa_id);
- global_job_queue->add(global_job_queue,delete_job);
+ charon->job_queue->add(charon->job_queue,delete_job);
return SUCCESS;
}
@@ -738,7 +738,7 @@ static void destroy (private_ike_sa_t *this)
this->current_state->destroy(this->current_state);
this->logger->log(this->logger, CONTROL | MOST, "Destroy logger of IKE_SA");
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -776,7 +776,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
/* initialize private fields */
- this->logger = global_logger_manager->create_logger(global_logger_manager, IKE_SA, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, IKE_SA, NULL);
this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
this->child_sas = linked_list_create();
diff --git a/Source/charon/sa/ike_sa_manager.c b/Source/charon/sa/ike_sa_manager.c
index 34b2a09b3..49b817642 100644
--- a/Source/charon/sa/ike_sa_manager.c
+++ b/Source/charon/sa/ike_sa_manager.c
@@ -25,7 +25,7 @@
#include "ike_sa_manager.h"
-#include <globals.h>
+#include <daemon.h>
#include <sa/ike_sa_id.h>
#include <utils/allocator.h>
#include <utils/logger.h>
@@ -645,7 +645,7 @@ static void destroy(private_ike_sa_manager_t *this)
pthread_mutex_unlock(&(this->mutex));
/* destroy logger at end */
- global_logger_manager->destroy_logger(global_logger_manager,this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
allocator_free(this);
}
@@ -672,7 +672,7 @@ ike_sa_manager_t *ike_sa_manager_create()
this->delete_entry = delete_entry;
/* initialize private variables */
- this->logger = global_logger_manager->create_logger(global_logger_manager,IKE_SA_MANAGER,NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager,IKE_SA_MANAGER,NULL);
this->ike_sa_list = linked_list_create();
diff --git a/Source/charon/sa/states/ike_sa_init_requested.c b/Source/charon/sa/states/ike_sa_init_requested.c
index d5ad12cf4..c039e733a 100644
--- a/Source/charon/sa/states/ike_sa_init_requested.c
+++ b/Source/charon/sa/states/ike_sa_init_requested.c
@@ -22,7 +22,7 @@
#include "ike_sa_init_requested.h"
-#include <globals.h>
+#include <daemon.h>
#include <utils/allocator.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/ke_payload.h>
@@ -143,7 +143,7 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
/* now let the configuration-manager check the selected proposals*/
this->logger->log(this->logger, CONTROL | MOST, "Check suggested proposals");
- status = global_configuration_manager->check_selected_proposals_for_host(global_configuration_manager,
+ status = charon->configuration_manager->check_selected_proposals_for_host(charon->configuration_manager,
this->ike_sa->get_other_host(this->ike_sa), suggested_proposals,&valid);
if (status != SUCCESS)
{
diff --git a/Source/charon/sa/states/initiator_init.c b/Source/charon/sa/states/initiator_init.c
index ade422fb1..7ade885d4 100644
--- a/Source/charon/sa/states/initiator_init.c
+++ b/Source/charon/sa/states/initiator_init.c
@@ -23,7 +23,7 @@
#include "initiator_init.h"
-#include <globals.h>
+#include <daemon.h>
#include <sa/states/state.h>
#include <sa/states/ike_sa_init_requested.h>
#include <utils/allocator.h>
@@ -148,7 +148,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
this->logger->log(this->logger, CONTROL, "Initializing connection %s",name);
/* get local host */
- status = global_configuration_manager->get_local_host(global_configuration_manager, name, &my_host);
+ status = charon->configuration_manager->get_local_host(charon->configuration_manager, name, &my_host);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR | MORE, "Could not retrieve local host configuration information for %s",name);
@@ -157,7 +157,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
this->ike_sa->set_my_host(this->ike_sa,my_host);
/* get remote host */
- status = global_configuration_manager->get_remote_host(global_configuration_manager, name, &other_host);
+ status = charon->configuration_manager->get_remote_host(charon->configuration_manager, name, &other_host);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR | MORE, "Could not retrieve remote host configuration information for %s",name);
@@ -166,7 +166,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
this->ike_sa->set_other_host(this->ike_sa,other_host);
/* get dh group */
- status = global_configuration_manager->get_dh_group_number(global_configuration_manager, name, &(this->dh_group_number), this->dh_group_priority);
+ status = charon->configuration_manager->get_dh_group_number(charon->configuration_manager, name, &(this->dh_group_number), this->dh_group_priority);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR | MORE, "Could not retrieve DH group number configuration for %s",name);
@@ -175,7 +175,8 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
/* get proposals */
proposal_iterator = this->proposals->create_iterator(this->proposals, FALSE);
- status = global_configuration_manager->get_proposals_for_host(global_configuration_manager, this->ike_sa->get_other_host(this->ike_sa), proposal_iterator);
+ status = charon->configuration_manager->get_proposals_for_host(charon->configuration_manager, this->ike_sa->get_other_host(this->ike_sa), proposal_iterator);
+
proposal_iterator->destroy(proposal_iterator);
if (status != SUCCESS)
{
@@ -220,7 +221,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name)
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
- global_send_queue->add(global_send_queue, packet);
+ charon->send_queue->add(charon->send_queue, packet);
/* state can now be changed */
this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
diff --git a/Source/charon/sa/states/responder_init.c b/Source/charon/sa/states/responder_init.c
index b528be0e2..ae906fc39 100644
--- a/Source/charon/sa/states/responder_init.c
+++ b/Source/charon/sa/states/responder_init.c
@@ -22,7 +22,7 @@
#include "responder_init.h"
-#include <globals.h>
+#include <daemon.h>
#include <sa/states/state.h>
#include <sa/states/ike_sa_init_responded.h>
#include <utils/allocator.h>
@@ -204,7 +204,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
suggested_proposals = sa_payload->create_proposal_substructure_iterator(sa_payload, TRUE);
/* now let the configuration-manager select a subset of the proposals */
- status = global_configuration_manager->select_proposals_for_host(global_configuration_manager,
+ status = charon->configuration_manager->select_proposals_for_host(charon->configuration_manager,
this->ike_sa->get_other_host(this->ike_sa), suggested_proposals, accepted_proposals);
if (status != SUCCESS)
{
@@ -253,7 +253,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
group = ke_payload->get_dh_group_number(ke_payload);
- status = global_configuration_manager->is_dh_group_allowed_for_host(global_configuration_manager,
+ status = charon->configuration_manager->is_dh_group_allowed_for_host(charon->configuration_manager,
this->ike_sa->get_other_host(this->ike_sa), group, &allowed_group);
if (status != SUCCESS)
@@ -353,7 +353,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
- global_send_queue->add(global_send_queue, packet);
+ charon->send_queue->add(charon->send_queue, packet);
/* state can now be changed */
this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
diff --git a/Source/charon/testcases/aes_cbc_crypter_test.c b/Source/charon/testcases/aes_cbc_crypter_test.c
index 1ffbd40f8..217448c2d 100644
--- a/Source/charon/testcases/aes_cbc_crypter_test.c
+++ b/Source/charon/testcases/aes_cbc_crypter_test.c
@@ -25,7 +25,7 @@
#include "aes_cbc_crypter_test.h"
#include <utils/allocator.h>
-#include <globals.h>
+#include <daemon.h>
void test_aes_cbc_crypter(tester_t *tester)
{
@@ -53,7 +53,7 @@ void test_aes_cbc_crypter(tester_t *tester)
chunk_t decrypted1;
logger_t *logger;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"AES CBC");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"AES CBC");
crypter = (crypter_t *) aes_cbc_crypter_create(16);
tester->assert_true(tester, (crypter != NULL), "create call test");
@@ -199,6 +199,6 @@ void test_aes_cbc_crypter(tester_t *tester)
crypter->destroy(crypter);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
diff --git a/Source/charon/testcases/diffie_hellman_test.c b/Source/charon/testcases/diffie_hellman_test.c
index d69a089f8..b4727f727 100644
--- a/Source/charon/testcases/diffie_hellman_test.c
+++ b/Source/charon/testcases/diffie_hellman_test.c
@@ -24,7 +24,7 @@
#include "../transforms/diffie_hellman.h"
-#include <globals.h>
+#include <daemon.h>
#include <utils/logger_manager.h>
#include <utils/allocator.h>
#include <encoding/payloads/transform_substructure.h>
@@ -39,7 +39,7 @@ void test_diffie_hellman(tester_t *tester)
chunk_t my_public_value, other_public_value;
chunk_t my_secret, other_secret;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Diffie Hellman");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Diffie Hellman");
my_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
@@ -73,5 +73,5 @@ void test_diffie_hellman(tester_t *tester)
my_diffie_hellman->destroy(my_diffie_hellman);
other_diffie_hellman->destroy(other_diffie_hellman);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
diff --git a/Source/charon/testcases/generator_test.c b/Source/charon/testcases/generator_test.c
index 636ffb224..b3faa9966 100644
--- a/Source/charon/testcases/generator_test.c
+++ b/Source/charon/testcases/generator_test.c
@@ -24,7 +24,7 @@
#include "generator_test.h"
-#include <globals.h>
+#include <daemon.h>
#include <encoding/generator.h>
#include <utils/allocator.h>
#include <utils/logger_manager.h>
@@ -50,7 +50,7 @@ void test_generator_with_header_payload(tester_t *tester)
chunk_t generated_data;
logger_t *logger;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"header payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"header payload");
header_data = ike_header_create();
header_data->set_initiator_spi(header_data,1);
@@ -121,7 +121,7 @@ void test_generator_with_header_payload(tester_t *tester)
header_data->destroy(header_data);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
generator->destroy(generator);
}
@@ -135,7 +135,7 @@ void test_generator_with_transform_attribute(tester_t *tester)
chunk_t generated_data;
logger_t *logger;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"transform_attribute payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"transform_attribute payload");
/* test empty attribute */
@@ -216,7 +216,7 @@ void test_generator_with_transform_attribute(tester_t *tester)
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -233,7 +233,7 @@ void test_generator_with_transform_substructure(tester_t *tester)
chunk_t generated_data;
logger_t *logger;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"transform substr.");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"transform substr.");
/* create generator */
generator = generator_create();
@@ -287,7 +287,7 @@ void test_generator_with_transform_substructure(tester_t *tester)
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -304,7 +304,7 @@ void test_generator_with_proposal_substructure(tester_t *tester)
chunk_t generated_data;
logger_t *logger;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"transform substr.");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"transform substr.");
/* create generator */
generator = generator_create();
@@ -403,7 +403,7 @@ void test_generator_with_proposal_substructure(tester_t *tester)
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
/*
@@ -422,7 +422,7 @@ void test_generator_with_sa_payload(tester_t *tester)
chunk_t generated_data;
logger_t *logger;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with SA Payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with SA Payload");
/* create generator */
generator = generator_create();
@@ -559,7 +559,7 @@ void test_generator_with_sa_payload(tester_t *tester)
sa_payload->destroy(sa_payload);
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -574,7 +574,7 @@ void test_generator_with_ke_payload(tester_t *tester)
chunk_t generated_data;
chunk_t key_exchange_data;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with KE Payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with KE Payload");
/* create generator */
generator = generator_create();
@@ -614,7 +614,7 @@ void test_generator_with_ke_payload(tester_t *tester)
ke_payload->destroy(ke_payload);
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -629,7 +629,7 @@ void test_generator_with_notify_payload(tester_t *tester)
chunk_t generated_data;
chunk_t spi,notification_data;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with Notify Payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with Notify Payload");
/* create generator */
generator = generator_create();
@@ -674,7 +674,7 @@ void test_generator_with_notify_payload(tester_t *tester)
notify_payload->destroy(notify_payload);
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -689,7 +689,7 @@ void test_generator_with_nonce_payload(tester_t *tester)
chunk_t generated_data;
chunk_t nonce;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with Nonce Payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with Nonce Payload");
/* create generator */
generator = generator_create();
@@ -728,7 +728,7 @@ void test_generator_with_nonce_payload(tester_t *tester)
nonce_payload->destroy(nonce_payload);
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -743,7 +743,7 @@ void test_generator_with_id_payload(tester_t *tester)
chunk_t generated_data;
chunk_t id;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with ID Payload");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with ID Payload");
/* create generator */
generator = generator_create();
@@ -782,7 +782,6 @@ void test_generator_with_id_payload(tester_t *tester)
id_payload->destroy(id_payload);
generator->destroy(generator);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
-
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
diff --git a/Source/charon/testcases/hmac_signer_test.c b/Source/charon/testcases/hmac_signer_test.c
index 08e989f01..a453fe6fd 100644
--- a/Source/charon/testcases/hmac_signer_test.c
+++ b/Source/charon/testcases/hmac_signer_test.c
@@ -27,7 +27,7 @@
#include <transforms/signers/signer.h>
#include <utils/allocator.h>
-#include <globals.h>
+#include <daemon.h>
/*
@@ -56,7 +56,7 @@ void test_hmac_md5_signer(tester_t *tester)
logger_t *logger;
bool valid;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"HMAC MD5 96");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"HMAC MD5 96");
signer_t *signer = (signer_t *) signer_create(AUTH_HMAC_MD5_96);
tester->assert_true(tester, (signer != NULL), "signer create call check");
@@ -109,7 +109,7 @@ void test_hmac_md5_signer(tester_t *tester)
signer->destroy(signer);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
@@ -138,7 +138,7 @@ void test_hmac_sha1_signer(tester_t *tester)
logger_t *logger;
bool valid;
- logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"HMAC SHA1 96");
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"HMAC SHA1 96");
signer_t *signer = (signer_t *) signer_create(AUTH_HMAC_SHA1_96);
tester->assert_true(tester, (signer != NULL), "signer create call check");
@@ -205,6 +205,6 @@ void test_hmac_sha1_signer(tester_t *tester)
}
signer->destroy(signer);
- global_logger_manager->destroy_logger(global_logger_manager,logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
diff --git a/Source/charon/testcases/packet_test.c b/Source/charon/testcases/packet_test.c
index 28a90be58..f933362af 100644
--- a/Source/charon/testcases/packet_test.c
+++ b/Source/charon/testcases/packet_test.c
@@ -24,7 +24,7 @@
#include "packet_test.h"
-#include <globals.h>
+#include <daemon.h>
#include <network/packet.h>
#include <utils/allocator.h>
#include <utils/logger_manager.h>
diff --git a/Source/charon/testcases/parser_test.c b/Source/charon/testcases/parser_test.c
index ae12c5720..928d96959 100644
--- a/Source/charon/testcases/parser_test.c
+++ b/Source/charon/testcases/parser_test.c
@@ -37,8 +37,6 @@
#include <encoding/payloads/notify_payload.h>
-extern logger_manager_t *global_logger_manager;
-
/*
* Described in Header
diff --git a/Source/charon/testcases/receiver_test.c b/Source/charon/testcases/receiver_test.c
index af3265096..b308193de 100644
--- a/Source/charon/testcases/receiver_test.c
+++ b/Source/charon/testcases/receiver_test.c
@@ -25,7 +25,7 @@
#include "receiver_test.h"
-#include <globals.h>
+#include <daemon.h>
#include <threads/receiver.h>
#include <network/packet.h>
#include <network/socket.h>
@@ -66,13 +66,13 @@ void test_receiver(tester_t *tester)
packet->data.ptr = allocator_alloc_thing(int);
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
- global_socket->send(global_socket,packet);
+ charon->socket->send(charon->socket,packet);
packet->destroy(packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
- job = global_job_queue->get(global_job_queue);
+ job = charon->job_queue->get(charon->job_queue);
tester->assert_true(tester, (job->get_type(job) == INCOMING_PACKET), "job type check");
received_packet = ((incoming_packet_job_t *)(job))->get_packet((incoming_packet_job_t *)(job));
diff --git a/Source/charon/testcases/scheduler_test.c b/Source/charon/testcases/scheduler_test.c
index e8ba827f4..a34527c8a 100644
--- a/Source/charon/testcases/scheduler_test.c
+++ b/Source/charon/testcases/scheduler_test.c
@@ -25,7 +25,7 @@
#include "scheduler_test.h"
-#include <globals.h>
+#include <daemon.h>
#include <threads/scheduler.h>
#include <queues/event_queue.h>
#include <queues/job_queue.h>
@@ -50,7 +50,7 @@ void test_scheduler(tester_t *tester)
{
/* misusing for testing only */
jobs[current] = (job_t *) incoming_packet_job_create((packet_t*)(current+1));
- global_event_queue->add_relative(global_event_queue, jobs[current], (current+1) * 500);
+ charon->event_queue->add_relative(charon->event_queue, jobs[current], (current+1) * 500);
}
@@ -66,18 +66,18 @@ void test_scheduler(tester_t *tester)
{
usleep(400 * 1000);
- tester->assert_true(tester, (global_job_queue->get_count(global_job_queue) == current ), "job-queue size before event");
- tester->assert_true(tester, (global_event_queue->get_count(global_event_queue) == job_count - current), "event-queue size before event");
+ tester->assert_true(tester, (charon->job_queue->get_count(charon->job_queue) == current ), "job-queue size before event");
+ tester->assert_true(tester, (charon->event_queue->get_count(charon->event_queue) == job_count - current), "event-queue size before event");
usleep(100 * 1000);
- tester->assert_true(tester, (global_job_queue->get_count(global_job_queue) == current + 1), "job-queue size after event");
- tester->assert_true(tester, (global_event_queue->get_count(global_event_queue) == job_count - current - 1), "event-queue size after event");
+ tester->assert_true(tester, (charon->job_queue->get_count(charon->job_queue) == current + 1), "job-queue size after event");
+ tester->assert_true(tester, (charon->event_queue->get_count(charon->event_queue) == job_count - current - 1), "event-queue size after event");
}
/* check job order */
for (current = 0; current < job_count; current++)
{
- jobs[current] = global_job_queue->get(global_job_queue);
+ jobs[current] = charon->job_queue->get(charon->job_queue);
incoming_packet_job_t *current_job;
current_job = (incoming_packet_job_t*) jobs[current];
packet_t *packet;
diff --git a/Source/charon/testcases/sender_test.c b/Source/charon/testcases/sender_test.c
index d00bc5320..0fc7b931a 100644
--- a/Source/charon/testcases/sender_test.c
+++ b/Source/charon/testcases/sender_test.c
@@ -24,7 +24,7 @@
#include "sender_test.h"
-#include <globals.h>
+#include <daemon.h>
#include <threads/sender.h>
#include <network/packet.h>
#include <network/socket.h>
@@ -62,12 +62,12 @@ void test_sender(tester_t *tester)
packet->data.ptr = allocator_alloc_thing(int);
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
- global_send_queue->add(global_send_queue,packet);
+ charon->send_queue->add(charon->send_queue,packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
- global_socket->receive(global_socket,&received_packet);
+ charon->socket->receive(charon->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);
diff --git a/Source/charon/testcases/testcases.c b/Source/charon/testcases/testcases.c
index 2a41f469d..9d5b2e00d 100644
--- a/Source/charon/testcases/testcases.c
+++ b/Source/charon/testcases/testcases.c
@@ -23,6 +23,8 @@
#include <stdio.h>
+#include <daemon.h>
+
#include <queues/job_queue.h>
#include <queues/event_queue.h>
#include <queues/send_queue.h>
@@ -98,47 +100,53 @@ test_t hmac_signer_test1 = {test_hmac_md5_signer, "HMAC MD5 signer test"};
test_t hmac_signer_test2 = {test_hmac_sha1_signer, "HMAC SHA1 signer test"};
-/**
- * Global job-queue
- */
-job_queue_t *global_job_queue;
-
-/**
- * Global event-queue
- */
-event_queue_t *global_event_queue;
-
-/**
- * Global send-queue
- */
-send_queue_t *global_send_queue;
+daemon_t* charon;
-/**
- * Global configuration_manager
- */
-configuration_manager_t *global_configuration_manager;
+static void daemon_destroy(daemon_t *this, char* none)
+{
+ this->logger_manager->destroy(this->logger_manager);
+ this->socket->destroy(this->socket);
+ this->ike_sa_manager->destroy(this->ike_sa_manager);
+ this->job_queue->destroy(this->job_queue);
+ this->event_queue->destroy(this->event_queue);
+ this->send_queue->destroy(this->send_queue);
+ this->configuration_manager->destroy(this->configuration_manager);
+ allocator_free(charon);
+}
/**
- * Global configuration_manager
+ * @brief Create the dummy daemon for testing.
+ *
+ * @return created daemon_t
*/
-ike_sa_manager_t *global_ike_sa_manager;
-
- /**
- * Global socket
- */
-socket_t *global_socket;
+daemon_t *daemon_create()
+{
+ charon = allocator_alloc_thing(daemon_t);
+
+ /* assign methods */
+ charon->destroy = daemon_destroy;
+
+ charon->logger_manager = logger_manager_create(0);
+ charon->socket = socket_create(4600);
+ charon->ike_sa_manager = ike_sa_manager_create();
+ charon->job_queue = job_queue_create();
+ charon->event_queue = event_queue_create();
+ charon->send_queue = send_queue_create();
+ charon->configuration_manager = configuration_manager_create();
+ charon->sender = NULL;
+ charon->receiver = NULL;
+ charon->scheduler = NULL;
+ charon->thread_pool = NULL;
+
+ return charon;
+}
-/**
- * Global logger
- */
-logger_manager_t *global_logger_manager;
-
- int main()
+int main()
{
- FILE * test_output = stderr;
-
- test_t *all_tests[] ={
+ FILE * test_output = stderr;
+
+ test_t *all_tests[] ={
&linked_list_test,
&iterator_test,
&linked_list_insert_and_remove_test,
@@ -180,42 +188,22 @@ logger_manager_t *global_logger_manager;
&hmac_signer_test2,
NULL
};
- global_logger_manager = logger_manager_create(0);
-
- global_socket = socket_create(4600);
-
- global_job_queue = job_queue_create();
- global_event_queue = event_queue_create();
- global_send_queue = send_queue_create();
- global_configuration_manager = configuration_manager_create();
- global_ike_sa_manager = ike_sa_manager_create();
-
- global_logger_manager->disable_logger_level(global_logger_manager,TESTER,FULL);
- //global_logger_manager->enable_logger_level(global_logger_manager,TESTER,RAW);
-
- tester_t *tester = tester_create(test_output, FALSE);
-
-
+
+ daemon_create();
+
+ charon->logger_manager->disable_logger_level(charon->logger_manager,TESTER,FULL);
+ //charon->logger_manager->enable_logger_level(charon->logger_manager,TESTER,RAW);
+
+ tester_t *tester = tester_create(test_output, FALSE);
+
+
tester->perform_tests(tester,all_tests);
//tester->perform_test(tester,&generator_test9);
-
-
-
- tester->destroy(tester);
-
-
- /* Destroy objects*/
- global_configuration_manager->destroy(global_configuration_manager);
- global_ike_sa_manager->destroy(global_ike_sa_manager);
- /* Destroy all queues */
- global_job_queue->destroy(global_job_queue);
- global_event_queue->destroy(global_event_queue);
- global_send_queue->destroy(global_send_queue);
- global_socket->destroy(global_socket);
+ tester->destroy(tester);
- global_logger_manager->destroy(global_logger_manager);
+ charon->destroy(charon, NULL);
#ifdef LEAK_DETECTIVE
/* Leaks are reported on stderr */
diff --git a/Source/charon/threads/receiver.c b/Source/charon/threads/receiver.c
index e2fb192db..e02fd89e1 100644
--- a/Source/charon/threads/receiver.c
+++ b/Source/charon/threads/receiver.c
@@ -26,7 +26,7 @@
#include "receiver.h"
-#include <globals.h>
+#include <daemon.h>
#include <network/socket.h>
#include <network/packet.h>
#include <queues/job_queue.h>
@@ -78,12 +78,12 @@ static void receive_packets(private_receiver_t * this)
while (1)
{
- while (global_socket->receive(global_socket,&current_packet) == SUCCESS)
+ while (charon->socket->receive(charon->socket,&current_packet) == SUCCESS)
{
this->logger->log(this->logger, CONTROL, "creating job from packet");
current_job = (job_t *) incoming_packet_job_create(current_packet);
- global_job_queue->add(global_job_queue,current_job);
+ charon->job_queue->add(charon->job_queue,current_job);
}
/* bad bad, rebuild the socket ? */
@@ -102,7 +102,7 @@ static void destroy(private_receiver_t *this)
pthread_join(this->assigned_thread, NULL);
this->logger->log(this->logger, CONTROL | MORE, "Receiver thread terminated");
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -117,12 +117,12 @@ receiver_t * receiver_create()
this->public.destroy = (void(*)(receiver_t*)) destroy;
this->receive_packets = receive_packets;
- this->logger = global_logger_manager->create_logger(global_logger_manager, RECEIVER, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, RECEIVER, NULL);
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->receive_packets, this) != 0)
{
this->logger->log(this->logger, ERROR, "Receiver thread could not be started");
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
return NULL;
}
diff --git a/Source/charon/threads/scheduler.c b/Source/charon/threads/scheduler.c
index cc051e702..50271eb62 100644
--- a/Source/charon/threads/scheduler.c
+++ b/Source/charon/threads/scheduler.c
@@ -26,7 +26,7 @@
#include "scheduler.h"
-#include <globals.h>
+#include <daemon.h>
#include <definitions.h>
#include <utils/allocator.h>
#include <utils/logger_manager.h>
@@ -79,9 +79,9 @@ static void get_events(private_scheduler_t * this)
{
this->logger->log(this->logger, CONTROL|MORE, "waiting for next event...");
/* get a job, this block until one is available */
- current_job = global_event_queue->get(global_event_queue);
+ current_job = charon->event_queue->get(charon->event_queue);
/* queue the job in the job queue, workers will eat them */
- global_job_queue->add(global_job_queue, current_job);
+ charon->job_queue->add(charon->job_queue, current_job);
this->logger->log(this->logger, CONTROL, "got event, added job %s to job-queue.",
mapping_find(job_type_m, current_job->get_type(current_job)));
}
@@ -98,7 +98,7 @@ static void destroy(private_scheduler_t *this)
pthread_join(this->assigned_thread, NULL);
this->logger->log(this->logger, CONTROL | MORE, "Scheduler thread terminated");
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -111,13 +111,13 @@ scheduler_t * scheduler_create()
this->public.destroy = (void(*)(scheduler_t*)) destroy;
this->get_events = get_events;
- this->logger = global_logger_manager->create_logger(global_logger_manager, SCHEDULER, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, SCHEDULER, NULL);
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->get_events, this) != 0)
{
/* thread could not be created */
this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
return NULL;
}
diff --git a/Source/charon/threads/sender.c b/Source/charon/threads/sender.c
index bdd7ccf58..7c7180ad8 100644
--- a/Source/charon/threads/sender.c
+++ b/Source/charon/threads/sender.c
@@ -26,7 +26,7 @@
#include "sender.h"
-#include <globals.h>
+#include <daemon.h>
#include <network/socket.h>
#include <network/packet.h>
#include <queues/send_queue.h>
@@ -78,9 +78,9 @@ static void send_packets(private_sender_t * this)
while (1)
{
- current_packet = global_send_queue->get(global_send_queue);
+ current_packet = charon->send_queue->get(charon->send_queue);
this->logger->log(this->logger, CONTROL|MORE, "got a packet, sending it");
- status = global_socket->send(global_socket,current_packet);
+ status = charon->socket->send(charon->socket,current_packet);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "sending failed, socket returned %s",
@@ -101,7 +101,7 @@ static void destroy(private_sender_t *this)
pthread_join(this->assigned_thread, NULL);
this->logger->log(this->logger, CONTROL | MORE, "Sender thread terminated");
- global_logger_manager->destroy_logger(global_logger_manager, this->logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
allocator_free(this);
}
@@ -116,7 +116,7 @@ sender_t * sender_create()
this->send_packets = send_packets;
this->public.destroy = (void(*)(sender_t*)) destroy;
- this->logger = global_logger_manager->create_logger(global_logger_manager, SENDER, NULL);
+ this->logger = charon->logger_manager->create_logger(charon->logger_manager, SENDER, NULL);
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->send_packets, this) != 0)
{
diff --git a/Source/charon/threads/thread_pool.c b/Source/charon/threads/thread_pool.c
index 58310ebc5..0157e2af3 100644
--- a/Source/charon/threads/thread_pool.c
+++ b/Source/charon/threads/thread_pool.c
@@ -28,7 +28,7 @@
#include "thread_pool.h"
-#include <globals.h>
+#include <daemon.h>
#include <queues/job_queue.h>
#include <queues/jobs/delete_ike_sa_job.h>
#include <queues/jobs/incoming_packet_job.h>
@@ -115,7 +115,7 @@ static void process_jobs(private_thread_pool_t *this)
job_t *job;
job_type_t job_type;
- job = global_job_queue->get(global_job_queue);
+ job = charon->job_queue->get(charon->job_queue);
job_type = job->get_type(job);
this->worker_logger->log(this->worker_logger, CONTROL|MORE, "got a job of type %s",
mapping_find(job_type_m,job_type));
@@ -194,7 +194,7 @@ static void process_incoming_packet_job(private_thread_pool_t *this, incoming_pa
ike_sa_id->get_responder_spi(ike_sa_id),
ike_sa_id->is_initiator(ike_sa_id) ? "initiator" : "responder");
- status = global_ike_sa_manager->checkout(global_ike_sa_manager,ike_sa_id, &ike_sa);
+ status = charon->ike_sa_manager->checkout(charon->ike_sa_manager,ike_sa_id, &ike_sa);
if (status != SUCCESS)
{
this->worker_logger->log(this->worker_logger, ERROR, "IKE SA could not be checked out");
@@ -215,7 +215,7 @@ static void process_incoming_packet_job(private_thread_pool_t *this, incoming_pa
ike_sa_id->is_initiator(ike_sa_id) ? "initiator" : "responder");
ike_sa_id->destroy(ike_sa_id);
- status = global_ike_sa_manager->checkin(global_ike_sa_manager, ike_sa);
+ status = charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
if (status != SUCCESS)
{
this->worker_logger->log(this->worker_logger, ERROR, "checkin of IKE SA failed");
@@ -240,7 +240,7 @@ static void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ik
this->worker_logger->log(this->worker_logger, CONTROL|MOST, "create and checking out IKE SA");
- global_ike_sa_manager->create_and_checkout(global_ike_sa_manager, &ike_sa);
+ charon->ike_sa_manager->create_and_checkout(charon->ike_sa_manager, &ike_sa);
this->worker_logger->log(this->worker_logger, CONTROL|MOST, "initializing connection \"%s\"",
job->get_configuration_name(job));
@@ -249,12 +249,12 @@ static void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ik
{
this->worker_logger->log(this->worker_logger, ERROR, "%s by initialize_conection, job and rejected, IKE_SA deleted.",
mapping_find(status_m, status));
- global_ike_sa_manager->checkin_and_delete(global_ike_sa_manager, ike_sa);
+ charon->ike_sa_manager->checkin_and_delete(charon->ike_sa_manager, ike_sa);
return;
}
this->worker_logger->log(this->worker_logger, CONTROL|MOST, "checking in IKE SA");
- status = global_ike_sa_manager->checkin(global_ike_sa_manager, ike_sa);
+ status = charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
if (status != SUCCESS)
{
this->worker_logger->log(this->worker_logger, ERROR, "%s could not checkin IKE_SA.",
@@ -275,7 +275,7 @@ static void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa
ike_sa_id->get_responder_spi(ike_sa_id),
ike_sa_id->is_initiator(ike_sa_id) ? "initiator" : "responder");
- status = global_ike_sa_manager->delete(global_ike_sa_manager, ike_sa_id);
+ status = charon->ike_sa_manager->delete(charon->ike_sa_manager, ike_sa_id);
if (status != SUCCESS)
{
this->worker_logger->log(this->worker_logger, ERROR, "could not delete IKE_SA (%s)",
@@ -311,8 +311,8 @@ static void destroy(private_thread_pool_t *this)
}
/* free mem */
- global_logger_manager->destroy_logger(global_logger_manager, this->pool_logger);
- global_logger_manager->destroy_logger(global_logger_manager, this->worker_logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->pool_logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->worker_logger);
allocator_free(this->threads);
allocator_free(this);
}
@@ -338,9 +338,9 @@ thread_pool_t *thread_pool_create(size_t pool_size)
this->threads = allocator_alloc(sizeof(pthread_t) * pool_size);
- this->pool_logger = global_logger_manager->create_logger(global_logger_manager,THREAD_POOL,NULL);
+ this->pool_logger = charon->logger_manager->create_logger(charon->logger_manager,THREAD_POOL,NULL);
- this->worker_logger = global_logger_manager->create_logger(global_logger_manager,WORKER,NULL);
+ this->worker_logger = charon->logger_manager->create_logger(charon->logger_manager,WORKER,NULL);
/* try to create as many threads as possible, up tu pool_size */
for (current = 0; current < pool_size; current++)
@@ -355,8 +355,8 @@ thread_pool_t *thread_pool_create(size_t pool_size)
if (current == 0)
{
this->pool_logger->log(this->pool_logger, ERROR, "could not create any thread");
- global_logger_manager->destroy_logger(global_logger_manager, this->pool_logger);
- global_logger_manager->destroy_logger(global_logger_manager, this->worker_logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->pool_logger);
+ charon->logger_manager->destroy_logger(charon->logger_manager, this->worker_logger);
allocator_free(this->threads);
allocator_free(this);
return NULL;