diff options
151 files changed, 1091 insertions, 1058 deletions
diff --git a/src/charon/bus/bus.h b/src/charon/bus/bus.h index cd5ca37c2..974d460b9 100644 --- a/src/charon/bus/bus.h +++ b/src/charon/bus/bus.h @@ -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. diff --git a/src/charon/config/configuration.c b/src/charon/config/configuration.c index e983e5968..39fc4d922 100755 --- a/src/charon/config/configuration.c +++ b/src/charon/config/configuration.c @@ -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. diff --git a/src/charon/config/configuration.h b/src/charon/config/configuration.h index 57e4885eb..2bb0b106e 100755 --- a/src/charon/config/configuration.h +++ b/src/charon/config/configuration.h @@ -25,7 +25,7 @@ typedef struct configuration_t configuration_t; -#include <types.h> +#include <library.h> /** * @brief The interface for various daemon related configs. diff --git a/src/charon/config/connections/connection.h b/src/charon/config/connections/connection.h index 3f552d914..3a2e57bb2 100644 --- a/src/charon/config/connections/connection.h +++ b/src/charon/config/connections/connection.h @@ -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> diff --git a/src/charon/config/connections/connection_store.h b/src/charon/config/connections/connection_store.h index 1e73bd01f..70f209d3b 100755 --- a/src/charon/config/connections/connection_store.h +++ b/src/charon/config/connections/connection_store.h @@ -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> diff --git a/src/charon/config/connections/local_connection_store.c b/src/charon/config/connections/local_connection_store.c index 37bf94c13..df4ec230a 100644 --- a/src/charon/config/connections/local_connection_store.c +++ b/src/charon/config/connections/local_connection_store.c @@ -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); diff --git a/src/charon/config/connections/local_connection_store.h b/src/charon/config/connections/local_connection_store.h index e36a66c93..e78ed809a 100644 --- a/src/charon/config/connections/local_connection_store.h +++ b/src/charon/config/connections/local_connection_store.h @@ -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> /** diff --git a/src/charon/config/credentials/credential_store.h b/src/charon/config/credentials/credential_store.h index e991ce3d2..59fc4a002 100755 --- a/src/charon/config/credentials/credential_store.h +++ b/src/charon/config/credentials/credential_store.h @@ -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> diff --git a/src/charon/config/credentials/local_credential_store.c b/src/charon/config/credentials/local_credential_store.c index 3f4267aea..e108df42d 100644 --- a/src/charon/config/credentials/local_credential_store.c +++ b/src/charon/config/credentials/local_credential_store.c @@ -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) diff --git a/src/charon/config/credentials/local_credential_store.h b/src/charon/config/credentials/local_credential_store.h index 05ad5f540..160ac3575 100644 --- a/src/charon/config/credentials/local_credential_store.h +++ b/src/charon/config/credentials/local_credential_store.h @@ -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> diff --git a/src/charon/config/policies/local_policy_store.c b/src/charon/config/policies/local_policy_store.c index 32b0154e6..6c841b4d6 100644 --- a/src/charon/config/policies/local_policy_store.c +++ b/src/charon/config/policies/local_policy_store.c @@ -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); } diff --git a/src/charon/config/policies/local_policy_store.h b/src/charon/config/policies/local_policy_store.h index 5834b8e3e..01d5d2d60 100644 --- a/src/charon/config/policies/local_policy_store.h +++ b/src/charon/config/policies/local_policy_store.h @@ -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> diff --git a/src/charon/config/policies/policy.h b/src/charon/config/policies/policy.h index 279ce93aa..a040434c1 100644 --- a/src/charon/config/policies/policy.h +++ b/src/charon/config/policies/policy.h @@ -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> diff --git a/src/charon/config/policies/policy_store.h b/src/charon/config/policies/policy_store.h index b89bbab77..6b470055e 100755 --- a/src/charon/config/policies/policy_store.h +++ b/src/charon/config/policies/policy_store.h @@ -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> diff --git a/src/charon/config/proposal.h b/src/charon/config/proposal.h index 6099eca30..abcb40999 100644 --- a/src/charon/config/proposal.h +++ b/src/charon/config/proposal.h @@ -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> diff --git a/src/charon/config/traffic_selector.c b/src/charon/config/traffic_selector.c index 9c1520061..2361f67f4 100644 --- a/src/charon/config/traffic_selector.c +++ b/src/charon/config/traffic_selector.c @@ -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) { diff --git a/src/charon/config/traffic_selector.h b/src/charon/config/traffic_selector.h index 09fdaf6ae..b611b611a 100644 --- a/src/charon/config/traffic_selector.h +++ b/src/charon/config/traffic_selector.h @@ -27,15 +27,10 @@ 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 diff --git a/src/charon/daemon.c b/src/charon/daemon.c index be148668c..1fd9f9a0a 100644 --- a/src/charon/daemon.c +++ b/src/charon/daemon.c @@ -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> diff --git a/src/charon/encoding/generator.c b/src/charon/encoding/generator.c index def14cb64..847fda49f 100644 --- a/src/charon/encoding/generator.c +++ b/src/charon/encoding/generator.c @@ -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> diff --git a/src/charon/encoding/generator.h b/src/charon/encoding/generator.h index 924e1e666..8eff957cc 100644 --- a/src/charon/encoding/generator.h +++ b/src/charon/encoding/generator.h @@ -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> diff --git a/src/charon/encoding/message.c b/src/charon/encoding/message.c index d8f5efe7b..f1b92e934 100644 --- a/src/charon/encoding/message.c +++ b/src/charon/encoding/message.c @@ -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); } /** diff --git a/src/charon/encoding/message.h b/src/charon/encoding/message.h index 8b7e3c7cd..dfb6d64af 100644 --- a/src/charon/encoding/message.h +++ b/src/charon/encoding/message.h @@ -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 diff --git a/src/charon/encoding/parser.c b/src/charon/encoding/parser.c index 6e8bad546..d7f10f711 100644 --- a/src/charon/encoding/parser.c +++ b/src/charon/encoding/parser.c @@ -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> diff --git a/src/charon/encoding/parser.h b/src/charon/encoding/parser.h index bff3b50f6..e9978524c 100644 --- a/src/charon/encoding/parser.h +++ b/src/charon/encoding/parser.h @@ -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> diff --git a/src/charon/encoding/payloads/auth_payload.c b/src/charon/encoding/payloads/auth_payload.c index 5e3569750..256d6c8a4 100644 --- a/src/charon/encoding/payloads/auth_payload.c +++ b/src/charon/encoding/payloads/auth_payload.c @@ -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)); } diff --git a/src/charon/encoding/payloads/auth_payload.h b/src/charon/encoding/payloads/auth_payload.h index 7616a6ed2..2db82ec0b 100644 --- a/src/charon/encoding/payloads/auth_payload.h +++ b/src/charon/encoding/payloads/auth_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/cert_payload.c b/src/charon/encoding/payloads/cert_payload.c index f5a5655ae..2e690b45d 100644 --- a/src/charon/encoding/payloads/cert_payload.c +++ b/src/charon/encoding/payloads/cert_payload.c @@ -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)); } diff --git a/src/charon/encoding/payloads/cert_payload.h b/src/charon/encoding/payloads/cert_payload.h index c1ba0bdc0..fb0cf684c 100644 --- a/src/charon/encoding/payloads/cert_payload.h +++ b/src/charon/encoding/payloads/cert_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/certreq_payload.c b/src/charon/encoding/payloads/certreq_payload.c index 4001712b8..07d3ce2bc 100644 --- a/src/charon/encoding/payloads/certreq_payload.c +++ b/src/charon/encoding/payloads/certreq_payload.c @@ -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)); } diff --git a/src/charon/encoding/payloads/certreq_payload.h b/src/charon/encoding/payloads/certreq_payload.h index e00d673e7..2985fdae1 100644 --- a/src/charon/encoding/payloads/certreq_payload.h +++ b/src/charon/encoding/payloads/certreq_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/configuration_attribute.c b/src/charon/encoding/payloads/configuration_attribute.c index 5982214ac..e7000e1b5 100644 --- a/src/charon/encoding/payloads/configuration_attribute.c +++ b/src/charon/encoding/payloads/configuration_attribute.c @@ -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)); diff --git a/src/charon/encoding/payloads/configuration_attribute.h b/src/charon/encoding/payloads/configuration_attribute.h index 51abab61e..5a11d0a35 100644 --- a/src/charon/encoding/payloads/configuration_attribute.h +++ b/src/charon/encoding/payloads/configuration_attribute.h @@ -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> diff --git a/src/charon/encoding/payloads/cp_payload.h b/src/charon/encoding/payloads/cp_payload.h index 1978b69cf..af36b48a3 100644 --- a/src/charon/encoding/payloads/cp_payload.h +++ b/src/charon/encoding/payloads/cp_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/delete_payload.c b/src/charon/encoding/payloads/delete_payload.c index dcc66e8fa..81436e2a8 100644 --- a/src/charon/encoding/payloads/delete_payload.c +++ b/src/charon/encoding/payloads/delete_payload.c @@ -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); diff --git a/src/charon/encoding/payloads/delete_payload.h b/src/charon/encoding/payloads/delete_payload.h index 3484f0235..9fc558f09 100644 --- a/src/charon/encoding/payloads/delete_payload.h +++ b/src/charon/encoding/payloads/delete_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/eap_payload.c b/src/charon/encoding/payloads/eap_payload.c index e31c4b2b9..aa886e9c4 100644 --- a/src/charon/encoding/payloads/eap_payload.c +++ b/src/charon/encoding/payloads/eap_payload.c @@ -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)); } diff --git a/src/charon/encoding/payloads/eap_payload.h b/src/charon/encoding/payloads/eap_payload.h index 17af03d40..bf493eb7f 100644 --- a/src/charon/encoding/payloads/eap_payload.h +++ b/src/charon/encoding/payloads/eap_payload.h @@ -26,7 +26,7 @@ typedef struct eap_payload_t eap_payload_t; -#include <types.h> +#include <library.h> #include <encoding/payloads/payload.h> /** diff --git a/src/charon/encoding/payloads/encodings.h b/src/charon/encoding/payloads/encodings.h index d69de4f1d..ed5596ecd 100644 --- a/src/charon/encoding/payloads/encodings.h +++ b/src/charon/encoding/payloads/encodings.h @@ -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. diff --git a/src/charon/encoding/payloads/encryption_payload.c b/src/charon/encoding/payloads/encryption_payload.c index 908de3d30..23b6e8d9f 100644 --- a/src/charon/encoding/payloads/encryption_payload.c +++ b/src/charon/encoding/payloads/encryption_payload.c @@ -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(); diff --git a/src/charon/encoding/payloads/encryption_payload.h b/src/charon/encoding/payloads/encryption_payload.h index c0b476b73..7cf53619f 100644 --- a/src/charon/encoding/payloads/encryption_payload.h +++ b/src/charon/encoding/payloads/encryption_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/id_payload.c b/src/charon/encoding/payloads/id_payload.c index 954336a22..1a8293a76 100644 --- a/src/charon/encoding/payloads/id_payload.c +++ b/src/charon/encoding/payloads/id_payload.c @@ -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)); diff --git a/src/charon/encoding/payloads/id_payload.h b/src/charon/encoding/payloads/id_payload.h index 01c6a4e1d..b67d85d2e 100644 --- a/src/charon/encoding/payloads/id_payload.h +++ b/src/charon/encoding/payloads/id_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/ike_header.h b/src/charon/encoding/payloads/ike_header.h index 4cf253f80..95c20f810 100644 --- a/src/charon/encoding/payloads/ike_header.h +++ b/src/charon/encoding/payloads/ike_header.h @@ -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> /** diff --git a/src/charon/encoding/payloads/ke_payload.c b/src/charon/encoding/payloads/ke_payload.c index fc875517c..5a83fd0a2 100644 --- a/src/charon/encoding/payloads/ke_payload.c +++ b/src/charon/encoding/payloads/ke_payload.c @@ -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; diff --git a/src/charon/encoding/payloads/ke_payload.h b/src/charon/encoding/payloads/ke_payload.h index 18f9dece7..52be8ffe3 100644 --- a/src/charon/encoding/payloads/ke_payload.h +++ b/src/charon/encoding/payloads/ke_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/nonce_payload.h b/src/charon/encoding/payloads/nonce_payload.h index 444110a99..96d83b028 100644 --- a/src/charon/encoding/payloads/nonce_payload.h +++ b/src/charon/encoding/payloads/nonce_payload.h @@ -26,7 +26,7 @@ typedef struct nonce_payload_t nonce_payload_t; -#include <types.h> +#include <library.h> #include <encoding/payloads/payload.h> /** diff --git a/src/charon/encoding/payloads/notify_payload.h b/src/charon/encoding/payloads/notify_payload.h index df956334b..2b419bb98 100644 --- a/src/charon/encoding/payloads/notify_payload.h +++ b/src/charon/encoding/payloads/notify_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/payload.h b/src/charon/encoding/payloads/payload.h index dfc30542f..9a8c2f482 100644 --- a/src/charon/encoding/payloads/payload.h +++ b/src/charon/encoding/payloads/payload.h @@ -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> diff --git a/src/charon/encoding/payloads/proposal_substructure.c b/src/charon/encoding/payloads/proposal_substructure.c index bb18c799b..182d2b6e8 100644 --- a/src/charon/encoding/payloads/proposal_substructure.c +++ b/src/charon/encoding/payloads/proposal_substructure.c @@ -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> diff --git a/src/charon/encoding/payloads/proposal_substructure.h b/src/charon/encoding/payloads/proposal_substructure.h index f1ce5bc47..93a8d7b2f 100644 --- a/src/charon/encoding/payloads/proposal_substructure.h +++ b/src/charon/encoding/payloads/proposal_substructure.h @@ -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> diff --git a/src/charon/encoding/payloads/sa_payload.h b/src/charon/encoding/payloads/sa_payload.h index 90ded9a0f..67d687857 100644 --- a/src/charon/encoding/payloads/sa_payload.h +++ b/src/charon/encoding/payloads/sa_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/traffic_selector_substructure.c b/src/charon/encoding/payloads/traffic_selector_substructure.c index 4a1404244..573139bf3 100644 --- a/src/charon/encoding/payloads/traffic_selector_substructure.c +++ b/src/charon/encoding/payloads/traffic_selector_substructure.c @@ -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; diff --git a/src/charon/encoding/payloads/traffic_selector_substructure.h b/src/charon/encoding/payloads/traffic_selector_substructure.h index 5fc7dced6..14efccc89 100644 --- a/src/charon/encoding/payloads/traffic_selector_substructure.h +++ b/src/charon/encoding/payloads/traffic_selector_substructure.h @@ -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> diff --git a/src/charon/encoding/payloads/transform_attribute.c b/src/charon/encoding/payloads/transform_attribute.c index eddad000a..066885c55 100644 --- a/src/charon/encoding/payloads/transform_attribute.c +++ b/src/charon/encoding/payloads/transform_attribute.c @@ -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; diff --git a/src/charon/encoding/payloads/transform_attribute.h b/src/charon/encoding/payloads/transform_attribute.h index 1588b8f57..30583b23f 100644 --- a/src/charon/encoding/payloads/transform_attribute.h +++ b/src/charon/encoding/payloads/transform_attribute.h @@ -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> diff --git a/src/charon/encoding/payloads/transform_substructure.c b/src/charon/encoding/payloads/transform_substructure.c index 4ad1948f9..d64d6c754 100644 --- a/src/charon/encoding/payloads/transform_substructure.c +++ b/src/charon/encoding/payloads/transform_substructure.c @@ -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> diff --git a/src/charon/encoding/payloads/transform_substructure.h b/src/charon/encoding/payloads/transform_substructure.h index ee297f826..97f587d5d 100644 --- a/src/charon/encoding/payloads/transform_substructure.h +++ b/src/charon/encoding/payloads/transform_substructure.h @@ -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> diff --git a/src/charon/encoding/payloads/ts_payload.h b/src/charon/encoding/payloads/ts_payload.h index a5595c98a..1addee22c 100644 --- a/src/charon/encoding/payloads/ts_payload.h +++ b/src/charon/encoding/payloads/ts_payload.h @@ -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> diff --git a/src/charon/encoding/payloads/unknown_payload.c b/src/charon/encoding/payloads/unknown_payload.c index df126b50b..bbe736085 100644 --- a/src/charon/encoding/payloads/unknown_payload.c +++ b/src/charon/encoding/payloads/unknown_payload.c @@ -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)); } diff --git a/src/charon/encoding/payloads/unknown_payload.h b/src/charon/encoding/payloads/unknown_payload.h index 23cf421a6..8d13a03a3 100644 --- a/src/charon/encoding/payloads/unknown_payload.h +++ b/src/charon/encoding/payloads/unknown_payload.h @@ -26,7 +26,7 @@ typedef struct unknown_payload_t unknown_payload_t; -#include <types.h> +#include <library.h> #include <encoding/payloads/payload.h> /** diff --git a/src/charon/encoding/payloads/vendor_id_payload.c b/src/charon/encoding/payloads/vendor_id_payload.c index ef704007c..e3a4d2e1f 100644 --- a/src/charon/encoding/payloads/vendor_id_payload.c +++ b/src/charon/encoding/payloads/vendor_id_payload.c @@ -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)); } diff --git a/src/charon/encoding/payloads/vendor_id_payload.h b/src/charon/encoding/payloads/vendor_id_payload.h index 8972eaa03..c7eebc155 100644 --- a/src/charon/encoding/payloads/vendor_id_payload.h +++ b/src/charon/encoding/payloads/vendor_id_payload.h @@ -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> /** diff --git a/src/charon/network/packet.c b/src/charon/network/packet.c index 6c16a9d8d..6948fb4be 100644 --- a/src/charon/network/packet.c +++ b/src/charon/network/packet.c @@ -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); } diff --git a/src/charon/network/packet.h b/src/charon/network/packet.h index 0736e8562..acf953032 100644 --- a/src/charon/network/packet.h +++ b/src/charon/network/packet.h @@ -26,7 +26,7 @@ typedef struct packet_t packet_t; -#include <types.h> +#include <library.h> #include <utils/host.h> /** diff --git a/src/charon/network/socket.h b/src/charon/network/socket.h index a6437c86e..70d7b943f 100644 --- a/src/charon/network/socket.h +++ b/src/charon/network/socket.h @@ -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> diff --git a/src/charon/queues/event_queue.c b/src/charon/queues/event_queue.c index df5284f80..40bcb1ed8 100644 --- a/src/charon/queues/event_queue.c +++ b/src/charon/queues/event_queue.c @@ -26,7 +26,7 @@ #include "event_queue.h" -#include <types.h> +#include <library.h> #include <utils/linked_list.h> diff --git a/src/charon/queues/event_queue.h b/src/charon/queues/event_queue.h index 583fb2f1f..cd275123b 100644 --- a/src/charon/queues/event_queue.h +++ b/src/charon/queues/event_queue.h @@ -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> /** diff --git a/src/charon/queues/job_queue.h b/src/charon/queues/job_queue.h index 8dd542e95..c971ba514 100644 --- a/src/charon/queues/job_queue.h +++ b/src/charon/queues/job_queue.h @@ -26,7 +26,7 @@ typedef struct job_queue_t job_queue_t; -#include <types.h> +#include <library.h> #include <queues/jobs/job.h> /** diff --git a/src/charon/queues/jobs/acquire_job.h b/src/charon/queues/jobs/acquire_job.h index 5a59c38a2..54f1b9b5b 100644 --- a/src/charon/queues/jobs/acquire_job.h +++ b/src/charon/queues/jobs/acquire_job.h @@ -25,7 +25,7 @@ typedef struct acquire_job_t acquire_job_t; -#include <types.h> +#include <library.h> #include <queues/jobs/job.h> /** diff --git a/src/charon/queues/jobs/delete_child_sa_job.h b/src/charon/queues/jobs/delete_child_sa_job.h index 99e042f7a..9c2e4fa4d 100644 --- a/src/charon/queues/jobs/delete_child_sa_job.h +++ b/src/charon/queues/jobs/delete_child_sa_job.h @@ -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> diff --git a/src/charon/queues/jobs/delete_ike_sa_job.h b/src/charon/queues/jobs/delete_ike_sa_job.h index 5857e9937..43701a354 100644 --- a/src/charon/queues/jobs/delete_ike_sa_job.h +++ b/src/charon/queues/jobs/delete_ike_sa_job.h @@ -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> diff --git a/src/charon/queues/jobs/incoming_packet_job.h b/src/charon/queues/jobs/incoming_packet_job.h index 9228d2e7d..5ce0750f7 100644 --- a/src/charon/queues/jobs/incoming_packet_job.h +++ b/src/charon/queues/jobs/incoming_packet_job.h @@ -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> diff --git a/src/charon/queues/jobs/initiate_job.h b/src/charon/queues/jobs/initiate_job.h index 677150508..846f2f62f 100644 --- a/src/charon/queues/jobs/initiate_job.h +++ b/src/charon/queues/jobs/initiate_job.h @@ -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> diff --git a/src/charon/queues/jobs/job.h b/src/charon/queues/jobs/job.h index aa29797c0..ae3fe7974 100644 --- a/src/charon/queues/jobs/job.h +++ b/src/charon/queues/jobs/job.h @@ -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. diff --git a/src/charon/queues/jobs/rekey_child_sa_job.h b/src/charon/queues/jobs/rekey_child_sa_job.h index 4aacf57c1..19e1b5d32 100644 --- a/src/charon/queues/jobs/rekey_child_sa_job.h +++ b/src/charon/queues/jobs/rekey_child_sa_job.h @@ -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> diff --git a/src/charon/queues/jobs/rekey_ike_sa_job.h b/src/charon/queues/jobs/rekey_ike_sa_job.h index b1fdb3303..4848369d3 100644 --- a/src/charon/queues/jobs/rekey_ike_sa_job.h +++ b/src/charon/queues/jobs/rekey_ike_sa_job.h @@ -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> diff --git a/src/charon/queues/jobs/retransmit_request_job.h b/src/charon/queues/jobs/retransmit_request_job.h index c57a870ab..1897af16d 100644 --- a/src/charon/queues/jobs/retransmit_request_job.h +++ b/src/charon/queues/jobs/retransmit_request_job.h @@ -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> diff --git a/src/charon/queues/jobs/route_job.h b/src/charon/queues/jobs/route_job.h index ad7b48b95..2743a70ab 100644 --- a/src/charon/queues/jobs/route_job.h +++ b/src/charon/queues/jobs/route_job.h @@ -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> diff --git a/src/charon/queues/jobs/send_dpd_job.h b/src/charon/queues/jobs/send_dpd_job.h index fb1757471..f3900f9a2 100644 --- a/src/charon/queues/jobs/send_dpd_job.h +++ b/src/charon/queues/jobs/send_dpd_job.h @@ -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> diff --git a/src/charon/queues/jobs/send_keepalive_job.h b/src/charon/queues/jobs/send_keepalive_job.h index 1bb7afd7a..c7d05be65 100644 --- a/src/charon/queues/jobs/send_keepalive_job.h +++ b/src/charon/queues/jobs/send_keepalive_job.h @@ -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> diff --git a/src/charon/queues/send_queue.h b/src/charon/queues/send_queue.h index 8043f1758..b69499cc1 100644 --- a/src/charon/queues/send_queue.h +++ b/src/charon/queues/send_queue.h @@ -26,7 +26,7 @@ typedef struct send_queue_t send_queue_t; -#include <types.h> +#include <library.h> #include <network/packet.h> /** diff --git a/src/charon/sa/authenticators/authenticator.h b/src/charon/sa/authenticators/authenticator.h index b1645c21c..9d37a0653 100644 --- a/src/charon/sa/authenticators/authenticator.h +++ b/src/charon/sa/authenticators/authenticator.h @@ -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> diff --git a/src/charon/sa/child_sa.c b/src/charon/sa/child_sa.c index 2f73e49d8..eac1ca6ee 100644 --- a/src/charon/sa/child_sa.c +++ b/src/charon/sa/child_sa.c @@ -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); } /** diff --git a/src/charon/sa/child_sa.h b/src/charon/sa/child_sa.h index 881c50000..5b1df9e6d 100644 --- a/src/charon/sa/child_sa.h +++ b/src/charon/sa/child_sa.h @@ -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 { diff --git a/src/charon/sa/ike_sa.c b/src/charon/sa/ike_sa.c index 2ac59b2c2..eca8c92cc 100644 --- a/src/charon/sa/ike_sa.c +++ b/src/charon/sa/ike_sa.c @@ -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; diff --git a/src/charon/sa/ike_sa.h b/src/charon/sa/ike_sa.h index f4710b1d2..8f3b73169 100644 --- a/src/charon/sa/ike_sa.h +++ b/src/charon/sa/ike_sa.h @@ -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. * diff --git a/src/charon/sa/ike_sa_id.c b/src/charon/sa/ike_sa_id.c index cac9cc3b5..95a39066f 100644 --- a/src/charon/sa/ike_sa_id.c +++ b/src/charon/sa/ike_sa_id.c @@ -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. */ diff --git a/src/charon/sa/ike_sa_id.h b/src/charon/sa/ike_sa_id.h index 8462d655b..0606b7222 100644 --- a/src/charon/sa/ike_sa_id.h +++ b/src/charon/sa/ike_sa_id.h @@ -27,12 +27,8 @@ 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. diff --git a/src/charon/sa/ike_sa_manager.h b/src/charon/sa/ike_sa_manager.h index c14d04af6..42e743138 100644 --- a/src/charon/sa/ike_sa_manager.h +++ b/src/charon/sa/ike_sa_manager.h @@ -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> /** diff --git a/src/charon/sa/transactions/create_child_sa.c b/src/charon/sa/transactions/create_child_sa.c index 60d316fff..cd53c5eb9 100644 --- a/src/charon/sa/transactions/create_child_sa.c +++ b/src/charon/sa/transactions/create_child_sa.c @@ -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; diff --git a/src/charon/sa/transactions/ike_auth.c b/src/charon/sa/transactions/ike_auth.c index 5fd64e77d..ae155ec88 100644 --- a/src/charon/sa/transactions/ike_auth.c +++ b/src/charon/sa/transactions/ike_auth.c @@ -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; diff --git a/src/charon/sa/transactions/ike_sa_init.c b/src/charon/sa/transactions/ike_sa_init.c index 34e7f7053..937f4ce43 100644 --- a/src/charon/sa/transactions/ike_sa_init.c +++ b/src/charon/sa/transactions/ike_sa_init.c @@ -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; diff --git a/src/charon/sa/transactions/rekey_ike_sa.c b/src/charon/sa/transactions/rekey_ike_sa.c index 06c8707ec..ee72026d1 100644 --- a/src/charon/sa/transactions/rekey_ike_sa.c +++ b/src/charon/sa/transactions/rekey_ike_sa.c @@ -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; diff --git a/src/charon/sa/transactions/transaction.h b/src/charon/sa/transactions/transaction.h index a22cf7154..4a401e12b 100644 --- a/src/charon/sa/transactions/transaction.h +++ b/src/charon/sa/transactions/transaction.h @@ -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> diff --git a/src/charon/threads/receiver.h b/src/charon/threads/receiver.h index 19c0a05f4..ff0971cad 100644 --- a/src/charon/threads/receiver.h +++ b/src/charon/threads/receiver.h @@ -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. diff --git a/src/charon/threads/scheduler.c b/src/charon/threads/scheduler.c index 87dcceaac..74091e3a3 100644 --- a/src/charon/threads/scheduler.c +++ b/src/charon/threads/scheduler.c @@ -27,7 +27,6 @@ #include "scheduler.h" #include <daemon.h> -#include <definitions.h> #include <queues/job_queue.h> diff --git a/src/charon/threads/scheduler.h b/src/charon/threads/scheduler.h index e794cceeb..daecce3c6 100644 --- a/src/charon/threads/scheduler.h +++ b/src/charon/threads/scheduler.h @@ -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. diff --git a/src/charon/threads/sender.h b/src/charon/threads/sender.h index 6ec83a745..bc2a1eab1 100644 --- a/src/charon/threads/sender.h +++ b/src/charon/threads/sender.h @@ -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. diff --git a/src/charon/threads/stroke_interface.c b/src/charon/threads/stroke_interface.c index 0163f18a2..1561c09f3 100755 --- a/src/charon/threads/stroke_interface.c +++ b/src/charon/threads/stroke_interface.c @@ -34,7 +34,7 @@ #include "stroke_interface.h" -#include <types.h> +#include <library.h> #include <stroke.h> #include <daemon.h> #include <crypto/x509.h> diff --git a/src/charon/threads/thread_pool.h b/src/charon/threads/thread_pool.h index 2d8fd4f4d..8e1989bda 100644 --- a/src/charon/threads/thread_pool.h +++ b/src/charon/threads/thread_pool.h @@ -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. diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am index a7deeef70..9f1dd4fbc 100644 --- a/src/libstrongswan/Makefile.am +++ b/src/libstrongswan/Makefile.am @@ -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 \ diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c index c73ee2a25..c844ba2d6 100644 --- a/src/libstrongswan/asn1/asn1.c +++ b/src/libstrongswan/asn1/asn1.c @@ -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) { diff --git a/src/libstrongswan/asn1/asn1.h b/src/libstrongswan/asn1/asn1.h index 64774f649..5ab519ec8 100644 --- a/src/libstrongswan/asn1/asn1.h +++ b/src/libstrongswan/asn1/asn1.h @@ -19,7 +19,7 @@ #include <stdarg.h> #include <gmp.h> -#include <types.h> +#include <library.h> #include <asn1/oid.h> diff --git a/src/libstrongswan/asn1/pem.c b/src/libstrongswan/asn1/pem.c index f1c6a4218..e88db249d 100755 --- a/src/libstrongswan/asn1/pem.c +++ b/src/libstrongswan/asn1/pem.c @@ -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) diff --git a/src/libstrongswan/asn1/pem.h b/src/libstrongswan/asn1/pem.h index 2c0b45748..0f4b7202c 100755 --- a/src/libstrongswan/asn1/pem.h +++ b/src/libstrongswan/asn1/pem.h @@ -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); diff --git a/src/libstrongswan/asn1/ttodata.h b/src/libstrongswan/asn1/ttodata.h index b2b5adefd..6125c6b82 100644 --- a/src/libstrongswan/asn1/ttodata.h +++ b/src/libstrongswan/asn1/ttodata.h @@ -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/types.c b/src/libstrongswan/chunk.c index 8e201f87b..811a9757a 100644 --- a/src/libstrongswan/types.c +++ b/src/libstrongswan/chunk.c @@ -1,8 +1,8 @@ /** - * @file types.c - * - * @brief Generic types. - * + * @file chunk.c + * + * @brief Pointer/lenght abstraction and its functions. + * */ /* @@ -21,41 +21,23 @@ * 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", -); +#include "chunk.h" +#include <printf_hook.h> /** * Empty chunk. */ -chunk_t CHUNK_INITIALIZER = { NULL, 0 }; +chunk_t chunk_empty = { NULL, 0 }; /** * Described in header. */ chunk_t chunk_clone(chunk_t chunk) { - chunk_t clone = CHUNK_INITIALIZER; + chunk_t clone = chunk_empty; if (chunk.ptr && chunk.len > 0) { @@ -142,7 +124,7 @@ chunk_t chunk_alloc(size_t bytes) 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); + a.len == b.len && memeq(a.ptr, b.ptr, a.len); } /** @@ -156,56 +138,6 @@ bool chunk_equals_or_null(chunk_t a, chunk_t b) } /** - * 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 @@ -253,7 +185,7 @@ static int print_bytes(FILE *stream, const struct printf_info *info, ascii_buffer[i] = '\0'; written += fprintf(stream, "\n%4d: %s %s", - line_start, buffer, ascii_buffer); + line_start, buffer, ascii_buffer); buffer_pos = buffer; @@ -302,137 +234,10 @@ static int print_chunk(FILE *stream, const struct printf_info *info, } /** - * 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 + * register printf() handlers */ 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); + 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 index 000000000..93c4b512f --- /dev/null +++ b/src/libstrongswan/chunk.h @@ -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_ */ diff --git a/src/libstrongswan/crypto/certinfo.c b/src/libstrongswan/crypto/certinfo.c index 20a695753..baebe3fc0 100644 --- a/src/libstrongswan/crypto/certinfo.c +++ b/src/libstrongswan/crypto/certinfo.c @@ -22,8 +22,7 @@ #include <time.h> -#include <types.h> -#include <definitions.h> +#include <library.h> #include "certinfo.h" diff --git a/src/libstrongswan/crypto/certinfo.h b/src/libstrongswan/crypto/certinfo.h index b391cbc53..8d60e3933 100644 --- a/src/libstrongswan/crypto/certinfo.h +++ b/src/libstrongswan/crypto/certinfo.h @@ -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 diff --git a/src/libstrongswan/crypto/crl.c b/src/libstrongswan/crypto/crl.c index e6a1c35a2..b79c474ee 100755 --- a/src/libstrongswan/crypto/crl.c +++ b/src/libstrongswan/crypto/crl.c @@ -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)) diff --git a/src/libstrongswan/crypto/crl.h b/src/libstrongswan/crypto/crl.h index ff4ccd860..216cafad0 100755 --- a/src/libstrongswan/crypto/crl.h +++ b/src/libstrongswan/crypto/crl.h @@ -25,21 +25,13 @@ 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: diff --git a/src/libstrongswan/crypto/crypters/crypter.h b/src/libstrongswan/crypto/crypters/crypter.h index 411dfeda6..46d94ce93 100644 --- a/src/libstrongswan/crypto/crypters/crypter.h +++ b/src/libstrongswan/crypto/crypters/crypter.h @@ -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. diff --git a/src/libstrongswan/crypto/diffie_hellman.h b/src/libstrongswan/crypto/diffie_hellman.h index 65921a530..29a2ab45b 100644 --- a/src/libstrongswan/crypto/diffie_hellman.h +++ b/src/libstrongswan/crypto/diffie_hellman.h @@ -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. diff --git a/src/libstrongswan/crypto/hashers/hasher.h b/src/libstrongswan/crypto/hashers/hasher.h index 3c6192f01..a1b5f5805 100644 --- a/src/libstrongswan/crypto/hashers/hasher.h +++ b/src/libstrongswan/crypto/hashers/hasher.h @@ -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. diff --git a/src/libstrongswan/crypto/hashers/md5_hasher.c b/src/libstrongswan/crypto/hashers/md5_hasher.c index 5cf4643b8..fa61cac5b 100644 --- a/src/libstrongswan/crypto/hashers/md5_hasher.c +++ b/src/libstrongswan/crypto/hashers/md5_hasher.c @@ -30,8 +30,6 @@ #include "md5_hasher.h" -#include <definitions.h> - /* Constants for MD5Transform routine. */ #define S11 7 diff --git a/src/libstrongswan/crypto/hashers/sha1_hasher.c b/src/libstrongswan/crypto/hashers/sha1_hasher.c index 33eec5969..cca336694 100644 --- a/src/libstrongswan/crypto/hashers/sha1_hasher.c +++ b/src/libstrongswan/crypto/hashers/sha1_hasher.c @@ -28,8 +28,6 @@ #include "sha1_hasher.h" -#include <definitions.h> - /* * ugly macro stuff */ diff --git a/src/libstrongswan/crypto/hashers/sha2_hasher.c b/src/libstrongswan/crypto/hashers/sha2_hasher.c index 2c59438c0..f6fd0404e 100644 --- a/src/libstrongswan/crypto/hashers/sha2_hasher.c +++ b/src/libstrongswan/crypto/hashers/sha2_hasher.c @@ -27,8 +27,6 @@ #include "sha2_hasher.h" -#include <definitions.h> - typedef struct private_sha512_hasher_t private_sha512_hasher_t; diff --git a/src/libstrongswan/crypto/hmac.h b/src/libstrongswan/crypto/hmac.h index 0f9ac7071..d320bc5aa 100644 --- a/src/libstrongswan/crypto/hmac.h +++ b/src/libstrongswan/crypto/hmac.h @@ -26,7 +26,6 @@ typedef struct hmac_t hmac_t; #include <crypto/hashers/hasher.h> -#include <definitions.h> /** * @brief Message authentication using hash functions. diff --git a/src/libstrongswan/crypto/prf_plus.c b/src/libstrongswan/crypto/prf_plus.c index 761a8a7bc..6bd444b1f 100644 --- a/src/libstrongswan/crypto/prf_plus.c +++ b/src/libstrongswan/crypto/prf_plus.c @@ -25,8 +25,6 @@ #include "prf_plus.h" -#include <definitions.h> - typedef struct private_prf_plus_t private_prf_plus_t; /** diff --git a/src/libstrongswan/crypto/prfs/hmac_prf.h b/src/libstrongswan/crypto/prfs/hmac_prf.h index ecd61960c..9b06ee3a2 100644 --- a/src/libstrongswan/crypto/prfs/hmac_prf.h +++ b/src/libstrongswan/crypto/prfs/hmac_prf.h @@ -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> diff --git a/src/libstrongswan/crypto/prfs/prf.h b/src/libstrongswan/crypto/prfs/prf.h index b95cc451a..897cf906b 100644 --- a/src/libstrongswan/crypto/prfs/prf.h +++ b/src/libstrongswan/crypto/prfs/prf.h @@ -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. diff --git a/src/libstrongswan/crypto/rsa/rsa_private_key.c b/src/libstrongswan/crypto/rsa/rsa_private_key.c index 8dfced51d..5b1647965 100644 --- a/src/libstrongswan/crypto/rsa/rsa_private_key.c +++ b/src/libstrongswan/crypto/rsa/rsa_private_key.c @@ -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)) diff --git a/src/libstrongswan/crypto/rsa/rsa_private_key.h b/src/libstrongswan/crypto/rsa/rsa_private_key.h index 2263d2f31..9ec07704e 100644 --- a/src/libstrongswan/crypto/rsa/rsa_private_key.h +++ b/src/libstrongswan/crypto/rsa/rsa_private_key.h @@ -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> diff --git a/src/libstrongswan/crypto/rsa/rsa_public_key.c b/src/libstrongswan/crypto/rsa/rsa_public_key.c index f42ff0611..38899670f 100644 --- a/src/libstrongswan/crypto/rsa/rsa_public_key.c +++ b/src/libstrongswan/crypto/rsa/rsa_public_key.c @@ -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)) diff --git a/src/libstrongswan/crypto/rsa/rsa_public_key.h b/src/libstrongswan/crypto/rsa/rsa_public_key.h index b56df28b2..1ee54dcc3 100644 --- a/src/libstrongswan/crypto/rsa/rsa_public_key.h +++ b/src/libstrongswan/crypto/rsa/rsa_public_key.h @@ -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. diff --git a/src/libstrongswan/crypto/signers/signer.h b/src/libstrongswan/crypto/signers/signer.h index a9a80a5e0..57f7d8fe6 100644 --- a/src/libstrongswan/crypto/signers/signer.h +++ b/src/libstrongswan/crypto/signers/signer.h @@ -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. diff --git a/src/libstrongswan/crypto/x509.c b/src/libstrongswan/crypto/x509.c index 43fe589fa..8ed79ebd9 100755 --- a/src/libstrongswan/crypto/x509.c +++ b/src/libstrongswan/crypto/x509.c @@ -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)) diff --git a/src/libstrongswan/crypto/x509.h b/src/libstrongswan/crypto/x509.h index 346590ed4..f17d086bd 100755 --- a/src/libstrongswan/crypto/x509.h +++ b/src/libstrongswan/crypto/x509.h @@ -25,21 +25,13 @@ 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 index 000000000..996cae502 --- /dev/null +++ b/src/libstrongswan/debug.c @@ -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 index 000000000..c424a1c11 --- /dev/null +++ b/src/libstrongswan/debug.h @@ -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.h b/src/libstrongswan/definitions.h deleted file mode 100644 index b02e8092d..000000000 --- a/src/libstrongswan/definitions.h +++ /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/definitions.c b/src/libstrongswan/enum.c index 087476838..c3dd2e549 100644 --- a/src/libstrongswan/definitions.c +++ b/src/libstrongswan/enum.c @@ -1,13 +1,12 @@ /** - * @file definitions.c - * - * @brief General purpose definitions and macros. - * + * @file library.c + * + * @brief enum value to string conversion functions. + * */ /* - * Copyright (C) 2005-2006 Martin Willi - * Copyright (C) 2005 Jan Hutter + * Copyright (C) 2006 Martin Willi * Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it @@ -21,13 +20,15 @@ * for more details. */ -#include <printf.h> +#include <stddef.h> #include <stdio.h> -#include "definitions.h" +#include "enum.h" -/* - * Described in header +#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) { @@ -42,15 +43,14 @@ static char *enum_name(enum_name_t *e, long val) return NULL; } - /** * output handler in printf() for enum names */ static int print_enum(FILE *stream, const struct printf_info *info, - const void *const *args) + const void *const *args) { enum_name_t *ed = *((void**)(args[0])); - long val = *((size_t*)(args[1])); + long val = *((long*)(args[1])); char *name; name = enum_name(ed, val); @@ -62,24 +62,9 @@ static int print_enum(FILE *stream, const struct printf_info *info, } /** - * 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 + * register printf() handlers */ static void __attribute__ ((constructor))print_register() { - register_printf_function(ENUM_PRINTF_SPEC, print_enum, print_enum_arginfo); + 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 index 000000000..3b90ce945 --- /dev/null +++ b/src/libstrongswan/enum.h @@ -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_ */ diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index 0394f32d7..cd40b6477 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -1,7 +1,7 @@ /** * @file library.c * - * @brief Library (de-)initialization. + * @brief Helper functions and definitions. * */ @@ -21,22 +21,150 @@ * 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); +} diff --git a/src/libstrongswan/library.h b/src/libstrongswan/library.h index 58cd4bb33..12aa0cb3c 100644 --- a/src/libstrongswan/library.h +++ b/src/libstrongswan/library.h @@ -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 @@ -96,13 +96,196 @@ * @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 index 000000000..e4089c4ff --- /dev/null +++ b/src/libstrongswan/printf_hook.c @@ -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 index 000000000..14931bd6b --- /dev/null +++ b/src/libstrongswan/printf_hook.h @@ -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.h b/src/libstrongswan/types.h deleted file mode 100644 index 34100d9e8..000000000 --- a/src/libstrongswan/types.h +++ /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_*/ diff --git a/src/libstrongswan/utils/host.c b/src/libstrongswan/utils/host.c index 702d4bd4e..29c30753f 100644 --- a/src/libstrongswan/utils/host.c +++ b/src/libstrongswan/utils/host.c @@ -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) { diff --git a/src/libstrongswan/utils/host.h b/src/libstrongswan/utils/host.h index 74b75ee97..20b5c6345 100644 --- a/src/libstrongswan/utils/host.h +++ b/src/libstrongswan/utils/host.h @@ -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 diff --git a/src/libstrongswan/utils/identification.c b/src/libstrongswan/utils/identification.c index d09c992e2..90c12279e 100644 --- a/src/libstrongswan/utils/identification.c +++ b/src/libstrongswan/utils/identification.c @@ -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; } diff --git a/src/libstrongswan/utils/identification.h b/src/libstrongswan/utils/identification.h index 8d8b59935..80fc27d7c 100644 --- a/src/libstrongswan/utils/identification.h +++ b/src/libstrongswan/utils/identification.h @@ -28,13 +28,9 @@ 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. diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c index 7cf036eea..f132c5120 100644 --- a/src/libstrongswan/utils/leak_detective.c +++ b/src/libstrongswan/utils/leak_detective.c @@ -37,8 +37,8 @@ #include "leak_detective.h" -#include <types.h> #include <library.h> +#include <debug.h> #ifdef LEAK_DETECTIVE diff --git a/src/libstrongswan/utils/lexparser.c b/src/libstrongswan/utils/lexparser.c index 13fe35ef4..9d3f06593 100644 --- a/src/libstrongswan/utils/lexparser.c +++ b/src/libstrongswan/utils/lexparser.c @@ -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 == '"') diff --git a/src/libstrongswan/utils/lexparser.h b/src/libstrongswan/utils/lexparser.h index 29c1bf701..e3c2c4c70 100644 --- a/src/libstrongswan/utils/lexparser.h +++ b/src/libstrongswan/utils/lexparser.h @@ -19,7 +19,7 @@ * for more details. */ -#include <types.h> +#include <library.h> /** * @brief Eats whitespace diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c index 6ca10515e..4aea69034 100644 --- a/src/libstrongswan/utils/linked_list.c +++ b/src/libstrongswan/utils/linked_list.c @@ -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; diff --git a/src/libstrongswan/utils/linked_list.h b/src/libstrongswan/utils/linked_list.h index 6a97d4445..58bcbbdaa 100644 --- a/src/libstrongswan/utils/linked_list.h +++ b/src/libstrongswan/utils/linked_list.h @@ -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> /** diff --git a/src/libstrongswan/utils/randomizer.h b/src/libstrongswan/utils/randomizer.h index d797633af..afbade059 100644 --- a/src/libstrongswan/utils/randomizer.h +++ b/src/libstrongswan/utils/randomizer.h @@ -26,7 +26,7 @@ typedef struct randomizer_t randomizer_t; -#include <types.h> +#include <library.h> #ifndef DEV_RANDOM /** diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c index 3cc297afb..b7ee4319e 100644 --- a/src/stroke/stroke.c +++ b/src/stroke/stroke.c @@ -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: diff --git a/src/stroke/stroke.h b/src/stroke/stroke.h index 42a8a9616..b6a47ee27 100644 --- a/src/stroke/stroke.h +++ b/src/stroke/stroke.h @@ -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 */ |