better split up of library files "types.h" & "definitions.h"
authorMartin Willi <martin@strongswan.org>
Tue, 31 Oct 2006 12:27:59 +0000 (12:27 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 31 Oct 2006 12:27:59 +0000 (12:27 -0000)
centralized all printf specifier character definitions
reuse of arginfo handlers
more cleanups
fixed more AMD64 issues
added DEBUG_LEVEL compile flag to exclude DBGn() statements

153 files changed:
src/charon/bus/bus.h
src/charon/config/configuration.c
src/charon/config/configuration.h
src/charon/config/connections/connection.h
src/charon/config/connections/connection_store.h
src/charon/config/connections/local_connection_store.c
src/charon/config/connections/local_connection_store.h
src/charon/config/credentials/credential_store.h
src/charon/config/credentials/local_credential_store.c
src/charon/config/credentials/local_credential_store.h
src/charon/config/policies/local_policy_store.c
src/charon/config/policies/local_policy_store.h
src/charon/config/policies/policy.h
src/charon/config/policies/policy_store.h
src/charon/config/proposal.h
src/charon/config/traffic_selector.c
src/charon/config/traffic_selector.h
src/charon/daemon.c
src/charon/encoding/generator.c
src/charon/encoding/generator.h
src/charon/encoding/message.c
src/charon/encoding/message.h
src/charon/encoding/parser.c
src/charon/encoding/parser.h
src/charon/encoding/payloads/auth_payload.c
src/charon/encoding/payloads/auth_payload.h
src/charon/encoding/payloads/cert_payload.c
src/charon/encoding/payloads/cert_payload.h
src/charon/encoding/payloads/certreq_payload.c
src/charon/encoding/payloads/certreq_payload.h
src/charon/encoding/payloads/configuration_attribute.c
src/charon/encoding/payloads/configuration_attribute.h
src/charon/encoding/payloads/cp_payload.h
src/charon/encoding/payloads/delete_payload.c
src/charon/encoding/payloads/delete_payload.h
src/charon/encoding/payloads/eap_payload.c
src/charon/encoding/payloads/eap_payload.h
src/charon/encoding/payloads/encodings.h
src/charon/encoding/payloads/encryption_payload.c
src/charon/encoding/payloads/encryption_payload.h
src/charon/encoding/payloads/id_payload.c
src/charon/encoding/payloads/id_payload.h
src/charon/encoding/payloads/ike_header.h
src/charon/encoding/payloads/ke_payload.c
src/charon/encoding/payloads/ke_payload.h
src/charon/encoding/payloads/nonce_payload.h
src/charon/encoding/payloads/notify_payload.h
src/charon/encoding/payloads/payload.h
src/charon/encoding/payloads/proposal_substructure.c
src/charon/encoding/payloads/proposal_substructure.h
src/charon/encoding/payloads/sa_payload.h
src/charon/encoding/payloads/traffic_selector_substructure.c
src/charon/encoding/payloads/traffic_selector_substructure.h
src/charon/encoding/payloads/transform_attribute.c
src/charon/encoding/payloads/transform_attribute.h
src/charon/encoding/payloads/transform_substructure.c
src/charon/encoding/payloads/transform_substructure.h
src/charon/encoding/payloads/ts_payload.h
src/charon/encoding/payloads/unknown_payload.c
src/charon/encoding/payloads/unknown_payload.h
src/charon/encoding/payloads/vendor_id_payload.c
src/charon/encoding/payloads/vendor_id_payload.h
src/charon/network/packet.c
src/charon/network/packet.h
src/charon/network/socket.h
src/charon/queues/event_queue.c
src/charon/queues/event_queue.h
src/charon/queues/job_queue.h
src/charon/queues/jobs/acquire_job.h
src/charon/queues/jobs/delete_child_sa_job.h
src/charon/queues/jobs/delete_ike_sa_job.h
src/charon/queues/jobs/incoming_packet_job.h
src/charon/queues/jobs/initiate_job.h
src/charon/queues/jobs/job.h
src/charon/queues/jobs/rekey_child_sa_job.h
src/charon/queues/jobs/rekey_ike_sa_job.h
src/charon/queues/jobs/retransmit_request_job.h
src/charon/queues/jobs/route_job.h
src/charon/queues/jobs/send_dpd_job.h
src/charon/queues/jobs/send_keepalive_job.h
src/charon/queues/send_queue.h
src/charon/sa/authenticators/authenticator.h
src/charon/sa/child_sa.c
src/charon/sa/child_sa.h
src/charon/sa/ike_sa.c
src/charon/sa/ike_sa.h
src/charon/sa/ike_sa_id.c
src/charon/sa/ike_sa_id.h
src/charon/sa/ike_sa_manager.h
src/charon/sa/transactions/create_child_sa.c
src/charon/sa/transactions/ike_auth.c
src/charon/sa/transactions/ike_sa_init.c
src/charon/sa/transactions/rekey_ike_sa.c
src/charon/sa/transactions/transaction.h
src/charon/threads/receiver.h
src/charon/threads/scheduler.c
src/charon/threads/scheduler.h
src/charon/threads/sender.h
src/charon/threads/stroke_interface.c
src/charon/threads/thread_pool.h
src/libstrongswan/Makefile.am
src/libstrongswan/asn1/asn1.c
src/libstrongswan/asn1/asn1.h
src/libstrongswan/asn1/pem.c
src/libstrongswan/asn1/pem.h
src/libstrongswan/asn1/ttodata.h
src/libstrongswan/chunk.c [new file with mode: 0644]
src/libstrongswan/chunk.h [new file with mode: 0644]
src/libstrongswan/crypto/certinfo.c
src/libstrongswan/crypto/certinfo.h
src/libstrongswan/crypto/crl.c
src/libstrongswan/crypto/crl.h
src/libstrongswan/crypto/crypters/crypter.h
src/libstrongswan/crypto/diffie_hellman.h
src/libstrongswan/crypto/hashers/hasher.h
src/libstrongswan/crypto/hashers/md5_hasher.c
src/libstrongswan/crypto/hashers/sha1_hasher.c
src/libstrongswan/crypto/hashers/sha2_hasher.c
src/libstrongswan/crypto/hmac.h
src/libstrongswan/crypto/prf_plus.c
src/libstrongswan/crypto/prfs/hmac_prf.h
src/libstrongswan/crypto/prfs/prf.h
src/libstrongswan/crypto/rsa/rsa_private_key.c
src/libstrongswan/crypto/rsa/rsa_private_key.h
src/libstrongswan/crypto/rsa/rsa_public_key.c
src/libstrongswan/crypto/rsa/rsa_public_key.h
src/libstrongswan/crypto/signers/signer.h
src/libstrongswan/crypto/x509.c
src/libstrongswan/crypto/x509.h
src/libstrongswan/debug.c [new file with mode: 0644]
src/libstrongswan/debug.h [new file with mode: 0644]
src/libstrongswan/definitions.c [deleted file]
src/libstrongswan/definitions.h [deleted file]
src/libstrongswan/enum.c [new file with mode: 0644]
src/libstrongswan/enum.h [new file with mode: 0644]
src/libstrongswan/library.c
src/libstrongswan/library.h
src/libstrongswan/printf_hook.c [new file with mode: 0644]
src/libstrongswan/printf_hook.h [new file with mode: 0644]
src/libstrongswan/types.c [deleted file]
src/libstrongswan/types.h [deleted file]
src/libstrongswan/utils/host.c
src/libstrongswan/utils/host.h
src/libstrongswan/utils/identification.c
src/libstrongswan/utils/identification.h
src/libstrongswan/utils/leak_detective.c
src/libstrongswan/utils/lexparser.c
src/libstrongswan/utils/lexparser.h
src/libstrongswan/utils/linked_list.c
src/libstrongswan/utils/linked_list.h
src/libstrongswan/utils/randomizer.h
src/stroke/stroke.c
src/stroke/stroke.h

index cd5ca37..974d460 100644 (file)
@@ -146,15 +146,11 @@ enum level_t {
        LEVEL_PRIVATE = LEVEL_4,
 };
 
-/**
- * @brief Raise a signal for an occured event.
- *
- * @param sig          signal_t signal description
- * @param format       printf() style format string
- * @param ...          printf() style agument list
- */
-#define SIG(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_0, format, ##__VA_ARGS__)
+#ifndef DEBUG_LEVEL
+# define DEBUG_LEVEL 4
+#endif /* DEBUG_LEVEL */
 
+#if DEBUG_LEVEL >= 1
 /**
  * @brief Log a debug message via the signal bus.
  *
@@ -162,10 +158,39 @@ enum level_t {
  * @param format       printf() style format string
  * @param ...          printf() style agument list
  */
-#define DBG1(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_1, format, ##__VA_ARGS__)
+# define DBG1(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_1, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 2
 #define DBG2(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_2, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 3
 #define DBG3(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_3, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 4
 #define DBG4(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_4, format, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+
+#ifndef DBG1
+# define DBG1(...) {}
+#endif /* DBG1 */
+#ifndef DBG2
+# define DBG2(...) {}
+#endif /* DBG2 */
+#ifndef DBG3
+# define DBG3(...) {}
+#endif /* DBG3 */
+#ifndef DBG4
+# define DBG4(...) {}
+#endif /* DBG4 */
+
+/**
+ * @brief Raise a signal for an occured event.
+ *
+ * @param sig          signal_t signal description
+ * @param format       printf() style format string
+ * @param ...          printf() style agument list
+ */
+#define SIG(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_0, format, ##__VA_ARGS__)
 
 /**
  * @brief Get the type of a signal.
index e983e59..39fc4d9 100755 (executable)
@@ -25,7 +25,7 @@
 
 #include "configuration.h"
 
-#include <types.h>
+#include <library.h>
 
 /**
  * Timeout in milliseconds after that a half open IKE_SA gets deleted.
index 57e4885..2bb0b10 100755 (executable)
@@ -25,7 +25,7 @@
 
 typedef struct configuration_t configuration_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief The interface for various daemon related configs.
index 3f552d9..3a2e57b 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum cert_policy_t cert_policy_t;
 typedef struct connection_t connection_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/host.h>
 #include <utils/linked_list.h>
 #include <utils/identification.h>
index 1e73bd0..70f209d 100755 (executable)
@@ -25,7 +25,7 @@
 
 typedef struct connection_store_t connection_store_t;
 
-#include <types.h>
+#include <library.h>
 #include <config/connections/connection.h>
 #include <utils/iterator.h>
 
index 37bf94c..df4ec23 100644 (file)
@@ -113,11 +113,9 @@ static connection_t *get_connection_by_hosts(private_local_connection_store_t *t
        
        if (found)
        {
-               host_t *found_my_host    = found->get_my_host(found);
-               host_t *found_other_host = found->get_other_host(found);
-               
                DBG2(DBG_CFG, "found matching connection \"%s\": %H...%H (prio=%d)",
-                        found->get_name(found), found_my_host, found_other_host, best_prio);
+                        found->get_name(found), found->get_my_host(found),
+                        found->get_other_host(found), best_prio);
                
                /* give out a new reference to it */
                found->get_ref(found);
index e36a66c..e78ed80 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct local_connection_store_t local_connection_store_t;
 
-#include <types.h>
+#include <library.h>
 #include <config/connections/connection_store.h>
 
 /**
index e991ce3..59fc4a0 100755 (executable)
@@ -26,7 +26,7 @@
 
 typedef struct credential_store_t credential_store_t;
 
-#include <types.h>
+#include <library.h>
 #include <crypto/x509.h>
 #include <crypto/rsa/rsa_private_key.h>
 #include <crypto/rsa/rsa_public_key.h>
index 3f4267a..e108df4 100644 (file)
@@ -25,7 +25,7 @@
 #include <string.h>
 #include <pthread.h>
 
-#include <types.h>
+#include <library.h>
 #include <utils/lexparser.h>
 #include <utils/linked_list.h>
 #include <crypto/certinfo.h>
@@ -152,7 +152,7 @@ static status_t get_shared_key(private_local_credential_store_t *this,
        } prio_t;
 
        prio_t best_prio = PRIO_UNDEFINED;
-       chunk_t found = CHUNK_INITIALIZER;
+       chunk_t found = chunk_empty;
        shared_key_t *shared_key;
 
        iterator_t *iterator = this->shared_keys->create_iterator(this->shared_keys, TRUE);
@@ -511,11 +511,8 @@ static bool verify(private_local_credential_store_t *this, x509_t *cert, bool *f
                rsa_public_key_t *issuer_public_key;
                bool valid_signature;
 
-               identification_t *subject = cert->get_subject(cert);
-               identification_t *issuer  = cert->get_issuer(cert);
-
-               DBG2(DBG_CFG, "subject: '%D'", subject);
-               DBG2(DBG_CFG, "issuer:  '%D'", issuer);
+               DBG2(DBG_CFG, "subject: '%D'", cert->get_subject(cert));
+               DBG2(DBG_CFG, "issuer:  '%D'", cert->get_issuer(cert));
 
                ugh = cert->is_valid(cert, &until);
                if (ugh != NULL)
index 05ad5f5..160ac35 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct local_credential_store_t local_credential_store_t;
 
-#include <types.h>
+#include <library.h>
 #include <daemon.h>
 #include <config/credentials/credential_store.h>
 
index 32b0154..6c841b4 100644 (file)
@@ -157,11 +157,9 @@ static policy_t *get_policy(private_local_policy_store_t *this,
        
        if (found)
        {
-               identification_t *found_my_id = found->get_my_id(found);
-               identification_t *found_other_id = found->get_other_id(found);
-               
                DBG1(DBG_CFG, "found matching policy '%s': %D...%D (prio=%d)",
-                        found->get_name(found), found_my_id, found_other_id, best_prio);
+                        found->get_name(found), found->get_my_id(found),
+                        found->get_other_id(found), best_prio);
                /* give out a new reference to it */
                found->get_ref(found);
        }
index 5834b8e..01d5d2d 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct local_policy_store_t local_policy_store_t;
 
-#include <types.h>
+#include <library.h>
 #include <config/policies/policy_store.h>
 
 
index 279ce93..a040434 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum dpd_action_t dpd_action_t;
 typedef struct policy_t policy_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/identification.h>
 #include <config/traffic_selector.h>
 #include <config/proposal.h>
index b89bbab..6b47005 100755 (executable)
@@ -25,7 +25,7 @@
 
 typedef struct policy_store_t policy_store_t;
 
-#include <types.h>
+#include <library.h>
 #include <config/policies/policy.h>
 #include <utils/linked_list.h>
 
index 6099eca..abcb409 100644 (file)
@@ -29,7 +29,7 @@ typedef enum extended_sequence_numbers_t extended_sequence_numbers_t;
 typedef struct algorithm_t algorithm_t;
 typedef struct proposal_t proposal_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/identification.h>
 #include <utils/linked_list.h>
 #include <utils/host.h>
index 9c15200..2361f67 100644 (file)
@@ -238,23 +238,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(TRAFFIC_SELECTOR_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_TRAFFIC_SELECTOR, print, arginfo_ptr);
 }
 
 /**
@@ -368,7 +356,7 @@ static bool equals(private_traffic_selector_t *this, private_traffic_selector_t
  */
 static chunk_t get_from_address(private_traffic_selector_t *this)
 {
-       chunk_t from = CHUNK_INITIALIZER;
+       chunk_t from = chunk_empty;
        
        switch (this->type)
        {
@@ -395,7 +383,7 @@ static chunk_t get_from_address(private_traffic_selector_t *this)
  */
 static chunk_t get_to_address(private_traffic_selector_t *this)
 {
-       chunk_t to = CHUNK_INITIALIZER;
+       chunk_t to = chunk_empty;
        
        switch (this->type)
        {
index 09fdaf6..b611b61 100644 (file)
 typedef enum ts_type_t ts_type_t;
 typedef struct traffic_selector_t traffic_selector_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/host.h>
 
 /**
- * printf() specifier for tRaffic selectors
- */
-#define TRAFFIC_SELECTOR_PRINTF_SPEC 'R'
-
-/**
  * Traffic selector types.
  * 
  * @ingroup config
index be14866..1fd9f9a 100644 (file)
@@ -36,7 +36,7 @@
 
 #include "daemon.h"
 
-#include <types.h>
+#include <library.h>
 #include <config/credentials/local_credential_store.h>
 #include <config/connections/local_connection_store.h>
 #include <config/policies/local_policy_store.h>
index def14cb..847fda4 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "generator.h"
 
-#include <types.h>
+#include <library.h>
 #include <daemon.h>
 #include <utils/linked_list.h>
 #include <encoding/payloads/payload.h>
index 924e1e6..8eff957 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct generator_t generator_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/encodings.h>
 #include <encoding/payloads/payload.h>
 
index d8f5efe..f1b92e9 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "message.h"
 
-#include <types.h>
+#include <library.h>
 #include <daemon.h>
 #include <sa/ike_sa_id.h>
 #include <encoding/generator.h>
@@ -589,23 +589,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(MESSAGE_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_MESSAGE, print, arginfo_ptr);
 }
 
 /**
index 8b7e3c7..dfb6d64 100644 (file)
@@ -27,7 +27,7 @@
 
 typedef struct message_t message_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa_id.h>
 #include <network/packet.h>
 #include <encoding/payloads/ike_header.h>
@@ -37,11 +37,6 @@ typedef struct message_t message_t;
 #include <crypto/signers/signer.h>
 
 /**
- * printf() specifier for message
- */
-#define MESSAGE_PRINTF_SPEC 'M'
-
-/**
  * @brief This class is used to represent an IKEv2-Message.
  *
  * The message handles parsing and generation of payloads
index 6e8bad5..d7f10f7 100644 (file)
@@ -27,8 +27,7 @@
 
 #include "parser.h"
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <daemon.h>
 #include <utils/linked_list.h>
 #include <encoding/payloads/encodings.h>
index bff3b50..e997852 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct parser_t parser_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/encodings.h>
 #include <encoding/payloads/payload.h>
 
index 5e35697..256d6c8 100644 (file)
@@ -259,7 +259,7 @@ auth_payload_t *auth_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length =AUTH_PAYLOAD_HEADER_LENGTH;
-       this->auth_data = CHUNK_INITIALIZER;
+       this->auth_data = chunk_empty;
 
        return (&(this->public));
 }
index 7616a6e..2db82ec 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct auth_payload_t auth_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <sa/authenticators/authenticator.h>
 
index f5a5655..2e690b4 100644 (file)
@@ -271,7 +271,7 @@ cert_payload_t *cert_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length =CERT_PAYLOAD_HEADER_LENGTH;
-       this->cert_data = CHUNK_INITIALIZER;
+       this->cert_data = chunk_empty;
 
        return (&(this->public));
 }
index c1ba0bd..fb0cf68 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum cert_encoding_t cert_encoding_t;
 typedef struct cert_payload_t cert_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <crypto/x509.h>
 #include <encoding/payloads/payload.h>
 
index 4001712..07d3ce2 100644 (file)
@@ -258,7 +258,7 @@ certreq_payload_t *certreq_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length =CERTREQ_PAYLOAD_HEADER_LENGTH;
-       this->certreq_data = CHUNK_INITIALIZER;
+       this->certreq_data = chunk_empty;
 
        return (&(this->public));
 }
index e00d673..2985fda 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct certreq_payload_t certreq_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/cert_payload.h>
 
index 5982214..e7000e1 100644 (file)
@@ -26,7 +26,7 @@
 #include "configuration_attribute.h"
 
 #include <encoding/payloads/encodings.h>
-#include <types.h>
+#include <library.h>
 
 
 typedef struct private_configuration_attribute_t private_configuration_attribute_t;
@@ -272,7 +272,7 @@ configuration_attribute_t *configuration_attribute_create()
        
        /* set default values of the fields */
        this->attribute_type = 0;
-       this->attribute_value = CHUNK_INITIALIZER;
+       this->attribute_value = chunk_empty;
        this->attribute_length = 0;
 
        return (&(this->public));
index 51abab6..5a11d0a 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum configuration_attribute_type_t configuration_attribute_type_t;
 typedef struct configuration_attribute_t configuration_attribute_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 
index 1978b69..af36b48 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum config_type_t config_type_t;
 typedef struct cp_payload_t cp_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/configuration_attribute.h>
 #include <utils/linked_list.h>
index dcc66e8..81436e2 100644 (file)
@@ -355,7 +355,7 @@ delete_payload_t *delete_payload_create(protocol_id_t protocol_id)
        this->protocol_id = protocol_id;
        this->spi_size = protocol_id == PROTO_AH || protocol_id == PROTO_ESP ? 4 : 0;
        this->spi_count = 0;
-       this->spis = CHUNK_INITIALIZER;
+       this->spis = chunk_empty;
        this->spi_list = NULL;
 
        return (&this->public);
index 3484f02..9fc558f 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct delete_payload_t delete_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/proposal_substructure.h>
 
index e31c4b2..aa886e9 100644 (file)
@@ -222,7 +222,7 @@ eap_payload_t *eap_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length = EAP_PAYLOAD_HEADER_LENGTH;
-       this->message = CHUNK_INITIALIZER;
+       this->message = chunk_empty;
 
        return (&(this->public));
 }
index 17af03d..bf493eb 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct eap_payload_t eap_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 /**
index d69de4f..ed5596e 100644 (file)
@@ -27,9 +27,7 @@
 typedef enum encoding_type_t encoding_type_t;
 typedef struct encoding_rule_t encoding_rule_t;
 
-
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 
 /**
  * @brief All different kinds of encoding types. 
index 908de3d..23b6e8d 100644 (file)
@@ -293,7 +293,7 @@ static void generate(private_encryption_payload_t *this)
                /* no paylads? */
                DBG2(DBG_ENC, "generating contained payloads, but none available");
                free(this->decrypted.ptr);
-               this->decrypted = CHUNK_INITIALIZER;
+               this->decrypted = chunk_empty;
                iterator->destroy(iterator);
                return;
        }
@@ -636,8 +636,8 @@ encryption_payload_t *encryption_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length = ENCRYPTION_PAYLOAD_HEADER_LENGTH;
-       this->encrypted = CHUNK_INITIALIZER;
-       this->decrypted = CHUNK_INITIALIZER;
+       this->encrypted = chunk_empty;
+       this->decrypted = chunk_empty;
        this->signer = NULL;
        this->crypter = NULL;
        this->payloads = linked_list_create();
index c0b476b..7cf5361 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct encryption_payload_t encryption_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <crypto/crypters/crypter.h>
 #include <crypto/signers/signer.h>
 #include <encoding/payloads/payload.h>
index 954336a..1a8293a 100644 (file)
@@ -303,7 +303,7 @@ id_payload_t *id_payload_create(bool is_initiator)
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length =ID_PAYLOAD_HEADER_LENGTH;
-       this->id_data = CHUNK_INITIALIZER;
+       this->id_data = chunk_empty;
        this->is_initiator = is_initiator;
 
        return (&(this->public));
index 01c6a4e..b67d85d 100644 (file)
@@ -27,7 +27,7 @@
 
 typedef struct id_payload_t id_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/identification.h>
 #include <encoding/payloads/payload.h>
 
index 4cf253f..95c20f8 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum exchange_type_t exchange_type_t;
 typedef struct ike_header_t ike_header_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 /**
index fc87551..5a83fd0 100644 (file)
@@ -256,7 +256,7 @@ ke_payload_t *ke_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length = KE_PAYLOAD_HEADER_LENGTH;
-       this->key_exchange_data = CHUNK_INITIALIZER;
+       this->key_exchange_data = chunk_empty;
        this->dh_group_number = MODP_NONE;
 
        return &this->public;
index 18f9dec..52be8ff 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct ke_payload_t ke_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/transform_substructure.h>
 #include <utils/linked_list.h>
index 444110a..96d83b0 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct nonce_payload_t nonce_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 /**
index df95633..2b419bb 100644 (file)
@@ -29,7 +29,7 @@
 typedef enum notify_type_t notify_type_t;
 typedef struct notify_payload_t notify_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/proposal_substructure.h>
 #include <utils/linked_list.h>
index dfc3054..9a8c2f4 100644 (file)
@@ -27,8 +27,7 @@
 typedef enum payload_type_t payload_type_t;
 typedef struct payload_t payload_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <encoding/payloads/encodings.h>
 
 
index bb18c79..182d2b6 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <encoding/payloads/encodings.h>
 #include <encoding/payloads/transform_substructure.h>
-#include <types.h>
+#include <library.h>
 #include <utils/linked_list.h>
 #include <daemon.h>
 
index f1ce5bc..93a8d7b 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct proposal_substructure_t proposal_substructure_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/transform_substructure.h>
 #include <config/proposal.h>
index 90ded9a..67d6878 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct sa_payload_t sa_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/proposal_substructure.h>
 #include <utils/linked_list.h>
index 4a14042..573139b 100644 (file)
@@ -255,8 +255,8 @@ traffic_selector_substructure_t *traffic_selector_substructure_create()
        this->payload_length = TRAFFIC_SELECTOR_HEADER_LENGTH;
        this->start_port = 0;
        this->end_port = 0;
-       this->starting_address = CHUNK_INITIALIZER;
-       this->ending_address = CHUNK_INITIALIZER;
+       this->starting_address = chunk_empty;
+       this->ending_address = chunk_empty;
        this->ip_protocol_id = 0;
        /* must be set to be valid */
        this->ts_type = TS_IPV4_ADDR_RANGE;
index 5fc7dce..14efccc 100644 (file)
@@ -27,7 +27,7 @@
 
 typedef struct traffic_selector_substructure_t traffic_selector_substructure_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <utils/host.h>
 #include <config/traffic_selector.h>
index eddad00..066885c 100644 (file)
@@ -27,7 +27,7 @@
 #include "transform_attribute.h"
 
 #include <encoding/payloads/encodings.h>
-#include <types.h>
+#include <library.h>
 
 typedef struct private_transform_attribute_t private_transform_attribute_t;
 
index 1588b8f..30583b2 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum transform_attribute_type_t transform_attribute_type_t;
 typedef struct transform_attribute_t transform_attribute_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 
index 4ad1948..d64d6c7 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <encoding/payloads/transform_attribute.h>
 #include <encoding/payloads/encodings.h>
-#include <types.h>
+#include <library.h>
 #include <utils/linked_list.h>
 #include <daemon.h>
 
index ee297f8..97f587d 100644 (file)
@@ -26,8 +26,7 @@
 
 typedef struct transform_substructure_t transform_substructure_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 #include <encoding/payloads/transform_attribute.h>
 #include <utils/linked_list.h>
index a5595c9..1addee2 100644 (file)
@@ -27,7 +27,7 @@
 
 typedef struct ts_payload_t ts_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/linked_list.h>
 #include <config/traffic_selector.h>
 #include <encoding/payloads/payload.h>
index df126b5..bbe7360 100644 (file)
@@ -202,7 +202,7 @@ unknown_payload_t *unknown_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length = UNKNOWN_PAYLOAD_HEADER_LENGTH;
-       this->data = CHUNK_INITIALIZER;
+       this->data = chunk_empty;
 
        return (&(this->public));
 }
index 23cf421..8d13a03 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct unknown_payload_t unknown_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 /**
index ef70400..e3a4d2e 100644 (file)
@@ -222,7 +222,7 @@ vendor_id_payload_t *vendor_id_payload_create()
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length = VENDOR_ID_PAYLOAD_HEADER_LENGTH;
-       this->vendor_id_data = CHUNK_INITIALIZER;
+       this->vendor_id_data = chunk_empty;
 
        return (&(this->public));
 }
index 8972eaa..c7eebc1 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct vendor_id_payload_t vendor_id_payload_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/payloads/payload.h>
 
 /**
index 6c16a9d..6948fb4 100644 (file)
@@ -168,7 +168,7 @@ packet_t *packet_create(void)
        
        this->destination = NULL;
        this->source = NULL;
-       this->data = CHUNK_INITIALIZER;
+       this->data = chunk_empty;
        
        return &(this->public);
 }
index 0736e85..acf9530 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct packet_t packet_t;
 
-#include <types.h>
+#include <library.h>
 #include <utils/host.h>
 
 /**
index a6437c8..70d7b94 100644 (file)
@@ -27,7 +27,7 @@
 
 typedef struct socket_t socket_t;
 
-#include <types.h>
+#include <library.h>
 #include <network/packet.h>
 #include <utils/host.h>
 #include <utils/linked_list.h>
index df5284f..40bcb1e 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "event_queue.h"
 
-#include <types.h>
+#include <library.h>
 #include <utils/linked_list.h>
 
 
index 583fb2f..cd27512 100644 (file)
@@ -28,7 +28,7 @@ typedef struct event_queue_t event_queue_t;
 
 #include <sys/time.h>
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 
 /**
index 8dd542e..c971ba5 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct job_queue_t job_queue_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 
 /**
index 5a59c38..54f1b9b 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct acquire_job_t acquire_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 
 /**
index 99e042f..9c2e4fa 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct delete_child_sa_job_t delete_child_sa_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa_id.h>
 #include <queues/jobs/job.h>
 #include <config/proposal.h>
index 5857e99..43701a3 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct delete_ike_sa_job_t delete_ike_sa_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa_id.h>
 #include <queues/jobs/job.h>
 
index 9228d2e..5ce0750 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct incoming_packet_job_t incoming_packet_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <network/packet.h>
 #include <queues/jobs/job.h>
 
index 6771505..846f2f6 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct initiate_job_t initiate_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 #include <config/connections/connection.h>
 #include <config/policies/policy.h>
index aa29797..ae3fe79 100644 (file)
@@ -27,8 +27,7 @@
 typedef enum job_type_t job_type_t;
 typedef struct job_t job_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 
 /**
  * @brief Definition of the various job types.
index 4aacf57..19e1b5d 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct rekey_child_sa_job_t rekey_child_sa_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa_id.h>
 #include <queues/jobs/job.h>
 #include <config/proposal.h>
index b1fdb33..4848369 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct rekey_ike_sa_job_t rekey_ike_sa_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa_id.h>
 #include <queues/jobs/job.h>
 
index c57a870..1897af1 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct retransmit_request_job_t retransmit_request_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 #include <sa/ike_sa_id.h>
 
index ad7b48b..2743a70 100644 (file)
@@ -24,7 +24,7 @@
 
 typedef struct route_job_t route_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 #include <config/policies/policy.h>
 #include <config/connections/connection.h>
index fb17574..f3900f9 100644 (file)
@@ -24,7 +24,7 @@
 
 typedef struct send_dpd_job_t send_dpd_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 #include <config/connections/connection.h>
 #include <sa/ike_sa_id.h>
index 1bb7afd..c7d05be 100644 (file)
@@ -24,7 +24,7 @@
 
 typedef struct send_keepalive_job_t send_keepalive_job_t;
 
-#include <types.h>
+#include <library.h>
 #include <queues/jobs/job.h>
 #include <config/connections/connection.h>
 #include <sa/ike_sa_id.h>
index 8043f17..b69499c 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct send_queue_t send_queue_t;
 
-#include <types.h>
+#include <library.h>
 #include <network/packet.h>
 
 /**
index b1645c2..9d37a06 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum auth_method_t auth_method_t;
 typedef struct authenticator_t authenticator_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa.h>
 #include <encoding/payloads/auth_payload.h>
 
index 2f73e49..eac1ca6 100644 (file)
@@ -857,23 +857,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(CHILD_SA_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_CHILD_SA, print, arginfo_ptr);
 }
 
 /**
index 881c500..5b1df9e 100644 (file)
@@ -28,7 +28,7 @@
 typedef enum child_sa_state_t child_sa_state_t;
 typedef struct child_sa_t child_sa_t;
 
-#include <types.h>
+#include <library.h>
 #include <crypto/prf_plus.h>
 #include <encoding/payloads/proposal_substructure.h>
 #include <config/proposal.h>
@@ -40,11 +40,6 @@ typedef struct child_sa_t child_sa_t;
 #define REQID_START 2000000000
 
 /**
- * Printf() specifier for child_sa_t
- */
-#define CHILD_SA_PRINTF_SPEC 'P'
-
-/**
  * @brief States of a CHILD_SA
  */
 enum child_sa_state_t {
index 2ac59b2..eca8c92 100644 (file)
@@ -28,9 +28,8 @@
 
 #include "ike_sa.h"
 
-#include <types.h>
+#include <library.h>
 #include <daemon.h>
-#include <definitions.h>
 #include <utils/linked_list.h>
 #include <crypto/diffie_hellman.h>
 #include <crypto/prf_plus.h>
@@ -1898,23 +1897,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(IKE_SA_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_IKE_SA, print, arginfo_ptr);
 }
 
 /**
@@ -2006,8 +1993,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        this->child_sas = linked_list_create();
        this->my_host = host_create_from_string("0.0.0.0", 0);
        this->other_host = host_create_from_string("0.0.0.0", 0);
-       this->my_id = identification_create_from_encoding(ID_ANY, CHUNK_INITIALIZER);
-       this->other_id = identification_create_from_encoding(ID_ANY, CHUNK_INITIALIZER);
+       this->my_id = identification_create_from_encoding(ID_ANY, chunk_empty);
+       this->other_id = identification_create_from_encoding(ID_ANY, chunk_empty);
        this->crypter_in = NULL;
        this->crypter_out = NULL;
        this->signer_in = NULL;
index f4710b1..8f3b731 100644 (file)
@@ -28,7 +28,7 @@
 typedef enum ike_sa_state_t ike_sa_state_t;
 typedef struct ike_sa_t ike_sa_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/message.h>
 #include <encoding/payloads/proposal_substructure.h>
 #include <sa/ike_sa_id.h>
@@ -43,8 +43,6 @@ typedef struct ike_sa_t ike_sa_t;
 #include <config/policies/policy.h>
 #include <config/proposal.h>
 
-#define IKE_SA_PRINTF_SPEC 'K'
-
 /**
  * @brief State of an IKE_SA.
  *
index cac9cc3..95a3906 100644 (file)
@@ -170,26 +170,13 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(IKE_SA_ID_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_IKE_SA_ID, print, arginfo_ptr);
 }
 
-
 /**
  * Implementation of ike_sa_id_t.destroy.
  */
index 8462d65..0606b72 100644 (file)
 
 typedef struct ike_sa_id_t ike_sa_id_t;
 
-#include <types.h>
+#include <library.h>
 
-/**
- * printf() specifier to print a ike_sa_id.
- */
-#define IKE_SA_ID_PRINTF_SPEC 'J'
 
 /**
  * @brief An object of type ike_sa_id_t is used to identify an IKE_SA.
index c14d04a..42e7431 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct ike_sa_manager_t ike_sa_manager_t;
 
-#include <types.h>
+#include <library.h>
 #include <sa/ike_sa.h>
 
 /**
index 60d316f..cd53c5e 100644 (file)
@@ -540,7 +540,7 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
        if (this->ike_sa->get_state(this->ike_sa) == IKE_REKEYING ||
                this->ike_sa->get_state(this->ike_sa) == IKE_DELETING)
        {
-               build_notify(NO_ADDITIONAL_SAS, CHUNK_INITIALIZER, response, TRUE);
+               build_notify(NO_ADDITIONAL_SAS, chunk_empty, response, TRUE);
                DBG1(DBG_IKE, "unable to create new CHILD_SAs, as rekeying in progress");
                return FAILED;
        }
@@ -605,7 +605,7 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
        /* check if we have all payloads */
        if (!(sa_request && nonce_request && tsi_request && tsr_request))
        {
-               build_notify(INVALID_SYNTAX, CHUNK_INITIALIZER, response, TRUE);
+               build_notify(INVALID_SYNTAX, chunk_empty, response, TRUE);
                SIG(this->failsig, "request message incomplete, no CHILD_SA created");
                return FAILED;
        }
@@ -615,7 +615,7 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
                if (this->randomizer->allocate_pseudo_random_bytes(this->randomizer, 
                        NONCE_SIZE, &this->nonce_r) != SUCCESS)
                {
-                       build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                        SIG(this->failsig, "nonce generation failed, no CHILD_SA created");
                        return FAILED;
                }
@@ -649,7 +649,7 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
                if (this->policy == NULL)
                {
                        SIG(this->failsig, "no acceptable policy found, sending TS_UNACCEPTABLE notify");
-                       build_notify(TS_UNACCEPTABLE, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(TS_UNACCEPTABLE, chunk_empty, response, TRUE);
                        return FAILED;
                }
        }
@@ -672,14 +672,14 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
                if (this->proposal == NULL)
                {
                        SIG(this->failsig, "CHILD_SA proposals unacceptable, sending NO_PROPOSAL_CHOSEN notify");
-                       build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                        return FAILED;
                }
                /* do we have traffic selectors? */
                else if (this->tsi->get_count(this->tsi) == 0 || this->tsr->get_count(this->tsr) == 0)
                {
                        SIG(this->failsig, "CHILD_SA traffic selectors unacceptable, sending TS_UNACCEPTABLE notify");
-                       build_notify(TS_UNACCEPTABLE, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(TS_UNACCEPTABLE, chunk_empty, response, TRUE);
                        return FAILED;
                }
                else
@@ -700,7 +700,7 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
                        if (install_child_sa(this, FALSE) != SUCCESS)
                        {
                                SIG(this->failsig, "installing CHILD_SA failed, sending NO_PROPOSAL_CHOSEN notify");
-                               build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                               build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                                return FAILED;
                        }
                        /* add proposal to sa payload */
@@ -975,9 +975,9 @@ create_child_sa_t *create_child_sa_create(ike_sa_t *ike_sa)
        this->requested = 0;
        this->rekey_spi = 0;
        this->reqid = 0;
-       this->nonce_i = CHUNK_INITIALIZER;
-       this->nonce_r = CHUNK_INITIALIZER;
-       this->nonce_s = CHUNK_INITIALIZER;
+       this->nonce_i = chunk_empty;
+       this->nonce_r = chunk_empty;
+       this->nonce_s = chunk_empty;
        this->child_sa = NULL;
        this->rekeyed_sa = NULL;
        this->lost = FALSE;
index 5fd64e7..ae155ec 100644 (file)
@@ -685,7 +685,7 @@ static status_t get_response(private_ike_auth_t *this, message_t *request,
                }
                else
                {
-                       my_id = identification_create_from_encoding(ID_ANY, CHUNK_INITIALIZER);
+                       my_id = identification_create_from_encoding(ID_ANY, chunk_empty);
                }
        }
        
@@ -1116,10 +1116,10 @@ ike_auth_t *ike_auth_create(ike_sa_t *ike_sa)
        this->message_id = 0;
        this->message = NULL;
        this->requested = 0;
-       this->nonce_i = CHUNK_INITIALIZER;
-       this->nonce_r = CHUNK_INITIALIZER;
-       this->init_request = CHUNK_INITIALIZER;
-       this->init_response = CHUNK_INITIALIZER;
+       this->nonce_i = chunk_empty;
+       this->nonce_r = chunk_empty;
+       this->init_request = chunk_empty;
+       this->init_response = chunk_empty;
        this->child_sa = NULL;
        this->proposal = NULL;
        this->tsi = NULL;
index 34e7f70..937f4ce 100644 (file)
@@ -1099,8 +1099,8 @@ ike_sa_init_t *ike_sa_init_create(ike_sa_t *ike_sa)
        this->message = NULL;
        this->requested = 0;
        this->diffie_hellman = NULL;
-       this->nonce_i = CHUNK_INITIALIZER;
-       this->nonce_r = CHUNK_INITIALIZER;
+       this->nonce_i = chunk_empty;
+       this->nonce_r = chunk_empty;
        this->connection = NULL;
        this->policy = NULL;
        this->proposal = NULL;
@@ -1108,8 +1108,8 @@ ike_sa_init_t *ike_sa_init_create(ike_sa_t *ike_sa)
        this->reqid = 0;
        this->randomizer = randomizer_create();
        this->nat_hasher = hasher_create(HASH_SHA1);
-       this->natd_src_hash = CHUNK_INITIALIZER;
-       this->natd_dst_hash = CHUNK_INITIALIZER;
+       this->natd_src_hash = chunk_empty;
+       this->natd_dst_hash = chunk_empty;
        this->natd_src_seen = FALSE;
        this->natd_dst_seen = FALSE;
        this->natd_src_matched = FALSE;
index 06c8707..ee72026 100644 (file)
@@ -445,7 +445,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
        /* if we already initiate a delete, we do not allow rekeying */
        if (this->ike_sa->get_state(this->ike_sa) == IKE_DELETING)
        {
-               build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+               build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                DBG1(DBG_IKE, "unable to rekey, as delete in progress. Sending NO_PROPOSAL_CHOSEN");
                return FAILED;
        }
@@ -459,7 +459,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
                        state == CHILD_REKEYING ||
                        state == CHILD_DELETING)
                {
-                       build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                        DBG1(DBG_IKE, "unable to rekey, one CHILD_SA is half open. Sending NO_PROPOSAL_CHOSEN");
                        iterator->destroy(iterator);
                        return FAILED;
@@ -482,7 +482,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
                if (this->connection == NULL)
                {
                        DBG1(DBG_IKE, "no connection found to rekey IKE_SA, sending NO_RROPOSAL_CHOSEN");
-                       build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                        return FAILED;
                }
        }
@@ -527,7 +527,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
        /* check if we have all payloads */
        if (!(sa_request && nonce_request && ke_request))
        {
-               build_notify(INVALID_SYNTAX, CHUNK_INITIALIZER, response, TRUE);
+               build_notify(INVALID_SYNTAX, chunk_empty, response, TRUE);
                DBG1(DBG_IKE, "request message incomplete, IKE_SA rekeying failed");
                return FAILED;
        }
@@ -537,7 +537,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
                if (this->randomizer->allocate_pseudo_random_bytes(this->randomizer, 
                        NONCE_SIZE, &this->nonce_r) != SUCCESS)
                {
-                       build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                        return FAILED;
                }
                nonce_response = nonce_payload_create();
@@ -561,7 +561,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
                if (this->proposal == NULL)
                {
                        DBG1(DBG_IKE, "no proposals acceptable to rekey IKE_SA, sending NO_PROPOSAL_CHOSEN");
-                       build_notify(NO_PROPOSAL_CHOSEN, CHUNK_INITIALIZER, response, TRUE);
+                       build_notify(NO_PROPOSAL_CHOSEN, chunk_empty, response, TRUE);
                        return FAILED;
                }
                
@@ -874,9 +874,9 @@ rekey_ike_sa_t *rekey_ike_sa_create(ike_sa_t *ike_sa)
        this->message_id = 0;
        this->message = NULL;
        this->requested = 0;
-       this->nonce_i = CHUNK_INITIALIZER;
-       this->nonce_r = CHUNK_INITIALIZER;
-       this->nonce_s = CHUNK_INITIALIZER;
+       this->nonce_i = chunk_empty;
+       this->nonce_r = chunk_empty;
+       this->nonce_s = chunk_empty;
        this->new_sa = NULL;
        this->lost = FALSE;
        this->connection = NULL;
index a22cf71..4a401e1 100644 (file)
@@ -25,7 +25,7 @@
 
 typedef struct transaction_t transaction_t;
 
-#include <types.h>
+#include <library.h>
 #include <encoding/message.h>
 #include <sa/ike_sa.h>
 
index 19c0a05..ff0971c 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct receiver_t receiver_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Receives packets from the socket and adds them to the job queue.
index 87dccea..74091e3 100644 (file)
@@ -27,7 +27,6 @@
 #include "scheduler.h"
 
 #include <daemon.h>
-#include <definitions.h>
 #include <queues/job_queue.h>
 
 
index e794cce..daecce3 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct scheduler_t scheduler_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief The scheduler thread is responsible for timed events.
index 6ec83a7..bc2a1ea 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct sender_t sender_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Thread responsible for sending packets over the socket.
index 0163f18..1561c09 100755 (executable)
@@ -34,7 +34,7 @@
 
 #include "stroke_interface.h"
 
-#include <types.h>
+#include <library.h>
 #include <stroke.h>
 #include <daemon.h>
 #include <crypto/x509.h>
index 2d8fd4f..8e1989b 100644 (file)
@@ -28,7 +28,7 @@ typedef struct thread_pool_t thread_pool_t;
 
 #include <stdlib.h>
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief A thread_pool consists of a pool of threads processing jobs from the job queue.
index a7deeef..9f1dd4f 100644 (file)
@@ -1,9 +1,11 @@
 lib_LTLIBRARIES = libstrongswan.la
 
 libstrongswan_la_SOURCES = \
-definitions.c definitions.h \
-types.c types.h \
 library.c library.h \
+chunk.c chunk.h \
+debug.c debug.h \
+enum.c enum.h \
+printf_hook.c printf_hook.h \
 asn1/oid.c asn1/oid.h \
 asn1/asn1.c asn1/asn1.h \
 asn1/pem.c asn1/pem.h \
index c73ee2a..c844ba2 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "asn1.h"
 
-#include <types.h>
 #include <library.h>
+#include <debug.h>
 
 /* some common prefabricated ASN.1 constants */
 static u_char ASN1_INTEGER_0_str[] = { 0x02, 0x00 };
@@ -98,7 +98,7 @@ chunk_t asn1_algorithmIdentifier(int oid)
                case OID_SHA1:
                        return ASN1_sha1_id;
                default:
-                       return CHUNK_INITIALIZER;
+                       return chunk_empty;
        }
 }
 
@@ -320,9 +320,13 @@ static void debug_asn1_simple_object(chunk_t object, asn1_t type, bool private)
                        break;
        }
        if (private)
+       {
                DBG4("%B", &object);
+       }
        else
+       {
                DBG3("%B", &object);
+       }
 }
 
 /**
@@ -335,7 +339,7 @@ bool extract_object(asn1Object_t const *objects, u_int *objectID, chunk_t *objec
        chunk_t *blob1;
        u_char *start_ptr;
        
-       *object = CHUNK_INITIALIZER;
+       *object = chunk_empty;
        
        if (obj.flags & ASN1_END)  /* end of loop or option found */
        {
@@ -447,9 +451,13 @@ bool extract_object(asn1Object_t const *objects, u_int *objectID, chunk_t *objec
                object->ptr = start_ptr;
                object->len = (size_t)(blob->ptr - start_ptr);
                if (ctx->private)
+               {
                        DBG4("%B", object);
+               }
                else
+               {
                        DBG3("%B", object);
+               }
        }
        else if (obj.flags & ASN1_BODY)
        {
index 64774f6..5ab519e 100644 (file)
@@ -19,7 +19,7 @@
 #include <stdarg.h>
 #include <gmp.h>
 
-#include <types.h>
+#include <library.h>
 #include <asn1/oid.h>
 
 
index f1c6a42..e88db24 100755 (executable)
@@ -23,6 +23,7 @@
 #include "pem.h"
 
 #include <library.h>
+#include <debug.h>
 #include <asn1/asn1.h>
 #include <asn1/ttodata.h>
 
@@ -53,7 +54,7 @@ static bool present(const char* pattern, chunk_t* ch)
  */
 static bool find_boundary(const char* tag, chunk_t *line)
 {
-       chunk_t name = CHUNK_INITIALIZER;
+       chunk_t name = chunk_empty;
 
        if (!present("-----", line))
                return FALSE;
@@ -162,8 +163,8 @@ err_t pem_to_bin(chunk_t *blob, chunk_t *passphrase, bool *pgp)
 
        chunk_t src    = *blob;
        chunk_t dst    = *blob;
-       chunk_t line   = CHUNK_INITIALIZER;
-       chunk_t iv     = CHUNK_INITIALIZER;
+       chunk_t line   = chunk_empty;
+       chunk_t iv     = chunk_empty;
 
        u_char iv_buf[16]; /* MD5 digest size */
 
@@ -198,8 +199,8 @@ err_t pem_to_bin(chunk_t *blob, chunk_t *passphrase, bool *pgp)
                        if (state == PEM_HEADER)
                        {
                                err_t ugh = NULL;
-                               chunk_t name  = CHUNK_INITIALIZER;
-                               chunk_t value = CHUNK_INITIALIZER;
+                               chunk_t name  = chunk_empty;
+                               chunk_t value = chunk_empty;
 
                                /* an empty line separates HEADER and BODY */
                                if (line.len == 0)
index 2c0b457..0f4b720 100755 (executable)
@@ -17,7 +17,7 @@
 
 #include <stdio.h>
 
-#include <types.h>
+#include <library.h>
 
 err_t pem_to_bin(chunk_t *blob, chunk_t *passphrase, bool *pgp);
 
index b2b5ade..6125c6b 100644 (file)
@@ -16,7 +16,7 @@
 #ifndef TTODATA_H_
 #define TTODATA_H_
 
-#include <types.h>
+#include <library.h>
 
 #define        TTODATAV_BUF    40      /* ttodatav's largest non-literal message */
 #define TTODATAV_IGNORESPACE  (1<<1)  /* ignore spaces in base64 encodings*/
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c
new file mode 100644 (file)
index 0000000..811a975
--- /dev/null
@@ -0,0 +1,243 @@
+/**
+ * @file chunk.c
+ *
+ * @brief Pointer/lenght abstraction and its functions.
+ *
+ */
+
+/*
+ * Copyright (C) 2005-2006 Martin Willi
+ * Copyright (C) 2005 Jan Hutter
+ * 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 <stdio.h>
+
+#include "chunk.h"
+
+#include <printf_hook.h>
+
+/**
+ * Empty chunk.
+ */
+chunk_t chunk_empty = { NULL, 0 };
+
+/**
+ * Described in header.
+ */
+chunk_t chunk_clone(chunk_t chunk)
+{
+       chunk_t clone = chunk_empty;
+       
+       if (chunk.ptr && chunk.len > 0)
+       {
+               clone.ptr = malloc(chunk.len);
+               clone.len = chunk.len;
+               memcpy(clone.ptr, chunk.ptr, chunk.len);
+       }
+       
+       return clone;
+}
+
+/**
+ * Decribed in header.
+ */
+chunk_t chunk_cat(const char* mode, ...)
+{
+       chunk_t construct;
+       va_list chunks;
+       u_char *pos;
+       int i;
+       int count = strlen(mode);
+
+       /* sum up lengths of individual chunks */
+       va_start(chunks, mode);
+       construct.len = 0;
+       for (i = 0; i < count; i++)
+       {
+               chunk_t ch = va_arg(chunks, chunk_t);
+               construct.len += ch.len;
+       }
+       va_end(chunks);
+
+       /* allocate needed memory for construct */
+       construct.ptr = malloc(construct.len);
+       pos = construct.ptr;
+
+       /* copy or move the chunks */
+       va_start(chunks, mode);
+       for (i = 0; i < count; i++)
+       {
+               chunk_t ch = va_arg(chunks, chunk_t);
+               switch (*mode++)
+               {
+                       case 'm':
+                               memcpy(pos, ch.ptr, ch.len); 
+                               pos += ch.len;
+                               free(ch.ptr);
+                               break;
+                       case 'c':
+                       default:
+                               memcpy(pos, ch.ptr, ch.len); 
+                               pos += ch.len;
+               }
+       }
+       va_end(chunks);
+       
+       return construct;
+}
+
+/**
+ * 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.
+ */
+bool chunk_equals(chunk_t a, chunk_t b)
+{
+       return a.ptr != NULL  && b.ptr != NULL &&
+                       a.len == b.len && memeq(a.ptr, b.ptr, a.len);
+}
+
+/**
+ * Described in header.
+ */
+bool chunk_equals_or_null(chunk_t a, chunk_t b)
+{
+       if (a.ptr == NULL || b.ptr == NULL)
+               return TRUE;
+       return a.len == b.len && memeq(a.ptr, b.ptr, a.len);
+}
+
+/**
+ * Number of bytes per line to dump raw data
+ */
+#define BYTES_PER_LINE 16
+
+/**
+ * output handler in printf() for byte ranges
+ */
+static int print_bytes(FILE *stream, const struct printf_info *info,
+                                          const void *const *args)
+{
+       char *bytes = *((void**)(args[0]));
+       int len = *((size_t*)(args[1]));
+       
+       char buffer[BYTES_PER_LINE * 3];
+       char ascii_buffer[BYTES_PER_LINE + 1];
+       char *buffer_pos = buffer;
+       char *bytes_pos  = bytes;
+       char *bytes_roof = bytes + len;
+       int line_start = 0;
+       int i = 0;
+       int written = 0;
+       
+       written += fprintf(stream, "=> %d bytes @ %p", len, bytes);
+       
+       while (bytes_pos < bytes_roof)
+       {
+               static char hexdig[] = "0123456789ABCDEF";
+               
+               *buffer_pos++ = hexdig[(*bytes_pos >> 4) & 0xF];
+               *buffer_pos++ = hexdig[ *bytes_pos       & 0xF];
+
+               ascii_buffer[i++] =
+                               (*bytes_pos > 31 && *bytes_pos < 127) ? *bytes_pos : '.';
+
+               if (++bytes_pos == bytes_roof || i == BYTES_PER_LINE) 
+               {
+                       int padding = 3 * (BYTES_PER_LINE - i);
+                       int written;
+                       
+                       while (padding--)
+                       {
+                               *buffer_pos++ = ' ';
+                       }
+                       *buffer_pos++ = '\0';
+                       ascii_buffer[i] = '\0';
+                       
+                       written += fprintf(stream, "\n%4d: %s  %s",
+                                                          line_start, buffer, ascii_buffer);
+
+                       
+                       buffer_pos = buffer;
+                       line_start += BYTES_PER_LINE;
+                       i = 0;
+               }
+               else
+               {
+                       *buffer_pos++ = ' ';
+               }
+       }
+       return written;
+}
+
+/**
+ * output handler in printf() for chunks
+ */
+static int print_chunk(FILE *stream, const struct printf_info *info,
+                                          const void *const *args)
+{
+       chunk_t *chunk = *((chunk_t**)(args[0]));
+       bool first = TRUE;
+       chunk_t copy = *chunk;
+       int written = 0;
+       
+       if (!info->alt)
+       {
+               const void *new_args[] = {&chunk->ptr, &chunk->len};
+               return print_bytes(stream, info, new_args);
+       }
+       
+       while (copy.len > 0)
+       {
+               if (first)
+               {
+                       first = FALSE;
+               }
+               else
+               {
+                       written += fprintf(stream, ":");
+               }
+               written += fprintf(stream, "%02x", *copy.ptr++);
+               copy.len--;
+       }
+       return written;
+}
+
+/**
+ * register printf() handlers
+ */
+static void __attribute__ ((constructor))print_register()
+{
+       register_printf_function(PRINTF_CHUNK, print_chunk, arginfo_ptr);
+       register_printf_function(PRINTF_BYTES, print_bytes, arginfo_ptr_int);
+}
diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h
new file mode 100644 (file)
index 0000000..93c4b51
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * @file chunk.h
+ *
+ * @brief Pointer/lenght abstraction and its functions.
+ *
+ */
+
+/*
+ * Copyright (C) 2005-2006 Martin Willi
+ * Copyright (C) 2005 Jan Hutter
+ * 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 CHUNK_H_
+#define CHUNK_H_
+
+#include <string.h>
+#include <stdarg.h>
+
+#include <library.h>
+
+typedef struct chunk_t chunk_t;
+
+/**
+ * General purpose pointer/length abstraction.
+ */
+struct chunk_t {
+       /** Pointer to start of data */
+       u_char *ptr;
+       /** Length of data in bytes */
+       size_t len;
+};
+
+/**
+ * A { NULL, 0 }-chunk handy for initialization.
+ */
+extern chunk_t chunk_empty;
+
+/**
+ * Initialize a chunk to point to a static(!) buffer
+ */
+#define chunk_from_buf(str) { str, sizeof(str) }
+
+/**
+ * Clone chunk contents in a newly allocated chunk
+ */
+chunk_t chunk_clone(chunk_t chunk);
+
+/**
+ * Allocate a chunk from concatenation of other chunks.
+ * mode is a string 'm' and 'c, 'm' means move chunk,
+ * 'c' means copy chunk.
+ */
+chunk_t chunk_cat(const char* mode, ...);
+
+/**
+ * Free contents of a chunk
+ */
+void chunk_free(chunk_t *chunk);
+
+/**
+ * Allocate a chunk
+ */
+chunk_t chunk_alloc(size_t bytes);
+
+/**
+ * Compare two chunks for equality,
+ * NULL chunks are never equal.
+ */
+bool chunk_equals(chunk_t a, chunk_t b);
+
+/**
+ * Compare two chunks for equality,
+ * NULL chunks are always equal.
+ */
+bool chunk_equals_or_null(chunk_t a, chunk_t b);
+
+#endif /* CHUNK_H_ */
index 20a6957..baebe3f 100644 (file)
@@ -22,8 +22,7 @@
 
 #include <time.h>
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 
 #include "certinfo.h"
 
index b391cbc..8d60e39 100644 (file)
@@ -27,8 +27,7 @@ typedef enum cert_status_t cert_status_t;
 typedef enum crl_reason_t crl_reason_t;
 typedef struct certinfo_t certinfo_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 
 /**
  * RFC 2560 OCSP - certificate status
index e6a1c35..b79c474 100755 (executable)
@@ -25,9 +25,8 @@
 #include <string.h>
 #include <printf.h>
 
-#include <types.h>
 #include <library.h>
-#include <definitions.h>
+#include <debug.h>
 #include <asn1/oid.h>
 #include <asn1/asn1.h>
 #include <asn1/pem.h>
@@ -219,7 +218,7 @@ bool parse_x509crl(chunk_t blob, u_int level0, private_crl_t *crl)
        asn1_ctx_t ctx;
        bool critical;
        chunk_t extnID;
-       chunk_t userCertificate = CHUNK_INITIALIZER;
+       chunk_t userCertificate = chunk_empty;
        revokedCert_t *revokedCert = NULL;
        chunk_t object;
        u_int level;
@@ -474,33 +473,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (info->alt)
-       {
-               if (n > 1)
-               {
-                       argtypes[0] = PA_POINTER;
-                       argtypes[1] = PA_INT;
-               }
-               return 2;
-       }
-       
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(CRL_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_CRL, print, arginfo_ptr_alt_ptr_int);
 }
 
 /*
@@ -512,11 +489,11 @@ crl_t *crl_create_from_chunk(chunk_t chunk)
        
        /* initialize */
        this->crlDistributionPoints = linked_list_create();
-       this->tbsCertList = CHUNK_INITIALIZER;
+       this->tbsCertList = chunk_empty;
        this->issuer = NULL;
        this->revokedCertificates = linked_list_create();
-       this->authKeyID = CHUNK_INITIALIZER;
-       this->authKeySerialNumber = CHUNK_INITIALIZER;
+       this->authKeyID = chunk_empty;
+       this->authKeySerialNumber = chunk_empty;
        
        /* public functions */
        this->public.get_issuer = (identification_t* (*) (const crl_t*))get_issuer;
@@ -543,7 +520,7 @@ crl_t *crl_create_from_chunk(chunk_t chunk)
 crl_t *crl_create_from_file(const char *filename)
 {
        bool pgp = FALSE;
-       chunk_t chunk = CHUNK_INITIALIZER;
+       chunk_t chunk = chunk_empty;
        crl_t *crl = NULL;
 
        if (!pem_asn1_load_file(filename, NULL, "crl", &chunk, &pgp))
index ff4ccd8..216cafa 100755 (executable)
 
 typedef struct crl_t crl_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <crypto/rsa/rsa_public_key.h>
 #include <crypto/certinfo.h>
 #include <utils/identification.h>
 #include <utils/iterator.h>
 
 /**
- * printf specifier for printing crls. When using the
- * #-modifier, an additional bool argument defines if dates 
- * are printed in UTC.
- */
-#define CRL_PRINTF_SPEC 'U'
-
-/**
  * @brief X.509 certificate revocation list
  * 
  * @b Constructors:
index 411dfed..46d94ce 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum encryption_algorithm_t encryption_algorithm_t;
 typedef struct crypter_t crypter_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Encryption algorithm, as in IKEv2 RFC 3.3.2.
index 65921a5..29a2ab4 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum diffie_hellman_group_t diffie_hellman_group_t;
 typedef struct diffie_hellman_t diffie_hellman_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Diffie-Hellman group.
index 3c6192f..a1b5f58 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum hash_algorithm_t hash_algorithm_t;
 typedef struct hasher_t hasher_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Algorithms to use for hashing.
index 5cf4643..fa61cac 100644 (file)
@@ -30,8 +30,6 @@
 
 #include "md5_hasher.h"
 
-#include <definitions.h>
-
 
 /* Constants for MD5Transform routine. */
 #define S11 7
index 33eec59..cca3366 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "sha1_hasher.h"
 
-#include <definitions.h>
-
 /*
  * ugly macro stuff
  */ 
index 2c59438..f6fd040 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "sha2_hasher.h"
 
-#include <definitions.h>
-
 
 typedef struct private_sha512_hasher_t private_sha512_hasher_t;
 
index 0f9ac70..d320bc5 100644 (file)
@@ -26,7 +26,6 @@
 typedef struct hmac_t hmac_t;
 
 #include <crypto/hashers/hasher.h>
-#include <definitions.h>
 
 /**
  * @brief Message authentication using hash functions.
index 761a8a7..6bd444b 100644 (file)
@@ -25,8 +25,6 @@
 
 #include "prf_plus.h"
 
-#include <definitions.h>
-
 typedef struct private_prf_plus_t private_prf_plus_t;
 
 /**
index ecd6196..9b06ee3 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct hmac_prf_t hmac_prf_t;
 
-#include <types.h>
+#include <library.h>
 #include <crypto/prfs/prf.h>
 #include <crypto/hashers/hasher.h>
 
index b95cc45..897cf90 100644 (file)
@@ -27,7 +27,7 @@
 typedef enum pseudo_random_function_t pseudo_random_function_t;
 typedef struct prf_t prf_t;
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Pseudo random function, as in IKEv2 RFC 3.3.2.
index 8dfced5..5b16479 100644 (file)
@@ -762,7 +762,7 @@ rsa_private_key_t *rsa_private_key_create_from_chunk(chunk_t blob)
 rsa_private_key_t *rsa_private_key_create_from_file(char *filename, chunk_t *passphrase)
 {
        bool pgp = FALSE;
-       chunk_t chunk = CHUNK_INITIALIZER;
+       chunk_t chunk = chunk_empty;
        rsa_private_key_t *key = NULL;
 
        if (!pem_asn1_load_file(filename, passphrase, "private key", &chunk, &pgp))
index 2263d2f..9ec0770 100644 (file)
@@ -26,8 +26,7 @@
 
 typedef struct rsa_private_key_t rsa_private_key_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <crypto/rsa/rsa_public_key.h>
 #include <crypto/hashers/hasher.h>
 
index f42ff06..3889967 100644 (file)
@@ -485,7 +485,7 @@ rsa_public_key_t *rsa_public_key_create_from_chunk(chunk_t blob)
 rsa_public_key_t *rsa_public_key_create_from_file(char *filename)
 {
        bool pgp = FALSE;
-       chunk_t chunk = CHUNK_INITIALIZER;
+       chunk_t chunk = chunk_empty;
        rsa_public_key_t *pubkey = NULL;
 
        if (!pem_asn1_load_file(filename, NULL, "public key", &chunk, &pgp))
index b56df28..1ee54dc 100644 (file)
@@ -28,8 +28,7 @@ typedef struct rsa_public_key_t rsa_public_key_t;
 
 #include <gmp.h>
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 
 /**
  * @brief RSA public key with associated functions.
index a9a80a5..57f7d8f 100644 (file)
@@ -27,8 +27,7 @@
 typedef enum integrity_algorithm_t integrity_algorithm_t;
 typedef struct signer_t signer_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 
 /**
  * @brief Integrity algorithm, as in IKEv2 RFC 3.3.2.
index 43fe589..8ed79eb 100755 (executable)
@@ -28,9 +28,8 @@
 
 #include "x509.h"
 
-#include <types.h>
 #include <library.h>
-#include <definitions.h>
+#include <debug.h>
 #include <asn1/oid.h>
 #include <asn1/asn1.h>
 #include <asn1/pem.h>
@@ -1162,33 +1161,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (info->alt)
-       {
-               if (n > 1)
-               {
-                       argtypes[0] = PA_POINTER;
-                       argtypes[1] = PA_INT;
-               }
-               return 2;
-       }
-       
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(X509_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_X509, print, arginfo_ptr_alt_ptr_int);
 }
 
 /**
@@ -1215,15 +1192,15 @@ x509_t *x509_create_from_chunk(chunk_t chunk)
        private_x509_t *this = malloc_thing(private_x509_t);
        
        /* initialize */
-       this->subjectPublicKey = CHUNK_INITIALIZER;
+       this->subjectPublicKey = chunk_empty;
        this->public_key = NULL;
        this->subject = NULL;
        this->issuer = NULL;
        this->subjectAltNames = linked_list_create();
        this->crlDistributionPoints = linked_list_create();
-       this->subjectKeyID = CHUNK_INITIALIZER;
-       this->authKeyID = CHUNK_INITIALIZER;
-       this->authKeySerialNumber = CHUNK_INITIALIZER;
+       this->subjectKeyID = chunk_empty;
+       this->authKeyID = chunk_empty;
+       this->authKeySerialNumber = chunk_empty;
        
        /* public functions */
        this->public.equals = (bool (*) (const x509_t*,const x509_t*))equals;
@@ -1270,7 +1247,7 @@ x509_t *x509_create_from_chunk(chunk_t chunk)
 x509_t *x509_create_from_file(const char *filename, const char *label)
 {
        bool pgp = FALSE;
-       chunk_t chunk = CHUNK_INITIALIZER;
+       chunk_t chunk = chunk_empty;
        x509_t *cert = NULL;
 
        if (!pem_asn1_load_file(filename, NULL, label, &chunk, &pgp))
index 346590e..f17d086 100755 (executable)
 
 typedef struct x509_t x509_t;
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <crypto/rsa/rsa_public_key.h>
 #include <crypto/certinfo.h>
 #include <utils/identification.h>
 #include <utils/iterator.h>
 
 /**
- * printf specifier for printing certificates. When using the
- * #-modifier, an additional bool argument defines if dates
- * are printed in UTC.
- */
-#define X509_PRINTF_SPEC 'Q'
-
-/**
  * @brief X.509 certificate.
  * 
  * @b Constructors:
diff --git a/src/libstrongswan/debug.c b/src/libstrongswan/debug.c
new file mode 100644 (file)
index 0000000..996cae5
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * @file library.c
+ *
+ * @brief Logging functions for the library.
+ *
+ */
+
+/*
+ * 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 <stdarg.h>
+#include <stdio.h>
+
+#include "debug.h"
+
+/**
+ * default dbg function which printf all to stderr
+ */
+static void dbg_stderr(int level, char *fmt, ...)
+{
+       va_list args;
+       
+       va_start(args, fmt);
+       vfprintf(stderr, fmt, args);
+       fprintf(stderr, "\n");
+       va_end(args);
+}
+
+void (*dbg) (int level, char *fmt, ...) = dbg_stderr;
diff --git a/src/libstrongswan/debug.h b/src/libstrongswan/debug.h
new file mode 100644 (file)
index 0000000..c424a1c
--- /dev/null
@@ -0,0 +1,60 @@
+/**
+ * @file log.h
+ *
+ * @brief Logging functions for the library.
+ *
+ */
+
+/*
+ * 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 DEBUG_H_
+#define DEBUG_H_
+
+#ifndef DEBUG_LEVEL
+# define DEBUG_LEVEL 4
+#endif /* DEBUG_LEVEL */
+
+/** debug macros, they call the dbg function hook */
+#if DEBUG_LEVEL >= 1
+# define DBG1(fmt, ...) dbg(1, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 2
+# define DBG2(fmt, ...) dbg(2, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 3
+# define DBG3(fmt, ...) dbg(3, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+#if DEBUG_LEVEL >= 4
+# define DBG4(fmt, ...) dbg(4, fmt, ##__VA_ARGS__)
+#endif /* DEBUG_LEVEL */
+
+#ifndef DBG1
+# define DBG1(...) {}
+#endif
+#ifndef DBG2
+# define DBG2(...) {}
+#endif
+#ifndef DBG3
+# define DBG3(...) {}
+#endif
+#ifndef DBG4
+# define DBG4(...) {}
+#endif
+
+/** dbg function hook, uses stderr logger by default */
+extern void (*dbg) (int level, char *fmt, ...);
+
+#endif /* DEBUG_H_ */
diff --git a/src/libstrongswan/definitions.c b/src/libstrongswan/definitions.c
deleted file mode 100644 (file)
index 0874768..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * @file definitions.c
- * 
- * @brief General purpose definitions and macros.
- * 
- */
-
-/*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
- * 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 <printf.h>
-#include <stdio.h>
-
-#include "definitions.h"
-
-/*
- * Described in header
- */
-static char *enum_name(enum_name_t *e, long val)
-{
-       do
-       {
-               if (val >= e->first && val <= e->last)
-               {
-                       return e->names[val - e->first];
-               }
-       }
-       while ((e = e->next));
-       return NULL;
-}
-
-
-/**
- * output handler in printf() for enum names
- */
-static int print_enum(FILE *stream, const struct printf_info *info,
-                                          const void *const *args)
-{
-       enum_name_t *ed = *((void**)(args[0]));
-       long val = *((size_t*)(args[1]));
-       char *name;
-       
-       name = enum_name(ed, val);
-       if (name == NULL)
-       {
-               return fprintf(stream, "(unknown enum value: %ld)", val);
-       }
-       return fprintf(stream, "%s", name);
-}
-
-/**
- * arginfo handler in printf() for enum names
- */
-static int print_enum_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 1)
-       {
-               /* enum_names ptr */
-               argtypes[0] = PA_POINTER;
-               /* value */
-               argtypes[1] = PA_INT;
-       }
-       return 2;
-}
-
-/**
- * register printf() handlers for enum names
- */
-static void __attribute__ ((constructor))print_register()
-{
-       register_printf_function(ENUM_PRINTF_SPEC, print_enum, print_enum_arginfo);
-}
diff --git a/src/libstrongswan/definitions.h b/src/libstrongswan/definitions.h
deleted file mode 100644 (file)
index b02e809..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * @file definitions.h
- * 
- * @brief General purpose definitions and macros.
- * 
- */
-
-/*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
- * Copyright (C) 1998, 1999  D. Hugh Redelmeier. (Endian stuff)
- * 
- * 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 DEFINITIONS_H_
-#define DEFINITIONS_H_
-
-#include <stddef.h>
-
-#define BITS_PER_BYTE 8
-
-/**
-  * Default length for various auxiliary text buffers
-  */
-#define BUF_LEN 512
-
-/**
- * Macro compares two strings for equality
- */
-#define streq(x,y) (strcmp(x, y) == 0)
-
-/**
- * Macro compares two binary blobs for equality
- */
-#define memeq(x,y,len) (memcmp(x, y, len) == 0)
-
-/**
- * Macro gives back larger of two values.
- */
-#define max(x,y) ((x) > (y) ? (x):(y))
-
-/**
- * Macro gives back smaller of two values.
- */
-#define min(x,y) ((x) < (y) ? (x):(y))
-
-/**
- * Call destructor of a object if object != NULL
- */
-#define DESTROY_IF(obj) if (obj) obj->destroy(obj)
-
-/**
- * Debug macro to follow control flow
- */
-#define POS printf("%s, line %d\n", __FILE__, __LINE__)
-
-/**
- * Macro to allocate a sized type.
- */
-#define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
-
-/**
- * Assign a function as a class method
- */
-#define ASSIGN(method, function) (method = (typeof(method))function)
-
-/**
- * printf() specifier to resolf enum names, see enum_names
- */
-#define ENUM_PRINTF_SPEC 'N'
-
-typedef struct enum_name_t enum_name_t;
-
-/**
- * Struct to store names for enums. Use the convenience macros 
- * to define these.
- * For a single range, use:
- * ENUM(name, first, last, string1, string2, ...)
- *
- * For multiple ranges, use:
- * ENUM_BEGIN(name, first, last, string1, string2, ...)
- *   ENUM_NEXT(name, first, last, last_from_previous, string3, ...)
- *   ENUM_NEXT(name, first, last, last_from_previous, string4, ...)
- * ENUM_END(name, last_from_previous)
- */
-struct enum_name_t {
-       long first;
-       long last;
-       enum_name_t *next;
-       char *names[];
-};
-
-#define ENUM_BEGIN(name, first, last, ...) static enum_name_t name##last = {first, last, NULL, { __VA_ARGS__ }}
-#define ENUM_NEXT(name, first, last, prev, ...) static enum_name_t name##last = {first, last, &name##prev, { __VA_ARGS__ }}
-#define ENUM_END(name, prev) enum_name_t *name = &name##prev;
-#define ENUM(name, first, last, ...) ENUM_BEGIN(name, first, last, __VA_ARGS__); ENUM_END(name, last)
-
-#endif /*DEFINITIONS_H_*/
diff --git a/src/libstrongswan/enum.c b/src/libstrongswan/enum.c
new file mode 100644 (file)
index 0000000..c3dd2e5
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+ * @file library.c
+ *
+ * @brief enum value to string conversion functions.
+ *
+ */
+
+/*
+ * 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 <stdio.h>
+
+#include "enum.h"
+
+#include <printf_hook.h>
+
+/**
+ * get the name of an enum value in a enum_name_t list
+ */
+static char *enum_name(enum_name_t *e, long val)
+{
+       do
+       {
+               if (val >= e->first && val <= e->last)
+               {
+                       return e->names[val - e->first];
+               }
+       }
+       while ((e = e->next));
+       return NULL;
+}
+
+/**
+ * output handler in printf() for enum names
+ */
+static int print_enum(FILE *stream, const struct printf_info *info,
+                                         const void *const *args)
+{
+       enum_name_t *ed = *((void**)(args[0]));
+       long val = *((long*)(args[1]));
+       char *name;
+       
+       name = enum_name(ed, val);
+       if (name == NULL)
+       {
+               return fprintf(stream, "(unknown enum value: %ld)", val);
+       }
+       return fprintf(stream, "%s", name);
+}
+
+/**
+ * register printf() handlers
+ */
+static void __attribute__ ((constructor))print_register()
+{
+       register_printf_function(PRINTF_ENUM, print_enum, arginfo_ptr_int);
+}
diff --git a/src/libstrongswan/enum.h b/src/libstrongswan/enum.h
new file mode 100644 (file)
index 0000000..3b90ce9
--- /dev/null
@@ -0,0 +1,106 @@
+/**
+ * @file enum.h
+ *
+ * @brief enum value to string conversion functions.
+ *
+ */
+
+/*
+ * 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 ENUM_H_
+#define ENUM_H_
+
+typedef struct enum_name_t enum_name_t;
+
+/**
+ * @brief Struct to store names for enums.
+ *
+ * To print the string representation of enumeration values, the strings
+ * are stored in these structures. Every enum_name contains a range
+ * of strings, multiple ranges are linked together.
+ * Use the convenience macros to define these linked ranges.
+ *
+ * For a single range, use:
+ * ENUM(name, first, last, string1, string2, ...)
+ *
+ * For multiple linked ranges, use:
+ * ENUM_BEGIN(name, first, last, string1, string2, ...)
+ *   ENUM_NEXT(name, first, last, last_from_previous, string3, ...)
+ *   ENUM_NEXT(name, first, last, last_from_previous, string4, ...)
+ * ENUM_END(name, last_from_previous)
+ *
+ * The ENUM and the ENUM_END define a enum_name_t pointer with the name supplied
+ * in "name".
+ *
+ * Resolving of enum names is done using a printf hook. A printf fromat
+ * character %N is replaced by the enum string. Printf needs two arguments to
+ * resolve a %N, the enum_name_t* (the defined name in ENUM_BEGIN) followed
+ * by the numerical enum value.
+ */
+struct enum_name_t {
+       /** value of the first enum string */
+       long first;
+       /** value of the last enum string */
+       long last;
+       /** next enum_name_t in list */
+       enum_name_t *next;
+       /** array of strings containing names from first to last */
+       char *names[];
+};
+
+/**
+ * @brief Begin a new enum_name list.
+ *
+ * @param name name of the enum_name list
+ * @param first        enum value of the first enum string
+ * @param last enum value of the last enum string
+ * @param ...  a list of strings
+ */
+#define ENUM_BEGIN(name, first, last, ...) static enum_name_t name##last = {first, last, NULL, { __VA_ARGS__ }}
+
+/**
+ * @brief Continue a enum name list startetd with ENUM_BEGIN.
+ *
+ * @param name name of the enum_name list
+ * @param first        enum value of the first enum string
+ * @param last enum value of the last enum string
+ * @param prev enum value of the "last" defined in ENUM_BEGIN/previous ENUM_NEXT
+ * @param ...  a list of strings
+ */
+#define ENUM_NEXT(name, first, last, prev, ...) static enum_name_t name##last = {first, last, &name##prev, { __VA_ARGS__ }}
+
+/**
+ * @brief Complete enum name list started with ENUM_BEGIN.
+ *
+ * @param name name of the enum_name list
+ * @param prev enum value of the "last" defined in ENUM_BEGIN/previous ENUM_NEXT
+ */
+#define ENUM_END(name, prev) enum_name_t *name = &name##prev;
+
+/**
+ * @brief Define a enum name with only one range.
+ *
+ * This is a convenience macro to use when a enum_name list contains only
+ * one range, and is equal as defining ENUM_BEGIN followed by ENUM_END.
+ * 
+ * @param name name of the enum_name list
+ * @param first        enum value of the first enum string
+ * @param last enum value of the last enum string
+ * @param ...  a list of strings
+ */
+#define ENUM(name, first, last, ...) ENUM_BEGIN(name, first, last, __VA_ARGS__); ENUM_END(name, last)
+
+#endif /* ENUM_H_ */
index 0394f32..cd40b64 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * @file library.c
  *
- * @brief Library (de-)initialization.
+ * @brief Helper functions and definitions.
  *
  */
 
  * for more details.
  */
 
-#include <stdarg.h>
+#include <string.h>
+#include <time.h>
 #include <stdio.h>
+#include <stdarg.h>
+#include <pthread.h>
 
 #include "library.h"
 
+#include <printf_hook.h>
+
+ENUM(status_names, SUCCESS, DESTROY_ME,
+       "SUCCESS",
+       "FAILED",
+       "OUT_OF_RES",
+       "ALREADY_DONE",
+       "NOT_SUPPORTED",
+       "INVALID_ARG",
+       "NOT_FOUND",
+       "PARSE_ERROR",
+       "VERIFY_ERROR",
+       "INVALID_STATE",
+       "DESTROY_ME",
+);
+
 /**
- * default dbg function which printf all to stderr
+ * Described in header.
  */
-static void dbg_stderr(int level, char *fmt, ...)
+void *clalloc(void * pointer, size_t size)
 {
-       va_list args;
+       void *data;
+       data = malloc(size);
+       
+       memcpy(data, pointer,size);
        
-       va_start(args, fmt);
-       vfprintf(stderr, fmt, args);
-       fprintf(stderr, "\n");
-       va_end(args);
+       return (data);
+}
+
+/**
+ * We use a single mutex for all refcount variables. This
+ * is not optimal for performance, but the critical section
+ * is not that long...
+ * TODO: Consider to include a mutex in each refcount_t variable.
+ */
+static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/**
+ * Described in header.
+ * 
+ * TODO: May be implemented with atomic CPU instructions
+ * instead of a mutex.
+ */
+void ref_get(refcount_t *ref)
+{
+       pthread_mutex_lock(&ref_mutex);
+       (*ref)++;
+       pthread_mutex_unlock(&ref_mutex);
 }
 
-void (*dbg) (int level, char *fmt, ...) = dbg_stderr;
+/**
+ * Described in header.
+ * 
+ * TODO: May be implemented with atomic CPU instructions
+ * instead of a mutex.
+ */
+bool ref_put(refcount_t *ref)
+{
+       bool more_refs;
+       
+       pthread_mutex_lock(&ref_mutex);
+       more_refs = --(*ref);
+       pthread_mutex_unlock(&ref_mutex);
+       return !more_refs;
+}
+
+/**
+ * output handler in printf() for time_t
+ */
+static int print_time(FILE *stream, const struct printf_info *info,
+                                         const void *const *args)
+{
+       static const char* months[] = {
+               "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+       };
+       time_t time = *((time_t*)(args[0]));
+       bool utc = TRUE;
+       struct tm t;
+       
+       if (info->alt)
+       {
+               utc = *((bool*)(args[1]));
+       }
+       if (time == UNDEFINED_TIME)
+       {
+               return fprintf(stream, "--- -- --:--:--%s----",
+                                          info->alt ? " UTC " : " ");
+       }
+       if (utc)
+       {
+               gmtime_r(&time, &t);
+       }
+       else
+       {
+               localtime_r(&time, &t);
+       }
+       return fprintf(stream, "%s %02d %02d:%02d:%02d%s%04d",
+                                  months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,
+                                  t.tm_sec, utc ? " UTC " : " ", t.tm_year + 1900);
+}
+
+/**
+ * output handler in printf() for time deltas
+ */
+static int print_time_delta(FILE *stream, const struct printf_info *info,
+                                                       const void *const *args)
+{
+       time_t start = *((time_t*)(args[0]));
+       time_t end = *((time_t*)(args[1]));
+       u_int delta = abs(end - start);
+       char* unit = "second";
+       
+       if (delta > 2 * 60 * 60 * 24)
+       {
+               delta /= 60 * 60 * 24;
+               unit = "days";
+       }
+       else if (delta > 2 * 60 * 60)
+       {
+               delta /= 60 * 60;
+               unit = "hours";
+       }
+       else if (delta > 2 * 60)
+       {
+               delta /= 60;
+               unit = "minutes";
+       }
+       return fprintf(stream, "%d %s", delta, unit);
+}
+
+/**
+ * register printf() handlers for time_t
+ */
+static void __attribute__ ((constructor))print_register()
+{
+       register_printf_function(PRINTF_TIME, print_time, arginfo_int_alt_int_int);
+       register_printf_function(PRINTF_TIME_DELTA, print_time_delta, arginfo_int_int);
+}
index 58cd4bb..12aa0cb 100644 (file)
@@ -1,14 +1,14 @@
 /**
  * @file library.h
- * 
- * @brief Global library header.
- * 
+ *
+ * @brief Helper functions and definitions.
+ *
  */
 
 /*
  * 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
  * @ingroup libstrongswan
  */
 
-/** debug macros, they call the dbg function hook */
-#define DBG1(fmt, ...) dbg(1, fmt, ##__VA_ARGS__)
-#define DBG2(fmt, ...) dbg(2, fmt, ##__VA_ARGS__)
-#define DBG3(fmt, ...) dbg(3, fmt, ##__VA_ARGS__)
-#define DBG4(fmt, ...) dbg(4, fmt, ##__VA_ARGS__)
+#include <gmp.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <printf.h>
+
+#include <enum.h>
+
+/**
+ * Number of bits in a byte
+ */
+#define BITS_PER_BYTE 8
+
+/**
+ * Default length for various auxiliary text buffers
+ */
+#define BUF_LEN 512
+
+/**
+ * Macro compares two strings for equality
+ */
+#define streq(x,y) (strcmp(x, y) == 0)
+
+/**
+ * Macro compares two binary blobs for equality
+ */
+#define memeq(x,y,len) (memcmp(x, y, len) == 0)
+
+/**
+ * Macro gives back larger of two values.
+ */
+#define max(x,y) ((x) > (y) ? (x):(y))
+
+/**
+ * Macro gives back smaller of two values.
+ */
+#define min(x,y) ((x) < (y) ? (x):(y))
+
+/**
+ * Call destructor of a object if object != NULL
+ */
+#define DESTROY_IF(obj) if (obj) obj->destroy(obj)
+
+/**
+ * Debug macro to follow control flow
+ */
+#define POS printf("%s, line %d\n", __FILE__, __LINE__)
+
+/**
+ * Macro to allocate a sized type.
+ */
+#define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
+
+/**
+ * Assign a function as a class method
+ */
+#define ASSIGN(method, function) (method = (typeof(method))function)
+
+/**
+ * time_t not defined
+ */
+#define UNDEFINED_TIME 0
+
+/**
+ * General purpose boolean type.
+ */
+typedef int bool;
+#define FALSE 0
+#define TRUE  1
+
+typedef enum status_t status_t;
+
+/**
+ * Return values of function calls.
+ */
+enum status_t {
+       /**
+        * Call succeeded.
+        */
+       SUCCESS,
+       
+       /**
+        * Call failed.
+        */
+       FAILED,
+       
+       /**
+        * Out of resources.
+        */
+       OUT_OF_RES,
+       
+       /**
+        * The suggested operation is already done
+        */
+       ALREADY_DONE,
+       
+       /**
+        * Not supported.
+        */
+       NOT_SUPPORTED,
+       
+       /**
+        * One of the arguments is invalid.
+        */
+       INVALID_ARG,
+       
+       /**
+        * Something could not be found.
+        */
+       NOT_FOUND,
+       
+       /**
+        * Error while parsing.
+        */
+       PARSE_ERROR,
+       
+       /**
+        * Error while verifying.
+        */
+       VERIFY_ERROR,
+       
+       /**
+        * Object in invalid state.
+        */
+       INVALID_STATE,
+       
+       /**
+        * Destroy object which called method belongs to.
+        */
+       DESTROY_ME,
+};
+
+/**
+ * enum_names for type status_t.
+ */
+extern enum_name_t *status_names;
+
+/**
+ * deprecated pluto style return value:
+ * error message, NULL for success
+ */
+typedef const char *err_t;
+
+/**
+ * Handle struct timeval like an own type.
+ */
+typedef struct timeval timeval_t;
+
+/**
+ * Handle struct timespec like an own type.
+ */
+typedef struct timespec timespec_t;
+
+/**
+ * Handle struct chunk_t like an own type.
+ */
+typedef struct sockaddr sockaddr_t;
+
+/**
+ * Clone a data to a newly allocated buffer
+ */
+void *clalloc(void *pointer, size_t size);
+
+/**
+ * Special type to count references
+ */
+typedef volatile u_int refcount_t;
+
+/**
+ * @brief Get a new reference.
+ *
+ * Increments the reference counter atomic.
+ *
+ * @param ref  pointer to ref counter
+ */
+void ref_get(refcount_t *ref);
+
+/**
+ * @brief Put back a unused reference.
+ *
+ * Decrements the reference counter atomic and 
+ * says if more references available.
+ *
+ * @param ref  pointer to ref counter
+ * @return             TRUE if no more references counted
+ */
+bool ref_put(refcount_t *ref);
+
 
-/** dbg function hook, uses stderr logger by default */
-extern void (*dbg) (int level, char *fmt, ...);
+#include <chunk.h>
+#include <printf_hook.h>
 
 #endif /* LIBRARY_H_ */
diff --git a/src/libstrongswan/printf_hook.c b/src/libstrongswan/printf_hook.c
new file mode 100644 (file)
index 0000000..e4089c4
--- /dev/null
@@ -0,0 +1,105 @@
+/**
+ * @file printf_hook.c
+ *
+ * @brief Printf hook definitions and arginfo functions.
+ *
+ */
+
+/*
+ * 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 "printf_hook.h"
+
+/**
+ * arginfo handler in printf() pointer
+ */
+int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes)
+{
+       if (n > 0)
+       {
+               argtypes[0] = PA_POINTER;
+       }
+       return 1;
+}
+
+/**
+ * arginfo handler for one ptr, one int
+ */
+int arginfo_ptr_int(const struct printf_info *info, size_t n, int *argtypes)
+{
+       if (n > 1)
+       {
+               argtypes[0] = PA_POINTER;
+               argtypes[1] = PA_INT;
+       }
+       return 2;
+}
+
+/**
+ * arginfo handler for two int arguments
+ */
+int arginfo_int_int(const struct printf_info *info, size_t n, int *argtypes)
+{
+       if (n > 1)
+       {
+               argtypes[0] = PA_INT;
+               argtypes[1] = PA_INT;
+       }
+       return 2;
+}
+
+/**
+ * special arginfo handler respecting alt flag
+ */
+int arginfo_int_alt_int_int(const struct printf_info *info, size_t n, int *argtypes)
+{
+       if (info->alt)
+       {
+               if (n > 1)
+               {
+                       argtypes[0] = PA_INT;
+                       argtypes[1] = PA_INT;
+               }
+               return 2;
+       }
+       
+       if (n > 0)
+       {
+               argtypes[0] = PA_INT;
+       }
+       return 1;
+}
+
+/**
+ * special arginfo handler respecting alt flag
+ */
+int arginfo_ptr_alt_ptr_int(const struct printf_info *info, size_t n, int *argtypes)
+{
+       if (info->alt)
+       {
+               if (n > 1)
+               {
+                       argtypes[0] = PA_POINTER;
+                       argtypes[1] = PA_INT;
+               }
+               return 2;
+       }
+       
+       if (n > 0)
+       {
+               argtypes[0] = PA_POINTER;
+       }
+       return 1;
+}
diff --git a/src/libstrongswan/printf_hook.h b/src/libstrongswan/printf_hook.h
new file mode 100644 (file)
index 0000000..14931bd
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * @file printf_hook.h
+ *
+ * @brief Printf hook definitions and arginfo functions.
+ *
+ */
+
+/*
+ * 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 PRINTF_HOOK_H_
+#define PRINTF_HOOK_H_
+
+#include <printf.h>
+
+/**
+ * Printf() hook characters.
+ * We define all characters here to have them on a central place.
+ */
+
+/** 2 arguments: enum_name_t *name, long value */
+#define PRINTF_ENUM                            'N'
+/** 1 argument: chunk_t *chunk; use #-modifier to print inline */
+#define PRINTF_CHUNK                   'B'
+/** 2 arguments: u_char *buffer, int size */
+#define PRINTF_BYTES                   'b'
+/** 1 argument: int time; with #-modifier 2 arguments: int time, bool utc */
+#define PRINTF_TIME                            'T'
+/** 2 arguments: integer begin, int end */
+#define PRINTF_TIME_DELTA              'V'
+/** 1 argument: x509_t *cert; with #-modifier 2 arguments: x509_t *cert, bool utc */
+#define PRINTF_X509                            'Q'
+/** 1 argument: crl_t *crl; with #-modifier 2 arguments: crl_t *crl, bool utc */
+#define PRINTF_CRL                             'U'
+/** 1 argumnet: host_t *host; use #-modifier to include port number */
+#define PRINTF_HOST                            'H'
+/** 1 argument: identification_t *id */
+#define PRINTF_IDENTIFICATION  'D'
+/** 1 argument: traffic_selector_t *ts */
+#define PRINTF_TRAFFIC_SELECTOR        'R'
+/** 1 argument: ike_sa_t *ike_sa */
+#define PRINTF_IKE_SA                  'K'
+/** 1 argument: ike_sa_id_t *id */
+#define PRINTF_IKE_SA_ID               'J'
+/** 1 argument: child_sa_t *child_sa */
+#define PRINTF_CHILD_SA                        'P'
+/** 1 argument: message_t *message */
+#define PRINTF_MESSAGE                 'M'
+
+/**
+ * Generic arginfo handlers for printf() hooks
+ */
+int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes);
+int arginfo_ptr_int(const struct printf_info *info, size_t n, int *argtypes);
+int arginfo_int_int(const struct printf_info *info, size_t n, int *argtypes);
+int arginfo_ptr_alt_ptr_int(const struct printf_info *info, size_t n, int *argtypes);
+int arginfo_int_alt_int_int(const struct printf_info *info, size_t n, int *argtypes);
+
+#endif /* PRINTF_HOOK_H_ */
diff --git a/src/libstrongswan/types.c b/src/libstrongswan/types.c
deleted file mode 100644 (file)
index 8e201f8..0000000
+++ /dev/null
@@ -1,438 +0,0 @@
-/**
- * @file types.c
- * 
- * @brief Generic types.
- * 
- */
-
-/*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
- * 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 <string.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <printf.h>
-
-#include "types.h"
-
-ENUM(status_names, SUCCESS, DESTROY_ME,
-       "SUCCESS",
-       "FAILED",
-       "OUT_OF_RES",
-       "ALREADY_DONE",
-       "NOT_SUPPORTED",
-       "INVALID_ARG",
-       "NOT_FOUND",
-       "PARSE_ERROR",
-       "VERIFY_ERROR",
-       "INVALID_STATE",
-       "DESTROY_ME",
-);
-
-
-/**
- * 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;
-}
-
-/**
- * Decribed in header.
- */
-chunk_t chunk_cat(const char* mode, ...)
-{
-       chunk_t construct;
-       va_list chunks;
-       u_char *pos;
-       int i;
-       int count = strlen(mode);
-
-       /* sum up lengths of individual chunks */
-       va_start(chunks, mode);
-       construct.len = 0;
-       for (i = 0; i < count; i++)
-       {
-               chunk_t ch = va_arg(chunks, chunk_t);
-               construct.len += ch.len;
-       }
-       va_end(chunks);
-
-       /* allocate needed memory for construct */
-       construct.ptr = malloc(construct.len);
-       pos = construct.ptr;
-
-       /* copy or move the chunks */
-       va_start(chunks, mode);
-       for (i = 0; i < count; i++)
-       {
-               chunk_t ch = va_arg(chunks, chunk_t);
-               switch (*mode++)
-               {
-                       case 'm':
-                               memcpy(pos, ch.ptr, ch.len); 
-                               pos += ch.len;
-                               free(ch.ptr);
-                               break;
-                       case 'c':
-                       default:
-                               memcpy(pos, ch.ptr, ch.len); 
-                               pos += ch.len;
-               }
-       }
-       va_end(chunks);
-       
-       return construct;
-}
-
-/**
- * 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.
- */
-bool chunk_equals(chunk_t a, chunk_t b)
-{
-       return a.ptr != NULL  && b.ptr != NULL &&
-                  a.len == b.len && memeq(a.ptr, b.ptr, a.len);
-}
-
-/**
- * Described in header.
- */
-bool chunk_equals_or_null(chunk_t a, chunk_t b)
-{
-       if (a.ptr == NULL || b.ptr == NULL)
-               return TRUE;
-       return a.len == b.len && memeq(a.ptr, b.ptr, a.len);
-}
-
-/**
- * Described in header.
- */
-void *clalloc(void * pointer, size_t size)
-{
-       void *data;
-       data = malloc(size);
-       
-       memcpy(data, pointer,size);
-       
-       return (data);
-}
-
-/**
- * We use a single mutex for all refcount variables. This
- * is not optimal for performance, but the critical section
- * is not that long...
- * TODO: Consider to include a mutex in each refcount_t variable.
- */
-static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/**
- * Described in header.
- * 
- * TODO: May be implemented with atomic CPU instructions
- * instead of a mutex.
- */
-void ref_get(refcount_t *ref)
-{
-       pthread_mutex_lock(&ref_mutex);
-       (*ref)++;
-       pthread_mutex_unlock(&ref_mutex);
-}
-
-/**
- * Described in header.
- * 
- * TODO: May be implemented with atomic CPU instructions
- * instead of a mutex.
- */
-bool ref_put(refcount_t *ref)
-{
-       bool more_refs;
-       
-       pthread_mutex_lock(&ref_mutex);
-       more_refs = --(*ref);
-       pthread_mutex_unlock(&ref_mutex);
-       return !more_refs;
-}
-
-/**
- * Number of bytes per line to dump raw data
- */
-#define BYTES_PER_LINE 16
-
-/**
- * output handler in printf() for byte ranges
- */
-static int print_bytes(FILE *stream, const struct printf_info *info,
-                                          const void *const *args)
-{
-       char *bytes = *((void**)(args[0]));
-       int len = *((size_t*)(args[1]));
-       
-       char buffer[BYTES_PER_LINE * 3];
-       char ascii_buffer[BYTES_PER_LINE + 1];
-       char *buffer_pos = buffer;
-       char *bytes_pos  = bytes;
-       char *bytes_roof = bytes + len;
-       int line_start = 0;
-       int i = 0;
-       int written = 0;
-       
-       written += fprintf(stream, "=> %d bytes @ %p", len, bytes);
-       
-       while (bytes_pos < bytes_roof)
-       {
-               static char hexdig[] = "0123456789ABCDEF";
-               
-               *buffer_pos++ = hexdig[(*bytes_pos >> 4) & 0xF];
-               *buffer_pos++ = hexdig[ *bytes_pos       & 0xF];
-
-               ascii_buffer[i++] =
-                               (*bytes_pos > 31 && *bytes_pos < 127) ? *bytes_pos : '.';
-
-               if (++bytes_pos == bytes_roof || i == BYTES_PER_LINE) 
-               {
-                       int padding = 3 * (BYTES_PER_LINE - i);
-                       int written;
-                       
-                       while (padding--)
-                       {
-                               *buffer_pos++ = ' ';
-                       }
-                       *buffer_pos++ = '\0';
-                       ascii_buffer[i] = '\0';
-                       
-                       written += fprintf(stream, "\n%4d: %s  %s",
-                                                         line_start, buffer, ascii_buffer);
-
-                       
-                       buffer_pos = buffer;
-                       line_start += BYTES_PER_LINE;
-                       i = 0;
-               }
-               else
-               {
-                       *buffer_pos++ = ' ';
-               }
-       }
-       return written;
-}
-
-/**
- * output handler in printf() for chunks
- */
-static int print_chunk(FILE *stream, const struct printf_info *info,
-                                          const void *const *args)
-{
-       chunk_t *chunk = *((chunk_t**)(args[0]));
-       bool first = TRUE;
-       chunk_t copy = *chunk;
-       int written = 0;
-       
-       if (!info->alt)
-       {
-               const void *new_args[] = {&chunk->ptr, &chunk->len};
-               return print_bytes(stream, info, new_args);
-       }
-       
-       while (copy.len > 0)
-       {
-               if (first)
-               {
-                       first = FALSE;
-               }
-               else
-               {
-                       written += fprintf(stream, ":");
-               }
-               written += fprintf(stream, "%02x", *copy.ptr++);
-               copy.len--;
-       }
-       return written;
-}
-
-/**
- * output handler in printf() for time_t
- */
-static int print_time(FILE *stream, const struct printf_info *info,
-                                const void *const *args)
-{
-       static const char* months[] = {
-               "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-       };
-       time_t time = *((time_t*)(args[0]));
-       bool utc = TRUE;
-       struct tm t;
-       
-       if (info->alt)
-       {
-               utc = *((bool*)(args[1]));
-       }
-       if (time == UNDEFINED_TIME)
-       {
-               return fprintf(stream, "--- -- --:--:--%s----",
-                                          info->alt ? " UTC " : " ");
-       }
-       if (utc)
-       {
-               gmtime_r(&time, &t);
-       }
-       else
-       {
-               localtime_r(&time, &t);
-       }
-       return fprintf(stream, "%s %02d %02d:%02d:%02d%s%04d",
-                                  months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,
-                                  t.tm_sec, utc ? " UTC " : " ", t.tm_year + 1900);
-}
-
-/**
- * output handler in printf() for time deltas
- */
-static int print_time_delta(FILE *stream, const struct printf_info *info,
-                                         const void *const *args)
-{
-       time_t start = *((time_t*)(args[0]));
-       time_t end = *((time_t*)(args[1]));
-       u_int delta = abs(end - start);
-       char* unit = "second";
-       
-       if (delta > 2 * 60 * 60 * 24)
-       {
-               delta /= 60 * 60 * 24;
-               unit = "days";
-       }
-       else if (delta > 2 * 60 * 60)
-       {
-               delta /= 60 * 60;
-               unit = "hours";
-       }
-       else if (delta > 2 * 60)
-       {
-               delta /= 60;
-               unit = "minutes";
-       }
-       return fprintf(stream, "%d %s", delta, unit);
-}
-
-/**
- * arginfo handler in printf() for byte ranges
- */
-static int print_bytes_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 1)
-       {
-               argtypes[0] = PA_POINTER;
-               argtypes[1] = PA_INT;
-       }
-       return 2;
-}
-
-/**
- * arginfo handler in printf() for time deltas
- */
-static int print_time_delta_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 1)
-       {
-               argtypes[0] = PA_INT;
-               argtypes[1] = PA_INT;
-       }
-       return 2;
-}
-
-/**
- * arginfo handler in printf() for time_t
- */
-static int print_time_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (info->alt)
-       {
-               if (n > 1)
-               {
-                       argtypes[0] = PA_INT;
-                       argtypes[1] = PA_INT;
-               }
-               return 2;
-       }
-       
-       if (n > 0)
-       {
-               argtypes[0] = PA_INT;
-       }
-       return 1;
-}
-
-/**
- * arginfo handler in printf() for chunks
- */
-static int print_chunk_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
- * register printf() handlers for time_t
- */
-static void __attribute__ ((constructor))print_register()
-{
-       register_printf_function(CHUNK_PRINTF_SPEC, print_chunk, print_chunk_arginfo);
-       register_printf_function(BYTES_PRINTF_SPEC, print_bytes, print_bytes_arginfo);
-       register_printf_function(TIME_PRINTF_SPEC, print_time, print_time_arginfo);
-       register_printf_function(TIME_DELTA_PRINTF_SPEC, print_time_delta, print_time_delta_arginfo);
-}
diff --git a/src/libstrongswan/types.h b/src/libstrongswan/types.h
deleted file mode 100644 (file)
index 34100d9..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/**
- * @file types.h
- * 
- * @brief Generic types.
- * 
- */
-
-/*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
- * 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 TYPES_H_
-#define TYPES_H_
-
-#include <gmp.h> 
-#include <sys/types.h>
-#include <stdlib.h>
-
-#include <definitions.h>
-
-/**
- * General purpose boolean type.
- */
-typedef int bool;
-#define FALSE  0
-#define TRUE   1
-
-/**
- *  error message, or NULL for success
- */
-typedef const char *err_t;
-
-typedef enum status_t status_t;
-
-/**
- * Return values of function calls.
- */
-enum status_t {
-       /**
-        * Call succeeded.
-        */
-       SUCCESS,
-       
-       /**
-        * Call failed.
-        */
-       FAILED,
-       
-       /**
-        * Out of resources.
-        */
-       OUT_OF_RES,
-       
-       /**
-        * The suggested operation is already done
-        */
-       ALREADY_DONE,
-       
-       /**
-        * Not supported.
-        */
-       NOT_SUPPORTED,
-       
-       /**
-        * One of the arguments is invalid.
-        */
-       INVALID_ARG,
-       
-       /**
-        * Something could not be found.
-        */
-       NOT_FOUND,
-       
-       /**
-        * Error while parsing.
-        */
-       PARSE_ERROR,
-       
-       /**
-        * Error while verifying.
-        */
-       VERIFY_ERROR,
-       
-       /**
-        * Object in invalid state.
-        */
-       INVALID_STATE,
-       
-       /**
-        * Destroy object which called method belongs to.
-        */
-       DESTROY_ME,
-};
-
-/**
- * enum_names for type status_t.
- */
-extern enum_name_t *status_names;
-
-/**
- * Handle struct timeval like an own type.
- */
-typedef struct timeval timeval_t;
-
-/**
- * Handle struct timespec like an own type.
- */
-typedef struct timespec timespec_t;
-
-/**
- * Handle struct chunk_t like an own type.
- */
-typedef struct sockaddr sockaddr_t;
-
-/**
- * Use struct chunk_t as chunk_t.
- */
-typedef struct chunk_t chunk_t;
-
-/**
- * General purpose pointer/length abstraction.
- */
-struct chunk_t {
-       /**
-        * Pointer to start of data
-        */
-       u_char *ptr;
-
-       /**
-        * Length of data in bytes
-        */
-       size_t len;
-};
-
-/**
- * used to initialize a chunk to { NULL, 0 }.
- */
-extern chunk_t CHUNK_INITIALIZER;
-
-
-
-/**
- * Printf() hook character to dump a chunk using printf.
- * The argument supplied to printf() is a pointer to a chunk.
- * E.g. printf("chunk xy is: %B", &xy);
- */
-#define CHUNK_PRINTF_SPEC 'B'
-
-/**
- * Printf() hook character to dump a chunk using printf. 
- * Two arguments are supplied for one format string charactar, 
- * first a pointer to the buffer, and as second the length of the buffer.
- * E.g. printf("buffer xy is: %b", buffer, sizeof(buffer));
- */
-#define BYTES_PRINTF_SPEC 'b'
-
-/**
- * printf specifier for time_t, use #-modifier to print time as UTC 
- */
-#define TIME_PRINTF_SPEC 'T'
-
-/**
- * printf specifier for time_t deltas, uses two arguments
- * E.g. printf("%V", begin, end);
- */
-#define TIME_DELTA_PRINTF_SPEC 'V'
-
-/**
- * time_t for a not defined time
- */
-#define UNDEFINED_TIME 0
-
-/**
- * Initialize a chunk to a static buffer
- */
-#define chunk_from_buf(str) { str, sizeof(str) }
-
-/**
- * Clone chunk contents in a newly allocated chunk
- */
-chunk_t chunk_clone(chunk_t chunk);
-
-/**
- * Allocate a chunk from concatenation of other chunks.
- * mode is a string 'm' and 'c, 'm' means move chunk,
- * 'c' means copy chunk.
- */
-chunk_t chunk_cat(const char* mode, ...);
-
-/**
- * Free contents of a chunk
- */
-void chunk_free(chunk_t *chunk);
-
-/**
- * Allocate a chunk
- */
-chunk_t chunk_alloc(size_t bytes);
-
-/**
- * Compare two chunks for equality,
- * NULL chunks are never equal.
- */
-bool chunk_equals(chunk_t a, chunk_t b);
-
-/**
- * Compare two chunks for equality,
- * NULL chunks are always equal.
- */
-bool chunk_equals_or_null(chunk_t a, chunk_t b);
-
-/**
- * Clone a data to a newly allocated buffer
- */
-void *clalloc(void *pointer, size_t size);
-
-/**
- * Special type to count references
- */
-typedef volatile u_int refcount_t;
-
-/**
- * @brief Get a new reference.
- *
- * Increments the reference counter atomic.
- *
- * @param ref  pointer to ref counter
- */
-void ref_get(refcount_t *ref);
-
-/**
- * @brief Put back a unused reference.
- *
- * Decrements the reference counter atomic and 
- * says if more references available.
- *
- * @param ref  pointer to ref counter
- * @return             TRUE if no more references counted
- */
-bool ref_put(refcount_t *ref);
-
-
-#endif /*TYPES_H_*/
index 702d4bd..29c3075 100644 (file)
@@ -155,23 +155,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(HOST_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_HOST, print, arginfo_ptr);
 }
 
 /**
@@ -179,7 +167,7 @@ static void __attribute__ ((constructor))print_register()
  */
 static chunk_t get_address(private_host_t *this)
 {
-       chunk_t address = CHUNK_INITIALIZER;
+       chunk_t address = chunk_empty;
        
        switch (this->address.sa_family) 
        {
index 74b75ee..20b5c63 100644 (file)
@@ -36,14 +36,7 @@ typedef struct host_t host_t;
 #include <arpa/inet.h>
 #include <linux/xfrm.h>
 
-#include <types.h>
-
-/**
- * printf() specifier to print a host.
- * The specifier option '#' does include the port number, e.g.:
- * printf("my host is %#H\n", my_host);
- */
-#define HOST_PRINTF_SPEC 'H'
+#include <library.h>
 
 /**
  * Differences between two hosts. They differ in
index d09c992..90c1227 100644 (file)
@@ -30,7 +30,6 @@
 #include <ctype.h>
 #include <printf.h>
 
-#include "definitions.h"
 #include "identification.h"
 
 #include <asn1/asn1.h>
@@ -251,8 +250,8 @@ static chunk_t sanitize_chunk(chunk_t chunk)
  */
 static status_t init_rdn(chunk_t dn, chunk_t *rdn, chunk_t *attribute, bool *next)
 {
-       *rdn = CHUNK_INITIALIZER;
-       *attribute = CHUNK_INITIALIZER;
+       *rdn = chunk_empty;
+       *attribute = chunk_empty;
        
        /* a DN is a SEQUENCE OF RDNs */
        if (*dn.ptr != ASN1_SEQUENCE)
@@ -285,8 +284,8 @@ static status_t get_next_rdn(chunk_t *rdn, chunk_t * attribute, chunk_t *oid, ch
        chunk_t body;
 
        /* initialize return values */
-       *oid   = CHUNK_INITIALIZER;
-       *value = CHUNK_INITIALIZER;
+       *oid   = chunk_empty;
+       *value = chunk_empty;
 
        /* if all attributes have been parsed, get next rdn */
        if (attribute->len <= 0)
@@ -569,8 +568,8 @@ static status_t atodn(char *src, chunk_t *dn)
                UNKNOWN_OID =   4
        } state_t;
        
-       chunk_t oid  = CHUNK_INITIALIZER;
-       chunk_t name = CHUNK_INITIALIZER;
+       chunk_t oid  = chunk_empty;
+       chunk_t name = chunk_empty;
        chunk_t rdns[RDN_MAX];
        int rdn_count = 0;
        int dn_len = 0;
@@ -614,7 +613,7 @@ static status_t atodn(char *src, chunk_t *dn)
                                                break;
                                        }
                                        /* reset oid and change state */
-                                       oid = CHUNK_INITIALIZER;
+                                       oid = chunk_empty;
                                        state = SEARCH_NAME;
                                }
                                break;
@@ -658,7 +657,7 @@ static status_t atodn(char *src, chunk_t *dn)
                                                status = OUT_OF_RES;
                                        }
                                        /* reset name and change state */
-                                       name = CHUNK_INITIALIZER;
+                                       name = chunk_empty;
                                        state = SEARCH_OID;
                                }
                                break;
@@ -683,7 +682,7 @@ static status_t atodn(char *src, chunk_t *dn)
        if (status != SUCCESS)
        {
                free(dn->ptr);
-               *dn = CHUNK_INITIALIZER;
+               *dn = chunk_empty;
        }
        return status;
 }
@@ -912,23 +911,11 @@ static int print(FILE *stream, const struct printf_info *info,
 }
 
 /**
- * arginfo handler in printf()
- */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
-       if (n > 0)
-       {
-               argtypes[0] = PA_POINTER;
-       }
-       return 1;
-}
-
-/**
  * register printf() handlers
  */
 static void __attribute__ ((constructor))print_register()
 {
-       register_printf_function(IDENTIFICATION_PRINTF_SPEC, print, print_arginfo);
+       register_printf_function(PRINTF_IDENTIFICATION, print, arginfo_ptr);
 }
 
 /**
@@ -971,7 +958,7 @@ static private_identification_t *identification_create(void)
        this->public.equals = (bool (*) (identification_t*,identification_t*))equals_binary;
        this->public.matches = (bool (*) (identification_t*,identification_t*,int*))matches_binary;
        
-       this->encoded = CHUNK_INITIALIZER;
+       this->encoded = chunk_empty;
        
        return this;
 }
index 8d8b599..80fc27d 100644 (file)
 typedef enum id_type_t id_type_t;
 typedef struct identification_t identification_t;
 
-#include <types.h>
+#include <library.h>
 
 #define MAX_WILDCARDS     14
-/**
- * printf() specifier to print a identification.
- */
-#define IDENTIFICATION_PRINTF_SPEC 'D'
 
 /**
  * @brief ID Types in a ID payload.
index 7cf036e..f132c51 100644 (file)
@@ -37,8 +37,8 @@
 
 #include "leak_detective.h"
 
-#include <types.h>
 #include <library.h>
+#include <debug.h>
 
 #ifdef LEAK_DETECTIVE
 
index 13fe35e..9d3f065 100644 (file)
@@ -52,7 +52,7 @@ bool extract_token(chunk_t *token, const char termination, chunk_t *src)
        u_char *eot = memchr(src->ptr, termination, src->len);
        
        /* initialize empty token */
-       *token = CHUNK_INITIALIZER;
+       *token = chunk_empty;
        
        if (eot == NULL) /* termination symbol not found */
        {
@@ -98,7 +98,7 @@ err_t extract_value(chunk_t *value, chunk_t *line)
 
        if (!eat_whitespace(line))
        {
-               *value = CHUNK_INITIALIZER;
+               *value = chunk_empty;
                return NULL;
        }
        if (*line->ptr == '\'' || *line->ptr == '"')
index 29c1bf7..e3c2c4c 100644 (file)
@@ -19,7 +19,7 @@
  * for more details.
  */
 
-#include <types.h>
+#include <library.h>
 
 /**
  * @brief Eats whitespace
index 6ca1051..4aea690 100644 (file)
@@ -669,15 +669,15 @@ static iterator_t *create_iterator(private_linked_list_t *linked_list, bool forw
 {
        private_iterator_t *this = malloc_thing(private_iterator_t);
        
-       this->public.get_count = (bool (*) (iterator_t *this)) get_list_count;
-       this->public.iterate = (bool (*) (iterator_t *this, void **value)) iterate;
-       this->public.set_iterator_hook = (void(*)(iterator_t *this, void*(*)(void*)))set_iterator_hook;
-       this->public.insert_before = (void (*) (iterator_t *this, void *item)) insert_before;
-       this->public.insert_after = (void (*) (iterator_t *this, void *item)) insert_after;
-       this->public.replace = (status_t (*) (iterator_t *, void **, void *)) replace;
-       this->public.remove = (status_t (*) (iterator_t *this)) remove_;
-       this->public.reset = (void (*) (iterator_t *this)) iterator_reset;
-       this->public.destroy = (void (*) (iterator_t *this)) iterator_destroy;
+       this->public.get_count = (int (*) (iterator_t*)) get_list_count;
+       this->public.iterate = (bool (*) (iterator_t*, void **value)) iterate;
+       this->public.set_iterator_hook = (void(*)(iterator_t*, void*(*)(void*)))set_iterator_hook;
+       this->public.insert_before = (void (*) (iterator_t*, void *item)) insert_before;
+       this->public.insert_after = (void (*) (iterator_t*, void *item)) insert_after;
+       this->public.replace = (status_t (*) (iterator_t*, void **, void *)) replace;
+       this->public.remove = (status_t (*) (iterator_t*)) remove_;
+       this->public.reset = (void (*) (iterator_t*)) iterator_reset;
+       this->public.destroy = (void (*) (iterator_t*)) iterator_destroy;
        
        this->forward = forward;
        this->current = NULL;
index 6a97d44..58bcbbd 100644 (file)
@@ -28,7 +28,7 @@ typedef struct linked_list_t linked_list_t;
 
 #include <pthread.h>
 
-#include <types.h>
+#include <library.h>
 #include <utils/iterator.h>
 
 /**
index d797633..afbade0 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct randomizer_t randomizer_t;
 
-#include <types.h>
+#include <library.h>
 
 #ifndef DEV_RANDOM
 /**
index 3cc297a..b7ee431 100644 (file)
@@ -24,8 +24,6 @@
 #include <stdio.h>
 #include <linux/stddef.h>
 
-#include <types.h>
-
 #include "stroke.h"
 #include "stroke_keywords.h"
 
@@ -128,7 +126,7 @@ static int add_connection(char *name,
        msg.add_conn.me.cert = NULL;
        msg.add_conn.me.ca = NULL;
        msg.add_conn.me.sendcert = 1;
-       msg.add_conn.me.hostaccess = FALSE;
+       msg.add_conn.me.hostaccess = 0;
        msg.add_conn.me.protocol = 0;
        msg.add_conn.me.port = 0;
        
@@ -139,7 +137,7 @@ static int add_connection(char *name,
        msg.add_conn.other.cert = NULL;
        msg.add_conn.other.ca = NULL;
        msg.add_conn.other.sendcert = 1;
-       msg.add_conn.other.hostaccess = FALSE;
+       msg.add_conn.other.hostaccess = 0;
        msg.add_conn.other.protocol = 0;
        msg.add_conn.other.port = 0;
        
@@ -213,7 +211,7 @@ static int list_flags[] = {
        LIST_ALL
 };
 
-static int list(stroke_keyword_t kw, bool utc)
+static int list(stroke_keyword_t kw, int utc)
 {
        stroke_msg_t msg;
        
@@ -373,7 +371,7 @@ int main(int argc, char *argv[])
                case STROKE_LIST_CACERTS:
                case STROKE_LIST_CRLS:
                case STROKE_LIST_ALL:
-                       res = list(token->kw, argc > 2 && streq(argv[2], "--utc"));
+                       res = list(token->kw, argc > 2 && strcmp(argv[2], "--utc") == 0);
                        break;
                case STROKE_REREAD_CACERTS:
                case STROKE_REREAD_CRLS:
index 42a8a96..b6a47ee 100644 (file)
@@ -82,7 +82,7 @@ struct stroke_end_t {
        char *subnet;
        int subnet_mask;
        int sendcert;
-       bool hostaccess;
+       int hostaccess;
        u_int8_t protocol;
        u_int16_t port;
 };
@@ -135,7 +135,7 @@ struct stroke_msg_t {
                /* data for STR_ADD_CONN */
                struct {
                        char *name;
-                       bool ikev2;
+                       int ikev2;
                        int auth_method;
                        struct {
                                char *ike;
@@ -164,7 +164,7 @@ struct stroke_msg_t {
                /* data for STR_LIST */
                struct {
                        list_flag_t flags;
-                       bool utc;
+                       int utc;
                } list;
 
                /* data for STR_REREAD */