- split up in libstrong, charon, stroke, testing done
authorMartin Willi <martin@strongswan.org>
Mon, 10 Apr 2006 08:07:38 +0000 (08:07 -0000)
committerMartin Willi <martin@strongswan.org>
Mon, 10 Apr 2006 08:07:38 +0000 (08:07 -0000)
- new leak detective with malloc hook in library
  - useable, but needs improvements
- logger_manager has now a single instance per library
  - allows use of loggers from any linking prog
- a LOT of other things

116 files changed:
Source/Makefile
Source/charon/config/configuration.c
Source/charon/config/connection.c
Source/charon/config/policy.c
Source/charon/config/proposal.c
Source/charon/config/traffic_selector.c
Source/charon/daemon.c
Source/charon/daemon.h
Source/charon/encoding/generator.c
Source/charon/encoding/message.c
Source/charon/encoding/parser.c
Source/charon/encoding/payloads/auth_payload.c
Source/charon/encoding/payloads/cert_payload.c
Source/charon/encoding/payloads/certreq_payload.c
Source/charon/encoding/payloads/configuration_attribute.c
Source/charon/encoding/payloads/cp_payload.c
Source/charon/encoding/payloads/delete_payload.c
Source/charon/encoding/payloads/eap_payload.c
Source/charon/encoding/payloads/encryption_payload.c
Source/charon/encoding/payloads/id_payload.c
Source/charon/encoding/payloads/ike_header.c
Source/charon/encoding/payloads/ke_payload.c
Source/charon/encoding/payloads/nonce_payload.c
Source/charon/encoding/payloads/notify_payload.c
Source/charon/encoding/payloads/proposal_substructure.c
Source/charon/encoding/payloads/sa_payload.c
Source/charon/encoding/payloads/traffic_selector_substructure.c
Source/charon/encoding/payloads/transform_attribute.c
Source/charon/encoding/payloads/transform_substructure.c
Source/charon/encoding/payloads/ts_payload.c
Source/charon/encoding/payloads/unknown_payload.c
Source/charon/encoding/payloads/vendor_id_payload.c
Source/charon/network/packet.c
Source/charon/network/socket.c
Source/charon/queues/event_queue.c
Source/charon/queues/job_queue.c
Source/charon/queues/jobs/delete_established_ike_sa_job.c
Source/charon/queues/jobs/delete_half_open_ike_sa_job.c
Source/charon/queues/jobs/incoming_packet_job.c
Source/charon/queues/jobs/initiate_ike_sa_job.c
Source/charon/queues/jobs/retransmit_request_job.c
Source/charon/queues/send_queue.c
Source/charon/sa/authenticator.c
Source/charon/sa/child_sa.c
Source/charon/sa/ike_sa.c
Source/charon/sa/ike_sa_id.c
Source/charon/sa/ike_sa_manager.c
Source/charon/sa/states/ike_auth_requested.c
Source/charon/sa/states/ike_sa_established.c
Source/charon/sa/states/ike_sa_init_requested.c
Source/charon/sa/states/ike_sa_init_responded.c
Source/charon/sa/states/initiator_init.c
Source/charon/sa/states/responder_init.c
Source/charon/threads/kernel_interface.c
Source/charon/threads/receiver.c
Source/charon/threads/scheduler.c
Source/charon/threads/sender.c
Source/charon/threads/stroke_interface.c
Source/charon/threads/thread_pool.c
Source/lib/asn1/der_decoder.c
Source/lib/asn1/der_encoder.c
Source/lib/crypto/certificate.c
Source/lib/crypto/crypters/aes_cbc_crypter.c
Source/lib/crypto/diffie_hellman.c
Source/lib/crypto/hashers/md5_hasher.c
Source/lib/crypto/hashers/sha1_hasher.c
Source/lib/crypto/hmac.c
Source/lib/crypto/prf_plus.c
Source/lib/crypto/prfs/hmac_prf.c
Source/lib/crypto/rsa/rsa_private_key.c
Source/lib/crypto/rsa/rsa_public_key.c
Source/lib/crypto/signers/hmac_signer.c
Source/lib/definitions.h
Source/lib/types.c
Source/lib/types.h
Source/lib/utils/Makefile.utils
Source/lib/utils/allocator.c [deleted file]
Source/lib/utils/allocator.h [deleted file]
Source/lib/utils/host.c
Source/lib/utils/identification.c
Source/lib/utils/leak_detective.c [new file with mode: 0644]
Source/lib/utils/leak_detective.h [new file with mode: 0644]
Source/lib/utils/linked_list.c
Source/lib/utils/logger.c
Source/lib/utils/logger.h
Source/lib/utils/logger_manager.c
Source/lib/utils/logger_manager.h
Source/lib/utils/randomizer.c
Source/lib/utils/tester.c
Source/testing/Makefile.testcases
Source/testing/aes_cbc_crypter_test.c
Source/testing/certificate_test.c
Source/testing/child_sa_test.c
Source/testing/connection_test.c
Source/testing/der_decoder_test.c
Source/testing/diffie_hellman_test.c
Source/testing/encryption_payload_test.c
Source/testing/event_queue_test.c
Source/testing/generator_test.c
Source/testing/hasher_test.c
Source/testing/hmac_signer_test.c
Source/testing/hmac_test.c
Source/testing/job_queue_test.c
Source/testing/kernel_interface_test.c
Source/testing/leak_detective_test.c [new file with mode: 0644]
Source/testing/leak_detective_test.h [new file with mode: 0644]
Source/testing/packet_test.c
Source/testing/parser_test.c
Source/testing/policy_test.c
Source/testing/prf_plus_test.c
Source/testing/proposal_test.c
Source/testing/receiver_test.c
Source/testing/rsa_test.c
Source/testing/sender_test.c
Source/testing/socket_test.c
Source/testing/testcases.c

index 7a1f865..b202bcb 100644 (file)
@@ -27,9 +27,9 @@ BINNAMELIB=  $(BUILD_DIR)libstrong.so
 
 MAIN_DIR= ./
 
-LDFLAGS= -lgmp -lpthread 
+LDFLAGS= -ldl -lgmp -lpthread -rdynamic
 
-CFLAGS= -Icharon -Ilib -Istroke -Wall -g -fPIC -DLEAK_DETECTIVE 
+CFLAGS= -Icharon -Ilib -Istroke -Wall -g -fPIC -fomit-frame-pointer -DLEAK_DETECTIVE 
 
 # objects is extended by each included Makefile
 CHARON_OBJS=
@@ -58,13 +58,13 @@ build_dir:
                                                        mkdir -p $(BUILD_DIR)
                                                        
 $(BINNAMELIB) :                                build_dir $(LIB_OBJS)
-                                                       $(CC) -shared $(LIB_OBJS) $(LDFLAGS) -o $@
+                                                       $(CC) -shared $(LIB_OBJS) -o $@
 
 $(BINNAMECHARON) :                     build_dir $(CHARON_OBJS) $(BINNAMELIB) $(BUILD_DIR)daemon.o
-                                                       $(CC) $(LDFLAGS) -L./bin -lstrong $(CHARON_OBJS) $(BUILD_DIR)daemon.o -o $@
+                                                       $(CC) -ldl -lgmp -rdynamic -L./bin -lstrong -lpthread $(CHARON_OBJS) $(BUILD_DIR)daemon.o -o $@
 
 $(BINNAMETEST) :                       build_dir $(CHARON_OBJS) $(TEST_OBJS) $(BINNAMELIB) $(BUILD_DIR)testcases.o
-                                                       $(CC) $(LDFLAGS) -L./bin -lstrong $(CHARON_OBJS) $(TEST_OBJS) $(BUILD_DIR)testcases.o -o $@
+                                                       $(CC) -L./bin -lstrong  $(LDFLAGS) $(CHARON_OBJS) $(TEST_OBJS) $(BUILD_DIR)testcases.o -o $@
 
 $(BINNAMESTROKE) :                     build_dir $(BINNAMELIB) $(BUILD_DIR)stroke.o
                                                        $(CC) $(LDFLAGS) $(CFLAGS) $(BUILD_DIR)stroke.o -o $@
index 692fdd0..eac1bd4 100755 (executable)
@@ -25,7 +25,6 @@
 #include "configuration.h"
 
 #include <types.h>
-#include <utils/allocator.h>
 
 /**
  * First retransmit timeout in milliseconds.
@@ -94,7 +93,7 @@ static u_int32_t get_half_open_ike_sa_timeout (private_configuration_t *this)
  */
 static void destroy(private_configuration_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -102,7 +101,7 @@ static void destroy(private_configuration_t *this)
  */
 configuration_t *configuration_create()
 {
-       private_configuration_t *this = allocator_alloc_thing(private_configuration_t);
+       private_configuration_t *this = malloc_thing(private_configuration_t);
        
        /* public functions */
        this->public.destroy = (void(*)(configuration_t*))destroy;
index 24f16a0..d2e50c7 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "connection.h"
 
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 #include <utils/logger.h>
 
@@ -290,7 +289,7 @@ static void destroy (private_connection_t *this)
        this->other_host->destroy(this->other_host);
        this->my_id->destroy(this->my_id);
        this->other_id->destroy(this->other_id);
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -298,7 +297,7 @@ static void destroy (private_connection_t *this)
  */
 connection_t * connection_create(host_t *my_host, host_t *other_host, identification_t *my_id, identification_t *other_id, auth_method_t auth_method)
 {
-       private_connection_t *this = allocator_alloc_thing(private_connection_t);
+       private_connection_t *this = malloc_thing(private_connection_t);
 
        /* public functions */
        this->public.get_my_id = (identification_t*(*)(connection_t*))get_my_id;
index fbdc46d..cff87fc 100644 (file)
@@ -23,7 +23,6 @@
 #include "policy.h"
 
 #include <utils/linked_list.h>
-#include <utils/allocator.h>
 #include <utils/identification.h>
 #include <utils/logger.h>
 
@@ -310,7 +309,7 @@ static status_t destroy(private_policy_t *this)
        this->my_id->destroy(this->my_id);
        this->other_id->destroy(this->other_id);
        
-       allocator_free(this);
+       free(this);
        return SUCCESS;
 }
 
@@ -363,7 +362,7 @@ static policy_t *clone(private_policy_t *this)
  */
 policy_t *policy_create(identification_t *my_id, identification_t *other_id)
 {
-       private_policy_t *this = allocator_alloc_thing(private_policy_t);
+       private_policy_t *this = malloc_thing(private_policy_t);
 
        /* public functions */
        this->public.get_my_id = (identification_t*(*)(policy_t*))get_my_id;
index 760d580..cb71a75 100644 (file)
  * for more details.
  */
 
+#include <string.h>
+
 #include "proposal.h"
 
 #include <utils/linked_list.h>
-#include <utils/allocator.h>
 #include <utils/identification.h>
 #include <utils/logger.h>
 
@@ -152,7 +153,7 @@ static protocol_proposal_t *get_protocol_proposal(private_proposal_t *this, prot
        if (!proto_proposal && create)
        {
                /* nope, create a new one */
-               proto_proposal = allocator_alloc_thing(protocol_proposal_t);
+               proto_proposal = malloc_thing(protocol_proposal_t);
                proto_proposal->protocol = proto;
                proto_proposal->encryption_algos = linked_list_create();
                proto_proposal->integrity_algos = linked_list_create();
@@ -167,7 +168,7 @@ static protocol_proposal_t *get_protocol_proposal(private_proposal_t *this, prot
                {
                        proto_proposal->spi.len = 4;
                }
-               proto_proposal->spi.ptr = allocator_alloc(proto_proposal->spi.len);
+               proto_proposal->spi.ptr = malloc(proto_proposal->spi.len);
                /* add to the list */
                this->protocol_proposals->insert_last(this->protocol_proposals, (void*)proto_proposal);
        }
@@ -179,7 +180,7 @@ static protocol_proposal_t *get_protocol_proposal(private_proposal_t *this, prot
  */
 static void add_algo(linked_list_t *list, u_int8_t algo, size_t key_size)
 {
-       algorithm_t *algo_key = allocator_alloc_thing(algorithm_t);
+       algorithm_t *algo_key = malloc_thing(algorithm_t);
        
        algo_key->algorithm = algo;
        algo_key->key_size = key_size;
@@ -542,7 +543,7 @@ static void clone_algo_list(linked_list_t *list, linked_list_t *clone_list)
        while (iterator->has_next(iterator))
        {
                iterator->current(iterator, (void**)&algo);
-               clone_algo = allocator_alloc_thing(algorithm_t);
+               clone_algo = malloc_thing(algorithm_t);
                memcpy(clone_algo, algo, sizeof(algorithm_t));
                clone_list->insert_last(clone_list, (void*)clone_algo);
        }
@@ -586,7 +587,7 @@ static void free_algo_list(linked_list_t *list)
        while(list->get_count(list) > 0)
        {
                list->remove_last(list, (void**)&algo);
-               allocator_free(algo);
+               free(algo);
        }
        list->destroy(list);
 }
@@ -607,12 +608,12 @@ static void destroy(private_proposal_t *this)
                free_algo_list(proto_prop->dh_groups);
                free_algo_list(proto_prop->esns);
                
-               allocator_free(proto_prop->spi.ptr);
-               allocator_free(proto_prop);
+               free(proto_prop->spi.ptr);
+               free(proto_prop);
        }
        this->protocol_proposals->destroy(this->protocol_proposals);
        
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -620,7 +621,7 @@ static void destroy(private_proposal_t *this)
  */
 proposal_t *proposal_create(u_int8_t number)
 {
-       private_proposal_t *this = allocator_alloc_thing(private_proposal_t);
+       private_proposal_t *this = malloc_thing(private_proposal_t);
        
        this->public.add_algorithm = (void (*)(proposal_t*,protocol_id_t,transform_type_t,u_int16_t,size_t))add_algorithm;
        this->public.create_algorithm_iterator = (iterator_t* (*)(proposal_t*,protocol_id_t,transform_type_t))create_algorithm_iterator;
index 0b81931..8127265 100644 (file)
@@ -23,9 +23,9 @@
 #include "traffic_selector.h"
 
 #include <utils/linked_list.h>
-#include <utils/allocator.h>
 #include <utils/identification.h>
 #include <arpa/inet.h>
+#include <string.h>
 
 typedef struct private_traffic_selector_t private_traffic_selector_t;
 
@@ -133,7 +133,7 @@ static chunk_t get_from_address(private_traffic_selector_t *this)
                {
                        u_int32_t network;
                        from_addr.len = sizeof(network);
-                       from_addr.ptr = allocator_alloc(from_addr.len);
+                       from_addr.ptr = malloc(from_addr.len);
                        /* chunk must contain network order, convert! */
                        network = htonl(this->from_addr_ipv4);
                        memcpy(from_addr.ptr, &network, from_addr.len);
@@ -160,7 +160,7 @@ static chunk_t get_to_address(private_traffic_selector_t *this)
                {
                        u_int32_t network;
                        to_addr.len = sizeof(network);
-                       to_addr.ptr = allocator_alloc(to_addr.len);
+                       to_addr.ptr = malloc(to_addr.len);
                        /* chunk must contain network order, convert! */
                        network = htonl(this->to_addr_ipv4);
                        memcpy(to_addr.ptr, &network, to_addr.len);
@@ -248,7 +248,7 @@ static void update_address_range(private_traffic_selector_t *this, host_t *host)
                        chunk_t from = host->get_address_as_chunk(host);
                        this->from_addr_ipv4 = ntohl(*((u_int32_t*)from.ptr));
                        this->to_addr_ipv4 = this->from_addr_ipv4;
-                       allocator_free_chunk(&from);
+                       chunk_free(&from);
                }
        }
 }
@@ -271,7 +271,7 @@ static traffic_selector_t *clone(private_traffic_selector_t *this)
                case TS_IPV6_ADDR_RANGE:
                default:
                {
-                       allocator_free(this);
+                       free(this);
                        return NULL;    
                }
        }
@@ -282,7 +282,7 @@ static traffic_selector_t *clone(private_traffic_selector_t *this)
  */
 static void destroy(private_traffic_selector_t *this)
 {      
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -299,7 +299,7 @@ traffic_selector_t *traffic_selector_create_from_bytes(u_int8_t protocol, ts_typ
                {
                        if (from_addr.len != 4 || to_addr.len != 4)
                        {
-                               allocator_free(this);
+                               free(this);
                                return NULL;    
                        }
                        /* chunk contains network order, convert! */
@@ -310,7 +310,7 @@ traffic_selector_t *traffic_selector_create_from_bytes(u_int8_t protocol, ts_typ
                case TS_IPV6_ADDR_RANGE:
                default:
                {
-                       allocator_free(this);
+                       free(this);
                        return NULL;    
                }
        }
@@ -342,13 +342,13 @@ traffic_selector_t *traffic_selector_create_from_subnet(host_t *net, u_int8_t ne
                        {
                                this->to_addr_ipv4 = this->from_addr_ipv4 | ((1 << (32 - netbits)) - 1);
                        }
-                       allocator_free_chunk(&from);
+                       chunk_free(&from);
                        break;  
                }
                case AF_INET6:
                default:
                {
-                       allocator_free(this);
+                       free(this);
                        return NULL;    
                }
        }
@@ -373,12 +373,12 @@ traffic_selector_t *traffic_selector_create_from_string(u_int8_t protocol, ts_ty
                {
                        if (inet_aton(from_addr, (struct in_addr*)&(this->from_addr_ipv4)) == 0)
                        {
-                               allocator_free(this);
+                               free(this);
                                return NULL;
                        }
                        if (inet_aton(to_addr, (struct in_addr*)&(this->to_addr_ipv4)) == 0)
                        {
-                               allocator_free(this);
+                               free(this);
                                return NULL;
                        }
                        /* convert to host order, inet_aton has network order */
@@ -388,7 +388,7 @@ traffic_selector_t *traffic_selector_create_from_string(u_int8_t protocol, ts_ty
                }
                case TS_IPV6_ADDR_RANGE:
                {
-                       allocator_free(this);
+                       free(this);
                        return NULL;    
                }
        }
@@ -401,7 +401,7 @@ traffic_selector_t *traffic_selector_create_from_string(u_int8_t protocol, ts_ty
  */
 static private_traffic_selector_t *traffic_selector_create(u_int8_t protocol, ts_type_t type, u_int16_t from_port, u_int16_t to_port)
 {
-       private_traffic_selector_t *this = allocator_alloc_thing(private_traffic_selector_t);
+       private_traffic_selector_t *this = malloc_thing(private_traffic_selector_t);
 
        /* public functions */
        this->public.get_subset = (traffic_selector_t*(*)(traffic_selector_t*,traffic_selector_t*))get_subset;
index dcf7458..6361f30 100644 (file)
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <execinfo.h>
 
 #include "daemon.h" 
 
 #include <types.h>
-#include <utils/allocator.h>
 
 
 typedef struct private_daemon_t private_daemon_t;
@@ -90,7 +90,14 @@ daemon_t *charon;
  * Implementation of private_daemon_t.run.
  */
 static void run(private_daemon_t *this)
-{      
+{
+       /* reselect signals for this thread */
+       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);
+       
        while(TRUE)
        {
                int signal_number;
@@ -237,12 +244,32 @@ static void destroy(private_daemon_t *this)
        {
                this->public.stroke->destroy(this->public.stroke);
        }
-       
-       this->public.logger_manager->destroy(this->public.logger_manager);
-       allocator_free(this);
+       free(this);
 }
 
+void signal_handler(int signal)
+{
+       void *array[20];
+       size_t size;
+       char **strings;
+       size_t i;
+       logger_t *logger;
+
+       size = backtrace(array, 20);
+       strings = backtrace_symbols(array, size);
+       logger = logger_manager->get_logger(logger_manager, DAEMON);
+
+       logger->log(logger, ERROR, "Thread %u received SIGSEGV. Dumping %d frames from stack:", pthread_self(), size);
 
+       for (i = 0; i < size; i++)
+       {
+               logger->log(logger, ERROR, "\t%s", strings[i]);
+       }
+
+       free (strings);
+       
+       charon->kill(charon, "SIGSEGV received");
+}
 
 /**
  * @brief Create the daemon.
@@ -251,7 +278,8 @@ static void destroy(private_daemon_t *this)
  */
 private_daemon_t *daemon_create()
 {      
-       private_daemon_t *this = allocator_alloc_thing(private_daemon_t);
+       private_daemon_t *this = malloc_thing(private_daemon_t);
+       struct sigaction action;
                
        /* assign methods */
        this->run = run;
@@ -259,10 +287,6 @@ private_daemon_t *daemon_create()
        this->initialize = initialize;
        this->public.kill = (void (*) (daemon_t*,char*))kill_daemon;
        
-       /* first build a logger */
-       this->public.logger_manager = logger_manager_create(DEFAULT_LOGLEVEL);
-       this->logger = (this->public.logger_manager)->get_logger(this->public.logger_manager, DAEMON);
-       
        /* NULL members for clean destruction */
        this->public.socket = NULL;
        this->public.ike_sa_manager = NULL;
@@ -282,13 +306,22 @@ private_daemon_t *daemon_create()
        
        this->main_thread_id = pthread_self();
        
-       /* setup signal handling */
+       /* setup signal handling for all threads */
        sigemptyset(&(this->signal_set));
+       sigaddset(&(this->signal_set), SIGSEGV);
        sigaddset(&(this->signal_set), SIGINT); 
        sigaddset(&(this->signal_set), SIGHUP); 
        sigaddset(&(this->signal_set), SIGTERM); 
        pthread_sigmask(SIG_BLOCK, &(this->signal_set), 0);
        
+       /* setup SIGSEGV handler for all threads */
+       action.sa_handler = signal_handler;
+       action.sa_mask = this->signal_set;
+       action.sa_flags = 0;
+       if (sigaction(SIGSEGV, &action, NULL) == -1)
+       {
+               this->logger->log(this->logger, ERROR, "signal handler setup for SIGSEGV failed");
+       }
        return this;
 }
 
@@ -296,15 +329,15 @@ private_daemon_t *daemon_create()
  * Main function, manages the daemon.
  */
 int main(int argc, char *argv[])
-{
+{      
        private_daemon_t *private_charon;
        FILE *pid_file;
        struct stat stb;
        
-       /* allocation needs initialization, before any allocs are done */
-       allocator_init();
        private_charon = daemon_create();
        charon = (daemon_t*)private_charon;
+       
+       private_charon->logger = logger_manager->get_logger(logger_manager, DAEMON);
                
        /* check/setup PID file */
        if (stat(PID_FILE, &stb) == 0)
@@ -321,18 +354,15 @@ int main(int argc, char *argv[])
                fclose(pid_file);
        }
        
-       /* initialize and run daemon*/
+       /* initialize and run daemon */
        private_charon->initialize(private_charon);
        private_charon->run(private_charon);
        
        /* normal termination, cleanup and exit */
        private_charon->destroy(private_charon);
        unlink(PID_FILE);
-       
-#ifdef LEAK_DETECTIVE
-       report_memory_leaks(void);
-#endif
 
-       exit(0);
+       return 0;
 }
 
+
index 9f4d738..da71fd1 100644 (file)
  */
 #define PID_FILE "/var/run/charon.pid"
 
-/**
- * Output of log, use NULL for syslog
- */
-#define LOG_OUTPUT NULL
-
-/**
- * @brief Default loglevel for every logger context.
- * 
- * This is the maximum allowed level for ever context, the definiton
- * of the context may be less verbose.
- */
-#define DEFAULT_LOGLEVEL CONTROL | ERROR | AUDIT
-
 
 typedef struct daemon_t daemon_t;
 
@@ -157,11 +144,6 @@ struct daemon_t {
         * A event_queue_t instance.
         */
        event_queue_t *event_queue;
-       
-       /**
-        * A logger_manager_t instance.
-        */
-       logger_manager_t *logger_manager;
 
        /**
         * A ike_sa_manager_t instance.
index 0d7394a..ba12190 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <types.h>
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 #include <utils/logger_manager.h>
 #include <encoding/payloads/payload.h>
@@ -562,7 +561,7 @@ static void make_space_available (private_generator_t *this, size_t bits)
                                                        old_buffer_size, new_buffer_size);
                
                /* Reallocate space for new buffer */
-               this->buffer = allocator_realloc(this->buffer,new_buffer_size);
+               this->buffer = realloc(this->buffer,new_buffer_size);
 
                this->out_position = (this->buffer + out_position_offset);
                this->roof_position = (this->buffer + new_buffer_size);
@@ -629,7 +628,7 @@ static void write_to_chunk (private_generator_t *this,chunk_t *data)
 
        if (this->current_bit > 0)
        data_length++;
-       data->ptr = allocator_alloc(data_length);
+       data->ptr = malloc(data_length);
        memcpy(data->ptr,this->buffer,data_length);
        data->len = data_length;
        
@@ -1028,8 +1027,8 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
  */
 static status_t destroy(private_generator_t *this)
 {
-       allocator_free(this->buffer);
-       allocator_free(this);
+       free(this->buffer);
+       free(this);
        return SUCCESS;
 }
 
@@ -1040,7 +1039,7 @@ generator_t *generator_create()
 {
        private_generator_t *this;
 
-       this = allocator_alloc_thing(private_generator_t);
+       this = malloc_thing(private_generator_t);
 
        /* initiate public functions */
        this->public.generate_payload = (void(*)(generator_t*, payload_t *)) generate_payload;
@@ -1063,7 +1062,7 @@ generator_t *generator_create()
 
 
        /* allocate memory for buffer */
-       this->buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE);
+       this->buffer = malloc(GENERATOR_DATA_BUFFER_SIZE);
 
        /* initiate private variables */
        this->out_position = this->buffer;
@@ -1072,7 +1071,7 @@ generator_t *generator_create()
        this->current_bit = 0;
        this->last_payload_length_position_offset = 0;
        this->header_length_position_offset = 0;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, GENERATOR);
+       this->logger = logger_manager->get_logger(logger_manager, GENERATOR);
 
        return &(this->public);
 }
index 360e44a..a573152 100644 (file)
@@ -30,7 +30,6 @@
 #include <encoding/generator.h>
 #include <encoding/parser.h>
 #include <utils/linked_list.h>
-#include <utils/allocator.h>
 #include <utils/logger_manager.h>
 #include <encoding/payloads/encodings.h>
 #include <encoding/payloads/payload.h>
@@ -670,7 +669,7 @@ static packet_t *get_packet (private_message_t *this)
  */
 static chunk_t get_packet_data (private_message_t *this)
 {
-       return allocator_clone_chunk(this->packet->get_data(this->packet));
+       return chunk_clone(this->packet->get_data(this->packet));
 }
 
 /**
@@ -1154,7 +1153,7 @@ static void destroy (private_message_t *this)
        this->payloads->destroy(this->payloads);
        this->parser->destroy(this->parser);
        
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -1162,7 +1161,7 @@ static void destroy (private_message_t *this)
  */
 message_t *message_create_from_packet(packet_t *packet)
 {
-       private_message_t *this = allocator_alloc_thing(private_message_t);
+       private_message_t *this = malloc_thing(private_message_t);
 
        /* public functions */
        this->public.set_major_version = (void(*)(message_t*, u_int8_t))set_major_version;
@@ -1217,7 +1216,7 @@ message_t *message_create_from_packet(packet_t *packet)
        /* parser is created from data of packet */
        this->parser = parser_create(this->packet->get_data(this->packet));
                
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, MESSAGE);
+       this->logger = logger_manager->get_logger(logger_manager, MESSAGE);
 
        return (&this->public);
 }
index 769a815..a589e9b 100644 (file)
 
 #include <stdlib.h>
 #include <arpa/inet.h>
+#include <string.h>
 
 #include "parser.h"
 
 #include <types.h>
 #include <definitions.h>
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <utils/logger.h>
 #include <utils/linked_list.h>
 #include <encoding/payloads/encodings.h>
@@ -566,7 +566,7 @@ static status_t parse_chunk(private_parser_t *this, int rule_number, chunk_t *ou
        if (output_pos != NULL)
        {
                output_pos->len = length;
-               output_pos->ptr = allocator_alloc(length);
+               output_pos->ptr = malloc(length);
                memcpy(output_pos->ptr, this->byte_pos, length);
        }
        this->byte_pos += length;
@@ -1027,7 +1027,7 @@ static void reset_context (private_parser_t *this)
  */
 static void destroy(private_parser_t *this)
 {
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -1035,9 +1035,9 @@ static void destroy(private_parser_t *this)
  */
 parser_t *parser_create(chunk_t data)
 {
-       private_parser_t *this = allocator_alloc_thing(private_parser_t);
+       private_parser_t *this = malloc_thing(private_parser_t);
        
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, PARSER);
+       this->logger = logger_manager->get_logger(logger_manager, PARSER);
        
        this->public.parse_payload = (status_t(*)(parser_t*,payload_type_t,payload_t**)) parse_payload;
        this->public.reset_context = (void(*)(parser_t*)) reset_context;
index 8adb6fd..cc7c4bf 100644 (file)
@@ -23,7 +23,6 @@
 #include "auth_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 
 
 typedef struct private_auth_payload_t private_auth_payload_t;
@@ -189,9 +188,9 @@ static void set_data (private_auth_payload_t *this, chunk_t data)
 {
        if (this->auth_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->auth_data));
+               chunk_free(&(this->auth_data));
        }
-       this->auth_data.ptr = allocator_clone_bytes(data.ptr,data.len);
+       this->auth_data.ptr = clalloc(data.ptr,data.len);
        this->auth_data.len = data.len;
        this->payload_length = AUTH_PAYLOAD_HEADER_LENGTH + this->auth_data.len;
 }
@@ -214,7 +213,7 @@ static chunk_t get_data_clone (private_auth_payload_t *this)
        {
                return (this->auth_data);
        }
-       cloned_data.ptr = allocator_clone_bytes(this->auth_data.ptr,this->auth_data.len);
+       cloned_data.ptr = clalloc(this->auth_data.ptr,this->auth_data.len);
        cloned_data.len = this->auth_data.len;
        return cloned_data;
 }
@@ -226,10 +225,10 @@ static void destroy(private_auth_payload_t *this)
 {
        if (this->auth_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->auth_data));
+               chunk_free(&(this->auth_data));
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -237,7 +236,7 @@ static void destroy(private_auth_payload_t *this)
  */
 auth_payload_t *auth_payload_create()
 {
-       private_auth_payload_t *this = allocator_alloc_thing(private_auth_payload_t);
+       private_auth_payload_t *this = malloc_thing(private_auth_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index a361f13..146d42e 100644 (file)
@@ -20,9 +20,9 @@
  * for more details.
  */
 
-#include "cert_payload.h"
+#include <stddef.h>
 
-#include <utils/allocator.h>
+#include "cert_payload.h"
 
 
 /** 
@@ -202,9 +202,9 @@ static void set_data (private_cert_payload_t *this, chunk_t data)
 {
        if (this->cert_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->cert_data));
+               chunk_free(&(this->cert_data));
        }
-       this->cert_data.ptr = allocator_clone_bytes(data.ptr,data.len);
+       this->cert_data.ptr = clalloc(data.ptr,data.len);
        this->cert_data.len = data.len;
        this->payload_length = CERT_PAYLOAD_HEADER_LENGTH + this->cert_data.len;
 }
@@ -227,7 +227,7 @@ static chunk_t get_data_clone (private_cert_payload_t *this)
        {
                return (this->cert_data);
        }
-       cloned_data.ptr = allocator_clone_bytes(this->cert_data.ptr,this->cert_data.len);
+       cloned_data.ptr = clalloc(this->cert_data.ptr,this->cert_data.len);
        cloned_data.len = this->cert_data.len;
        return cloned_data;
 }
@@ -239,10 +239,10 @@ static void destroy(private_cert_payload_t *this)
 {
        if (this->cert_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->cert_data));
+               chunk_free(&(this->cert_data));
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -250,7 +250,7 @@ static void destroy(private_cert_payload_t *this)
  */
 cert_payload_t *cert_payload_create()
 {
-       private_cert_payload_t *this = allocator_alloc_thing(private_cert_payload_t);
+       private_cert_payload_t *this = malloc_thing(private_cert_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index b7372a7..cdab82b 100644 (file)
@@ -20,9 +20,9 @@
  * for more details.
  */
 
-#include "certreq_payload.h"
+#include <stddef.h>
 
-#include <utils/allocator.h>
+#include "certreq_payload.h"
 
 
 typedef struct private_certreq_payload_t private_certreq_payload_t;
@@ -182,9 +182,9 @@ static void set_data (private_certreq_payload_t *this, chunk_t data)
 {
        if (this->certreq_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->certreq_data));
+               chunk_free(&(this->certreq_data));
        }
-       this->certreq_data.ptr = allocator_clone_bytes(data.ptr,data.len);
+       this->certreq_data.ptr = clalloc(data.ptr,data.len);
        this->certreq_data.len = data.len;
        this->payload_length = CERTREQ_PAYLOAD_HEADER_LENGTH + this->certreq_data.len;
 }
@@ -207,7 +207,7 @@ static chunk_t get_data_clone (private_certreq_payload_t *this)
        {
                return (this->certreq_data);
        }
-       cloned_data.ptr = allocator_clone_bytes(this->certreq_data.ptr,this->certreq_data.len);
+       cloned_data.ptr = clalloc(this->certreq_data.ptr,this->certreq_data.len);
        cloned_data.len = this->certreq_data.len;
        return cloned_data;
 }
@@ -219,10 +219,10 @@ static void destroy(private_certreq_payload_t *this)
 {
        if (this->certreq_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->certreq_data));
+               chunk_free(&(this->certreq_data));
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -230,7 +230,7 @@ static void destroy(private_certreq_payload_t *this)
  */
 certreq_payload_t *certreq_payload_create()
 {
-       private_certreq_payload_t *this = allocator_alloc_thing(private_certreq_payload_t);
+       private_certreq_payload_t *this = malloc_thing(private_certreq_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 4f32948..489d7f3 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
 #include <stddef.h>
 
 #include "configuration_attribute.h"
 
 #include <encoding/payloads/encodings.h>
 #include <types.h>
-#include <utils/allocator.h>
 
 
 typedef struct private_configuration_attribute_t private_configuration_attribute_t;
@@ -196,10 +194,10 @@ static void set_value(private_configuration_attribute_t *this, chunk_t value)
        if (this->attribute_value.ptr != NULL)
        {
                /* free existing value */
-               allocator_free_chunk(&(this->attribute_value));         
+               chunk_free(&(this->attribute_value));           
        }
        
-       this->attribute_value.ptr = allocator_clone_bytes(value.ptr,value.len);
+       this->attribute_value.ptr = clalloc(value.ptr,value.len);
        this->attribute_value.len = value.len;
        
        this->attribute_length = this->attribute_value.len;
@@ -246,9 +244,9 @@ static void destroy(private_configuration_attribute_t *this)
 {
        if (this->attribute_value.ptr != NULL)
        {
-               allocator_free(this->attribute_value.ptr);
+               free(this->attribute_value.ptr);
        }       
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -256,7 +254,7 @@ static void destroy(private_configuration_attribute_t *this)
  */
 configuration_attribute_t *configuration_attribute_create()
 {
-       private_configuration_attribute_t *this = allocator_alloc_thing(private_configuration_attribute_t);
+       private_configuration_attribute_t *this = malloc_thing(private_configuration_attribute_t);
 
        /* payload interface */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index e9d8af7..5834883 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
 #include <stddef.h>
 
 #include "cp_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -265,7 +263,7 @@ static status_t destroy(private_cp_payload_t *this)
        }
        this->attributes->destroy(this->attributes);
        
-       allocator_free(this);
+       free(this);
        
        return SUCCESS;
 }
@@ -275,7 +273,7 @@ static status_t destroy(private_cp_payload_t *this)
  */
 cp_payload_t *cp_payload_create()
 {
-       private_cp_payload_t *this = allocator_alloc_thing(private_cp_payload_t);
+       private_cp_payload_t *this = malloc_thing(private_cp_payload_t);
        
        /* public interface */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 59d8779..28e7880 100644 (file)
@@ -20,9 +20,9 @@
  * for more details.
  */
 
-#include "delete_payload.h"
+#include <stddef.h>
 
-#include <utils/allocator.h>
+#include "delete_payload.h"
 
 
 typedef struct private_delete_payload_t private_delete_payload_t;
@@ -238,9 +238,9 @@ static void set_spis (private_delete_payload_t *this, chunk_t spis)
 {
        if (this->spis.ptr != NULL)
        {
-               allocator_free_chunk(&(this->spis));
+               chunk_free(&(this->spis));
        }
-       this->spis.ptr = allocator_clone_bytes(spis.ptr,spis.len);
+       this->spis.ptr = clalloc(spis.ptr,spis.len);
        this->spis.len = spis.len;
        this->payload_length = DELETE_PAYLOAD_HEADER_LENGTH + this->spis.len;
 }
@@ -263,7 +263,7 @@ static chunk_t get_spis_clone (private_delete_payload_t *this)
        {
                return (this->spis);
        }
-       cloned_spis.ptr = allocator_clone_bytes(this->spis.ptr,this->spis.len);
+       cloned_spis.ptr = clalloc(this->spis.ptr,this->spis.len);
        cloned_spis.len = this->spis.len;
        return cloned_spis;
 }
@@ -275,10 +275,10 @@ static void destroy(private_delete_payload_t *this)
 {
        if (this->spis.ptr != NULL)
        {
-               allocator_free_chunk(&(this->spis));
+               chunk_free(&(this->spis));
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -286,7 +286,7 @@ static void destroy(private_delete_payload_t *this)
  */
 delete_payload_t *delete_payload_create()
 {
-       private_delete_payload_t *this = allocator_alloc_thing(private_delete_payload_t);
+       private_delete_payload_t *this = malloc_thing(private_delete_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 2bd8d5e..2a0e176 100644 (file)
@@ -20,9 +20,9 @@
  * for more details.
  */
 
-#include "eap_payload.h"
+#include <stddef.h>
 
-#include <utils/allocator.h>
+#include "eap_payload.h"
 
 
 typedef struct private_eap_payload_t private_eap_payload_t;
@@ -152,9 +152,9 @@ static void set_message (private_eap_payload_t *this, chunk_t message)
 {
        if (this->message.ptr != NULL)
        {
-               allocator_free_chunk(&(this->message));
+               chunk_free(&(this->message));
        }
-       this->message.ptr = allocator_clone_bytes(message.ptr,message.len);
+       this->message.ptr = clalloc(message.ptr,message.len);
        this->message.len = message.len;
        this->payload_length = EAP_PAYLOAD_HEADER_LENGTH + this->message.len;
 }
@@ -177,7 +177,7 @@ static chunk_t get_message_clone (private_eap_payload_t *this)
        {
                return (this->message);
        }
-       cloned_message.ptr = allocator_clone_bytes(this->message.ptr,this->message.len);
+       cloned_message.ptr = clalloc(this->message.ptr,this->message.len);
        cloned_message.len = this->message.len;
        return cloned_message;
 }
@@ -189,10 +189,10 @@ static void destroy(private_eap_payload_t *this)
 {
        if (this->message.ptr != NULL)
        {
-               allocator_free_chunk(&(this->message));
+               chunk_free(&(this->message));
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -200,7 +200,7 @@ static void destroy(private_eap_payload_t *this)
  */
 eap_payload_t *eap_payload_create()
 {
-       private_eap_payload_t *this = allocator_alloc_thing(private_eap_payload_t);
+       private_eap_payload_t *this = malloc_thing(private_eap_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 70bbe97..e0ca74f 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
 #include <stddef.h>
+#include <string.h>
 
 #include "encryption_payload.h"
 
 #include <daemon.h>
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 #include <utils/logger.h>
 #include <encoding/generator.h>
@@ -303,7 +302,7 @@ static status_t encrypt(private_encryption_payload_t *this)
        
        /* concatenate payload data, padding, padding len */
        to_crypt.len = this->decrypted.len + padding.len + 1;
-       to_crypt.ptr = allocator_alloc(to_crypt.len);
+       to_crypt.ptr = malloc(to_crypt.len);
 
        memcpy(to_crypt.ptr, this->decrypted.ptr, this->decrypted.len);
        memcpy(to_crypt.ptr + this->decrypted.len, padding.ptr, padding.len);
@@ -315,22 +314,22 @@ static status_t encrypt(private_encryption_payload_t *this)
        randomizer->destroy(randomizer);
        if (status != SUCCESS)
        {
-               allocator_free_chunk(&to_crypt);
-               allocator_free_chunk(&padding);
+               chunk_free(&to_crypt);
+               chunk_free(&padding);
                return status;
        }
        
        this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before encryption with padding", to_crypt);
                
        /* encrypt to_crypt chunk */
-       allocator_free(this->encrypted.ptr);
+       free(this->encrypted.ptr);
        status = this->crypter->encrypt(this->crypter, to_crypt, iv, &result);
-       allocator_free(padding.ptr);
-       allocator_free(to_crypt.ptr);
+       free(padding.ptr);
+       free(to_crypt.ptr);
        if (status != SUCCESS)
        {
                this->logger->log(this->logger, ERROR|LEVEL1, "encryption failed");
-               allocator_free(iv.ptr);
+               free(iv.ptr);
                return status;
        }
        this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after encryption", result);
@@ -338,15 +337,15 @@ static status_t encrypt(private_encryption_payload_t *this)
        
        /* build encrypted result with iv and signature */
        this->encrypted.len = iv.len + result.len + this->signer->get_block_size(this->signer);
-       allocator_free(this->encrypted.ptr);
-       this->encrypted.ptr = allocator_alloc(this->encrypted.len);
+       free(this->encrypted.ptr);
+       this->encrypted.ptr = malloc(this->encrypted.len);
        
        /* fill in result, signature is left out */
        memcpy(this->encrypted.ptr, iv.ptr, iv.len);
        memcpy(this->encrypted.ptr + iv.len, result.ptr, result.len);
        
-       allocator_free(result.ptr);
-       allocator_free(iv.ptr);
+       free(result.ptr);
+       free(iv.ptr);
        this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after encryption with IV and (invalid) signature", this->encrypted);
        
        return SUCCESS;
@@ -391,7 +390,7 @@ static status_t decrypt(private_encryption_payload_t *this)
        }
        
        /* free previus data, if any */
-       allocator_free(this->decrypted.ptr);
+       free(this->decrypted.ptr);
        
        this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before decryption", concatenated);
        
@@ -419,7 +418,7 @@ static status_t decrypt(private_encryption_payload_t *this)
        }
        
        /* free padding */
-       this->decrypted.ptr = allocator_realloc(this->decrypted.ptr, this->decrypted.len);
+       this->decrypted.ptr = realloc(this->decrypted.ptr, this->decrypted.len);
        this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after decryption without padding", this->decrypted);
        this->logger->log(this->logger, CONTROL|LEVEL2, "decryption successful, trying to parse content");
        return (this->parse(this));
@@ -518,7 +517,7 @@ static void generate(private_encryption_payload_t *this)
        {
                /* no paylads? */
                this->logger->log(this->logger, CONTROL|LEVEL1, "generating contained payloads, but no available");
-               allocator_free(this->decrypted.ptr);
+               free(this->decrypted.ptr);
                this->decrypted = CHUNK_INITIALIZER;
                iterator->destroy(iterator);
                return;
@@ -541,7 +540,7 @@ static void generate(private_encryption_payload_t *this)
        generator->generate_payload(generator, current_payload);
        
        /* free already generated data */
-       allocator_free(this->decrypted.ptr);
+       free(this->decrypted.ptr);
        
        generator->write_to_chunk(generator, &(this->decrypted));
        generator->destroy(generator);
@@ -649,9 +648,9 @@ static void destroy(private_encryption_payload_t *this)
                current_payload->destroy(current_payload);
        }
        this->payloads->destroy(this->payloads);
-       allocator_free(this->encrypted.ptr);
-       allocator_free(this->decrypted.ptr);
-       allocator_free(this);
+       free(this->encrypted.ptr);
+       free(this->decrypted.ptr);
+       free(this);
 }
 
 /*
@@ -659,7 +658,7 @@ static void destroy(private_encryption_payload_t *this)
  */
 encryption_payload_t *encryption_payload_create()
 {
-       private_encryption_payload_t *this = allocator_alloc_thing(private_encryption_payload_t);
+       private_encryption_payload_t *this = malloc_thing(private_encryption_payload_t);
        
        /* payload_t interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
@@ -687,7 +686,7 @@ encryption_payload_t *encryption_payload_create()
        this->compute_length = compute_length;
        this->generate = generate;
        this->parse = parse;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, ENCRYPTION_PAYLOAD);
+       this->logger = logger_manager->get_logger(logger_manager, ENCRYPTION_PAYLOAD);
        
        /* set default values of the fields */
        this->critical = FALSE;
index df37a06..6a8d773 100644 (file)
  * for more details.
  */
 
+#include <stddef.h>
+
 #include "id_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 
 typedef struct private_id_payload_t private_id_payload_t;
 
@@ -202,9 +203,9 @@ static void set_data (private_id_payload_t *this, chunk_t data)
 {
        if (this->id_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->id_data));
+               chunk_free(&(this->id_data));
        }
-       this->id_data.ptr = allocator_clone_bytes(data.ptr,data.len);
+       this->id_data.ptr = clalloc(data.ptr,data.len);
        this->id_data.len = data.len;
        this->payload_length = ID_PAYLOAD_HEADER_LENGTH + this->id_data.len;
 }
@@ -228,7 +229,7 @@ static chunk_t get_data_clone (private_id_payload_t *this)
        {
                return (this->id_data);
        }
-       cloned_data.ptr = allocator_clone_bytes(this->id_data.ptr,this->id_data.len);
+       cloned_data.ptr = clalloc(this->id_data.ptr,this->id_data.len);
        cloned_data.len = this->id_data.len;
        return cloned_data;
 }
@@ -264,9 +265,9 @@ static void destroy(private_id_payload_t *this)
 {
        if (this->id_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->id_data));
+               chunk_free(&(this->id_data));
        }
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -274,7 +275,7 @@ static void destroy(private_id_payload_t *this)
  */
 id_payload_t *id_payload_create(bool is_initiator)
 {
-       private_id_payload_t *this = allocator_alloc_thing(private_id_payload_t);
+       private_id_payload_t *this = malloc_thing(private_id_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 6114c8d..ad46d3d 100644 (file)
@@ -26,7 +26,6 @@
 #include "ike_header.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 
 
 typedef struct private_ike_header_t private_ike_header_t;
@@ -324,7 +323,7 @@ static void set_message_id(private_ike_header_t *this, u_int32_t message_id)
  */
 static void destroy(ike_header_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -365,7 +364,7 @@ static size_t get_length(payload_t *this)
  */
 ike_header_t *ike_header_create()
 {
-       private_ike_header_t *this = allocator_alloc_thing(private_ike_header_t);
+       private_ike_header_t *this = malloc_thing(private_ike_header_t);
        
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
        this->public.payload_interface.get_encoding_rules = get_encoding_rules;
index 5cbf99b..0c92e03 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
 #include <stddef.h>
 
 #include "ke_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 
 
 typedef struct private_ke_payload_t private_ke_payload_t;
@@ -134,9 +132,9 @@ static void destroy(private_ke_payload_t *this)
 {
        if (this->key_exchange_data.ptr != NULL)
        {
-               allocator_free(this->key_exchange_data.ptr);
+               free(this->key_exchange_data.ptr);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -212,13 +210,13 @@ static void set_key_exchange_data(private_ke_payload_t *this, chunk_t key_exchan
        if (this->key_exchange_data.ptr != NULL)
        {
                /* free existing value */
-               allocator_free(this->key_exchange_data.ptr);
+               free(this->key_exchange_data.ptr);
                this->key_exchange_data.ptr = NULL;
                this->key_exchange_data.len = 0;
                
        }
        
-       this->key_exchange_data.ptr = allocator_clone_bytes(key_exchange_data.ptr,key_exchange_data.len);
+       this->key_exchange_data.ptr = clalloc(key_exchange_data.ptr,key_exchange_data.len);
 
        this->key_exchange_data.len = key_exchange_data.len;
        this->compute_length(this);
@@ -245,7 +243,7 @@ static void set_dh_group_number(private_ke_payload_t *this, diffie_hellman_group
  */
 ke_payload_t *ke_payload_create()
 {
-       private_ke_payload_t *this = allocator_alloc_thing(private_ke_payload_t);
+       private_ke_payload_t *this = malloc_thing(private_ke_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index aa71f8b..a7528fb 100644 (file)
@@ -26,7 +26,6 @@
 #include "nonce_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 
 
 typedef struct private_nonce_payload_t private_nonce_payload_t;
@@ -125,7 +124,7 @@ static status_t verify(private_nonce_payload_t *this)
  */
 static status_t set_nonce(private_nonce_payload_t *this, chunk_t nonce)
 {
-       this->nonce.ptr = allocator_clone_bytes(nonce.ptr, nonce.len);
+       this->nonce.ptr = clalloc(nonce.ptr, nonce.len);
        this->nonce.len = nonce.len;
        this->payload_length = NONCE_PAYLOAD_HEADER_LENGTH + nonce.len;
        return SUCCESS;
@@ -137,7 +136,7 @@ static status_t set_nonce(private_nonce_payload_t *this, chunk_t nonce)
 static chunk_t get_nonce(private_nonce_payload_t *this)
 {
        chunk_t nonce;
-       nonce.ptr = allocator_clone_bytes(this->nonce.ptr,this->nonce.len);
+       nonce.ptr = clalloc(this->nonce.ptr,this->nonce.len);
        nonce.len = this->nonce.len;
        return nonce;
 }
@@ -199,10 +198,10 @@ static void destroy(private_nonce_payload_t *this)
 {
        if (this->nonce.ptr != NULL)
        {
-               allocator_free(this->nonce.ptr);
+               free(this->nonce.ptr);
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -210,7 +209,7 @@ static void destroy(private_nonce_payload_t *this)
  */
 nonce_payload_t *nonce_payload_create()
 {
-       private_nonce_payload_t *this = allocator_alloc_thing(private_nonce_payload_t);
+       private_nonce_payload_t *this = malloc_thing(private_nonce_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index b26f89b..43d0c53 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
 #include <stddef.h>
 
 #include "notify_payload.h"
 
 #include <daemon.h>
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 
 /** 
  * String mappings for notify_message_type_t.
@@ -321,13 +319,13 @@ static void set_spi(private_notify_payload_t *this, chunk_t spi)
        if (this->spi.ptr != NULL)
        {
                /* free existing value */
-               allocator_free(this->spi.ptr);
+               free(this->spi.ptr);
                this->spi.ptr = NULL;
                this->spi.len = 0;
                
        }
        
-       this->spi.ptr = allocator_clone_bytes(spi.ptr,spi.len);
+       this->spi.ptr = clalloc(spi.ptr,spi.len);
 
        this->spi.len = spi.len;
        this->spi_size = spi.len;
@@ -352,13 +350,13 @@ static status_t set_notification_data(private_notify_payload_t *this, chunk_t no
        if (this->notification_data.ptr != NULL)
        {
                /* free existing value */
-               allocator_free(this->notification_data.ptr);
+               free(this->notification_data.ptr);
                this->notification_data.ptr = NULL;
                this->notification_data.len = 0;
                
        }
        
-       this->notification_data.ptr = allocator_clone_bytes(notification_data.ptr,notification_data.len);
+       this->notification_data.ptr = clalloc(notification_data.ptr,notification_data.len);
        this->notification_data.len = notification_data.len;
        this->compute_length(this);
        
@@ -372,14 +370,14 @@ static status_t destroy(private_notify_payload_t *this)
 {
        if (this->notification_data.ptr != NULL)
        {
-               allocator_free(this->notification_data.ptr);
+               free(this->notification_data.ptr);
        }
        if (this->spi.ptr != NULL)
        {
-               allocator_free(this->spi.ptr);
+               free(this->spi.ptr);
        }
 
-       allocator_free(this);
+       free(this);
        return SUCCESS;
 }
 
@@ -388,7 +386,7 @@ static status_t destroy(private_notify_payload_t *this)
  */
 notify_payload_t *notify_payload_create()
 {
-       private_notify_payload_t *this = allocator_alloc_thing(private_notify_payload_t);
+       private_notify_payload_t *this = malloc_thing(private_notify_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
@@ -424,7 +422,7 @@ notify_payload_t *notify_payload_create()
        this->spi_size = 0;
        this->notification_data.ptr = NULL;
        this->notification_data.len = 0;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, PAYLOAD);
+       this->logger = logger_manager->get_logger(logger_manager, PAYLOAD);
 
        return (&(this->public));
 }
index 4ee2e91..cb3c695 100644 (file)
@@ -19,8 +19,7 @@
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
- /* offsetof macro */
+
 #include <stddef.h>
 
 #include "proposal_substructure.h"
@@ -28,7 +27,6 @@
 #include <encoding/payloads/encodings.h>
 #include <encoding/payloads/transform_substructure.h>
 #include <types.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -307,13 +305,13 @@ static void set_spi (private_proposal_substructure_t *this, chunk_t spi)
        /* first delete already set spi value */
        if (this->spi.ptr != NULL)
        {
-               allocator_free(this->spi.ptr);
+               free(this->spi.ptr);
                this->spi.ptr = NULL;
                this->spi.len = 0;
                this->compute_length(this);
        }
        
-       this->spi.ptr = allocator_clone_bytes(spi.ptr,spi.len);
+       this->spi.ptr = clalloc(spi.ptr,spi.len);
        this->spi.len = spi.len;
        this->spi_size = spi.len;
        this->compute_length(this);
@@ -452,7 +450,7 @@ static private_proposal_substructure_t* clone(private_proposal_substructure_t *t
        new_clone->spi_size = this->spi_size;
        if (this->spi.ptr != NULL)
        {
-               new_clone->spi.ptr = allocator_clone_bytes(this->spi.ptr,this->spi.len);
+               new_clone->spi.ptr = clalloc(this->spi.ptr,this->spi.len);
                new_clone->spi.len = this->spi.len;
        }
 
@@ -495,10 +493,10 @@ static status_t destroy(private_proposal_substructure_t *this)
        
        if (this->spi.ptr != NULL)
        {
-               allocator_free(this->spi.ptr);
+               free(this->spi.ptr);
        }
        
-       allocator_free(this);
+       free(this);
        
        return SUCCESS;
 }
@@ -508,7 +506,7 @@ static status_t destroy(private_proposal_substructure_t *this)
  */
 proposal_substructure_t *proposal_substructure_create()
 {
-       private_proposal_substructure_t *this = allocator_alloc_thing(private_proposal_substructure_t);
+       private_proposal_substructure_t *this = malloc_thing(private_proposal_substructure_t);
 
        /* interface functions */       
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
@@ -622,7 +620,7 @@ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *
        /* take over general infos */
        this->spi_size = proto == PROTO_IKE ? 8 : 4;
        this->spi.len = this->spi_size;
-       this->spi.ptr = allocator_alloc(this->spi_size);
+       this->spi.ptr = malloc(this->spi_size);
        *((u_int32_t*)this->spi.ptr) = proposal->get_spi(proposal, proto);
        this->proposal_number = proposal->get_number(proposal);
        this->protocol_id = proto;
index 91049dd..81b4e67 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
 #include <stddef.h>
 
 #include "sa_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -176,7 +174,7 @@ static status_t destroy(private_sa_payload_t *this)
        }
        this->proposals->destroy(this->proposals);
        
-       allocator_free(this);
+       free(this);
        
        return SUCCESS;
 }
@@ -329,7 +327,7 @@ static void compute_length (private_sa_payload_t *this)
  */
 sa_payload_t *sa_payload_create()
 {
-       private_sa_payload_t *this = allocator_alloc_thing(private_sa_payload_t);
+       private_sa_payload_t *this = malloc_thing(private_sa_payload_t);
        
        /* public interface */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 874b87e..c1a461e 100644 (file)
@@ -23,7 +23,6 @@
 #include "traffic_selector_substructure.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 /** 
@@ -254,7 +253,7 @@ static void set_start_host (private_traffic_selector_substructure_t *this,host_t
        this->start_port = start_host->get_port(start_host);
        if (this->starting_address.ptr != NULL)
        {
-               allocator_free_chunk(&(this->starting_address));
+               chunk_free(&(this->starting_address));
        }
        this->starting_address = start_host->get_address_as_chunk(start_host);
        this->compute_length(this);
@@ -276,7 +275,7 @@ static void set_end_host (private_traffic_selector_substructure_t *this,host_t *
        this->end_port = end_host->get_port(end_host);
        if (this->ending_address.ptr != NULL)
        {
-               allocator_free_chunk(&(this->ending_address));
+               chunk_free(&(this->ending_address));
        }
        this->ending_address = end_host->get_address_as_chunk(end_host);
        this->compute_length(this);
@@ -307,9 +306,9 @@ void compute_length(private_traffic_selector_substructure_t *this)
  */
 static void destroy(private_traffic_selector_substructure_t *this)
 {
-       allocator_free(this->starting_address.ptr);
-       allocator_free(this->ending_address.ptr);
-       allocator_free(this);   
+       free(this->starting_address.ptr);
+       free(this->ending_address.ptr);
+       free(this);     
 }
 
 /*
@@ -317,7 +316,7 @@ static void destroy(private_traffic_selector_substructure_t *this)
  */
 traffic_selector_substructure_t *traffic_selector_substructure_create()
 {
-       private_traffic_selector_substructure_t *this = allocator_alloc_thing(private_traffic_selector_substructure_t);
+       private_traffic_selector_substructure_t *this = malloc_thing(private_traffic_selector_substructure_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 9f9d829..71cdd59 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
-/* offsetof macro */
+
+#include <string.h>
 #include <stddef.h>
 
 #include "transform_attribute.h"
 
 #include <encoding/payloads/encodings.h>
 #include <types.h>
-#include <utils/allocator.h>
 
 typedef struct private_transform_attribute_t private_transform_attribute_t;
 
@@ -170,7 +169,7 @@ static void set_value_chunk(private_transform_attribute_t *this, chunk_t value)
        if (this->attribute_value.ptr != NULL)
        {
                /* free existing value */
-               allocator_free(this->attribute_value.ptr);
+               free(this->attribute_value.ptr);
                this->attribute_value.ptr = NULL;
                this->attribute_value.len = 0;
                
@@ -178,7 +177,7 @@ static void set_value_chunk(private_transform_attribute_t *this, chunk_t value)
        
        if (value.len > 2)
        {
-               this->attribute_value.ptr = allocator_clone_bytes(value.ptr,value.len);
+               this->attribute_value.ptr = clalloc(value.ptr,value.len);
                this->attribute_value.len = value.len;
                this->attribute_length_or_value = value.len;
                /* attribute has not a fixed length */
@@ -198,7 +197,7 @@ static void set_value(private_transform_attribute_t *this, u_int16_t value)
        if (this->attribute_value.ptr != NULL)
        {
                /* free existing value */
-               allocator_free(this->attribute_value.ptr);
+               free(this->attribute_value.ptr);
                this->attribute_value.ptr = NULL;
                this->attribute_value.len = 0;
                
@@ -267,7 +266,7 @@ static transform_attribute_t * clone(private_transform_attribute_t *this)
        
        if (!new_clone->attribute_format)
        {
-               new_clone->attribute_value.ptr = allocator_clone_bytes(this->attribute_value.ptr,this->attribute_value.len);            
+               new_clone->attribute_value.ptr = clalloc(this->attribute_value.ptr,this->attribute_value.len);          
                new_clone->attribute_value.len = this->attribute_value.len;
        }
        
@@ -281,9 +280,9 @@ static void destroy(private_transform_attribute_t *this)
 {
        if (this->attribute_value.ptr != NULL)
        {
-               allocator_free(this->attribute_value.ptr);
+               free(this->attribute_value.ptr);
        }       
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -291,7 +290,7 @@ static void destroy(private_transform_attribute_t *this)
  */
 transform_attribute_t *transform_attribute_create()
 {
-       private_transform_attribute_t *this = allocator_alloc_thing(private_transform_attribute_t);
+       private_transform_attribute_t *this = malloc_thing(private_transform_attribute_t);
 
        /* payload interface */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 9b0bbf4..350ad63 100644 (file)
@@ -19,8 +19,7 @@
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
- /* offsetof macro */
+
 #include <stddef.h>
 
 #include "transform_substructure.h"
@@ -28,7 +27,6 @@
 #include <encoding/payloads/transform_attribute.h>
 #include <encoding/payloads/encodings.h>
 #include <types.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -420,7 +418,7 @@ static void destroy(private_transform_substructure_t *this)
        }
        this->attributes->destroy(this->attributes);
        
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -428,7 +426,7 @@ static void destroy(private_transform_substructure_t *this)
  */
 transform_substructure_t *transform_substructure_create()
 {
-       private_transform_substructure_t *this = allocator_alloc_thing(private_transform_substructure_t);
+       private_transform_substructure_t *this = malloc_thing(private_transform_substructure_t);
 
        /* payload interface */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 33a0cda..58772e6 100644 (file)
  * for more details.
  */
 
+#include <stddef.h>
+
 #include "ts_payload.h"
 
 #include <encoding/payloads/encodings.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 typedef struct private_ts_payload_t private_ts_payload_t;
@@ -297,7 +298,7 @@ static void destroy(private_ts_payload_t *this)
        
        this->traffic_selectors->destroy(this->traffic_selectors);
                
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -305,7 +306,7 @@ static void destroy(private_ts_payload_t *this)
  */
 ts_payload_t *ts_payload_create(bool is_initiator)
 {
-       private_ts_payload_t *this = allocator_alloc_thing(private_ts_payload_t);
+       private_ts_payload_t *this = malloc_thing(private_ts_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 5d6d2cb..25bb37d 100644 (file)
  * for more details.
  */
 
+#include <stddef.h>
+
 #include "unknown_payload.h"
 
-#include <utils/allocator.h>
 
 
 typedef struct private_unknown_payload_t private_unknown_payload_t;
@@ -169,10 +170,10 @@ static void destroy(private_unknown_payload_t *this)
 {
        if (this->data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->data));
+               chunk_free(&(this->data));
        }
        
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -180,7 +181,7 @@ static void destroy(private_unknown_payload_t *this)
  */
 unknown_payload_t *unknown_payload_create()
 {
-       private_unknown_payload_t *this = allocator_alloc_thing(private_unknown_payload_t);
+       private_unknown_payload_t *this = malloc_thing(private_unknown_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index 28f0760..436b82d 100644 (file)
@@ -20,9 +20,9 @@
  * for more details.
  */
 
-#include "vendor_id_payload.h"
+#include <stddef.h>
 
-#include <utils/allocator.h>
+#include "vendor_id_payload.h"
 
 
 typedef struct private_vendor_id_payload_t private_vendor_id_payload_t;
@@ -153,9 +153,9 @@ static void set_data (private_vendor_id_payload_t *this, chunk_t data)
 {
        if (this->vendor_id_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->vendor_id_data));
+               chunk_free(&(this->vendor_id_data));
        }
-       this->vendor_id_data.ptr = allocator_clone_bytes(data.ptr,data.len);
+       this->vendor_id_data.ptr = clalloc(data.ptr,data.len);
        this->vendor_id_data.len = data.len;
        this->payload_length = VENDOR_ID_PAYLOAD_HEADER_LENGTH + this->vendor_id_data.len;
 }
@@ -178,7 +178,7 @@ static chunk_t get_data_clone (private_vendor_id_payload_t *this)
        {
                return (this->vendor_id_data);
        }
-       cloned_data.ptr = allocator_clone_bytes(this->vendor_id_data.ptr,this->vendor_id_data.len);
+       cloned_data.ptr = clalloc(this->vendor_id_data.ptr,this->vendor_id_data.len);
        cloned_data.len = this->vendor_id_data.len;
        return cloned_data;
 }
@@ -190,9 +190,9 @@ static void destroy(private_vendor_id_payload_t *this)
 {
        if (this->vendor_id_data.ptr != NULL)
        {
-               allocator_free_chunk(&(this->vendor_id_data));
+               chunk_free(&(this->vendor_id_data));
        }
-       allocator_free(this);   
+       free(this);     
 }
 
 /*
@@ -200,7 +200,7 @@ static void destroy(private_vendor_id_payload_t *this)
  */
 vendor_id_payload_t *vendor_id_payload_create()
 {
-       private_vendor_id_payload_t *this = allocator_alloc_thing(private_vendor_id_payload_t);
+       private_vendor_id_payload_t *this = malloc_thing(private_vendor_id_payload_t);
 
        /* interface functions */
        this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
index b6501d8..6cded72 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "packet.h"
 
-#include <utils/allocator.h>
-
 
 typedef struct private_packet_t private_packet_t;
 
@@ -107,7 +105,7 @@ static chunk_t get_data(private_packet_t *this)
  */
 static void set_data(private_packet_t *this, chunk_t data)
 {
-       allocator_free(this->data.ptr);
+       free(this->data.ptr);
        this->data = data;
 }
 
@@ -124,8 +122,8 @@ static void destroy(private_packet_t *this)
        {
                this->destination->destroy(this->destination);
        }
-       allocator_free(this->data.ptr);
-       allocator_free(this);
+       free(this->data.ptr);
+       free(this);
 }
 
 /**
@@ -156,7 +154,7 @@ static packet_t *clone(private_packet_t *this)
        /* only clone existing chunks :-) */
        if (this->data.ptr != NULL)
        {
-               other->data.ptr = allocator_clone_bytes(this->data.ptr,this->data.len);
+               other->data.ptr = clalloc(this->data.ptr,this->data.len);
                other->data.len = this->data.len;
        }
        else
@@ -172,7 +170,7 @@ static packet_t *clone(private_packet_t *this)
  */
 packet_t *packet_create()
 {
-       private_packet_t *this = allocator_alloc_thing(private_packet_t);
+       private_packet_t *this = malloc_thing(private_packet_t);
 
        this->public.set_data = (void(*) (packet_t *,chunk_t)) set_data;
        this->public.get_data = (chunk_t(*) (packet_t *)) get_data;
index c7a7ab1..733071f 100644 (file)
@@ -40,7 +40,6 @@
 #include "socket.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <utils/logger_manager.h>
 
 
@@ -218,7 +217,7 @@ status_t receiver(private_socket_t *this, packet_t **packet)
 
        /* fill in packet */
        data.len = bytes_read - IP_HEADER_LENGTH - UDP_HEADER_LENGTH;
-       data.ptr = allocator_alloc(data.len);
+       data.ptr = malloc(data.len);
        memcpy(data.ptr, buffer + IP_HEADER_LENGTH + UDP_HEADER_LENGTH, data.len);
        pkt->set_data(pkt, data);
 
@@ -367,7 +366,7 @@ static status_t build_interface_list(private_socket_t *this, u_int16_t port)
                }
                
                /* add socket with interface name to list */
-               interface = allocator_alloc_thing(interface_t);
+               interface = malloc_thing(interface_t);
                memcpy(interface->name, buf[i].ifr_name, IFNAMSIZ);
                interface->name[IFNAMSIZ-1] = '\0';
                interface->socket_fd = skt;
@@ -424,11 +423,11 @@ static void destroy(private_socket_t *this)
        {
                interface->address->destroy(interface->address);
                close(interface->socket_fd);
-               allocator_free(interface);
+               free(interface);
        }
        this->interfaces->destroy(this->interfaces);
        close(this->master_fd);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -436,7 +435,7 @@ static void destroy(private_socket_t *this)
  */
 socket_t *socket_create(u_int16_t port)
 {
-       private_socket_t *this = allocator_alloc_thing(private_socket_t);
+       private_socket_t *this = malloc_thing(private_socket_t);
 
        /* public functions */
        this->public.send = (status_t(*)(socket_t*, packet_t*))sender;
@@ -444,7 +443,7 @@ socket_t *socket_create(u_int16_t port)
        this->public.is_listening_on = (bool (*)(socket_t*,host_t*))is_listening_on;
        this->public.destroy = (void(*)(socket_t*)) destroy;
        
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, SOCKET);
+       this->logger = logger_manager->get_logger(logger_manager, SOCKET);
        this->interfaces = linked_list_create();
        
        if (build_interface_list(this, port) != SUCCESS)
index 741fe14..ece9d15 100644 (file)
@@ -26,7 +26,6 @@
 #include "event_queue.h"
 
 #include <types.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -64,7 +63,7 @@ struct event_t{
  */
 static void event_destroy(event_t *event)
 {
-       allocator_free(event);
+       free(event);
 }
 
 /**
@@ -77,7 +76,7 @@ static void event_destroy(event_t *event)
  */
 static event_t *event_create(timeval_t time, job_t *job)
 {
-       event_t *this = allocator_alloc_thing(event_t);
+       event_t *this = malloc_thing(event_t);
 
        this->destroy = event_destroy;
        this->time = time;
@@ -326,7 +325,7 @@ static void event_queue_destroy(private_event_queue_t *this)
 
        pthread_cond_destroy(&(this->condvar));
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -334,7 +333,7 @@ static void event_queue_destroy(private_event_queue_t *this)
  */
 event_queue_t *event_queue_create()
 {
-       private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t);
+       private_event_queue_t *this = malloc_thing(private_event_queue_t);
 
        this->public.get_count = (int (*) (event_queue_t *event_queue)) get_count;
        this->public.get = (job_t *(*) (event_queue_t *event_queue)) get;
index 9d383d7..3640395 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "job_queue.h"
 
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -130,7 +129,7 @@ static void job_queue_destroy (private_job_queue_t *this)
 
        pthread_cond_destroy(&(this->condvar));
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -139,7 +138,7 @@ static void job_queue_destroy (private_job_queue_t *this)
  */
 job_queue_t *job_queue_create()
 {
-       private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t);
+       private_job_queue_t *this = malloc_thing(private_job_queue_t);
 
        this->public.get_count = (int(*)(job_queue_t*))get_count;
        this->public.get = (job_t*(*)(job_queue_t*))get;
index 595bdd1..7251e2c 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "delete_established_ike_sa_job.h"
 
-#include <utils/allocator.h>
 
 
 typedef struct private_delete_established_ike_sa_job_t private_delete_established_ike_sa_job_t;
@@ -64,7 +63,7 @@ static ike_sa_id_t *get_ike_sa_id(private_delete_established_ike_sa_job_t *this)
 static void destroy(private_delete_established_ike_sa_job_t *this)
 {
        this->ike_sa_id->destroy(this->ike_sa_id);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -72,7 +71,7 @@ static void destroy(private_delete_established_ike_sa_job_t *this)
  */
 delete_established_ike_sa_job_t *delete_established_ike_sa_job_create(ike_sa_id_t *ike_sa_id)
 {
-       private_delete_established_ike_sa_job_t *this = allocator_alloc_thing(private_delete_established_ike_sa_job_t);
+       private_delete_established_ike_sa_job_t *this = malloc_thing(private_delete_established_ike_sa_job_t);
        
        /* interface functions */
        this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
index 47354d6..610285e 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "delete_half_open_ike_sa_job.h"
 
-#include <utils/allocator.h>
 
 
 typedef struct private_delete_half_open_ike_sa_job_t private_delete_half_open_ike_sa_job_t;
@@ -64,7 +63,7 @@ static ike_sa_id_t *get_ike_sa_id(private_delete_half_open_ike_sa_job_t *this)
 static void destroy(private_delete_half_open_ike_sa_job_t *this)
 {
        this->ike_sa_id->destroy(this->ike_sa_id);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -72,7 +71,7 @@ static void destroy(private_delete_half_open_ike_sa_job_t *this)
  */
 delete_half_open_ike_sa_job_t *delete_half_open_ike_sa_job_create(ike_sa_id_t *ike_sa_id)
 {
-       private_delete_half_open_ike_sa_job_t *this = allocator_alloc_thing(private_delete_half_open_ike_sa_job_t);
+       private_delete_half_open_ike_sa_job_t *this = malloc_thing(private_delete_half_open_ike_sa_job_t);
        
        /* interface functions */
        this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
index ee8dac6..fc71f63 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "incoming_packet_job.h"
 
-#include <utils/allocator.h>
 
 
 typedef struct private_incoming_packet_job_t private_incoming_packet_job_t;
@@ -68,7 +67,7 @@ static void destroy_all(private_incoming_packet_job_t *this)
        {
                this->packet->destroy(this->packet);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -77,7 +76,7 @@ static void destroy_all(private_incoming_packet_job_t *this)
 static void destroy(job_t *job)
 {
        private_incoming_packet_job_t *this = (private_incoming_packet_job_t *) job;
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -85,7 +84,7 @@ static void destroy(job_t *job)
  */
 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);
+       private_incoming_packet_job_t *this = malloc_thing(private_incoming_packet_job_t);
 
        /* interface functions */
        this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
index 8837cd8..ac9ace3 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "initiate_ike_sa_job.h"
 
-#include <utils/allocator.h>
 
 
 typedef struct private_initiate_ike_sa_job_t private_initiate_ike_sa_job_t;
@@ -68,7 +67,7 @@ static connection_t *get_connection(private_initiate_ike_sa_job_t *this)
 static void destroy_all(private_initiate_ike_sa_job_t *this)
 {
        this->connection->destroy(this->connection);
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -76,7 +75,7 @@ static void destroy_all(private_initiate_ike_sa_job_t *this)
  */
 static void destroy(private_initiate_ike_sa_job_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -84,7 +83,7 @@ static void destroy(private_initiate_ike_sa_job_t *this)
  */
 initiate_ike_sa_job_t *initiate_ike_sa_job_create(connection_t *connection)
 {
-       private_initiate_ike_sa_job_t *this = allocator_alloc_thing(private_initiate_ike_sa_job_t);
+       private_initiate_ike_sa_job_t *this = malloc_thing(private_initiate_ike_sa_job_t);
        
        /* interface functions */
        this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
index 089ebbf..e171df5 100644 (file)
@@ -23,7 +23,6 @@
 #include "retransmit_request_job.h"
 
 
-#include <utils/allocator.h>
 
 
 typedef struct private_retransmit_request_job_t private_retransmit_request_job_t;
@@ -101,7 +100,7 @@ static u_int32_t get_message_id(private_retransmit_request_job_t *this)
 static void destroy(private_retransmit_request_job_t *this)
 {
        this->ike_sa_id->destroy(this->ike_sa_id);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -109,7 +108,7 @@ static void destroy(private_retransmit_request_job_t *this)
  */
 retransmit_request_job_t *retransmit_request_job_create(u_int32_t message_id,ike_sa_id_t *ike_sa_id)
 {
-       private_retransmit_request_job_t *this = allocator_alloc_thing(private_retransmit_request_job_t);
+       private_retransmit_request_job_t *this = malloc_thing(private_retransmit_request_job_t);
        
        /* interface functions */
        this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
index df1f7b3..0852e53 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "send_queue.h"
 
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -130,7 +129,7 @@ static void destroy (private_send_queue_t *this)
 
        pthread_cond_destroy(&(this->condvar));
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -139,7 +138,7 @@ static void destroy (private_send_queue_t *this)
  */
 send_queue_t *send_queue_create()
 {
-       private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t);
+       private_send_queue_t *this = malloc_thing(private_send_queue_t);
        
        this->public.get_count = (int(*)(send_queue_t*)) get_count;
        this->public.get = (packet_t*(*)(send_queue_t*)) get;
index 9c2a05c..32817b0 100644 (file)
  * for more details.
  */
 
+#include <string.h>
+
 #include "authenticator.h"
 
-#include <utils/allocator.h>
 #include <daemon.h>
 
 /**
@@ -141,7 +142,7 @@ static chunk_t allocate_octets(private_authenticator_t *this,
        
        /* 4 bytes are id type and reserved fields of id payload */
        octets.len = last_message.len + other_nonce.len + prf->get_block_size(prf);
-       octets.ptr = allocator_alloc(octets.len);
+       octets.ptr = malloc(octets.len);
        current_pos = octets.ptr;
        memcpy(current_pos,last_message.ptr,last_message.len);
        current_pos += last_message.len;
@@ -175,7 +176,7 @@ static chunk_t build_preshared_secret_signature(private_authenticator_t *this,
        this->prf->get_bytes(this->prf, key_pad, key_buffer);
        this->prf->set_key(this->prf, key);
        this->prf->allocate_bytes(this->prf, octets, &auth_data);
-       allocator_free_chunk(&octets);
+       chunk_free(&octets);
        this->logger->log_chunk(this->logger,RAW | LEVEL2, "Authenticated data",auth_data);
 
        return auth_data;
@@ -217,11 +218,11 @@ static status_t verify_auth_data (private_authenticator_t *this,
                                                                                                                                                  other_id_payload,
                                                                                                                                                  initiator,
                                                                                                                                                  preshared_secret);
-                       allocator_free_chunk(&preshared_secret);
+                       chunk_free(&preshared_secret);
                        
                        if (auth_data.len != my_auth_data.len)
                        {
-                               allocator_free_chunk(&my_auth_data);
+                               chunk_free(&my_auth_data);
                                status = FAILED;
                        }
                        else if (memcmp(auth_data.ptr,my_auth_data.ptr, my_auth_data.len) == 0)
@@ -237,7 +238,7 @@ static status_t verify_auth_data (private_authenticator_t *this,
                                status = FAILED;
                        }
                        other_id->destroy(other_id);
-                       allocator_free_chunk(&my_auth_data);
+                       chunk_free(&my_auth_data);
                        return status;
                }
                case RSA_DIGITAL_SIGNATURE:
@@ -276,7 +277,7 @@ static status_t verify_auth_data (private_authenticator_t *this,
                        
                        public_key->destroy(public_key);
                        other_id->destroy(other_id);
-                       allocator_free_chunk(&octets);
+                       chunk_free(&octets);
                        return status;
                }
                default:
@@ -322,12 +323,12 @@ static status_t compute_auth_data (private_authenticator_t *this,
                        
                        auth_data = this->build_preshared_secret_signature(this, last_sent_packet, other_nonce,
                                                                                                                           my_id_payload, initiator, preshared_secret);
-                       allocator_free_chunk(&preshared_secret);
+                       chunk_free(&preshared_secret);
                        *auth_payload = auth_payload_create();
                        (*auth_payload)->set_auth_method(*auth_payload, SHARED_KEY_MESSAGE_INTEGRITY_CODE);
                        (*auth_payload)->set_data(*auth_payload, auth_data);
 
-                       allocator_free_chunk(&auth_data);
+                       chunk_free(&auth_data);
                        return SUCCESS;
                }
                case RSA_DIGITAL_SIGNATURE:
@@ -350,7 +351,7 @@ static status_t compute_auth_data (private_authenticator_t *this,
                        octets = this->allocate_octets(this,last_sent_packet,other_nonce,my_id_payload,initiator);
                        
                        status = private_key->build_emsa_pkcs1_signature(private_key, HASH_SHA1, octets, &auth_data);
-                       allocator_free_chunk(&octets);
+                       chunk_free(&octets);
                        if (status != SUCCESS)
                        {
                                private_key->destroy(private_key);
@@ -362,7 +363,7 @@ static status_t compute_auth_data (private_authenticator_t *this,
                        (*auth_payload)->set_data(*auth_payload, auth_data);
 
                        private_key->destroy(private_key);
-                       allocator_free_chunk(&auth_data);
+                       chunk_free(&auth_data);
                        return SUCCESS;
                }
                default:
@@ -377,7 +378,7 @@ static status_t compute_auth_data (private_authenticator_t *this,
  */
 static void destroy (private_authenticator_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -385,7 +386,7 @@ static void destroy (private_authenticator_t *this)
  */
 authenticator_t *authenticator_create(protected_ike_sa_t *ike_sa)
 {
-       private_authenticator_t *this = allocator_alloc_thing(private_authenticator_t);
+       private_authenticator_t *this = malloc_thing(private_authenticator_t);
 
        /* Public functions */
        this->public.destroy = (void(*)(authenticator_t*))destroy;
@@ -399,7 +400,7 @@ authenticator_t *authenticator_create(protected_ike_sa_t *ike_sa)
        /* private data */
        this->ike_sa = ike_sa;
        this->prf = this->ike_sa->get_prf(this->ike_sa);
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        
        return &(this->public);
 }
index 7f19f87..fd82f12 100644 (file)
@@ -23,7 +23,6 @@
 #include "child_sa.h"
 
 
-#include <utils/allocator.h>
 #include <daemon.h>
 
 
@@ -305,11 +304,11 @@ static status_t install(private_child_sa_t *this, proposal_t *proposal, prf_plus
                        /* clean up for next round */
                        if (enc_algo != ENCR_UNDEFINED)
                        {
-                               allocator_free_chunk(&enc_key);
+                               chunk_free(&enc_key);
                        }
                        if (int_algo != AUTH_UNDEFINED)
                        {
-                               allocator_free_chunk(&int_key);
+                               chunk_free(&int_key);
                        }
                        
                        if (status != SUCCESS)
@@ -396,7 +395,7 @@ static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list
                        {
                                continue;
                        }
-                       policy = allocator_alloc_thing(sa_policy_t);
+                       policy = malloc_thing(sa_policy_t);
                        policy->upper_proto = my_ts->get_protocol(my_ts);
                
                        /* calculate net and ports for local side */
@@ -407,7 +406,7 @@ static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list
                        from_port = (from_port != to_port) ? 0 : from_port;
                        policy->my_net = host_create_from_chunk(family, from_addr, from_port);
                        policy->my_net_mask = my_ts->get_netmask(my_ts);
-                       allocator_free_chunk(&from_addr);
+                       chunk_free(&from_addr);
                        
                        /* calculate net and ports for remote side */
                        family = other_ts->get_type(other_ts) == TS_IPV4_ADDR_RANGE ? AF_INET : AF_INET6;
@@ -417,7 +416,7 @@ static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list
                        from_port = (from_port != to_port) ? 0 : from_port;
                        policy->other_net = host_create_from_chunk(family, from_addr, from_port);
                        policy->other_net_mask = other_ts->get_netmask(other_ts);
-                       allocator_free_chunk(&from_addr);
+                       chunk_free(&from_addr);
        
                        /* install 3 policies: out, in and forward */
                        status = charon->kernel_interface->add_policy(charon->kernel_interface,
@@ -448,7 +447,7 @@ static status_t add_policies(private_child_sa_t *this, linked_list_t *my_ts_list
                        {
                                my_iter->destroy(my_iter);
                                other_iter->destroy(other_iter);
-                               allocator_free(policy);
+                               free(policy);
                                return status;
                        }
                        
@@ -491,7 +490,7 @@ static void destroy(private_child_sa_t *this)
                
                policy->my_net->destroy(policy->my_net);
                policy->other_net->destroy(policy->other_net);
-               allocator_free(policy);
+               free(policy);
        }
        this->policies->destroy(this->policies);
        
@@ -510,7 +509,7 @@ static void destroy(private_child_sa_t *this)
                charon->kernel_interface->del_sa(charon->kernel_interface,
                                                                                 this->me, this->other_esp_spi, PROTO_ESP);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -519,7 +518,7 @@ static void destroy(private_child_sa_t *this)
 child_sa_t * child_sa_create(host_t *me, host_t* other)
 {
        static u_int32_t reqid = 0xc0000000;
-       private_child_sa_t *this = allocator_alloc_thing(private_child_sa_t);
+       private_child_sa_t *this = malloc_thing(private_child_sa_t);
 
        /* public functions */
        this->public.alloc = (status_t(*)(child_sa_t*,linked_list_t*))alloc;
@@ -529,7 +528,7 @@ child_sa_t * child_sa_create(host_t *me, host_t* other)
        this->public.destroy = (void(*)(child_sa_t*))destroy;
 
        /* private data */
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, CHILD_SA);
+       this->logger = logger_manager->get_logger(logger_manager, CHILD_SA);
        this->me = me;
        this->other = other;
        this->my_ah_spi = 0;
index 43de291..63879f1 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
+#include <string.h>
 
 #include "ike_sa.h"
 
 #include <types.h>
 #include <daemon.h>
 #include <definitions.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 #include <utils/logger_manager.h>
 #include <utils/randomizer.h>
@@ -526,12 +526,12 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        }
        
        /* concatenate nonces =  nonce_i | nonce_r */
-       nonces = allocator_alloc_as_chunk(nonce_i.len + nonce_r.len);
+       nonces = chunk_alloc(nonce_i.len + nonce_r.len);
        memcpy(nonces.ptr, nonce_i.ptr, nonce_i.len);
        memcpy(nonces.ptr + nonce_i.len, nonce_r.ptr, nonce_r.len);
 
        /* concatenate prf_seed = nonce_i | nonce_r | spi_i | spi_r */
-       nonces_spis = allocator_alloc_as_chunk(nonces.len + 16);
+       nonces_spis = chunk_alloc(nonces.len + 16);
        memcpy(nonces_spis.ptr, nonces.ptr, nonces.len);
        spi_i = this->ike_sa_id->get_initiator_spi(this->ike_sa_id);
        spi_r = this->ike_sa_id->get_responder_spi(this->ike_sa_id);
@@ -544,7 +544,7 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        this->prf->set_key(this->prf, nonces);
        this->prf->allocate_bytes(this->prf, secret, &skeyseed);
        this->logger->log_chunk(this->logger, PRIVATE | LEVEL1, "SKEYSEED", skeyseed);
-       allocator_free_chunk(&secret);
+       chunk_free(&secret);
 
        /* prf+ (SKEYSEED, Ni | Nr | SPIi | SPIr )
         * = SK_d | SK_ai | SK_ar | SK_ei | SK_er | SK_pi | SK_pr
@@ -555,9 +555,9 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        prf_plus = prf_plus_create(this->prf, nonces_spis);
        
        /* clean up unused stuff */
-       allocator_free_chunk(&nonces);
-       allocator_free_chunk(&nonces_spis);
-       allocator_free_chunk(&skeyseed);
+       chunk_free(&nonces);
+       chunk_free(&nonces_spis);
+       chunk_free(&skeyseed);
        
        
        /*
@@ -572,7 +572,7 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_d secret", key);
        this->child_prf->set_key(this->child_prf, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
        
        
        /* SK_ai/SK_ar used for integrity protection */
@@ -605,12 +605,12 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_ai secret", key);
        this->signer_initiator->set_key(this->signer_initiator, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
 
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_ar secret", key);
        this->signer_responder->set_key(this->signer_responder, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
        
        
        /* SK_ei/SK_er used for encryption */
@@ -644,12 +644,12 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_ei secret", key);
        this->crypter_initiator->set_key(this->crypter_initiator, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
        
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_er secret", key);
        this->crypter_responder->set_key(this->crypter_responder, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
        
        /* SK_pi/SK_pr used for authentication */
        proposal->get_algorithm(proposal, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, &algo);
@@ -669,12 +669,12 @@ static status_t build_transforms(private_ike_sa_t *this, proposal_t *proposal, d
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_pi secret", key);
        this->prf_auth_i->set_key(this->prf_auth_i, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
        
        prf_plus->allocate_bytes(prf_plus, key_size, &key);
        this->logger->log_chunk(this->logger, PRIVATE, "Sk_pr secret", key);
        this->prf_auth_r->set_key(this->prf_auth_r, key);
-       allocator_free_chunk(&key);
+       chunk_free(&key);
        
        /* all done, prf_plus not needed anymore */
        prf_plus->destroy(prf_plus);
@@ -1038,7 +1038,7 @@ static void destroy (private_ike_sa_t *this)
        this->randomizer->destroy(this->randomizer);
        this->current_state->destroy(this->current_state);
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -1046,7 +1046,7 @@ static void destroy (private_ike_sa_t *this)
  */
 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
 {
-       private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t);
+       private_ike_sa_t *this = malloc_thing(private_ike_sa_t);
 
        /* Public functions */
        this->protected.public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
@@ -1090,7 +1090,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        this->resend_last_reply = resend_last_reply;
 
        /* initialize private fields */
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        
        this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
        this->child_sas = linked_list_create();
index b4c285f..bf3a05d 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "ike_sa_id.h"
 
-#include <utils/allocator.h>
 
 
 typedef struct private_ike_sa_id_t private_ike_sa_id_t;
@@ -155,7 +154,7 @@ static ike_sa_id_t* clone(private_ike_sa_id_t *this)
  */
 static void destroy(private_ike_sa_id_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -163,7 +162,7 @@ static void destroy(private_ike_sa_id_t *this)
  */
 ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiator_flag)
 {
-       private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t);
+       private_ike_sa_id_t *this = malloc_thing(private_ike_sa_id_t);
 
        /* public functions */
        this->public.set_responder_spi = (void(*)(ike_sa_id_t*,u_int64_t)) set_responder_spi;
index 2838d2b..d0120fa 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <daemon.h>
 #include <sa/ike_sa_id.h>
-#include <utils/allocator.h>
 #include <utils/logger.h>
 #include <utils/logger_manager.h>
 #include <utils/linked_list.h>
@@ -87,7 +86,7 @@ static status_t ike_sa_entry_destroy(ike_sa_entry_t *this)
        /* also destroy IKE SA */
        this->ike_sa->destroy(this->ike_sa);
        this->ike_sa_id->destroy(this->ike_sa_id);
-       allocator_free(this);
+       free(this);
        return SUCCESS;
 }
 
@@ -101,7 +100,7 @@ static status_t ike_sa_entry_destroy(ike_sa_entry_t *this)
  */
 static ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
 {
-       ike_sa_entry_t *this = allocator_alloc_thing(ike_sa_entry_t);
+       ike_sa_entry_t *this = malloc_thing(ike_sa_entry_t);
 
        /* destroy function */
        this->destroy = ike_sa_entry_destroy;
@@ -752,7 +751,7 @@ static void destroy(private_ike_sa_manager_t *this)
        this->logger->log(this->logger,CONTROL | LEVEL2,"IKE_SA's deleted");
        pthread_mutex_unlock(&(this->mutex));
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -760,7 +759,7 @@ static void destroy(private_ike_sa_manager_t *this)
  */
 ike_sa_manager_t *ike_sa_manager_create()
 {
-       private_ike_sa_manager_t *this = allocator_alloc_thing(private_ike_sa_manager_t);
+       private_ike_sa_manager_t *this = malloc_thing(private_ike_sa_manager_t);
 
        /* assign public functions */
        this->public.destroy = (void(*)(ike_sa_manager_t*))destroy;
@@ -779,7 +778,7 @@ ike_sa_manager_t *ike_sa_manager_create()
        this->delete_entry = delete_entry;
 
        /* initialize private variables */
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA_MANAGER);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA_MANAGER);
        
        this->ike_sa_list = linked_list_create();
 
index b037cfc..00c38a8 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
+
+#include <string.h>
+
 #include "ike_auth_requested.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <encoding/payloads/ts_payload.h>
 #include <encoding/payloads/sa_payload.h>
 #include <encoding/payloads/id_payload.h>
@@ -329,11 +330,11 @@ static status_t process_message(private_ike_auth_requested_t *this, message_t *i
        }
        else
        {
-               seed = allocator_alloc_as_chunk(this->sent_nonce.len + this->received_nonce.len);
+               seed = chunk_alloc(this->sent_nonce.len + this->received_nonce.len);
                memcpy(seed.ptr, this->sent_nonce.ptr, this->sent_nonce.len);
                memcpy(seed.ptr + this->sent_nonce.len, this->received_nonce.ptr, this->received_nonce.len);
                prf_plus = prf_plus_create(this->ike_sa->get_child_prf(this->ike_sa), seed);
-               allocator_free_chunk(&seed);
+               chunk_free(&seed);
                
                status = this->child_sa->update(this->child_sa, this->proposal, prf_plus);
                prf_plus->destroy(prf_plus);
@@ -571,9 +572,9 @@ static ike_sa_state_t get_state(private_ike_auth_requested_t *this)
  */
 static void destroy(private_ike_auth_requested_t *this)
 {
-       allocator_free_chunk(&(this->received_nonce));
-       allocator_free_chunk(&(this->sent_nonce));
-       allocator_free_chunk(&(this->ike_sa_init_reply_data));
+       chunk_free(&(this->received_nonce));
+       chunk_free(&(this->sent_nonce));
+       chunk_free(&(this->ike_sa_init_reply_data));
        if (this->child_sa)
        {
                this->child_sa->destroy(this->child_sa);
@@ -600,16 +601,16 @@ static void destroy(private_ike_auth_requested_t *this)
        {
                this->proposal->destroy(this->proposal);
        }
-       allocator_free(this);
+       free(this);
 }
 /**
  * Implements protected_ike_sa_t.destroy_after_state_change
  */
 static void destroy_after_state_change(private_ike_auth_requested_t *this)
 {
-       allocator_free_chunk(&(this->received_nonce));
-       allocator_free_chunk(&(this->sent_nonce));
-       allocator_free_chunk(&(this->ike_sa_init_reply_data));
+       chunk_free(&(this->received_nonce));
+       chunk_free(&(this->sent_nonce));
+       chunk_free(&(this->ike_sa_init_reply_data));
        if (this->my_ts)
        {
                traffic_selector_t *ts;
@@ -632,7 +633,7 @@ static void destroy_after_state_change(private_ike_auth_requested_t *this)
        {
                this->proposal->destroy(this->proposal);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /* 
@@ -640,7 +641,7 @@ static void destroy_after_state_change(private_ike_auth_requested_t *this)
  */
 ike_auth_requested_t *ike_auth_requested_create(protected_ike_sa_t *ike_sa,chunk_t sent_nonce,chunk_t received_nonce,chunk_t ike_sa_init_reply_data, child_sa_t *child_sa)
 {
-       private_ike_auth_requested_t *this = allocator_alloc_thing(private_ike_auth_requested_t);
+       private_ike_auth_requested_t *this = malloc_thing(private_ike_auth_requested_t);
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
@@ -660,7 +661,7 @@ ike_auth_requested_t *ike_auth_requested_create(protected_ike_sa_t *ike_sa,chunk
        this->received_nonce = received_nonce;
        this->sent_nonce = sent_nonce;
        this->ike_sa_init_reply_data = ike_sa_init_reply_data;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        this->my_ts = NULL;
        this->other_ts = NULL;
        this->proposal = NULL;
index f967344..e91409f 100644 (file)
@@ -23,7 +23,6 @@
 #include "ike_sa_established.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <encoding/payloads/delete_payload.h>
 
 
@@ -214,7 +213,7 @@ static ike_sa_state_t get_state(private_ike_sa_established_t *this)
  */
 static void destroy(private_ike_sa_established_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /* 
@@ -222,7 +221,7 @@ static void destroy(private_ike_sa_established_t *this)
  */
 ike_sa_established_t *ike_sa_established_create(protected_ike_sa_t *ike_sa)
 {
-       private_ike_sa_established_t *this = allocator_alloc_thing(private_ike_sa_established_t);
+       private_ike_sa_established_t *this = malloc_thing(private_ike_sa_established_t);
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
@@ -234,7 +233,7 @@ ike_sa_established_t *ike_sa_established_create(protected_ike_sa_t *ike_sa)
        
        /* private data */
        this->ike_sa = ike_sa;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        
        return &(this->public);
 }
index 8d3ae55..e376930 100644 (file)
@@ -23,7 +23,6 @@
 #include "ike_sa_init_requested.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <encoding/payloads/sa_payload.h>
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/nonce_payload.h>
@@ -411,7 +410,7 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
  */
 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
 {
-       allocator_free(this->received_nonce.ptr);
+       free(this->received_nonce.ptr);
        this->received_nonce = nonce_payload->get_nonce(nonce_payload);
        return SUCCESS;
 }
@@ -693,12 +692,12 @@ static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
 {
        this->diffie_hellman->destroy(this->diffie_hellman);
-       allocator_free_chunk(&(this->ike_sa_init_request_data));
+       chunk_free(&(this->ike_sa_init_request_data));
        if (this->proposal)
        {
                this->proposal->destroy(this->proposal);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -707,9 +706,9 @@ static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
 static void destroy(private_ike_sa_init_requested_t *this)
 {
        this->diffie_hellman->destroy(this->diffie_hellman);
-       allocator_free(this->sent_nonce.ptr);
-       allocator_free(this->received_nonce.ptr);
-       allocator_free_chunk(&(this->ike_sa_init_request_data));
+       free(this->sent_nonce.ptr);
+       free(this->received_nonce.ptr);
+       chunk_free(&(this->ike_sa_init_request_data));
        if (this->child_sa)
        {
                this->child_sa->destroy(this->child_sa);
@@ -718,7 +717,7 @@ static void destroy(private_ike_sa_init_requested_t *this)
        {
                this->proposal->destroy(this->proposal);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /* 
@@ -726,7 +725,7 @@ static void destroy(private_ike_sa_init_requested_t *this)
  */
 ike_sa_init_requested_t *ike_sa_init_requested_create(protected_ike_sa_t *ike_sa, diffie_hellman_t *diffie_hellman, chunk_t sent_nonce,chunk_t ike_sa_init_request_data)
 {
-       private_ike_sa_init_requested_t *this = allocator_alloc_thing(private_ike_sa_init_requested_t);
+       private_ike_sa_init_requested_t *this = malloc_thing(private_ike_sa_init_requested_t);
        
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
@@ -748,7 +747,7 @@ ike_sa_init_requested_t *ike_sa_init_requested_create(protected_ike_sa_t *ike_sa
        /* private data */
        this->ike_sa = ike_sa;
        this->received_nonce = CHUNK_INITIALIZER;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        this->diffie_hellman = diffie_hellman;
        this->proposal = NULL;
        this->sent_nonce = sent_nonce;
index 5254874..54c0cc2 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
+
+#include <string.h>
+
 #include "ike_sa_init_responded.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <sa/authenticator.h>
 #include <sa/child_sa.h>
 #include <encoding/payloads/ts_payload.h>
@@ -473,11 +474,11 @@ static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_paylo
        }
        
        /* set up child sa */
-       seed = allocator_alloc_as_chunk(this->received_nonce.len + this->sent_nonce.len);
+       seed = chunk_alloc(this->received_nonce.len + this->sent_nonce.len);
        memcpy(seed.ptr, this->received_nonce.ptr, this->received_nonce.len);
        memcpy(seed.ptr + this->received_nonce.len, this->sent_nonce.ptr, this->sent_nonce.len);
        prf_plus = prf_plus_create(this->ike_sa->get_child_prf(this->ike_sa), seed);
-       allocator_free_chunk(&seed);
+       chunk_free(&seed);
        
        connection = this->ike_sa->get_connection(this->ike_sa);
        this->child_sa = child_sa_create(connection->get_my_host(connection),
@@ -607,10 +608,10 @@ static ike_sa_state_t get_state(private_ike_sa_init_responded_t *this)
  */
 static void destroy(private_ike_sa_init_responded_t *this)
 {
-       allocator_free_chunk(&(this->received_nonce));
-       allocator_free_chunk(&(this->sent_nonce));
-       allocator_free_chunk(&(this->ike_sa_init_response_data));
-       allocator_free_chunk(&(this->ike_sa_init_request_data));
+       chunk_free(&(this->received_nonce));
+       chunk_free(&(this->sent_nonce));
+       chunk_free(&(this->ike_sa_init_response_data));
+       chunk_free(&(this->ike_sa_init_request_data));
        if (this->my_ts)
        {
                traffic_selector_t *ts;
@@ -634,17 +635,17 @@ static void destroy(private_ike_sa_init_responded_t *this)
                this->child_sa->destroy(this->child_sa);
        }
 
-       allocator_free(this);
+       free(this);
 }
 /**
  * Implementation of private_ike_sa_init_responded.destroy_after_state_change.
  */
 static void destroy_after_state_change(private_ike_sa_init_responded_t *this)
 {
-       allocator_free_chunk(&(this->received_nonce));
-       allocator_free_chunk(&(this->sent_nonce));
-       allocator_free_chunk(&(this->ike_sa_init_response_data));
-       allocator_free_chunk(&(this->ike_sa_init_request_data));
+       chunk_free(&(this->received_nonce));
+       chunk_free(&(this->sent_nonce));
+       chunk_free(&(this->ike_sa_init_response_data));
+       chunk_free(&(this->ike_sa_init_request_data));
        if (this->my_ts)
        {
                traffic_selector_t *ts;
@@ -664,7 +665,7 @@ static void destroy_after_state_change(private_ike_sa_init_responded_t *this)
                this->other_ts->destroy(this->other_ts);
        }
 
-       allocator_free(this);
+       free(this);
 }
 
 /* 
@@ -672,7 +673,7 @@ static void destroy_after_state_change(private_ike_sa_init_responded_t *this)
  */
 ike_sa_init_responded_t *ike_sa_init_responded_create(protected_ike_sa_t *ike_sa, chunk_t received_nonce, chunk_t sent_nonce,chunk_t ike_sa_init_request_data, chunk_t ike_sa_init_response_data)
 {
-       private_ike_sa_init_responded_t *this = allocator_alloc_thing(private_ike_sa_init_responded_t);
+       private_ike_sa_init_responded_t *this = malloc_thing(private_ike_sa_init_responded_t);
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
@@ -696,7 +697,7 @@ ike_sa_init_responded_t *ike_sa_init_responded_create(protected_ike_sa_t *ike_sa
        this->my_ts = NULL;
        this->other_ts = NULL;
        this->child_sa = NULL;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        
        return &(this->public);
 }
index 8588513..35d1523 100644 (file)
@@ -26,7 +26,6 @@
 #include <daemon.h>
 #include <sa/states/state.h>
 #include <sa/states/ike_sa_init_requested.h>
-#include <utils/allocator.h>
 #include <queues/jobs/retransmit_request_job.h>
 #include <crypto/diffie_hellman.h>
 #include <encoding/payloads/sa_payload.h>
@@ -247,7 +246,7 @@ static void build_ke_payload(private_initiator_init_t *this, message_t *request)
        ke_payload->set_dh_group_number(ke_payload, dh_group);
        ke_payload->set_key_exchange_data(ke_payload, key_data);
        
-       allocator_free_chunk(&key_data);
+       chunk_free(&key_data);
        
        this->logger->log(this->logger, CONTROL|LEVEL2, "Add KE payload to message");
        request->add_payload(request, (payload_t *) ke_payload);
@@ -315,9 +314,9 @@ static void destroy(private_initiator_init_t *this)
        }
        if (this->sent_nonce.ptr != NULL)
        {
-               allocator_free(this->sent_nonce.ptr);
+               free(this->sent_nonce.ptr);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -326,7 +325,7 @@ static void destroy(private_initiator_init_t *this)
 static void destroy_after_state_change (private_initiator_init_t *this)
 {
        this->logger->log(this->logger, CONTROL | LEVEL3, "Going to destroy initiator_init_t state object");
-       allocator_free(this);
+       free(this);
 }
 
 /* 
@@ -334,7 +333,7 @@ static void destroy_after_state_change (private_initiator_init_t *this)
  */
 initiator_init_t *initiator_init_create(protected_ike_sa_t *ike_sa)
 {
-       private_initiator_init_t *this = allocator_alloc_thing(private_initiator_init_t);
+       private_initiator_init_t *this = malloc_thing(private_initiator_init_t);
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
@@ -353,7 +352,7 @@ initiator_init_t *initiator_init_create(protected_ike_sa_t *ike_sa)
        
        /* private data */
        this->ike_sa = ike_sa;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        this->sent_nonce = CHUNK_INITIALIZER;
        this->diffie_hellman = NULL;
 
index 32aa6db..10acf64 100644 (file)
@@ -25,7 +25,6 @@
 #include <daemon.h>
 #include <sa/states/state.h>
 #include <sa/states/ike_sa_init_responded.h>
-#include <utils/allocator.h>
 #include <encoding/payloads/sa_payload.h>
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/nonce_payload.h>
@@ -413,7 +412,7 @@ static status_t build_ke_payload(private_responder_init_t *this,ke_payload_t *ke
        ke_payload = ke_payload_create();
        ke_payload->set_key_exchange_data(ke_payload,key_data);
        ke_payload->set_dh_group_number(ke_payload, this->dh_group_number);
-       allocator_free_chunk(&key_data);
+       chunk_free(&key_data);
 
        this->logger->log(this->logger, CONTROL|LEVEL2, "Add KE payload to message");
        response->add_payload(response,(payload_t *) ke_payload);
@@ -431,7 +430,7 @@ static status_t build_nonce_payload(private_responder_init_t *this,nonce_payload
        status_t status;
 
        this->logger->log(this->logger, CONTROL | LEVEL2, "Process received NONCE payload");
-       allocator_free(this->received_nonce.ptr);
+       free(this->received_nonce.ptr);
        this->received_nonce = CHUNK_INITIALIZER;
 
        this->logger->log(this->logger, CONTROL | LEVEL2, "Get NONCE value and store it");
@@ -498,9 +497,9 @@ static void destroy(private_responder_init_t *this)
        this->logger->log(this->logger, CONTROL | LEVEL1, "Going to destroy responder init state object");
        
        this->logger->log(this->logger, CONTROL | LEVEL2, "Destroy sent nonce");
-       allocator_free_chunk(&(this->sent_nonce));
+       chunk_free(&(this->sent_nonce));
        this->logger->log(this->logger, CONTROL | LEVEL2, "Destroy received nonce");
-       allocator_free_chunk(&(this->received_nonce));
+       chunk_free(&(this->received_nonce));
 
        if (this->diffie_hellman != NULL)
        {
@@ -512,7 +511,7 @@ static void destroy(private_responder_init_t *this)
                this->proposal->destroy(this->proposal);
        }
        this->logger->log(this->logger, CONTROL | LEVEL2, "Destroy object");
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -534,7 +533,7 @@ static void destroy_after_state_change (private_responder_init_t *this)
        }
        
        this->logger->log(this->logger, CONTROL | LEVEL2, "Destroy object");    
-       allocator_free(this);
+       free(this);
 }
 
 /* 
@@ -542,7 +541,7 @@ static void destroy_after_state_change (private_responder_init_t *this)
  */
 responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa)
 {
-       private_responder_init_t *this = allocator_alloc_thing(private_responder_init_t);
+       private_responder_init_t *this = malloc_thing(private_responder_init_t);
 
        /* interface functions */
        this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
@@ -558,7 +557,7 @@ responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa)
        
        /* private data */
        this->ike_sa = ike_sa;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, IKE_SA);
+       this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
        this->sent_nonce = CHUNK_INITIALIZER;
        this->received_nonce = CHUNK_INITIALIZER;
        this->dh_group_number = MODP_UNDEFINED;
index 87238d0..180ea55 100644 (file)
@@ -35,7 +35,6 @@
 #include "kernel_interface.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 
@@ -239,7 +238,7 @@ static status_t get_spi(private_kernel_interface_t *this,
        }
        
        *spi = response->sa.id.spi;
-       allocator_free(response);
+       free(response);
        
        return status;
 }
@@ -329,7 +328,7 @@ static status_t add_sa(     private_kernel_interface_t *this,
                status = FAILED;
        }
        
-       allocator_free(response);
+       free(response);
        return SUCCESS;
 }
 
@@ -366,7 +365,7 @@ static status_t del_sa(     private_kernel_interface_t *this,
                status = FAILED;
        }
        
-       allocator_free(response);
+       free(response);
        return SUCCESS;
 }
 
@@ -458,7 +457,7 @@ static status_t add_policy(private_kernel_interface_t *this,
                status = FAILED;
        }
        
-       allocator_free(response);
+       free(response);
        return status;
 }
 
@@ -506,7 +505,7 @@ static status_t del_policy(private_kernel_interface_t *this,
                status = FAILED;
        }
        
-       allocator_free(response);
+       free(response);
        return status;
 }
 
@@ -623,7 +622,7 @@ static void receive_messages(private_kernel_interface_t *this)
                else
                {
                        /* add response to queue */                     
-                       listed_response = allocator_alloc(sizeof(response));
+                       listed_response = malloc(sizeof(response));
                        memcpy(listed_response, &response, sizeof(response));
 
                        pthread_mutex_lock(&(this->mutex));
@@ -645,7 +644,7 @@ static void destroy(private_kernel_interface_t *this)
        pthread_join(this->thread, NULL);
        close(this->socket);
        this->responses->destroy(this->responses);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -653,7 +652,7 @@ static void destroy(private_kernel_interface_t *this)
  */
 kernel_interface_t *kernel_interface_create()
 {
-       private_kernel_interface_t *this = allocator_alloc_thing(private_kernel_interface_t);
+       private_kernel_interface_t *this = malloc_thing(private_kernel_interface_t);
        
        /* public functions */
        this->public.get_spi = (status_t(*)(kernel_interface_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
@@ -675,17 +674,17 @@ kernel_interface_t *kernel_interface_create()
        this->socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_XFRM);
        if (this->socket <= 0)
        {
-               allocator_free(this);
+               free(this);
                charon->kill(charon, "Unable to create netlink socket");        
        }
        
        if (pthread_create(&(this->thread), NULL, (void*(*)(void*))this->receive_messages, this) != 0)
        {
                close(this->socket);
-               allocator_free(this);
+               free(this);
                charon->kill(charon, "Unable to create netlink thread");
        }
        
-       charon->logger_manager->enable_log_level(charon->logger_manager, TESTER, FULL);
+       logger_manager->enable_log_level(logger_manager, TESTER, FULL);
        return (&this->public);
 }
index 9058ecb..0cf8b7b 100644 (file)
@@ -31,7 +31,6 @@
 #include <queues/job_queue.h>
 #include <queues/jobs/job.h>
 #include <queues/jobs/incoming_packet_job.h>
-#include <utils/allocator.h>
 #include <utils/logger_manager.h>
 
 
@@ -103,7 +102,7 @@ static void destroy(private_receiver_t *this)
        pthread_join(this->assigned_thread, NULL);
        this->logger->log(this->logger, CONTROL | LEVEL1, "Receiver thread terminated");
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -111,17 +110,17 @@ static void destroy(private_receiver_t *this)
  */
 receiver_t * receiver_create()
 {
-       private_receiver_t *this = allocator_alloc_thing(private_receiver_t);
+       private_receiver_t *this = malloc_thing(private_receiver_t);
 
        this->public.destroy = (void(*)(receiver_t*)) destroy;
        this->receive_packets = receive_packets;
        
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, RECEIVER);
+       this->logger = logger_manager->get_logger(logger_manager, RECEIVER);
        
        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");
-               allocator_free(this);
+               free(this);
                charon->kill(charon, "Unable to create receiver thread");
        }
 
index 8750cda..47c5d6f 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <daemon.h>
 #include <definitions.h>
-#include <utils/allocator.h>
 #include <utils/logger_manager.h>
 #include <queues/job_queue.h>
 
@@ -98,7 +97,7 @@ static void destroy(private_scheduler_t *this)
        pthread_join(this->assigned_thread, NULL);
        this->logger->log(this->logger, CONTROL | LEVEL1, "Scheduler thread terminated");
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -106,18 +105,18 @@ static void destroy(private_scheduler_t *this)
  */
 scheduler_t * scheduler_create()
 {
-       private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t);
+       private_scheduler_t *this = malloc_thing(private_scheduler_t);
 
        this->public.destroy = (void(*)(scheduler_t*)) destroy;
        this->get_events = get_events;
        
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, SCHEDULER);
+       this->logger = logger_manager->get_logger(logger_manager, SCHEDULER);
        
        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!");
-               allocator_free(this);
+               free(this);
                charon->kill(charon, "Unable to create scheduler thread");
        }
 
index 90d9e40..42d11be 100644 (file)
@@ -29,7 +29,6 @@
 #include <network/socket.h>
 #include <network/packet.h>
 #include <queues/send_queue.h>
-#include <utils/allocator.h>
 #include <utils/logger_manager.h>
 
 
@@ -101,7 +100,7 @@ static void destroy(private_sender_t *this)
        pthread_join(this->assigned_thread, NULL);
        this->logger->log(this->logger, CONTROL | LEVEL1, "Sender thread terminated");
 
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -109,17 +108,17 @@ static void destroy(private_sender_t *this)
  */
 sender_t * sender_create()
 {
-       private_sender_t *this = allocator_alloc_thing(private_sender_t);
+       private_sender_t *this = malloc_thing(private_sender_t);
 
        this->send_packets = send_packets;
        this->public.destroy = (void(*)(sender_t*)) destroy;
        
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, SENDER);
+       this->logger = logger_manager->get_logger(logger_manager, SENDER);
 
        if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->send_packets, this) != 0)
        {
                this->logger->log(this->logger, ERROR, "Sender thread could not be created");
-               allocator_free(this);
+               free(this);
                charon->kill(charon, "Unable to create sender thread");
        }
 
index 4468a37..b95884c 100755 (executable)
@@ -37,7 +37,6 @@
 #include <types.h>
 #include <daemon.h>
 #include <crypto/certificate.h>
-#include <utils/allocator.h>
 #include <queues/jobs/initiate_ike_sa_job.h>
 
 
@@ -97,8 +96,8 @@ static void configuration_entry_destroy (configuration_entry_t *this)
        {
                this->public_key->destroy(this->public_key);
        }
-       allocator_free(this->name);
-       allocator_free(this);
+       free(this->name);
+       free(this);
 }
 
 /**
@@ -107,7 +106,7 @@ static void configuration_entry_destroy (configuration_entry_t *this)
 static configuration_entry_t * configuration_entry_create(char *name, connection_t* connection, policy_t *policy, 
                                                                                                                  rsa_private_key_t *private_key, rsa_public_key_t *public_key)
 {
-       configuration_entry_t *entry = allocator_alloc_thing(configuration_entry_t);
+       configuration_entry_t *entry = malloc_thing(configuration_entry_t);
 
        /* functions */
        entry->destroy = configuration_entry_destroy;
@@ -117,7 +116,7 @@ static configuration_entry_t * configuration_entry_create(char *name, connection
        entry->policy = policy;
        entry->public_key = public_key;
        entry->private_key = private_key;
-       entry->name = allocator_alloc(strlen(name) + 1);
+       entry->name = malloc(strlen(name) + 1);
        strcpy(entry->name, name);
        
        return entry;
@@ -627,13 +626,11 @@ static void stroke_logtype(private_stroke_t *this, stroke_msg_t *msg)
        
        if (msg->logtype.enable)
        {
-               charon->logger_manager->enable_log_level(charon->logger_manager,
-                                                                                                context, level);
+               logger_manager->enable_log_level(logger_manager, context, level);
        }
        else
        {
-               charon->logger_manager->disable_log_level(charon->logger_manager,
-                               context, level);
+               logger_manager->disable_log_level(logger_manager, context, level);
        }
 }
 
@@ -677,7 +674,7 @@ static void stroke_loglevel(private_stroke_t *this, stroke_msg_t *msg)
                return;
        }
        
-       charon->logger_manager->enable_log_level(charon->logger_manager, context, level);
+       logger_manager->enable_log_level(logger_manager, context, level);
 }
 
 /**
@@ -692,11 +689,18 @@ static void stroke_receive(private_stroke_t *this)
        ssize_t bytes_read;
        int strokefd;
        FILE *strokefile;
+       int oldstate;
+       
+       /* disable cancellation by default */
+       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
        
        while (1)
        {
+               /* wait for connections, but allow thread to terminate */
+               pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
                strokefd = accept(this->socket, (struct sockaddr *)&strokeaddr, &strokeaddrlen);
-       
+               pthread_setcancelstate(oldstate, NULL);
+               
                if (strokefd < 0)
                {
                        this->logger->log(this->logger, ERROR, "accepting stroke connection failed: %s", strerror(errno));
@@ -713,7 +717,7 @@ static void stroke_receive(private_stroke_t *this)
                }
                
                /* read message */
-               msg = allocator_alloc(msg_length);
+               msg = malloc(msg_length);
                bytes_read = recv(strokefd, msg, msg_length, 0);
                if (bytes_read != msg_length)
                {
@@ -727,7 +731,7 @@ static void stroke_receive(private_stroke_t *this)
                {
                        this->logger->log(this->logger, ERROR, "opening stroke output channel failed:", strerror(errno));
                        close(strokefd);
-                       allocator_free(msg);
+                       free(msg);
                        continue;
                }
                
@@ -773,7 +777,7 @@ static void stroke_receive(private_stroke_t *this)
                this->stroke_logger->destroy(this->stroke_logger);
                fclose(strokefile);
                close(strokefd);
-               allocator_free(msg);
+               free(msg);
        }
 }
 
@@ -972,7 +976,7 @@ static status_t get_shared_secret(credential_store_t *this, identification_t *id
        preshared_secret->ptr = secret;
        preshared_secret->len = strlen(secret) + 1;
        
-       *preshared_secret = allocator_clone_chunk(*preshared_secret);
+       *preshared_secret = chunk_clone(*preshared_secret);
        return SUCCESS;
 }
 
@@ -1046,6 +1050,9 @@ static void destroy(private_stroke_t *this)
        configuration_entry_t *entry;
        rsa_private_key_t *priv_key;
        
+       pthread_cancel(this->assigned_thread);
+       pthread_join(this->assigned_thread, NULL);
+       
        while (this->configurations->remove_first(this->configurations, (void **)&entry) == SUCCESS)
        {
                entry->destroy(entry);
@@ -1060,7 +1067,7 @@ static void destroy(private_stroke_t *this)
 
        close(this->socket);
        unlink(socket_addr.sun_path);
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -1078,7 +1085,7 @@ void do_nothing(void *nothing)
  */
 stroke_t *stroke_create()
 {
-       private_stroke_t *this = allocator_alloc_thing(private_stroke_t);
+       private_stroke_t *this = malloc_thing(private_stroke_t);
        mode_t old;
 
        /* public functions */
@@ -1097,14 +1104,14 @@ stroke_t *stroke_create()
        this->stroke_receive = stroke_receive;
        this->get_connection_by_name = get_connection_by_name;
        
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, CONFIG);
+       this->logger = logger_manager->get_logger(logger_manager, CONFIG);
        
        /* set up unix socket */
        this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
        if (this->socket == -1)
        {
                this->logger->log(this->logger, ERROR, "could not create whack socket");
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
@@ -1113,7 +1120,7 @@ stroke_t *stroke_create()
        {
                this->logger->log(this->logger, ERROR, "could not bind stroke socket: %s", strerror(errno));
                close(this->socket);
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        umask(old);
@@ -1123,7 +1130,7 @@ stroke_t *stroke_create()
                this->logger->log(this->logger, ERROR, "could not listen on stroke socket: %s", strerror(errno));
                close(this->socket);
                unlink(socket_addr.sun_path);
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
@@ -1133,7 +1140,7 @@ stroke_t *stroke_create()
                this->logger->log(this->logger, ERROR, "Could not spawn stroke thread");
                close(this->socket);
                unlink(socket_addr.sun_path);
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
index 1f1584e..4482e79 100644 (file)
@@ -35,7 +35,6 @@
 #include <queues/jobs/initiate_ike_sa_job.h>
 #include <queues/jobs/retransmit_request_job.h>
 #include <encoding/payloads/notify_payload.h>
-#include <utils/allocator.h>
 #include <utils/logger.h>
 
 
@@ -292,8 +291,10 @@ static void process_incoming_packet_job(private_thread_pool_t *this, incoming_pa
 
        if (status == CREATED)
        {
-               this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3, "Create Job to delete half open IKE_SA.");
-               this->create_delete_half_open_ike_sa_job(this,ike_sa_id,charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
+               this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3, 
+                                                                "Create Job to delete half open IKE_SA.");
+               this->create_delete_half_open_ike_sa_job(this,ike_sa_id, 
+                               charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
        }
 
        status = ike_sa->process_message(ike_sa, message);
@@ -349,7 +350,8 @@ static void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ik
        }
 
        this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3, "Create Job to delete half open IKE_SA.");
-       this->create_delete_half_open_ike_sa_job(this,ike_sa->get_id(ike_sa),charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
+       this->create_delete_half_open_ike_sa_job(this,ike_sa->get_id(ike_sa),
+                                                                                        charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
        
        this->worker_logger->log(this->worker_logger, CONTROL|LEVEL2, "Checking in IKE SA");
        status = charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
@@ -543,19 +545,25 @@ static void destroy(private_thread_pool_t *this)
        int current;
        /* flag thread for termination */
        for (current = 0; current < this->pool_size; current++) {
-               this->pool_logger->log(this->pool_logger, CONTROL, "cancelling worker thread #%d", current+1);
+               this->pool_logger->log(this->pool_logger, CONTROL, "cancelling worker thread #%d", current+1);
                pthread_cancel(this->threads[current]);
        }
        
        /* wait for all threads */
        for (current = 0; current < this->pool_size; current++) {
-               pthread_join(this->threads[current], NULL);
-               this->pool_logger->log(this->pool_logger, CONTROL, "worker thread #%d terminated", current+1);
-       }       
+               if (pthread_join(this->threads[current], NULL) == 0)
+               {
+                       this->pool_logger->log(this->pool_logger, CONTROL, "worker thread #%d terminated", current+1);
+               }
+               else
+               {
+                       this->pool_logger->log(this->pool_logger, ERROR, "could not terminate worker thread #%d", current+1);
+               }
+       }
 
        /* free mem */
-       allocator_free(this->threads);
-       allocator_free(this);
+       free(this->threads);
+       free(this);
 }
 
 /*
@@ -565,7 +573,7 @@ thread_pool_t *thread_pool_create(size_t pool_size)
 {
        int current;
        
-       private_thread_pool_t *this = allocator_alloc_thing(private_thread_pool_t);
+       private_thread_pool_t *this = malloc_thing(private_thread_pool_t);
        
        /* fill in public fields */
        this->public.destroy = (void(*)(thread_pool_t*))destroy;
@@ -581,11 +589,11 @@ thread_pool_t *thread_pool_create(size_t pool_size)
        
        this->pool_size = pool_size;
        
-       this->threads = allocator_alloc(sizeof(pthread_t) * pool_size);
+       this->threads = malloc(sizeof(pthread_t) * pool_size);
 
-       this->pool_logger = charon->logger_manager->get_logger(charon->logger_manager, THREAD_POOL);
+       this->pool_logger = logger_manager->get_logger(logger_manager, THREAD_POOL);
 
-       this->worker_logger = charon->logger_manager->get_logger(charon->logger_manager, WORKER);
+       this->worker_logger = logger_manager->get_logger(logger_manager, WORKER);
        
        /* try to create as many threads as possible, up tu pool_size */
        for (current = 0; current < pool_size; current++) 
@@ -600,8 +608,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");
-                               allocator_free(this->threads);
-                               allocator_free(this);
+                               free(this->threads);
+                               free(this);
                                return NULL;
                        }
                        /* not all threads could be created, but at least one :-/ */
index f9a8425..75ad116 100644 (file)
  */
 
 #include <gmp.h>
+#include <string.h>
 
 #include "der_decoder.h"
 
-#include <utils/allocator.h>
 #include <daemon.h>
 
 
@@ -280,7 +280,7 @@ status_t read_bitstring(private_der_decoder_t *this, chunk_t data)
        
        chunk_t *chunk = (chunk_t*)((u_int8_t*)this->output + this->rule->data_offset);
        
-       *chunk = allocator_clone_chunk(data);
+       *chunk = chunk_clone(data);
        
        this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_BITSTRING", data);
        return SUCCESS;
@@ -293,7 +293,7 @@ status_t read_any(private_der_decoder_t *this, chunk_t data)
 {      
        chunk_t *chunk = (chunk_t*)((u_int8_t*)this->output + this->rule->data_offset);
        
-       *chunk = allocator_clone_chunk(data);
+       *chunk = chunk_clone(data);
        
        this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_ANY", data);
        return SUCCESS;
@@ -481,7 +481,7 @@ status_t decode(private_der_decoder_t *this, chunk_t input, void *output)
 static void destroy(private_der_decoder_t *this)
 {
        this->logger->destroy(this->logger);
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -489,7 +489,7 @@ static void destroy(private_der_decoder_t *this)
  */
 der_decoder_t *der_decoder_create(asn1_rule_t *rules)
 {
-       private_der_decoder_t *this = allocator_alloc_thing(private_der_decoder_t);
+       private_der_decoder_t *this = malloc_thing(private_der_decoder_t);
        
        /* public functions */
        this->public.decode = (status_t (*) (der_decoder_t*,chunk_t,void*))decode;
index 07beb58..f1fde3b 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "der_encoder.h"
 
-#include <utils/allocator.h>
 #include <daemon.h>
 
 
@@ -197,7 +196,7 @@ static status_t decode(private_der_encoder_t *this, chunk_t input, void *output)
  */
 static void destroy(private_der_encoder_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -205,14 +204,14 @@ static void destroy(private_der_encoder_t *this)
  */
 der_encoder_t *der_encoder_create(asn1_rule_t *rules)
 {
-       private_der_encoder_t *this = allocator_alloc_thing(private_der_encoder_t);
+       private_der_encoder_t *this = malloc_thing(private_der_encoder_t);
        
        /* public functions */
        this->public.decode = (status_t (*) (der_encoder_t*,chunk_t,void*))decode;
        this->public.destroy = (void (*) (der_encoder_t*))destroy;
        
        this->first_rule = rules;
-       this->logger = charon->logger_manager->get_logger(charon->logger_manager, DER_DECODER);
+       this->logger = logger_manager>logger_manager->get_logger(logger_manager>logger_manager, DER_DECODER);
        
        return &(this->public);
 }
index 2c8f30b..34c82e8 100755 (executable)
@@ -27,7 +27,6 @@
 #include "certificate.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <asn1/der_decoder.h>
 
 
@@ -151,10 +150,10 @@ static rsa_public_key_t *get_public_key(private_certificate_t *this)
 static void destroy(private_certificate_t *this)
 {
        this->public_key->destroy(this->public_key);
-       allocator_free(this->pubkey.ptr);
-       allocator_free(this->signature.ptr);
-       allocator_free(this->tbs_cert.ptr);
-       allocator_free(this);
+       free(this->pubkey.ptr);
+       free(this->signature.ptr);
+       free(this->tbs_cert.ptr);
+       free(this);
 }
 
 /*
@@ -162,7 +161,7 @@ static void destroy(private_certificate_t *this)
  */
 certificate_t *certificate_create_from_chunk(chunk_t chunk)
 {
-       private_certificate_t *this = allocator_alloc_thing(private_certificate_t);
+       private_certificate_t *this = malloc_thing(private_certificate_t);
        der_decoder_t *dd;
        
        /* public functions */
@@ -178,7 +177,7 @@ certificate_t *certificate_create_from_chunk(chunk_t chunk)
        
        if (dd->decode(dd, chunk, this) != SUCCESS)
        {
-               allocator_free(this);
+               free(this);
                dd->destroy(dd);
                return NULL;
        }
@@ -187,8 +186,8 @@ certificate_t *certificate_create_from_chunk(chunk_t chunk)
        this->public_key = rsa_public_key_create_from_chunk(this->pubkey);
        if (this->public_key == NULL)
        {
-               allocator_free(this->pubkey.ptr);
-               allocator_free(this);
+               free(this->pubkey.ptr);
+               free(this);
                return NULL;
        }
        
@@ -220,8 +219,10 @@ certificate_t *certificate_create_from_file(char *filename)
        
        if (fread(buffer, stb.st_size, 1, file) == -1)
        {
+               fclose(file);
                return NULL;
        }
+       fclose(file);
        
        chunk.ptr = buffer;
        chunk.len = stb.st_size;
index d5d0f9a..9b7b07c 100644 (file)
@@ -23,7 +23,6 @@
  
 #include "aes_cbc_crypter.h"
 
-#include <utils/allocator.h>
 
 
 /*
@@ -1385,7 +1384,7 @@ static status_t decrypt (private_aes_cbc_crypter_t *this, chunk_t data, chunk_t
                return INVALID_ARG;
        }
        
-       decrypted->ptr = allocator_alloc(data.len);
+       decrypted->ptr = malloc(data.len);
        if (decrypted->ptr == NULL)
        {
                return OUT_OF_RES;
@@ -1433,7 +1432,7 @@ static status_t encrypt (private_aes_cbc_crypter_t *this, chunk_t data, chunk_t
                return INVALID_ARG;
        }
        
-       encrypted->ptr = allocator_alloc(data.len);
+       encrypted->ptr = malloc(data.len);
        if (encrypted->ptr == NULL)
        {
                return OUT_OF_RES;
@@ -1579,7 +1578,7 @@ static status_t set_key (private_aes_cbc_crypter_t *this, chunk_t key)
  */
 static void destroy (private_aes_cbc_crypter_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -1587,7 +1586,7 @@ static void destroy (private_aes_cbc_crypter_t *this)
  */
 aes_cbc_crypter_t *aes_cbc_crypter_create(size_t key_size)
 {
-       private_aes_cbc_crypter_t *this = allocator_alloc_thing(private_aes_cbc_crypter_t);
+       private_aes_cbc_crypter_t *this = malloc_thing(private_aes_cbc_crypter_t);
        
        #if !defined(FIXED_TABLES)
        if(!tab_gen) { gen_tabs(); tab_gen = 1; }
@@ -1608,7 +1607,7 @@ aes_cbc_crypter_t *aes_cbc_crypter_create(size_t key_size)
                this->aes_Nkey = 4;
                break;
        default:
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
index 84cf1e5..e458fb8 100644 (file)
@@ -28,7 +28,6 @@
 #include "diffie_hellman.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <utils/randomizer.h>
 
 
@@ -553,7 +552,7 @@ static void destroy(private_diffie_hellman_t *this)
                /* other public value gets initialized together with shared secret */
                mpz_clear(this->shared_secret);
        }
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -561,7 +560,7 @@ static void destroy(private_diffie_hellman_t *this)
  */
 diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
 {
-       private_diffie_hellman_t *this = allocator_alloc_thing(private_diffie_hellman_t);
+       private_diffie_hellman_t *this = malloc_thing(private_diffie_hellman_t);
        randomizer_t *randomizer;
        chunk_t random_bytes;
 
@@ -587,24 +586,24 @@ diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number)
        /* set this->modulus */ 
        if (this->set_modulus(this) != SUCCESS)
        {
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        randomizer = randomizer_create();
        if (randomizer == NULL)
        {
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        if (randomizer->allocate_pseudo_random_bytes(randomizer, this->modulus_length, &random_bytes) != SUCCESS)
        {
                randomizer->destroy(randomizer);
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
        mpz_import(this->my_private_value, random_bytes.len, 1, 1, 1, 0, random_bytes.ptr);
-       allocator_free_chunk(&random_bytes);
+       chunk_free(&random_bytes);
        
        randomizer->destroy(randomizer);
        
index cd883d9..8d63611 100644 (file)
  * for more details.
  */
 
+#include <string.h>
+
 #include "md5_hasher.h"
 
 #include <definitions.h>
-#include <utils/allocator.h>
 
 #define BLOCK_SIZE_MD5 16
 
@@ -334,7 +335,7 @@ static void allocate_hash(private_md5_hasher_t *this, chunk_t chunk, chunk_t *ha
        MD5Update(this, chunk.ptr, chunk.len);
        if (hash != NULL)
        {       
-               allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_MD5);
+               allocated_hash.ptr = malloc(BLOCK_SIZE_MD5);
                allocated_hash.len = BLOCK_SIZE_MD5;
 
                MD5Final(this, allocated_hash.ptr);
@@ -370,7 +371,7 @@ static void reset(private_md5_hasher_t *this)
  */
 static void destroy(private_md5_hasher_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -378,7 +379,7 @@ static void destroy(private_md5_hasher_t *this)
  */
 md5_hasher_t *md5_hasher_create()
 {
-       private_md5_hasher_t *this = allocator_alloc_thing(private_md5_hasher_t);
+       private_md5_hasher_t *this = malloc_thing(private_md5_hasher_t);
 
        this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
        this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
index 2fa659f..b66e75a 100644 (file)
  * for more details.
  */
 
+#include <string.h>
+
 #include "sha1_hasher.h"
 
 #include <definitions.h>
-#include <utils/allocator.h>
 
 #define BLOCK_SIZE_SHA1 20
 
@@ -208,7 +209,7 @@ static void allocate_hash(private_sha1_hasher_t *this, chunk_t chunk, chunk_t *h
        SHA1Update(this, chunk.ptr, chunk.len);
        if (hash != NULL)
        {       
-               allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_SHA1);
+               allocated_hash.ptr = malloc(BLOCK_SIZE_SHA1);
                allocated_hash.len = BLOCK_SIZE_SHA1;
                
                SHA1Final(this, allocated_hash.ptr);
@@ -244,7 +245,7 @@ static void reset(private_sha1_hasher_t *this)
  */
 static void destroy(private_sha1_hasher_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 
@@ -253,7 +254,7 @@ static void destroy(private_sha1_hasher_t *this)
  */
 sha1_hasher_t *sha1_hasher_create()
 {
-       private_sha1_hasher_t *this = allocator_alloc_thing(private_sha1_hasher_t);
+       private_sha1_hasher_t *this = malloc_thing(private_sha1_hasher_t);
        
        this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
        this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
index dc31af3..84d6044 100644 (file)
  * for more details.
  */
 
+#include <string.h>
 
 #include "hmac.h"
 
-#include <utils/allocator.h>
-
 
 typedef struct private_hmac_t private_hmac_t;
 
@@ -111,7 +110,7 @@ static void allocate_mac(private_hmac_t *this, chunk_t data, chunk_t *out)
        else
        {
                out->len = this->h->get_block_size(this->h);
-               out->ptr = allocator_alloc(out->len);
+               out->ptr = malloc(out->len);
                this->hmac.get_mac(&(this->hmac), data, out->ptr);
        }
 }
@@ -163,9 +162,9 @@ static void set_key(private_hmac_t *this, chunk_t key)
 static void destroy(private_hmac_t *this)
 {
        this->h->destroy(this->h);
-       allocator_free(this->opaded_key.ptr);
-       allocator_free(this->ipaded_key.ptr);
-       allocator_free(this);
+       free(this->opaded_key.ptr);
+       free(this->ipaded_key.ptr);
+       free(this);
 }
 
 /*
@@ -175,7 +174,7 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
 {
        private_hmac_t *this;
        
-       this = allocator_alloc_thing(private_hmac_t);
+       this = malloc_thing(private_hmac_t);
 
        /* set hmac_t methods */
        this->hmac.get_mac = (void (*)(hmac_t *,chunk_t,u_int8_t*))get_mac;
@@ -192,7 +191,7 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
                        this->b = 64;
                        break;
                default:
-                       allocator_free(this);
+                       free(this);
                        return NULL;    
        }
                
@@ -200,10 +199,10 @@ hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
        this->h = hasher_create(hash_algorithm);
 
        /* build ipad and opad */
-       this->opaded_key.ptr = allocator_alloc(this->b);
+       this->opaded_key.ptr = malloc(this->b);
        this->opaded_key.len = this->b;
 
-       this->ipaded_key.ptr = allocator_alloc(this->b);
+       this->ipaded_key.ptr = malloc(this->b);
        this->ipaded_key.len = this->b;
 
        return &(this->hmac);
index f0f4a11..d408d05 100644 (file)
  * for more details.
  */
 
+#include <string.h>
 
 #include "prf_plus.h"
 
-#include <utils/allocator.h>
 #include <definitions.h>
 
 typedef struct private_prf_plus_t private_prf_plus_t;
@@ -102,7 +102,7 @@ static void get_bytes(private_prf_plus_t *this, size_t length, u_int8_t *buffer)
  */    
 static void allocate_bytes(private_prf_plus_t *this, size_t length, chunk_t *chunk)
 {
-       chunk->ptr = allocator_alloc(length);
+       chunk->ptr = malloc(length);
        chunk->len = length;
        this->public.get_bytes(&(this->public), length, chunk->ptr);
 }
@@ -112,9 +112,9 @@ static void allocate_bytes(private_prf_plus_t *this, size_t length, chunk_t *chu
  */
 static void destroy(private_prf_plus_t *this)
 {
-       allocator_free(this->buffer.ptr);
-       allocator_free(this->seed.ptr);
-       allocator_free(this);
+       free(this->buffer.ptr);
+       free(this->seed.ptr);
+       free(this);
 }
 
 /*
@@ -125,7 +125,7 @@ prf_plus_t *prf_plus_create(prf_t *prf, chunk_t seed)
        private_prf_plus_t *this;
        chunk_t appending_chunk;
        
-       this = allocator_alloc_thing(private_prf_plus_t);
+       this = malloc_thing(private_prf_plus_t);
 
        /* set public methods */
        this->public.get_bytes = (void (*)(prf_plus_t *,size_t,u_int8_t*))get_bytes;
@@ -137,12 +137,12 @@ prf_plus_t *prf_plus_create(prf_t *prf, chunk_t seed)
        
        /* allocate buffer for prf output */
        this->buffer.len = prf->get_block_size(prf);
-       this->buffer.ptr = allocator_alloc(this->buffer.len);
+       this->buffer.ptr = malloc(this->buffer.len);
 
        this->appending_octet = 0x01;
        
        /* clone seed */
-       this->seed.ptr = allocator_clone_bytes(seed.ptr, seed.len);
+       this->seed.ptr = clalloc(seed.ptr, seed.len);
        this->seed.len = seed.len;
 
        /* do the first run */
index 2ea0869..2a7d34a 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "hmac_prf.h"
 
-#include <utils/allocator.h>
 #include <crypto/hmac.h>
 
 
@@ -89,7 +88,7 @@ static void set_key(private_hmac_prf_t *this, chunk_t key)
  */
 static void destroy(private_hmac_prf_t *this)
 {
-       allocator_free(this);
+       free(this);
        this->hmac->destroy(this->hmac);
 }
 
@@ -98,7 +97,7 @@ static void destroy(private_hmac_prf_t *this)
  */
 hmac_prf_t *hmac_prf_create(hash_algorithm_t hash_algorithm)
 {
-       private_hmac_prf_t *this = allocator_alloc_thing(private_hmac_prf_t);
+       private_hmac_prf_t *this = malloc_thing(private_hmac_prf_t);
        
        this->public.prf_interface.get_bytes = (void (*) (prf_t *,chunk_t,u_int8_t*))get_bytes;
        this->public.prf_interface.allocate_bytes = (void (*) (prf_t*,chunk_t,chunk_t*))allocate_bytes;
@@ -110,7 +109,7 @@ hmac_prf_t *hmac_prf_create(hash_algorithm_t hash_algorithm)
        this->hmac = hmac_create(hash_algorithm);
        if (this->hmac == NULL)
        {
-               allocator_free(this);
+               free(this);
                return NULL;    
        }
        
index 0afadd1..879cade 100644 (file)
 #include <gmp.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <string.h>
 
 #include "rsa_private_key.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <asn1/der_decoder.h>
 
 
@@ -188,7 +188,7 @@ static status_t compute_prime(private_rsa_private_key_t *this, size_t prime_size
                /* get next prime */
                mpz_nextprime (*prime, *prime);
                
-               allocator_free(random_bytes.ptr);
+               free(random_bytes.ptr);
        }
        /* check if it isnt too large */
        while (((mpz_sizeinbase(*prime, 2) + 7) / 8) > prime_size);
@@ -301,7 +301,7 @@ static status_t build_emsa_pkcs1_signature(private_rsa_private_key_t *this, hash
         * T = oid || hash
         */
        em.len = this->k;
-       em.ptr = allocator_alloc(em.len);
+       em.ptr = malloc(em.len);
        
        /* fill em with padding */
        memset(em.ptr, 0xFF, em.len);
@@ -318,8 +318,8 @@ static status_t build_emsa_pkcs1_signature(private_rsa_private_key_t *this, hash
        /* build signature */
        *signature = this->rsasp1(this, em);
        
-       allocator_free(hash.ptr);
-       allocator_free(em.ptr);
+       free(hash.ptr);
+       free(em.ptr);
        
        return SUCCESS; 
 }
@@ -349,7 +349,7 @@ static status_t get_key(private_rsa_private_key_t *this, chunk_t *key)
        coeff.ptr = mpz_export(NULL, NULL, 1, coeff.len, 1, 0, this->coeff);
        
        key->len = this->k * 8;
-       key->ptr = allocator_alloc(key->len);
+       key->ptr = malloc(key->len);
        memcpy(key->ptr + this->k * 0, n.ptr , n.len);
        memcpy(key->ptr + this->k * 1, e.ptr, e.len);
        memcpy(key->ptr + this->k * 2, p.ptr, p.len);
@@ -359,14 +359,14 @@ static status_t get_key(private_rsa_private_key_t *this, chunk_t *key)
        memcpy(key->ptr + this->k * 6, exp2.ptr, exp2.len);
        memcpy(key->ptr + this->k * 7, coeff.ptr, coeff.len);
        
-       allocator_free(n.ptr);
-       allocator_free(e.ptr);
-       allocator_free(p.ptr);
-       allocator_free(q.ptr);
-       allocator_free(d.ptr);
-       allocator_free(exp1.ptr);
-       allocator_free(exp2.ptr);
-       allocator_free(coeff.ptr);
+       free(n.ptr);
+       free(e.ptr);
+       free(p.ptr);
+       free(q.ptr);
+       free(d.ptr);
+       free(exp1.ptr);
+       free(exp2.ptr);
+       free(coeff.ptr);
        
        return SUCCESS;
 }
@@ -432,7 +432,7 @@ static void destroy(private_rsa_private_key_t *this)
        mpz_clear(this->exp1);
        mpz_clear(this->exp2);
        mpz_clear(this->coeff);
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -440,7 +440,7 @@ static void destroy(private_rsa_private_key_t *this)
  */
 static private_rsa_private_key_t *rsa_private_key_create_empty()
 {
-       private_rsa_private_key_t *this = allocator_alloc_thing(private_rsa_private_key_t);
+       private_rsa_private_key_t *this = malloc_thing(private_rsa_private_key_t);
        
        /* public functions */
        this->public.build_emsa_pkcs1_signature = (status_t (*) (rsa_private_key_t*,hash_algorithm_t,chunk_t,chunk_t*))build_emsa_pkcs1_signature;
@@ -474,13 +474,13 @@ rsa_private_key_t *rsa_private_key_create(size_t key_size)
        /* Get values of primes p and q  */
        if (this->compute_prime(this, key_size/2, &p) != SUCCESS)
        {
-               allocator_free(this);
+               free(this);
                return NULL;
        }       
        if (this->compute_prime(this, key_size/2, &q) != SUCCESS)
        {
                mpz_clear(p);
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
@@ -605,8 +605,10 @@ rsa_private_key_t *rsa_private_key_create_from_file(char *filename, char *passph
        
        if (fread(buffer, stb.st_size, 1, file) != 1)
        {
+               fclose(file);
                return NULL;
        }
+       fclose(file);
        
        chunk.ptr = buffer;
        chunk.len = stb.st_size;
index 57ad101..5b85f52 100644 (file)
 #include <gmp.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <string.h>
 
 #include "rsa_public_key.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 #include <crypto/hashers/hasher.h>
 #include <asn1/der_decoder.h>
 
@@ -215,7 +215,7 @@ static status_t verify_emsa_pkcs1_signature(private_rsa_public_key_t *this, chun
        if ((*(em.ptr) != 0x00) ||
                (*(em.ptr+1) != 0x01))
        {
-               allocator_free(em.ptr);
+               free(em.ptr);
                return FAILED;
        }
        
@@ -232,7 +232,7 @@ static status_t verify_emsa_pkcs1_signature(private_rsa_public_key_t *this, chun
                else if (*pos != 0xFF)
                {
                        /* bad padding, decryption failed ?!*/
-                       allocator_free(em.ptr);
+                       free(em.ptr);
                        return FAILED;  
                }
                pos++;
@@ -241,7 +241,7 @@ static status_t verify_emsa_pkcs1_signature(private_rsa_public_key_t *this, chun
        if (pos + 20 > em.ptr + em.len)
        {
                /* not enought room for oid compare */
-               allocator_free(em.ptr);
+               free(em.ptr);
                return FAILED;  
        }
        
@@ -279,14 +279,14 @@ static status_t verify_emsa_pkcs1_signature(private_rsa_public_key_t *this, chun
        if (hasher == NULL)
        {
                /* not supported hash algorithm */
-               allocator_free(em.ptr);
+               free(em.ptr);
                return NOT_SUPPORTED;   
        }
        
        if (pos + hasher->get_block_size(hasher) != em.ptr + em.len)
        {
                /* bad length */
-               allocator_free(em.ptr);
+               free(em.ptr);
                hasher->destroy(hasher);
                return FAILED;  
        }
@@ -298,15 +298,15 @@ static status_t verify_emsa_pkcs1_signature(private_rsa_public_key_t *this, chun
        if (memcmp(hash.ptr, pos, hash.len) != 0)
        {
                /* hash does not equal */
-               allocator_free(hash.ptr);
-               allocator_free(em.ptr);
+               free(hash.ptr);
+               free(em.ptr);
                return FAILED;  
                        
        }
        
        /* seems good */
-       allocator_free(hash.ptr);
-       allocator_free(em.ptr);
+       free(hash.ptr);
+       free(em.ptr);
        return SUCCESS; 
 }
        
@@ -323,11 +323,11 @@ static status_t get_key(private_rsa_public_key_t *this, chunk_t *key)
        e.ptr = mpz_export(NULL, NULL, 1, e.len, 1, 0, this->e);
        
        key->len = this->k * 2;
-       key->ptr = allocator_alloc(key->len);
+       key->ptr = malloc(key->len);
        memcpy(key->ptr, n.ptr, n.len);
        memcpy(key->ptr + n.len, e.ptr, e.len);
-       allocator_free(n.ptr);
-       allocator_free(e.ptr);
+       free(n.ptr);
+       free(e.ptr);
        
        return SUCCESS;
 }
@@ -369,7 +369,7 @@ static void destroy(private_rsa_public_key_t *this)
 {
        mpz_clear(this->n);
        mpz_clear(this->e);
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -377,7 +377,7 @@ static void destroy(private_rsa_public_key_t *this)
  */
 private_rsa_public_key_t *rsa_public_key_create_empty()
 {
-       private_rsa_public_key_t *this = allocator_alloc_thing(private_rsa_public_key_t);
+       private_rsa_public_key_t *this = malloc_thing(private_rsa_public_key_t);
        
        /* public functions */
        this->public.verify_emsa_pkcs1_signature = (status_t (*) (rsa_public_key_t*,chunk_t,chunk_t))verify_emsa_pkcs1_signature;
@@ -458,11 +458,11 @@ rsa_public_key_t *rsa_public_key_create_from_file(char *filename)
        dd = der_decoder_create(rsa_public_key_info_rules);
        status = dd->decode(dd, chunk, &key_info);
        dd->destroy(dd);
-       allocator_free_chunk(&key_info.algorithm_oid);
+       chunk_free(&key_info.algorithm_oid);
        if (status == SUCCESS)
        {
                public_key = rsa_public_key_create_from_chunk(chunk);
        }
-       allocator_free_chunk(&key_info.public_key);
+       chunk_free(&key_info.public_key);
        return public_key;
 }
index e4311da..cb7d082 100644 (file)
  * for more details.
  */
 
+#include <string.h>
+
 #include "hmac_signer.h"
 
-#include <utils/allocator.h>
 #include <crypto/prfs/hmac_prf.h>
 
 /**
@@ -70,7 +71,7 @@ static void allocate_signature (private_hmac_signer_t *this, chunk_t data, chunk
        
        this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac);
 
-       signature.ptr = allocator_alloc(BLOCK_SIZE);
+       signature.ptr = malloc(BLOCK_SIZE);
        signature.len = BLOCK_SIZE;
        
        /* copy signature */
@@ -135,7 +136,7 @@ static void set_key (private_hmac_signer_t *this, chunk_t key)
 static status_t destroy(private_hmac_signer_t *this)
 {
        this->hmac_prf->destroy(this->hmac_prf);
-       allocator_free(this);
+       free(this);
        return SUCCESS;
 }
 
@@ -144,14 +145,14 @@ static status_t destroy(private_hmac_signer_t *this)
  */
 hmac_signer_t *hmac_signer_create(hash_algorithm_t hash_algoritm)
 {
-       private_hmac_signer_t *this = allocator_alloc_thing(private_hmac_signer_t);
+       private_hmac_signer_t *this = malloc_thing(private_hmac_signer_t);
 
        this->hmac_prf = (prf_t *) hmac_prf_create(hash_algoritm);
        
        if (this->hmac_prf == NULL)
        {
                /* algorithm not supported */
-               allocator_free(this);
+               free(this);
                return NULL;
        }
        
index 2acec8d..11bd04f 100644 (file)
  */
 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
 
+
+
+
 /**
- * Papping entry which defines the end of a mapping_t array.
+ * Macro to allocate a type as chunk_t.
+ * 
+ * @param thing        object on which a sizeof is performed
+ * @return                     chunk_t pointing to allocated memory
  */
-#define MAPPING_END (-1)
+#define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
+
+
 
 
+
+
+/**
+ * Mapping entry which defines the end of a mapping_t array.
+ */
+#define MAPPING_END (-1)
+
 typedef struct mapping_t mapping_t;
 
 /**
index 47a763e..22f29df 100644 (file)
@@ -19,7 +19,9 @@
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  */
+
+#include <string.h>
+
 #include "types.h"
 
 
@@ -46,3 +48,56 @@ mapping_t status_m[] = {
  * Empty chunk.
  */
 chunk_t CHUNK_INITIALIZER = {NULL,0};
+
+/**
+ * Described in header.
+ */
+chunk_t chunk_clone(chunk_t chunk)
+{
+       chunk_t clone = CHUNK_INITIALIZER;
+       
+       if (chunk.ptr && chunk.len > 0)
+       {
+               clone.ptr = malloc(chunk.len);
+               clone.len = chunk.len;
+               memcpy(clone.ptr, chunk.ptr, chunk.len);
+       }
+       
+       return clone;
+}
+
+/**
+ * Described in header.
+ */
+void chunk_free(chunk_t *chunk)
+{
+       free(chunk->ptr);
+       chunk->ptr = NULL;
+       chunk->len = 0;
+}
+
+/**
+ * Described in header.
+ */
+chunk_t chunk_alloc(size_t bytes)
+{
+       chunk_t new_chunk;
+       new_chunk.ptr = malloc(bytes);
+       new_chunk.len = bytes;
+       return new_chunk;
+}
+
+
+/**
+ * Described in header.
+ */
+void *clalloc(void * pointer, size_t size)
+{
+       
+       void *data;
+       data = malloc(size);
+       
+       memcpy(data, pointer,size);
+       
+       return (data);
+}
index 9c405de..fd96b36 100644 (file)
@@ -146,6 +146,27 @@ struct chunk_t {
 extern chunk_t CHUNK_INITIALIZER;
 
 /**
+ * Clone chunk contents in a newly allocated chunk
+ */
+chunk_t chunk_clone(chunk_t chunk);
+
+/**
+ * Free contents of a chunk
+ */
+void chunk_free(chunk_t *chunk);
+
+/**
+ * Allocate a chunk
+ */
+chunk_t chunk_alloc(size_t bytes);
+
+/**
+ * Clone a data to a newly allocated buffer
+ */
+void *clalloc(void *pointer, size_t size);
+
+
+/**
  * General purpose boolean type.
  */
 typedef int bool;
index ab513ff..9b6eac7 100644 (file)
 UTILS_DIR= $(LIB_DIR)utils/
 
 
-LIB_OBJS+= $(BUILD_DIR)allocator.o
-$(BUILD_DIR)allocator.o :              $(UTILS_DIR)allocator.c $(UTILS_DIR)allocator.h
-                                                               $(CC) $(CFLAGS) -c -o $@ $<
-
 LIB_OBJS+= $(BUILD_DIR)linked_list.o
 $(BUILD_DIR)linked_list.o :            $(UTILS_DIR)linked_list.c $(UTILS_DIR)linked_list.h
                                                                $(CC) $(CFLAGS) -c -o $@ $<
@@ -46,3 +42,7 @@ $(BUILD_DIR)identification.o :        $(UTILS_DIR)identification.c $(UTILS_DIR)identifi
 LIB_OBJS+= $(BUILD_DIR)host.o
 $(BUILD_DIR)host.o :                   $(UTILS_DIR)host.c $(UTILS_DIR)host.h
                                                                $(CC) $(CFLAGS) -c -o $@ $<
+
+LIB_OBJS+= $(BUILD_DIR)leak_detective.o
+$(BUILD_DIR)leak_detective.o : $(UTILS_DIR)leak_detective.c $(UTILS_DIR)leak_detective.h
+                                                               $(CC) $(CFLAGS) -c -o $@ $<
\ No newline at end of file
diff --git a/Source/lib/utils/allocator.c b/Source/lib/utils/allocator.c
deleted file mode 100644 (file)
index 0ed197c..0000000
+++ /dev/null
@@ -1,445 +0,0 @@
-/**
- * @file allocator.c
- * 
- * @brief Implementation of allocator_t.
- */
-
-/*
- * 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 <stddef.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <string.h>
-#include <assert.h>
-#include <stdio.h>
-#include <gmp.h>
-
-#include "allocator.h"
-
-
-#ifdef LEAK_DETECTIVE
-
-typedef union memory_hdr_t memory_hdr_t;
-
-/**
- * @brief Header of each allocated memory area.
- * 
- * Ideas stolen from pluto's defs.c.
- * 
- * Used to detect memory leaks.
- */
-union memory_hdr_t {
-       /**
-        * Informations.
-        */
-    struct {
-               /**
-                * Filename withing memory was allocated.
-                */
-               const char *filename;
-               /**
-                * Line number in given file.
-                */
-               size_t line;
-               /**
-                * Allocated memory size. Needed for reallocation.
-                */
-               size_t size_of_memory;
-               /**
-                * Link to the previous and next memory area.
-                */
-               memory_hdr_t *older, *newer;
-    } info;
-    /**
-     * Force maximal alignment ?
-     * 
-     */
-    unsigned long junk;        
-};
-
-typedef struct private_allocator_t private_allocator_t;
-
-/**
- * @brief Private allocator_t object.
- * 
- * Contains private variables of allocator_t object.
- */
-struct private_allocator_t
-{
-       /**
-        * Public part of an allocator_t object.
-        */
-       allocator_t public;
-       
-       /**
-        * Global list of allocations.
-        * 
-        * Thread-save through mutex.
-        */
-       memory_hdr_t *allocations;
-
-       /**
-        * Mutex used to make sure, all functions are thread-save.
-        */
-       pthread_mutex_t mutex;
-       
-       /** 
-        * Number of allocations done
-        */
-       u_int32_t allocs;
-       
-       /**
-        * Number of frees done
-        */
-       u_int32_t frees;
-       
-       /**
-        * Allocates memory with LEAK_DETECTION and 
-        * returns an empty data area filled with zeros.
-        *
-        * @param this          private_allocator_t object
-        * @param bytes         number of bytes to allocate
-        * @param file          filename from which the memory is allocated
-        * @param line          line number in specific file
-        * @param use_mutex if FALSE no mutex is used for allocation
-        * @return                      pointer to allocated memory area
-        */ 
-       void * (*allocate_special) (private_allocator_t *this,size_t bytes, char * file,int line, bool use_mutex);
-};
-
-/**
- * Implementation of private_allocator_t.allocate_special. 
- */
-static void *allocate_special(private_allocator_t *this,size_t bytes, char * file,int line, bool use_mutex)
-{
-    memory_hdr_t *allocated_memory = malloc(sizeof(memory_hdr_t) + bytes);
-       
-       this->allocs++;
-       
-       if (allocated_memory == NULL)
-    {
-               /* TODO LOG this case */
-               exit(-1);
-    }
-
-    if (use_mutex)
-    {
-           pthread_mutex_lock( &(this->mutex));
-    }
-       
-    allocated_memory->info.line = line;
-    allocated_memory->info.filename = file;
-    allocated_memory->info.size_of_memory = bytes;
-    allocated_memory->info.older = this->allocations;
-    if (this->allocations != NULL)
-    {
-               this->allocations->info.newer = allocated_memory;
-    }
-    this->allocations = allocated_memory;
-    allocated_memory->info.newer = NULL;
-
-       /* fill memory with zero's */
-    memset(allocated_memory+1, '\0', bytes);
-    if (use_mutex)
-    {
-           pthread_mutex_unlock(&(this->mutex));
-    }
-       
-    /* real memory starts after header */
-    return (allocated_memory+1);
-}
-
-/**
- * Implementation of allocator_t.allocate. 
- */
-static void * allocate(allocator_t *allocator,size_t bytes, char * file,int line)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-       return (this->allocate_special(this,bytes, file,line,TRUE));
-}
-
-/**
- * Implementation of allocator_t.allocate_as_chunk. 
- */
-static chunk_t allocate_as_chunk(allocator_t *allocator,size_t bytes, char * file,int line)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-       chunk_t new_chunk;
-       new_chunk.ptr = this->allocate_special(this,bytes, file,line,TRUE);
-       new_chunk.len = (new_chunk.ptr == NULL) ? 0 : bytes;
-       return new_chunk;
-}
-
-/**
- * Implementation of allocator_t.free_pointer. 
- */
-static void free_pointer(allocator_t *allocator, void * pointer)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-    memory_hdr_t *allocated_memory;
-       
-
-    if (pointer == NULL)
-    {
-               return; 
-    }
-       this->frees++;
-       pthread_mutex_lock( &(this->mutex));
-    allocated_memory = ((memory_hdr_t *)pointer) - 1;
-
-    if (allocated_memory->info.older != NULL)
-    {
-               assert(allocated_memory->info.older->info.newer == allocated_memory);
-               allocated_memory->info.older->info.newer = allocated_memory->info.newer;
-    }
-    if (allocated_memory->info.newer == NULL)
-    {
-               assert(allocated_memory == this->allocations);
-               this->allocations = allocated_memory->info.older;
-    }
-    else
-    {
-               assert(allocated_memory->info.newer->info.older == allocated_memory);
-               allocated_memory->info.newer->info.older = allocated_memory->info.older;
-    }
-    pthread_mutex_unlock(&(this->mutex));
-    free(allocated_memory);
-}
-
-/**
- * Implementation of allocator_t.reallocate. 
- */
-static void * reallocate(allocator_t *allocator, void * old, size_t bytes, char * file,int line)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-    memory_hdr_t *allocated_memory;
-
-
-       pthread_mutex_lock( &(this->mutex));
-    allocated_memory = ((memory_hdr_t *)old) - 1;
-    
-       void *new_space = this->allocate_special(this,bytes,file,line,FALSE);
-
-       if (old != NULL)
-       {       
-               /* the smaller size is copied to avoid overflows */
-               memcpy(new_space,old,(allocated_memory->info.size_of_memory < bytes) ? allocated_memory->info.size_of_memory : bytes);
-       }
-    pthread_mutex_unlock(&(this->mutex));
-    this->public.free_pointer(&(this->public),old);
-       
-       return new_space;
-}
-
-/**
- * Implementation of allocator_t.clone_bytes. 
- */
-static void * clone_bytes(allocator_t *allocator,void * to_clone, size_t bytes, char * file, int line)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-
-    if (to_clone == NULL)
-    {
-               return NULL;
-    }
-
-    
-       void *new_space = this->allocate_special(this,bytes,file,line,TRUE);
-
-       if (new_space == NULL)
-       {
-               return NULL;
-       }
-       
-       memcpy(new_space,to_clone,bytes);
-       
-       return new_space;
-}
-
-/**
- * Implementation of allocator_t.clone_chunk. 
- */
-static chunk_t clone_chunk(allocator_t *allocator, chunk_t chunk, char * file, int line)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-       chunk_t clone = CHUNK_INITIALIZER;
-       
-       if (chunk.ptr && chunk.len > 0)
-       {
-               clone.ptr = this->allocate_special(this,chunk.len,file,line,TRUE);
-               clone.len = chunk.len;
-               memcpy(clone.ptr, chunk.ptr, chunk.len);
-       }
-       
-    return clone;
-}
-
-/**
- * Implementation of allocator_t.allocator_report_memory_leaks. 
- */
-static void allocator_report_memory_leaks(allocator_t *allocator)
-{
-       private_allocator_t *this = (private_allocator_t *) allocator;
-    memory_hdr_t *p = this->allocations;
-    memory_hdr_t *pprev = NULL;
-    unsigned long n = 0;
-
-       pthread_mutex_lock(&(this->mutex));
-
-    while (p != NULL)
-    {
-       assert(pprev == p->info.newer);
-       pprev = p;
-       p = p->info.older;
-       n++;
-       if (p == NULL || pprev->info.filename != p->info.filename)
-       {
-           if (n != 1)
-               fprintf(stderr,"LEAK: \"%lu * %s, line %d\"\n", n, pprev->info.filename,pprev->info.line);
-           else
-               fprintf(stderr,"LEAK: \"%s, line %d\"\n", pprev->info.filename,pprev->info.line);
-           n = 0;
-       }
-    }
-       pthread_mutex_unlock( &(this->mutex));
-       fprintf(stderr, "Allocator statistics: %d allocs, %d frees\n", this->allocs, this->frees);
-}
-
-/** 
- * Only Initiation of allocator object.
- * 
- * All allocation macros use this object.
- */
-static private_allocator_t allocator = {
-       public: {allocate: allocate,
-                        allocate_as_chunk: allocate_as_chunk,
-                        free_pointer: free_pointer,
-                        reallocate: reallocate,
-                        clone_bytes : clone_bytes,
-                        clone_chunk : clone_chunk,
-                        report_memory_leaks: allocator_report_memory_leaks},
-       allocations: NULL,
-       allocate_special : allocate_special,
-       mutex: PTHREAD_MUTEX_INITIALIZER,
-       allocs: 0,
-       frees: 0
-};
-
-
-allocator_t *global_allocator = &(allocator.public);
-
-/*
- * Alloc function for gmp.
- */
-void *gmp_alloc(size_t bytes)
-{
-       return allocator.allocate_special(&allocator, bytes, "[ gmp internal ]", 0 , TRUE);
-}
-
-/*
- * Realloc function for gmp.
- */
-void *gmp_realloc(void *old, size_t old_bytes, size_t new_bytes)
-{
-       return global_allocator->reallocate(global_allocator, old, new_bytes, "[ gmp internal ]", 0);
-}
-/*
- * Free function for gmp.
- */
-void gmp_free(void *ptr, size_t bytes)
-{
-       free_pointer(global_allocator, ptr);
-}
-
-/*
- * Described in header
- */
-void allocator_init()
-{
-       mp_set_memory_functions (gmp_alloc, gmp_realloc, gmp_free);
-}
-
-#else /* !LEAK_DETECTION */
-
-/*
- * Described in header.
- */
-chunk_t allocator_alloc_as_chunk(size_t bytes)
-{
-       chunk_t new_chunk;
-       new_chunk.ptr = malloc(bytes); 
-       if (new_chunk.ptr == NULL)
-       {
-               exit(-1);
-       }
-       new_chunk.len = bytes; 
-       return new_chunk; 
-
-}
-
-/*
- * Described in header.
- */
-void * allocator_realloc(void * old, size_t newsize)
-{
-       void *data = realloc(old,newsize);
-       return data;
-} 
-
-/*
- * Described in header.
- */
-void * allocator_clone_bytes(void * pointer, size_t size)
-{
-       
-       void *data;
-       data = malloc(size);
-       
-       if (data == NULL){exit(-1);}
-       memmove(data,pointer,size);
-       
-       return (data);
-}
-
-/**
- * Described in header.
- */
-chunk_t allocator_clone_chunk(chunk_t chunk)
-{
-       chunk_t clone = CHUNK_INITIALIZER;
-       
-       if (chunk.ptr && chunk.len > 0)
-       {
-               clone.ptr = malloc(chunk.len);
-               if (clone.ptr == NULL) {exit(-1);}
-               clone.len = chunk.len;
-               memcpy(clone.ptr, chunk.ptr, chunk.len);
-       }
-       
-    return clone;
-}
-
-/*
- * Described in header.
- */
-void allocator_free_chunk(chunk_t *chunk)
-{
-       free(chunk->ptr);
-       chunk->ptr = NULL;
-       chunk->len = 0;
-}
-
-#endif /* LEAK_DETECTION */
diff --git a/Source/lib/utils/allocator.h b/Source/lib/utils/allocator.h
deleted file mode 100644 (file)
index 5b00496..0000000
+++ /dev/null
@@ -1,324 +0,0 @@
-/**
- * @file allocator.h
- * 
- * @brief Interface of allocator_t.
- */
-
-/*
- * 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 ALLOCATOR_H_
-#define ALLOCATOR_H_
-
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
-
-#include <types.h>
-
-
-/**
- * Macro to allocate a special type.
- * 
- * @param thing        object on which a sizeof is performed
- * @return                     pointer to allocated memory
- * 
- * @ingroup utils
- */
-#define allocator_alloc_thing_as_chunk(thing) (allocator_alloc_as_chunk(sizeof(thing)))
-
-/**
- * Macro to allocate a special type as chunk_t.
- * 
- * @param thing        object on which a sizeof is performed
- * @return                     chunk_t pointing to allocated memory
- *
- * @ingroup utils
- */
-#define allocator_alloc_thing(thing) (allocator_alloc(sizeof(thing)))
-
-#ifdef LEAK_DETECTIVE
-
-       typedef struct allocator_t allocator_t;
-
-       /**
-        *@brief Allocater object use to detect memory leaks.
-        *
-        * @ingroup utils
-        */
-       struct allocator_t {
-       
-               /**
-                * Allocates memory with LEAK_DETECTION and 
-                * returns an empty data area filled with zeros.
-                * 
-                * @warning     Use this function not directly, only with assigned macros 
-                *                              #allocator_alloc and #allocator_alloc_thing.
-                * 
-                * @param this  allocator_t object
-                * @param bytes number of bytes to allocate
-                * @param file  filename from which the memory is allocated
-                * @param line  line number in specific file
-                * @return              pointer to allocated memory area
-                */ 
-               void * (*allocate) (allocator_t *this,size_t bytes, char * file,int line);
-
-               /**
-                * Allocates memory with LEAK_DETECTION and 
-                * returns an chunk pointing to an empy data area filled with zeros.
-                * 
-                * @warning     Use this function not directly, only with assigned 
-                *                              macros #allocator_alloc_as_chunk and 
-                *                              #allocator_alloc_thing_as_chunk.
-                * 
-                * @param this  allocator_t object
-                * @param bytes number of bytes to allocate
-                * @param file  filename from which the memory is allocated
-                * @param line  line number in specific file
-                * @return              pointer to allocated memory area
-                */ 
-               chunk_t (*allocate_as_chunk) (allocator_t *this,size_t bytes, char * file,int line);
-       
-               /**
-                * Reallocates memory with LEAK_DETECTION and 
-                * returns an empty data area filled with zeros.
-                * 
-                * @warning     Use this function not directly, only with assigned macro 
-                *                              #allocator_realloc.
-                * 
-                * @param this  allocator_t object
-                * @param old   pointer to the old data area
-                * @param bytes number of bytes to allocate
-                * @param file  filename from which the memory is allocated
-                * @param line  line number in specific file
-                * @return              pointer to reallocated memory area
-                */ 
-               void * (*reallocate) (allocator_t *this,void * old, size_t bytes, char * file, int line);
-               
-               /**
-                * Clones memory with LEAK_DETECTION and returns a cloned data area.
-                * 
-                * @warning     Use this function not directly, only with assigned macro 
-                *                              #allocator_clone_bytes.
-                * 
-                * @param this  allocator_t object
-                * @param old   pointer to the old data area
-                * @param bytes number of bytes to allocate
-                * @param file  filename from which the memory is allocated
-                * @param line  line number in specific file
-                * @return              pointer to reallocated memory area
-                */ 
-               void * (*clone_bytes) (allocator_t *this,void * to_clone, size_t bytes, char * file, int line);         
-               
-               /**
-                * Clones a chunk with LEAK_DETECTION and returns a cloned chunk.
-                * 
-                * @warning     Use this function not directly, only with assigned macro 
-                *                              #allocator_clone_chunk-
-                * 
-                * @param this  allocator_t object
-                * @param chunk chunk to clone
-                * @param file  filename from which the memory is allocated
-                * @param line  line number in specific file
-                * @return              pointer to reallocated memory
-                */ 
-               chunk_t (*clone_chunk) (allocator_t *this, chunk_t chunk, char * file, int line);               
-                               
-               /**
-                * Frees memory with LEAK_DETECTION.
-                * 
-                * @warning             Use this function not directly, only with assigned macro 
-                *                                      #allocator_free.
-                * 
-                * @param this          allocator_t object
-                * @param pointer       pointer to the data area to free
-                */ 
-               void (*free_pointer) (allocator_t *this,void * pointer);
-               
-               /**
-                * Report memory leaks to stderr.
-                *
-                * @warning             Use this function not directly, only with assigned macro 
-                *                                      #report_memory_leaks
-                * 
-                * @param this          allocator_t object
-                */
-               void (*report_memory_leaks) (allocator_t *this);
-       };
-
-       
-       /**
-        * @brief Initialize the allocator.
-        * 
-        * Setup the allocator (set allocation functions for libgmp)
-        */
-       void allocator_init();
-       
-       /**
-        * @brief Global allocater_t object.
-        * 
-        * Only accessed over macros.
-        */
-       extern allocator_t *global_allocator;
-
-       
-       /**
-        * Macro to allocate some memory.
-        * 
-        * See #allocator_t.allocate for description.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_alloc(bytes) (global_allocator->allocate(global_allocator,bytes,__FILE__,__LINE__))
-       
-       /**
-        * Macro to allocate some memory for a chunk_t.
-        * 
-        * See #allocator_t.allocate_as_chunk for description.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_alloc_as_chunk(bytes) (global_allocator->allocate_as_chunk(global_allocator,bytes,__FILE__,__LINE__))
-       
-       /**
-        * Macro to reallocate some memory.
-        * 
-        * See #allocator_t.reallocate for description.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_realloc(old,bytes) (global_allocator->reallocate(global_allocator,old,bytes,__FILE__, __LINE__))
-       
-       /**
-        * Macro to clone some memory.
-        * 
-        * See #allocator_t.*clone_bytes for description.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_clone_bytes(old,bytes) (global_allocator->clone_bytes(global_allocator,old,bytes,__FILE__, __LINE__))
-       
-       /**
-        * Macro to clone a chunk and its contents
-        * 
-        * See #allocator_t.clone_chunk for description.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_clone_chunk(chunk) (global_allocator->clone_chunk(global_allocator,chunk,__FILE__, __LINE__))
-       
-       /**
-        * Macro to free some memory.
-        * 
-        * See #allocator_t.free_pointer for description.
-        *
-        * @ingroup utils
-        */
-       #define allocator_free(pointer) (global_allocator->free_pointer(global_allocator,pointer))
-
-       /**
-        * Macro to free a chunk.
-        */
-       #define allocator_free_chunk(chunk){    \
-               global_allocator->free_pointer(global_allocator,(chunk)->ptr);                  \
-               (chunk)->ptr = NULL;                            \
-               (chunk)->len = 0;                                       \
-       }
-       
-       /**
-        * Macro to report memory leaks.
-        * 
-        * See #allocator_s.report_memory_leaks for description.
-        * 
-        * @ingroup utils
-        */
-       #define report_memory_leaks(void) (global_allocator->report_memory_leaks(global_allocator))
-#else
-
-       /**
-        * Macro to allocate some memory.
-        *
-        * @ingroup utils
-        */
-       #define allocator_alloc(bytes) (malloc(bytes))  
-
-       /**
-        * Allocate some memory as chunk.
-        * 
-        * @ingroup utils
-        */
-       chunk_t allocator_alloc_as_chunk(size_t bytes);
-
-       /**
-        * Reallocate some memory.
-        * 
-        * @ingroup utils
-        */
-       void * allocator_realloc(void * old, size_t newsize);
-       
-       /**
-        * Free allocated memory.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_free(pointer) (free(pointer))
-       
-       /**
-        * Clone bytes.
-        *
-        *
-        * @param pointer       pointer to read data from
-        * @param size          number of bytes to clone
-        * 
-        * @ingroup utils
-        */
-       void * allocator_clone_bytes(void * pointer, size_t size);
-       
-       /**
-        * Clone a chunk and its contents.
-        *
-        *
-        * @param chunk         chunk to clone
-        * @return                      cloned chunk
-        * 
-        * @ingroup utils
-        */
-       chunk_t allocator_clone_chunk(chunk_t chunk);
-       
-       /**
-        * Frees memory used by chunk.
-        * 
-        * @param chunk         pointer of chunk to free
-        * 
-        * @ingroup utils
-        */
-       void allocator_free_chunk(chunk_t *chunk);
-       
-       /**
-        * Report memory leaks.
-        * 
-        * @ingroup utils
-        */
-       #define report_memory_leaks() {}
-       
-       /**
-        * Initialize the allocator.
-        * 
-        * @ingroup utils
-        */
-       #define allocator_init() {}
-#endif
-
-#endif /*ALLOCATOR_H_*/
index 245df8b..020ed27 100644 (file)
@@ -20,9 +20,9 @@
  * for more details.
  */
 
-#include "host.h"
+#include <string.h>
 
-#include <utils/allocator.h>
+#include "host.h"
 
 
 typedef struct private_host_t private_host_t;
@@ -114,9 +114,9 @@ static char *get_address(private_host_t *this)
                        /* we need to clone it, since inet_ntoa overwrites 
                         * internal buffer on subsequent calls
                         */
-                       allocator_free(this->string);
+                       free(this->string);
                        string = inet_ntoa(this->address4.sin_addr);
-                       this->string = allocator_alloc(strlen(string)+1);
+                       this->string = malloc(strlen(string)+1);
                        strcpy(this->string, string);
                        return this->string;
                }
@@ -139,7 +139,7 @@ static chunk_t get_address_as_chunk(private_host_t *this)
                case AF_INET: 
                {
                        /* allocate 4 bytes for IPV4 address*/
-                       address.ptr = allocator_alloc(4);
+                       address.ptr = malloc(4);
                        address.len = 4;
                        memcpy(address.ptr,&(this->address4.sin_addr.s_addr),4);
                }
@@ -196,13 +196,13 @@ static u_int16_t get_port(private_host_t *this)
  */
 static private_host_t *clone(private_host_t *this)
 {
-       private_host_t *new = allocator_alloc_thing(private_host_t);
+       private_host_t *new = malloc_thing(private_host_t);
        
                
        memcpy(new, this, sizeof(private_host_t));
        if (this->string)
        {
-               new->string = allocator_alloc(strlen(this->string)+1);
+               new->string = malloc(strlen(this->string)+1);
                strcpy(new->string, this->string);
        }
        return new;
@@ -254,8 +254,8 @@ static bool equals(private_host_t *this, private_host_t *other)
  */
 static void destroy(private_host_t *this)
 {
-       allocator_free(this->string);
-       allocator_free(this);
+       free(this->string);
+       free(this);
 }
 
 /**
@@ -263,7 +263,7 @@ static void destroy(private_host_t *this)
  */
 static private_host_t *host_create_empty()
 {
-       private_host_t *this = allocator_alloc_thing(private_host_t);
+       private_host_t *this = malloc_thing(private_host_t);
        
        this->public.get_sockaddr = (sockaddr_t* (*) (host_t*))get_sockaddr;
        this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len;
@@ -305,7 +305,7 @@ host_t *host_create(int family, char *address, u_int16_t port)
                }
                default:
                {
-                       allocator_free(this);
+                       free(this);
                        return NULL;
 
                }
@@ -337,7 +337,7 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
                        return &(this->public);
                }
        }
-       allocator_free(this);
+       free(this);
        return NULL;
 }
 
index 72d1610..05d9d76 100644 (file)
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <string.h>
 
 #include "identification.h"
 
-#include <utils/allocator.h>
-
 /** 
  * String mappings for id_type_t.
  */
@@ -145,8 +144,8 @@ static identification_t *clone(private_identification_t *this)
        private_identification_t *clone = identification_create();
        
        clone->type = this->type;
-       clone->encoded = allocator_clone_chunk(this->encoded);
-       clone->string = allocator_alloc(strlen(this->string) + 1);
+       clone->encoded = chunk_clone(this->encoded);
+       clone->string = malloc(strlen(this->string) + 1);
        strcpy(clone->string, this->string);
        
        return &clone->public;
@@ -157,9 +156,9 @@ static identification_t *clone(private_identification_t *this)
  */
 static void destroy(private_identification_t *this)
 {
-       allocator_free(this->string);
-       allocator_free(this->encoded.ptr);
-       allocator_free(this);   
+       free(this->string);
+       free(this->encoded.ptr);
+       free(this);     
 }
 
 /*
@@ -169,7 +168,7 @@ static void destroy(private_identification_t *this)
  */
 static private_identification_t *identification_create()
 {
-       private_identification_t *this = allocator_alloc_thing(private_identification_t);
+       private_identification_t *this = malloc_thing(private_identification_t);
        
        this->public.equals = (bool (*) (identification_t*,identification_t*))equals;
        this->public.belongs_to = (bool (*) (identification_t*,identification_t*))belongs_to;
@@ -200,15 +199,15 @@ identification_t *identification_create_from_string(id_type_t type, char *string
                {
                        /* convert string */
                        this->encoded.len = 4;
-                       this->encoded.ptr = allocator_alloc(this->encoded.len);
+                       this->encoded.ptr = malloc(this->encoded.len);
                        if (inet_aton(string, ((struct in_addr*)(this->encoded.ptr))) == 0)
                        {
-                               allocator_free(this->encoded.ptr);
-                               allocator_free(this);
+                               free(this->encoded.ptr);
+                               free(this);
                                return NULL;
                        }
                        /* clone string */
-                       this->string = allocator_alloc(strlen(string)+1);
+                       this->string = malloc(strlen(string)+1);
                        strcpy(this->string, string);
                        return &(this->public);
                }
@@ -221,7 +220,7 @@ identification_t *identification_create_from_string(id_type_t type, char *string
                default:
                {
                        /* not supported */
-                       allocator_free(this);
+                       free(this);
                        return NULL;
                }
        }
@@ -235,7 +234,7 @@ identification_t *identification_create_from_encoding(id_type_t type, chunk_t en
        char *string;
        private_identification_t *this = identification_create();
        
-       this->encoded = allocator_clone_chunk(encoded);
+       this->encoded = chunk_clone(encoded);
        
        this->type = type;
        switch (type)
@@ -284,7 +283,7 @@ identification_t *identification_create_from_encoding(id_type_t type, chunk_t en
        /* build string, must be cloned since 
         * inet_ntoa points to a subsequently 
         * overwritten buffer */
-       this->string = allocator_alloc(strlen(string)+1);
+       this->string = malloc(strlen(string)+1);
        strcpy(this->string, string);
        
        return &(this->public);
diff --git a/Source/lib/utils/leak_detective.c b/Source/lib/utils/leak_detective.c
new file mode 100644 (file)
index 0000000..67c123b
--- /dev/null
@@ -0,0 +1,382 @@
+/**
+ * @file leak_detective.c
+ * 
+ * @brief Implementation of leak_detective_t.
+ */
+
+/*
+ * Copyright (C) 2006 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 <stddef.h>
+#include <pthread.h>
+#include <string.h>
+#include <stdio.h>
+#include <malloc.h>
+#include <execinfo.h>
+#include <signal.h> 
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <dlfcn.h>
+
+#include "leak_detective.h"
+
+#include <types.h>
+
+#ifdef LEAK_DETECTIVE
+
+/**
+ * Magic value which helps to detect memory corruption
+ */
+#define MEMORY_HEADER_MAGIC 0xF1367ADF
+
+
+static void install_hooks(void);
+static void uninstall_hooks(void);
+static void *malloc_hook(size_t, const void *);
+static void *realloc_hook(void *, size_t, const void *);
+static void free_hook(void*, const void *);
+
+typedef struct memory_header_t memory_header_t;
+
+/**
+ * Header which is prepended to each allocated memory block
+ */
+struct memory_header_t {
+       /**
+        * Magci byte which must(!) hold MEMORY_HEADER_MAGIC
+        */
+       u_int32_t magic;
+       
+       /**
+        * Number of bytes following after the header
+        */
+       size_t bytes;
+       
+       /**
+        * Stack frames at the time of allocation
+        */
+       void *stack_frames[STACK_FRAMES_COUNT];
+       
+       /**
+        * Number of stacks frames obtained in stack_frames
+        */
+       int stack_frame_count;
+       
+       /**
+        * Pointer to previous entry in linked list
+        */
+       memory_header_t *previous;
+       
+       /**
+        * Pointer to next entry in linked list
+        */
+       memory_header_t *next;
+};
+
+/**
+ * first mem header is just a dummy to chain 
+ * the others on it...
+ */
+memory_header_t first_header = {
+       magic: MEMORY_HEADER_MAGIC,
+       bytes: 0,
+       stack_frame_count: 0,
+       previous: NULL,
+       next: NULL
+};
+
+/**
+ * standard hooks, used to temparily remove hooking
+ */
+void *old_malloc_hook, *old_realloc_hook, *old_free_hook;
+
+
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+
+/**
+ * log stack frames queried by backtrace()
+ * TODO: Dump symbols of static functions!!!
+ */
+void log_stack_frames(void *stack_frames, int stack_frame_count)
+{
+       char **strings;
+       size_t i;
+
+       strings = backtrace_symbols (stack_frames, stack_frame_count);
+
+       printf("  dumping %d stack frames.\n", stack_frame_count);
+
+       for (i = 0; i < stack_frame_count; i++)
+       {
+               printf ("    %s\n", strings[i]);
+       }
+       free (strings);
+}
+
+void (*__malloc_initialize_hook) (void) = install_hooks;
+
+/**
+ * Installs the malloc hooks, enables leak detection
+ */
+void install_hooks()
+{
+       old_malloc_hook = __malloc_hook;
+       old_realloc_hook = __realloc_hook;
+       old_free_hook = __free_hook;
+       __malloc_hook = malloc_hook;
+       __realloc_hook = realloc_hook;
+       __free_hook = free_hook;
+}
+
+/**
+ * Uninstalls the malloc hooks, disables leak detection
+ */
+void uninstall_hooks()
+{
+       __malloc_hook = old_malloc_hook;
+       __free_hook = old_free_hook;
+}
+
+/**
+ * Hook function for malloc()
+ */
+static void *malloc_hook(size_t bytes, const void *caller)
+{
+       memory_header_t *hdr;
+       
+       pthread_mutex_lock(&mutex);
+       uninstall_hooks();
+       hdr = malloc(bytes + sizeof(memory_header_t));
+       
+       hdr->magic = MEMORY_HEADER_MAGIC;
+       hdr->bytes = bytes;
+       hdr->stack_frame_count = backtrace(hdr->stack_frames, STACK_FRAMES_COUNT);
+       
+       /* insert at the beginning of the list */
+       hdr->next = first_header.next;
+       if (hdr->next)
+       {
+               hdr->next->previous = hdr;
+       }
+       hdr->previous = &first_header;
+       first_header.next = hdr;
+       install_hooks();
+       pthread_mutex_unlock(&mutex);
+       return hdr + 1;
+}
+
+/**
+ * Hook function for free()
+ */
+static void free_hook(void *ptr, const void *caller)
+{
+       void *stack_frames[STACK_FRAMES_COUNT];
+       int stack_frame_count;
+       memory_header_t *hdr = ptr - sizeof(memory_header_t);
+       
+       /* allow freeing of NULL */
+       if (ptr == NULL)
+       {
+               return;
+       }
+       
+       pthread_mutex_lock(&mutex);
+       if (hdr->magic != MEMORY_HEADER_MAGIC)
+       {
+               pthread_mutex_unlock(&mutex);
+               /* TODO: Since we get a lot of theses from the pthread lib, its deactivated for now... */
+               return;
+               printf("freeing of invalid memory (%p)\n", ptr);
+               stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
+               log_stack_frames(stack_frames, stack_frame_count);
+               kill(0, SIGSEGV);
+               return;
+       }
+       /* remove magic from hdr */
+       hdr->magic = 0;
+       
+       /* remove item from list */
+       if (hdr->next)
+       {
+               hdr->next->previous = hdr->previous;
+       }
+       hdr->previous->next = hdr->next;
+       
+       uninstall_hooks();
+       free(hdr);
+       install_hooks();
+       pthread_mutex_unlock(&mutex);
+}
+
+/**
+ * Hook function for realloc()
+ */
+static void *realloc_hook(void *old, size_t bytes, const void *caller)
+{
+       void *new;
+       memory_header_t *hdr = old - sizeof(memory_header_t);
+       void *stack_frames[STACK_FRAMES_COUNT];
+       int stack_frame_count;
+       
+       /* allow reallocation of NULL */
+       if (old == NULL)
+       {
+               return malloc_hook(bytes, caller);
+       }
+       if (hdr->magic != MEMORY_HEADER_MAGIC)
+       {
+               printf("reallocation of invalid memory (%p)\n", old);
+               stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
+               log_stack_frames(stack_frames, stack_frame_count);
+               kill(0, SIGSEGV);
+               return NULL;
+       }
+       
+       /* malloc and free is done with hooks */
+       new = malloc_hook(bytes, caller);
+       memcpy(new, old, min(bytes, hdr->bytes));
+       free_hook(old, caller);
+       
+       return new;
+}
+
+/**
+ * Report leaks at library destruction
+ */
+void __attribute__ ((destructor)) report_leaks()
+{
+       memory_header_t *hdr;
+       int leaks = 0;
+       
+       for (hdr = first_header.next; hdr != NULL; hdr = hdr->next)
+       {
+               printf("Leak (%d bytes at %p)\n", hdr->bytes, hdr + 1);
+               log_stack_frames(hdr->stack_frames, hdr->stack_frame_count);
+               leaks++;
+       }
+       switch (leaks)
+       {
+               case 0:
+                       printf("No leaks detected\n");
+                       break;
+               case 1:
+                       printf("One leak detected\n");
+                       break;
+               default:
+                       printf("%d leaks detected\n", leaks);
+                       break;
+       }
+}
+
+/*
+ * The following glibc functions are excluded from leak detection, since
+ * they use static allocated buffers or other ugly allocation hacks.
+ * The Makefile links theses function preferred to their counterparts
+ * in the target lib...
+ * TODO: Generic handling would be nice, with a list of blacklisted
+ * functions.
+ */
+
+
+char *inet_ntoa(struct in_addr in)
+{
+       char *(*_inet_ntoa)(struct in_addr);
+       void *handle;
+       char *result;
+       
+       pthread_mutex_lock(&mutex);
+       uninstall_hooks();
+       
+       handle = dlopen("libc.so.6", RTLD_LAZY);
+       if (handle == NULL)
+       {
+               kill(0, SIGSEGV);
+       }
+       _inet_ntoa = dlsym(handle, "inet_ntoa");
+       
+       if (_inet_ntoa == NULL)
+       {
+               kill(0, SIGSEGV);
+       }
+       result = _inet_ntoa(in);
+       dlclose(handle);
+       install_hooks();
+       pthread_mutex_unlock(&mutex);
+       return result;
+}
+
+
+int pthread_create(pthread_t *__restrict __threadp, __const pthread_attr_t *__restrict __attr, 
+                                       void *(*__start_routine) (void *), void *__restrict __arg)
+{
+       int (*_pthread_create) (pthread_t *__restrict __threadp,
+                                               __const pthread_attr_t *__restrict __attr,
+                                               void *(*__start_routine) (void *),
+                                               void *__restrict __arg);
+       void *handle;
+       int result;
+       
+       pthread_mutex_lock(&mutex);
+       uninstall_hooks();
+       
+       handle = dlopen("libpthread.so.0", RTLD_LAZY);
+       if (handle == NULL)
+       {
+               kill(0, SIGSEGV);
+       }
+       _pthread_create = dlsym(handle, "pthread_create");
+       
+       if (_pthread_create == NULL)
+       {
+               kill(0, SIGSEGV);
+       }
+       result = _pthread_create(__threadp, __attr, __start_routine, __arg);
+       dlclose(handle);
+       install_hooks();
+       pthread_mutex_unlock(&mutex);
+       return result;
+}
+
+
+time_t mktime(struct tm *tm)
+{
+       time_t (*_mktime)(struct tm *tm);
+       time_t result;
+       void *handle;
+
+       pthread_mutex_lock(&mutex);
+       uninstall_hooks();
+
+       handle = dlopen("libc.so.6", RTLD_LAZY);
+       if (handle == NULL)
+       {
+               kill(0, SIGSEGV);
+       }
+       _mktime = dlsym(handle, "mktime");
+
+       if (_mktime == NULL)
+       {
+               kill(0, SIGSEGV);
+       }
+       result = _mktime(tm);
+       dlclose(handle);
+       install_hooks();
+       pthread_mutex_unlock(&mutex);
+       return result;
+}
+
+#endif /* LEAK_DETECTION */
diff --git a/Source/lib/utils/leak_detective.h b/Source/lib/utils/leak_detective.h
new file mode 100644 (file)
index 0000000..1b0b222
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * @file leak_detective.h
+ * 
+ * @brief malloc/free hooks to detect leaks.
+ */
+
+/*
+ * Copyright (C) 2006 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 LEAK_DETECTIVE_H_
+#define LEAK_DETECTIVE_H_
+
+
+#ifdef LEAK_DETECTIVE
+
+/**
+ * Max number of stack frames to include in a backtrace.
+ */
+#define STACK_FRAMES_COUNT 30
+
+
+
+
+#endif /* LEAK_DETECTIVE */
+
+#endif /* LEAK_DETECTIVE_H_ */
index 407065d..6444343 100644 (file)
@@ -24,8 +24,6 @@
 
 #include "linked_list.h"
 
-#include <utils/allocator.h>
-
 
 
 typedef struct linked_list_element_t linked_list_element_t;
@@ -69,7 +67,7 @@ struct linked_list_element_t {
  */
 static void linked_list_element_destroy(linked_list_element_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -83,7 +81,7 @@ static void linked_list_element_destroy(linked_list_element_t *this)
 
 linked_list_element_t *linked_list_element_create(void *value)
 {
-       linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t);
+       linked_list_element_t *this = malloc_thing(linked_list_element_t);
 
        this->destroy = linked_list_element_destroy;
 
@@ -384,7 +382,7 @@ static void insert_after(private_iterator_t * iterator, void *item)
  */
 static void iterator_destroy(private_iterator_t *this)
 {
-       allocator_free(this);
+       free(this);
 }
 
 /**
@@ -665,7 +663,7 @@ static status_t get_last(private_linked_list_t *this, void **item)
  */
 static iterator_t *create_iterator (private_linked_list_t *linked_list,bool forward)
 {
-       private_iterator_t *this = allocator_alloc_thing(private_iterator_t);
+       private_iterator_t *this = malloc_thing(private_iterator_t);
 
        this->public.iterate = (bool (*) (iterator_t *this, void **value)) iterate;
        this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next;
@@ -696,7 +694,7 @@ static void linked_list_destroy(private_linked_list_t *this)
                /* values are not destroyed so memory leaks are possible
                 * if list is not empty when deleting */
        }
-       allocator_free(this);
+       free(this);
 }
 
 /*
@@ -704,7 +702,7 @@ static void linked_list_destroy(private_linked_list_t *this)
  */
 linked_list_t *linked_list_create()
 {
-       private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
+       private_linked_list_t *this = malloc_thing(private_linked_list_t);
 
        this->public.get_count = (int (*) (linked_list_t *)) get_count;
        this->public.create_iterator = (iterator_t * (*) (linked_list_t *,bool )) create_iterator;
index c66de48..1ae6bd6 100644 (file)
@@ -30,7 +30,6 @@
 #include "logger.h"
 
 #include <daemon.h>
-#include <utils/allocator.h>
 
 /**
  * Maximum length of a log entry (only used for logger_s.log).
@@ -314,8 +313,8 @@ static log_level_t get_level(private_logger_t *this)
  */
 static void destroy(private_logger_t *this)
 {
-       allocator_free(this->name);
-       allocator_free(this);
+       free(this->name);
+       free(this);
 }
 
 /*
@@ -323,7 +322,7 @@ static void destroy(private_logger_t *this)
  */    
 logger_t *logger_create(char *logger_name, log_level_t log_level, bool log_thread_id, FILE * output)
 {
-       private_logger_t *this = allocator_alloc_thing(private_logger_t);
+       private_logger_t *this = malloc_thing(private_logger_t);
        
        /* public functions */
        this->public.log = (void(*)(logger_t*,log_level_t,char*,...))logg;
@@ -346,7 +345,7 @@ logger_t *logger_create(char *logger_name, log_level_t log_level, bool log_threa
        /* private variables */
        this->level = log_level;
        this->log_thread_id = log_thread_id;
-       this->name = allocator_alloc(strlen(logger_name) + 1);
+       this->name = malloc(strlen(logger_name) + 1);
 
        strcpy(this->name,logger_name);
        this->output = output;
index 637915e..9f9a37c 100644 (file)
@@ -38,7 +38,7 @@ typedef enum log_level_t log_level_t;
  * - levels to specify the detail-level of the log
  * 
  * Use combinations of these to build detailed loglevels, such
- * as CONTROL|MORE fore a detailed cotrol level, or
+ * as CONTROL|LEVEL2 fore a detailed cotrol level, or
  * use RAW to see all raw data dumps (except private).
  * 
  * @ingroup utils
@@ -189,7 +189,7 @@ struct logger_t {
  * @param log_level            or'ed set of log_levels to assign to the new logger_t object
  * @param log_thread_id        TRUE if thread id should also be logged
  * @param output               FILE * if log has to go on a file output, NULL for syslog
- * @return                             logger_t object 
+ * @return                             logger_t object
  * 
  * @ingroup utils
  */
index 8270191..18ff299 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <daemon.h>
 #include <definitions.h>
-#include <utils/allocator.h>
 #include <utils/linked_list.h>
 
 /**
@@ -54,33 +53,30 @@ mapping_t logger_context_t_mappings[] = {
        {MAPPING_END, NULL},
 };
 
-#define DEFAULT_OUTPUT NULL
-
 struct {
        char *name;
        log_level_t level;
        bool log_thread_ids;
-       FILE *output;
 } logger_defaults[] = {
-       { "PARSR", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* PARSER */
-       { "GNRAT", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* GENERATOR */
-       { "IKESA", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* IKE_SA */
-       { "SAMGR", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* IKE_SA_MANAGER */
-       { "CHDSA", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* CHILD_SA */
-       { "MESSG", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* MESSAGE */
-       { "TPOOL", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* THREAD_POOL */
-       { "WORKR", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* WORKER */
-       { "SCHED", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* SCHEDULER */
-       { "SENDR", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* SENDER */
-       { "RECVR", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* RECEIVER */
-       { "SOCKT", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* SOCKET */
-       { "TESTR", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* TESTER */
-       { "DAEMN", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE, DEFAULT_OUTPUT}, /* DAEMON */
-       { "CONFG", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* CONFIG */
-       { "ENCPL", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* ENCRYPTION_PAYLOAD */
-       { "PAYLD", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* PAYLOAD */
-       { "DERDC", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* DER_DECODER */
-       { "DEREC", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE,  DEFAULT_OUTPUT}, /* DER_ENCODER */
+       { "PARSR", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* PARSER */
+       { "GNRAT", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* GENERATOR */
+       { "IKESA", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* IKE_SA */
+       { "SAMGR", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* IKE_SA_MANAGER */
+       { "CHDSA", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* CHILD_SA */
+       { "MESSG", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* MESSAGE */
+       { "TPOOL", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* THREAD_POOL */
+       { "WORKR", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* WORKER */
+       { "SCHED", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* SCHEDULER */
+       { "SENDR", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* SENDER */
+       { "RECVR", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* RECEIVER */
+       { "SOCKT", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* SOCKET */
+       { "TESTR", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* TESTER */
+       { "DAEMN", ERROR|CONTROL|AUDIT|LEVEL0,  FALSE}, /* DAEMON */
+       { "CONFG", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* CONFIG */
+       { "ENCPL", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* ENCRYPTION_PAYLOAD */
+       { "PAYLD", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* PAYLOAD */
+       { "DERDC", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* DER_DECODER */
+       { "DEREC", ERROR|CONTROL|AUDIT|LEVEL0,  TRUE }, /* DER_ENCODER */
 };
 
 
@@ -99,10 +95,19 @@ struct private_logger_manager_t {
         * Array of loggers, one for each context
         */
        logger_t *loggers[LOGGER_CONTEXT_ROOF];
-       
 };
 
 /**
+ * The one and only instance of the logger manager
+ */
+static private_logger_manager_t private_logger_manager;
+
+/**
+ * Exported pointer for the logger manager
+ */
+logger_manager_t *logger_manager = (logger_manager_t *)&private_logger_manager;
+
+/**
  * Implementation of logger_manager_t.get_logger.
  */
 static logger_t *get_logger(private_logger_manager_t *this, logger_context_t context)
@@ -174,39 +179,36 @@ static void set_output(private_logger_manager_t *this, logger_context_t context,
 
 
 /**
- * Implementation of logger_manager_t.destroy.
+ * Creates the instance of the logger manager at library startup
  */
-static void destroy(private_logger_manager_t *this)
+void __attribute__ ((constructor)) logger_manager_create()
 {
        int i;
+       
+       logger_manager->get_logger = (logger_t *(*)(logger_manager_t*,logger_context_t context))get_logger;
+       logger_manager->get_log_level = (log_level_t (*)(logger_manager_t *, logger_context_t)) get_log_level;
+       logger_manager->enable_log_level = (void (*)(logger_manager_t *, logger_context_t, log_level_t)) enable_log_level;
+       logger_manager->disable_log_level = (void (*)(logger_manager_t *, logger_context_t, log_level_t)) disable_log_level;
+       logger_manager->set_output = (void (*)(logger_manager_t *, logger_context_t, FILE*)) set_output;
+       
        for (i = 0; i < LOGGER_CONTEXT_ROOF; i++)
        {
-               this->loggers[i]->destroy(this->loggers[i]);
+               private_logger_manager.loggers[i] = logger_create(logger_defaults[i].name,
+                                                                                                                 logger_defaults[i].level, 
+                                                                                                                 logger_defaults[i].log_thread_ids, 
+                                                                                                                 stdout);
        }
-       allocator_free(this);
+       
 }
 
-/*
- * Described in header.
+/**
+ * Destroy the logger manager at library exit
  */
-logger_manager_t *logger_manager_create(log_level_t default_log_level)
+void __attribute__ ((destructor)) logger_manager_destroy()
 {
-       private_logger_manager_t *this = allocator_alloc_thing(private_logger_manager_t);
        int i;
-       
-       this->public.get_logger = (logger_t *(*)(logger_manager_t*,logger_context_t context))get_logger;
-       this->public.get_log_level = (log_level_t (*)(logger_manager_t *, logger_context_t)) get_log_level;
-       this->public.enable_log_level = (void (*)(logger_manager_t *, logger_context_t, log_level_t)) enable_log_level;
-       this->public.disable_log_level = (void (*)(logger_manager_t *, logger_context_t, log_level_t)) disable_log_level;
-       this->public.set_output = (void (*)(logger_manager_t *, logger_context_t, FILE*)) set_output;
-       this->public.destroy = (void(*)(logger_manager_t*))destroy;
-       
        for (i = 0; i < LOGGER_CONTEXT_ROOF; i++)
        {
-               this->loggers[i] = logger_create(logger_defaults[i].name, logger_defaults[i].level, 
-                                                                                logger_defaults[i].log_thread_ids, stdout);//logger_defaults[i].output);
+               private_logger_manager.loggers[i]->destroy(private_logger_manager.loggers[i]);
        }
-       
-       return &this->public;
 }
-
index bc8f0e6..a4daa46 100644 (file)
@@ -68,9 +68,12 @@ typedef struct logger_manager_t logger_manager_t;
  * The logger manager manages all logger_t object in a list and
  * allows their manipulation. Via a logger_context_t, the loglevel
  * of a specific logging type can be adjusted at runtime.
+ * This class differs from others, as it has no constructor or destroy
+ * function. The one and only instance "logger_manager" is created at
+ * library start and destroyed at exit.
  * 
  * @b Constructors:
- *  - logger_manager_create()
+ *  - none, logger_manager is an instance
  * 
  * @see logger_t
  * 
@@ -130,26 +133,11 @@ struct logger_manager_t {
         * @param log_level     logger level to disable
         */
        void (*set_output) (logger_manager_t *this, logger_context_t context, FILE *output);
-       
-       /**
-        * @brief Destroys a logger_manager_t object.
-        * 
-        * All managed logger_t objects are also destroyed.
-        *
-        * @param this          logger_manager_t object
-        */
-       void (*destroy) (logger_manager_t *this);
 };
 
 /**
- * @brief Constructor to create a logger_manager_t object.
- *
- * @param default_log_level    default log level for all context
- * @return                                             logger_manager_t object
- * 
- * @ingroup utils
+ * The single and global instance of the logger_manager
  */
-logger_manager_t *logger_manager_create(log_level_t default_log_level);
-
+extern logger_manager_t *logger_manager;
 
 #endif /*LOGGER_MANAGER_H_*/