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.
*
* @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.
#include "configuration.h"
-#include <types.h>
+#include <library.h>
/**
* Timeout in milliseconds after that a half open IKE_SA gets deleted.
typedef struct configuration_t configuration_t;
-#include <types.h>
+#include <library.h>
/**
* @brief The interface for various daemon related configs.
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>
typedef struct connection_store_t connection_store_t;
-#include <types.h>
+#include <library.h>
#include <config/connections/connection.h>
#include <utils/iterator.h>
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);
typedef struct local_connection_store_t local_connection_store_t;
-#include <types.h>
+#include <library.h>
#include <config/connections/connection_store.h>
/**
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>
#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>
} 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);
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)
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>
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);
}
typedef struct local_policy_store_t local_policy_store_t;
-#include <types.h>
+#include <library.h>
#include <config/policies/policy_store.h>
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>
typedef struct policy_store_t policy_store_t;
-#include <types.h>
+#include <library.h>
#include <config/policies/policy.h>
#include <utils/linked_list.h>
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>
}
/**
- * 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);
}
/**
*/
static chunk_t get_from_address(private_traffic_selector_t *this)
{
- chunk_t from = CHUNK_INITIALIZER;
+ chunk_t from = chunk_empty;
switch (this->type)
{
*/
static chunk_t get_to_address(private_traffic_selector_t *this)
{
- chunk_t to = CHUNK_INITIALIZER;
+ chunk_t to = chunk_empty;
switch (this->type)
{
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
#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>
#include "generator.h"
-#include <types.h>
+#include <library.h>
#include <daemon.h>
#include <utils/linked_list.h>
#include <encoding/payloads/payload.h>
typedef struct generator_t generator_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/encodings.h>
#include <encoding/payloads/payload.h>
#include "message.h"
-#include <types.h>
+#include <library.h>
#include <daemon.h>
#include <sa/ike_sa_id.h>
#include <encoding/generator.h>
}
/**
- * 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);
}
/**
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>
#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
#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>
typedef struct parser_t parser_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/encodings.h>
#include <encoding/payloads/payload.h>
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));
}
typedef struct auth_payload_t auth_payload_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/payload.h>
#include <sa/authenticators/authenticator.h>
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));
}
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>
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));
}
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>
#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;
/* 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));
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>
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>
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);
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>
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));
}
typedef struct eap_payload_t eap_payload_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/payload.h>
/**
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.
/* 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;
}
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();
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>
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));
typedef struct id_payload_t id_payload_t;
-#include <types.h>
+#include <library.h>
#include <utils/identification.h>
#include <encoding/payloads/payload.h>
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>
/**
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;
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>
typedef struct nonce_payload_t nonce_payload_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/payload.h>
/**
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>
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>
#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>
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>
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>
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;
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>
#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;
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>
#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>
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>
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>
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));
}
typedef struct unknown_payload_t unknown_payload_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/payload.h>
/**
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));
}
typedef struct vendor_id_payload_t vendor_id_payload_t;
-#include <types.h>
+#include <library.h>
#include <encoding/payloads/payload.h>
/**
this->destination = NULL;
this->source = NULL;
- this->data = CHUNK_INITIALIZER;
+ this->data = chunk_empty;
return &(this->public);
}
typedef struct packet_t packet_t;
-#include <types.h>
+#include <library.h>
#include <utils/host.h>
/**
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>
#include "event_queue.h"
-#include <types.h>
+#include <library.h>
#include <utils/linked_list.h>
#include <sys/time.h>
-#include <types.h>
+#include <library.h>
#include <queues/jobs/job.h>
/**
typedef struct job_queue_t job_queue_t;
-#include <types.h>
+#include <library.h>
#include <queues/jobs/job.h>
/**
typedef struct acquire_job_t acquire_job_t;
-#include <types.h>
+#include <library.h>
#include <queues/jobs/job.h>
/**
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>
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>
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>
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>
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.
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>
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>
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>
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>
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>
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>
typedef struct send_queue_t send_queue_t;
-#include <types.h>
+#include <library.h>
#include <network/packet.h>
/**
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>
}
/**
- * 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);
}
/**
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>
#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 {
#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>
}
/**
- * 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);
}
/**
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;
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>
#include <config/policies/policy.h>
#include <config/proposal.h>
-#define IKE_SA_PRINTF_SPEC 'K'
-
/**
* @brief State of an IKE_SA.
*
}
/**
- * 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.
*/
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.
typedef struct ike_sa_manager_t ike_sa_manager_t;
-#include <types.h>
+#include <library.h>
#include <sa/ike_sa.h>
/**
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;
}
/* 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;
}
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;
}
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;
}
}
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
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 */
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;
}
else
{
- my_id = identification_create_from_encoding(ID_ANY, CHUNK_INITIALIZER);
+ my_id = identification_create_from_encoding(ID_ANY, chunk_empty);
}
}
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;
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;
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;
/* 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;
}
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;
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;
}
}
/* 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;
}
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();
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;
}
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;
typedef struct transaction_t transaction_t;
-#include <types.h>
+#include <library.h>
#include <encoding/message.h>
#include <sa/ike_sa.h>
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.
#include "scheduler.h"
#include <daemon.h>
-#include <definitions.h>
#include <queues/job_queue.h>
typedef struct scheduler_t scheduler_t;
-#include <types.h>
+#include <library.h>
/**
* @brief The scheduler thread is responsible for timed events.
typedef struct sender_t sender_t;
-#include <types.h>
+#include <library.h>
/**
* @brief Thread responsible for sending packets over the socket.
#include "stroke_interface.h"
-#include <types.h>
+#include <library.h>
#include <stroke.h>
#include <daemon.h>
#include <crypto/x509.h>
#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.
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 \
#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 };
case OID_SHA1:
return ASN1_sha1_id;
default:
- return CHUNK_INITIALIZER;
+ return chunk_empty;
}
}
break;
}
if (private)
+ {
DBG4("%B", &object);
+ }
else
+ {
DBG3("%B", &object);
+ }
}
/**
chunk_t *blob1;
u_char *start_ptr;
- *object = CHUNK_INITIALIZER;
+ *object = chunk_empty;
if (obj.flags & ASN1_END) /* end of loop or option found */
{
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)
{
#include <stdarg.h>
#include <gmp.h>
-#include <types.h>
+#include <library.h>
#include <asn1/oid.h>
#include "pem.h"
#include <library.h>
+#include <debug.h>
#include <asn1/asn1.h>
#include <asn1/ttodata.h>
*/
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;
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 */
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)
#include <stdio.h>
-#include <types.h>
+#include <library.h>
err_t pem_to_bin(chunk_t *blob, chunk_t *passphrase, bool *pgp);
#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*/
--- /dev/null
+/**
+ * @file chunk.c
+ *
+ * @brief Pointer/lenght abstraction and its functions.
+ *
+ */
+
+/*
+ * Copyright (C) 2005-2006 Martin Willi
+ * Copyright (C) 2005 Jan Hutter
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <stdio.h>
+
+#include "chunk.h"
+
+#include <printf_hook.h>
+
+/**
+ * Empty chunk.
+ */
+chunk_t chunk_empty = { NULL, 0 };
+
+/**
+ * Described in header.
+ */
+chunk_t chunk_clone(chunk_t chunk)
+{
+ chunk_t clone = chunk_empty;
+
+ if (chunk.ptr && chunk.len > 0)
+ {
+ clone.ptr = malloc(chunk.len);
+ clone.len = chunk.len;
+ memcpy(clone.ptr, chunk.ptr, chunk.len);
+ }
+
+ return clone;
+}
+
+/**
+ * Decribed in header.
+ */
+chunk_t chunk_cat(const char* mode, ...)
+{
+ chunk_t construct;
+ va_list chunks;
+ u_char *pos;
+ int i;
+ int count = strlen(mode);
+
+ /* sum up lengths of individual chunks */
+ va_start(chunks, mode);
+ construct.len = 0;
+ for (i = 0; i < count; i++)
+ {
+ chunk_t ch = va_arg(chunks, chunk_t);
+ construct.len += ch.len;
+ }
+ va_end(chunks);
+
+ /* allocate needed memory for construct */
+ construct.ptr = malloc(construct.len);
+ pos = construct.ptr;
+
+ /* copy or move the chunks */
+ va_start(chunks, mode);
+ for (i = 0; i < count; i++)
+ {
+ chunk_t ch = va_arg(chunks, chunk_t);
+ switch (*mode++)
+ {
+ case 'm':
+ memcpy(pos, ch.ptr, ch.len);
+ pos += ch.len;
+ free(ch.ptr);
+ break;
+ case 'c':
+ default:
+ memcpy(pos, ch.ptr, ch.len);
+ pos += ch.len;
+ }
+ }
+ va_end(chunks);
+
+ return construct;
+}
+
+/**
+ * Described in header.
+ */
+void chunk_free(chunk_t *chunk)
+{
+ free(chunk->ptr);
+ chunk->ptr = NULL;
+ chunk->len = 0;
+}
+
+/**
+ * Described in header.
+ */
+chunk_t chunk_alloc(size_t bytes)
+{
+ chunk_t new_chunk;
+ new_chunk.ptr = malloc(bytes);
+ new_chunk.len = bytes;
+ return new_chunk;
+}
+
+/**
+ * Described in header.
+ */
+bool chunk_equals(chunk_t a, chunk_t b)
+{
+ return a.ptr != NULL && b.ptr != NULL &&
+ a.len == b.len && memeq(a.ptr, b.ptr, a.len);
+}
+
+/**
+ * Described in header.
+ */
+bool chunk_equals_or_null(chunk_t a, chunk_t b)
+{
+ if (a.ptr == NULL || b.ptr == NULL)
+ return TRUE;
+ return a.len == b.len && memeq(a.ptr, b.ptr, a.len);
+}
+
+/**
+ * Number of bytes per line to dump raw data
+ */
+#define BYTES_PER_LINE 16
+
+/**
+ * output handler in printf() for byte ranges
+ */
+static int print_bytes(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ char *bytes = *((void**)(args[0]));
+ int len = *((size_t*)(args[1]));
+
+ char buffer[BYTES_PER_LINE * 3];
+ char ascii_buffer[BYTES_PER_LINE + 1];
+ char *buffer_pos = buffer;
+ char *bytes_pos = bytes;
+ char *bytes_roof = bytes + len;
+ int line_start = 0;
+ int i = 0;
+ int written = 0;
+
+ written += fprintf(stream, "=> %d bytes @ %p", len, bytes);
+
+ while (bytes_pos < bytes_roof)
+ {
+ static char hexdig[] = "0123456789ABCDEF";
+
+ *buffer_pos++ = hexdig[(*bytes_pos >> 4) & 0xF];
+ *buffer_pos++ = hexdig[ *bytes_pos & 0xF];
+
+ ascii_buffer[i++] =
+ (*bytes_pos > 31 && *bytes_pos < 127) ? *bytes_pos : '.';
+
+ if (++bytes_pos == bytes_roof || i == BYTES_PER_LINE)
+ {
+ int padding = 3 * (BYTES_PER_LINE - i);
+ int written;
+
+ while (padding--)
+ {
+ *buffer_pos++ = ' ';
+ }
+ *buffer_pos++ = '\0';
+ ascii_buffer[i] = '\0';
+
+ written += fprintf(stream, "\n%4d: %s %s",
+ line_start, buffer, ascii_buffer);
+
+
+ buffer_pos = buffer;
+ line_start += BYTES_PER_LINE;
+ i = 0;
+ }
+ else
+ {
+ *buffer_pos++ = ' ';
+ }
+ }
+ return written;
+}
+
+/**
+ * output handler in printf() for chunks
+ */
+static int print_chunk(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ chunk_t *chunk = *((chunk_t**)(args[0]));
+ bool first = TRUE;
+ chunk_t copy = *chunk;
+ int written = 0;
+
+ if (!info->alt)
+ {
+ const void *new_args[] = {&chunk->ptr, &chunk->len};
+ return print_bytes(stream, info, new_args);
+ }
+
+ while (copy.len > 0)
+ {
+ if (first)
+ {
+ first = FALSE;
+ }
+ else
+ {
+ written += fprintf(stream, ":");
+ }
+ written += fprintf(stream, "%02x", *copy.ptr++);
+ copy.len--;
+ }
+ return written;
+}
+
+/**
+ * register printf() handlers
+ */
+static void __attribute__ ((constructor))print_register()
+{
+ register_printf_function(PRINTF_CHUNK, print_chunk, arginfo_ptr);
+ register_printf_function(PRINTF_BYTES, print_bytes, arginfo_ptr_int);
+}
--- /dev/null
+/**
+ * @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_ */
#include <time.h>
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
#include "certinfo.h"
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
#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>
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;
}
/**
- * 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);
}
/*
/* 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;
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))
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:
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.
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.
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.
#include "md5_hasher.h"
-#include <definitions.h>
-
/* Constants for MD5Transform routine. */
#define S11 7
#include "sha1_hasher.h"
-#include <definitions.h>
-
/*
* ugly macro stuff
*/
#include "sha2_hasher.h"
-#include <definitions.h>
-
typedef struct private_sha512_hasher_t private_sha512_hasher_t;
typedef struct hmac_t hmac_t;
#include <crypto/hashers/hasher.h>
-#include <definitions.h>
/**
* @brief Message authentication using hash functions.
#include "prf_plus.h"
-#include <definitions.h>
-
typedef struct private_prf_plus_t private_prf_plus_t;
/**
typedef struct hmac_prf_t hmac_prf_t;
-#include <types.h>
+#include <library.h>
#include <crypto/prfs/prf.h>
#include <crypto/hashers/hasher.h>
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.
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))
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>
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))
#include <gmp.h>
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
/**
* @brief RSA public key with associated functions.
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.
#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>
}
/**
- * 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);
}
/**
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;
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))
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:
--- /dev/null
+/**
+ * @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;
--- /dev/null
+/**
+ * @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_ */
+++ /dev/null
-/**
- * @file definitions.c
- *
- * @brief General purpose definitions and macros.
- *
- */
-
-/*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include <printf.h>
-#include <stdio.h>
-
-#include "definitions.h"
-
-/*
- * Described in header
- */
-static char *enum_name(enum_name_t *e, long val)
-{
- do
- {
- if (val >= e->first && val <= e->last)
- {
- return e->names[val - e->first];
- }
- }
- while ((e = e->next));
- return NULL;
-}
-
-
-/**
- * output handler in printf() for enum names
- */
-static int print_enum(FILE *stream, const struct printf_info *info,
- const void *const *args)
-{
- enum_name_t *ed = *((void**)(args[0]));
- long val = *((size_t*)(args[1]));
- char *name;
-
- name = enum_name(ed, val);
- if (name == NULL)
- {
- return fprintf(stream, "(unknown enum value: %ld)", val);
- }
- return fprintf(stream, "%s", name);
-}
-
-/**
- * arginfo handler in printf() for enum names
- */
-static int print_enum_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
- if (n > 1)
- {
- /* enum_names ptr */
- argtypes[0] = PA_POINTER;
- /* value */
- argtypes[1] = PA_INT;
- }
- return 2;
-}
-
-/**
- * register printf() handlers for enum names
- */
-static void __attribute__ ((constructor))print_register()
-{
- register_printf_function(ENUM_PRINTF_SPEC, print_enum, print_enum_arginfo);
-}
+++ /dev/null
-/**
- * @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_*/
--- /dev/null
+/**
+ * @file library.c
+ *
+ * @brief enum value to string conversion functions.
+ *
+ */
+
+/*
+ * Copyright (C) 2006 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <stddef.h>
+#include <stdio.h>
+
+#include "enum.h"
+
+#include <printf_hook.h>
+
+/**
+ * get the name of an enum value in a enum_name_t list
+ */
+static char *enum_name(enum_name_t *e, long val)
+{
+ do
+ {
+ if (val >= e->first && val <= e->last)
+ {
+ return e->names[val - e->first];
+ }
+ }
+ while ((e = e->next));
+ return NULL;
+}
+
+/**
+ * output handler in printf() for enum names
+ */
+static int print_enum(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ enum_name_t *ed = *((void**)(args[0]));
+ long val = *((long*)(args[1]));
+ char *name;
+
+ name = enum_name(ed, val);
+ if (name == NULL)
+ {
+ return fprintf(stream, "(unknown enum value: %ld)", val);
+ }
+ return fprintf(stream, "%s", name);
+}
+
+/**
+ * register printf() handlers
+ */
+static void __attribute__ ((constructor))print_register()
+{
+ register_printf_function(PRINTF_ENUM, print_enum, arginfo_ptr_int);
+}
--- /dev/null
+/**
+ * @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_ */
/**
* @file library.c
*
- * @brief Library (de-)initialization.
+ * @brief Helper functions and definitions.
*
*/
* for more details.
*/
-#include <stdarg.h>
+#include <string.h>
+#include <time.h>
#include <stdio.h>
+#include <stdarg.h>
+#include <pthread.h>
#include "library.h"
+#include <printf_hook.h>
+
+ENUM(status_names, SUCCESS, DESTROY_ME,
+ "SUCCESS",
+ "FAILED",
+ "OUT_OF_RES",
+ "ALREADY_DONE",
+ "NOT_SUPPORTED",
+ "INVALID_ARG",
+ "NOT_FOUND",
+ "PARSE_ERROR",
+ "VERIFY_ERROR",
+ "INVALID_STATE",
+ "DESTROY_ME",
+);
+
/**
- * default dbg function which printf all to stderr
+ * Described in header.
*/
-static void dbg_stderr(int level, char *fmt, ...)
+void *clalloc(void * pointer, size_t size)
{
- va_list args;
+ void *data;
+ data = malloc(size);
+
+ memcpy(data, pointer,size);
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
- va_end(args);
+ return (data);
+}
+
+/**
+ * We use a single mutex for all refcount variables. This
+ * is not optimal for performance, but the critical section
+ * is not that long...
+ * TODO: Consider to include a mutex in each refcount_t variable.
+ */
+static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/**
+ * Described in header.
+ *
+ * TODO: May be implemented with atomic CPU instructions
+ * instead of a mutex.
+ */
+void ref_get(refcount_t *ref)
+{
+ pthread_mutex_lock(&ref_mutex);
+ (*ref)++;
+ pthread_mutex_unlock(&ref_mutex);
}
-void (*dbg) (int level, char *fmt, ...) = dbg_stderr;
+/**
+ * Described in header.
+ *
+ * TODO: May be implemented with atomic CPU instructions
+ * instead of a mutex.
+ */
+bool ref_put(refcount_t *ref)
+{
+ bool more_refs;
+
+ pthread_mutex_lock(&ref_mutex);
+ more_refs = --(*ref);
+ pthread_mutex_unlock(&ref_mutex);
+ return !more_refs;
+}
+
+/**
+ * output handler in printf() for time_t
+ */
+static int print_time(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ static const char* months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ time_t time = *((time_t*)(args[0]));
+ bool utc = TRUE;
+ struct tm t;
+
+ if (info->alt)
+ {
+ utc = *((bool*)(args[1]));
+ }
+ if (time == UNDEFINED_TIME)
+ {
+ return fprintf(stream, "--- -- --:--:--%s----",
+ info->alt ? " UTC " : " ");
+ }
+ if (utc)
+ {
+ gmtime_r(&time, &t);
+ }
+ else
+ {
+ localtime_r(&time, &t);
+ }
+ return fprintf(stream, "%s %02d %02d:%02d:%02d%s%04d",
+ months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,
+ t.tm_sec, utc ? " UTC " : " ", t.tm_year + 1900);
+}
+
+/**
+ * output handler in printf() for time deltas
+ */
+static int print_time_delta(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ time_t start = *((time_t*)(args[0]));
+ time_t end = *((time_t*)(args[1]));
+ u_int delta = abs(end - start);
+ char* unit = "second";
+
+ if (delta > 2 * 60 * 60 * 24)
+ {
+ delta /= 60 * 60 * 24;
+ unit = "days";
+ }
+ else if (delta > 2 * 60 * 60)
+ {
+ delta /= 60 * 60;
+ unit = "hours";
+ }
+ else if (delta > 2 * 60)
+ {
+ delta /= 60;
+ unit = "minutes";
+ }
+ return fprintf(stream, "%d %s", delta, unit);
+}
+
+/**
+ * register printf() handlers for time_t
+ */
+static void __attribute__ ((constructor))print_register()
+{
+ register_printf_function(PRINTF_TIME, print_time, arginfo_int_alt_int_int);
+ register_printf_function(PRINTF_TIME_DELTA, print_time_delta, arginfo_int_int);
+}
/**
* @file library.h
- *
- * @brief Global library header.
- *
+ *
+ * @brief Helper functions and definitions.
+ *
*/
/*
* Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil
- *
+ *
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* @ingroup libstrongswan
*/
-/** debug macros, they call the dbg function hook */
-#define DBG1(fmt, ...) dbg(1, fmt, ##__VA_ARGS__)
-#define DBG2(fmt, ...) dbg(2, fmt, ##__VA_ARGS__)
-#define DBG3(fmt, ...) dbg(3, fmt, ##__VA_ARGS__)
-#define DBG4(fmt, ...) dbg(4, fmt, ##__VA_ARGS__)
+#include <gmp.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <printf.h>
+
+#include <enum.h>
+
+/**
+ * Number of bits in a byte
+ */
+#define BITS_PER_BYTE 8
+
+/**
+ * Default length for various auxiliary text buffers
+ */
+#define BUF_LEN 512
+
+/**
+ * Macro compares two strings for equality
+ */
+#define streq(x,y) (strcmp(x, y) == 0)
+
+/**
+ * Macro compares two binary blobs for equality
+ */
+#define memeq(x,y,len) (memcmp(x, y, len) == 0)
+
+/**
+ * Macro gives back larger of two values.
+ */
+#define max(x,y) ((x) > (y) ? (x):(y))
+
+/**
+ * Macro gives back smaller of two values.
+ */
+#define min(x,y) ((x) < (y) ? (x):(y))
+
+/**
+ * Call destructor of a object if object != NULL
+ */
+#define DESTROY_IF(obj) if (obj) obj->destroy(obj)
+
+/**
+ * Debug macro to follow control flow
+ */
+#define POS printf("%s, line %d\n", __FILE__, __LINE__)
+
+/**
+ * Macro to allocate a sized type.
+ */
+#define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
+
+/**
+ * Assign a function as a class method
+ */
+#define ASSIGN(method, function) (method = (typeof(method))function)
+
+/**
+ * time_t not defined
+ */
+#define UNDEFINED_TIME 0
+
+/**
+ * General purpose boolean type.
+ */
+typedef int bool;
+#define FALSE 0
+#define TRUE 1
+
+typedef enum status_t status_t;
+
+/**
+ * Return values of function calls.
+ */
+enum status_t {
+ /**
+ * Call succeeded.
+ */
+ SUCCESS,
+
+ /**
+ * Call failed.
+ */
+ FAILED,
+
+ /**
+ * Out of resources.
+ */
+ OUT_OF_RES,
+
+ /**
+ * The suggested operation is already done
+ */
+ ALREADY_DONE,
+
+ /**
+ * Not supported.
+ */
+ NOT_SUPPORTED,
+
+ /**
+ * One of the arguments is invalid.
+ */
+ INVALID_ARG,
+
+ /**
+ * Something could not be found.
+ */
+ NOT_FOUND,
+
+ /**
+ * Error while parsing.
+ */
+ PARSE_ERROR,
+
+ /**
+ * Error while verifying.
+ */
+ VERIFY_ERROR,
+
+ /**
+ * Object in invalid state.
+ */
+ INVALID_STATE,
+
+ /**
+ * Destroy object which called method belongs to.
+ */
+ DESTROY_ME,
+};
+
+/**
+ * enum_names for type status_t.
+ */
+extern enum_name_t *status_names;
+
+/**
+ * deprecated pluto style return value:
+ * error message, NULL for success
+ */
+typedef const char *err_t;
+
+/**
+ * Handle struct timeval like an own type.
+ */
+typedef struct timeval timeval_t;
+
+/**
+ * Handle struct timespec like an own type.
+ */
+typedef struct timespec timespec_t;
+
+/**
+ * Handle struct chunk_t like an own type.
+ */
+typedef struct sockaddr sockaddr_t;
+
+/**
+ * Clone a data to a newly allocated buffer
+ */
+void *clalloc(void *pointer, size_t size);
+
+/**
+ * Special type to count references
+ */
+typedef volatile u_int refcount_t;
+
+/**
+ * @brief Get a new reference.
+ *
+ * Increments the reference counter atomic.
+ *
+ * @param ref pointer to ref counter
+ */
+void ref_get(refcount_t *ref);
+
+/**
+ * @brief Put back a unused reference.
+ *
+ * Decrements the reference counter atomic and
+ * says if more references available.
+ *
+ * @param ref pointer to ref counter
+ * @return TRUE if no more references counted
+ */
+bool ref_put(refcount_t *ref);
+
-/** dbg function hook, uses stderr logger by default */
-extern void (*dbg) (int level, char *fmt, ...);
+#include <chunk.h>
+#include <printf_hook.h>
#endif /* LIBRARY_H_ */
--- /dev/null
+/**
+ * @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;
+}
--- /dev/null
+/**
+ * @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_ */
+++ /dev/null
-/**
- * @file types.c
- *
- * @brief Generic types.
- *
- */
-
-/*
- * Copyright (C) 2005-2006 Martin Willi
- * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include <string.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <printf.h>
-
-#include "types.h"
-
-ENUM(status_names, SUCCESS, DESTROY_ME,
- "SUCCESS",
- "FAILED",
- "OUT_OF_RES",
- "ALREADY_DONE",
- "NOT_SUPPORTED",
- "INVALID_ARG",
- "NOT_FOUND",
- "PARSE_ERROR",
- "VERIFY_ERROR",
- "INVALID_STATE",
- "DESTROY_ME",
-);
-
-
-/**
- * Empty chunk.
- */
-chunk_t CHUNK_INITIALIZER = { NULL, 0 };
-
-/**
- * Described in header.
- */
-chunk_t chunk_clone(chunk_t chunk)
-{
- chunk_t clone = CHUNK_INITIALIZER;
-
- if (chunk.ptr && chunk.len > 0)
- {
- clone.ptr = malloc(chunk.len);
- clone.len = chunk.len;
- memcpy(clone.ptr, chunk.ptr, chunk.len);
- }
-
- return clone;
-}
-
-/**
- * Decribed in header.
- */
-chunk_t chunk_cat(const char* mode, ...)
-{
- chunk_t construct;
- va_list chunks;
- u_char *pos;
- int i;
- int count = strlen(mode);
-
- /* sum up lengths of individual chunks */
- va_start(chunks, mode);
- construct.len = 0;
- for (i = 0; i < count; i++)
- {
- chunk_t ch = va_arg(chunks, chunk_t);
- construct.len += ch.len;
- }
- va_end(chunks);
-
- /* allocate needed memory for construct */
- construct.ptr = malloc(construct.len);
- pos = construct.ptr;
-
- /* copy or move the chunks */
- va_start(chunks, mode);
- for (i = 0; i < count; i++)
- {
- chunk_t ch = va_arg(chunks, chunk_t);
- switch (*mode++)
- {
- case 'm':
- memcpy(pos, ch.ptr, ch.len);
- pos += ch.len;
- free(ch.ptr);
- break;
- case 'c':
- default:
- memcpy(pos, ch.ptr, ch.len);
- pos += ch.len;
- }
- }
- va_end(chunks);
-
- return construct;
-}
-
-/**
- * Described in header.
- */
-void chunk_free(chunk_t *chunk)
-{
- free(chunk->ptr);
- chunk->ptr = NULL;
- chunk->len = 0;
-}
-
-/**
- * Described in header.
- */
-chunk_t chunk_alloc(size_t bytes)
-{
- chunk_t new_chunk;
- new_chunk.ptr = malloc(bytes);
- new_chunk.len = bytes;
- return new_chunk;
-}
-
-/**
- * Described in header.
- */
-bool chunk_equals(chunk_t a, chunk_t b)
-{
- return a.ptr != NULL && b.ptr != NULL &&
- a.len == b.len && memeq(a.ptr, b.ptr, a.len);
-}
-
-/**
- * Described in header.
- */
-bool chunk_equals_or_null(chunk_t a, chunk_t b)
-{
- if (a.ptr == NULL || b.ptr == NULL)
- return TRUE;
- return a.len == b.len && memeq(a.ptr, b.ptr, a.len);
-}
-
-/**
- * Described in header.
- */
-void *clalloc(void * pointer, size_t size)
-{
- void *data;
- data = malloc(size);
-
- memcpy(data, pointer,size);
-
- return (data);
-}
-
-/**
- * We use a single mutex for all refcount variables. This
- * is not optimal for performance, but the critical section
- * is not that long...
- * TODO: Consider to include a mutex in each refcount_t variable.
- */
-static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/**
- * Described in header.
- *
- * TODO: May be implemented with atomic CPU instructions
- * instead of a mutex.
- */
-void ref_get(refcount_t *ref)
-{
- pthread_mutex_lock(&ref_mutex);
- (*ref)++;
- pthread_mutex_unlock(&ref_mutex);
-}
-
-/**
- * Described in header.
- *
- * TODO: May be implemented with atomic CPU instructions
- * instead of a mutex.
- */
-bool ref_put(refcount_t *ref)
-{
- bool more_refs;
-
- pthread_mutex_lock(&ref_mutex);
- more_refs = --(*ref);
- pthread_mutex_unlock(&ref_mutex);
- return !more_refs;
-}
-
-/**
- * Number of bytes per line to dump raw data
- */
-#define BYTES_PER_LINE 16
-
-/**
- * output handler in printf() for byte ranges
- */
-static int print_bytes(FILE *stream, const struct printf_info *info,
- const void *const *args)
-{
- char *bytes = *((void**)(args[0]));
- int len = *((size_t*)(args[1]));
-
- char buffer[BYTES_PER_LINE * 3];
- char ascii_buffer[BYTES_PER_LINE + 1];
- char *buffer_pos = buffer;
- char *bytes_pos = bytes;
- char *bytes_roof = bytes + len;
- int line_start = 0;
- int i = 0;
- int written = 0;
-
- written += fprintf(stream, "=> %d bytes @ %p", len, bytes);
-
- while (bytes_pos < bytes_roof)
- {
- static char hexdig[] = "0123456789ABCDEF";
-
- *buffer_pos++ = hexdig[(*bytes_pos >> 4) & 0xF];
- *buffer_pos++ = hexdig[ *bytes_pos & 0xF];
-
- ascii_buffer[i++] =
- (*bytes_pos > 31 && *bytes_pos < 127) ? *bytes_pos : '.';
-
- if (++bytes_pos == bytes_roof || i == BYTES_PER_LINE)
- {
- int padding = 3 * (BYTES_PER_LINE - i);
- int written;
-
- while (padding--)
- {
- *buffer_pos++ = ' ';
- }
- *buffer_pos++ = '\0';
- ascii_buffer[i] = '\0';
-
- written += fprintf(stream, "\n%4d: %s %s",
- line_start, buffer, ascii_buffer);
-
-
- buffer_pos = buffer;
- line_start += BYTES_PER_LINE;
- i = 0;
- }
- else
- {
- *buffer_pos++ = ' ';
- }
- }
- return written;
-}
-
-/**
- * output handler in printf() for chunks
- */
-static int print_chunk(FILE *stream, const struct printf_info *info,
- const void *const *args)
-{
- chunk_t *chunk = *((chunk_t**)(args[0]));
- bool first = TRUE;
- chunk_t copy = *chunk;
- int written = 0;
-
- if (!info->alt)
- {
- const void *new_args[] = {&chunk->ptr, &chunk->len};
- return print_bytes(stream, info, new_args);
- }
-
- while (copy.len > 0)
- {
- if (first)
- {
- first = FALSE;
- }
- else
- {
- written += fprintf(stream, ":");
- }
- written += fprintf(stream, "%02x", *copy.ptr++);
- copy.len--;
- }
- return written;
-}
-
-/**
- * output handler in printf() for time_t
- */
-static int print_time(FILE *stream, const struct printf_info *info,
- const void *const *args)
-{
- static const char* months[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
- time_t time = *((time_t*)(args[0]));
- bool utc = TRUE;
- struct tm t;
-
- if (info->alt)
- {
- utc = *((bool*)(args[1]));
- }
- if (time == UNDEFINED_TIME)
- {
- return fprintf(stream, "--- -- --:--:--%s----",
- info->alt ? " UTC " : " ");
- }
- if (utc)
- {
- gmtime_r(&time, &t);
- }
- else
- {
- localtime_r(&time, &t);
- }
- return fprintf(stream, "%s %02d %02d:%02d:%02d%s%04d",
- months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,
- t.tm_sec, utc ? " UTC " : " ", t.tm_year + 1900);
-}
-
-/**
- * output handler in printf() for time deltas
- */
-static int print_time_delta(FILE *stream, const struct printf_info *info,
- const void *const *args)
-{
- time_t start = *((time_t*)(args[0]));
- time_t end = *((time_t*)(args[1]));
- u_int delta = abs(end - start);
- char* unit = "second";
-
- if (delta > 2 * 60 * 60 * 24)
- {
- delta /= 60 * 60 * 24;
- unit = "days";
- }
- else if (delta > 2 * 60 * 60)
- {
- delta /= 60 * 60;
- unit = "hours";
- }
- else if (delta > 2 * 60)
- {
- delta /= 60;
- unit = "minutes";
- }
- return fprintf(stream, "%d %s", delta, unit);
-}
-
-/**
- * arginfo handler in printf() for byte ranges
- */
-static int print_bytes_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
- if (n > 1)
- {
- argtypes[0] = PA_POINTER;
- argtypes[1] = PA_INT;
- }
- return 2;
-}
-
-/**
- * arginfo handler in printf() for time deltas
- */
-static int print_time_delta_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
- if (n > 1)
- {
- argtypes[0] = PA_INT;
- argtypes[1] = PA_INT;
- }
- return 2;
-}
-
-/**
- * arginfo handler in printf() for time_t
- */
-static int print_time_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
- if (info->alt)
- {
- if (n > 1)
- {
- argtypes[0] = PA_INT;
- argtypes[1] = PA_INT;
- }
- return 2;
- }
-
- if (n > 0)
- {
- argtypes[0] = PA_INT;
- }
- return 1;
-}
-
-/**
- * arginfo handler in printf() for chunks
- */
-static int print_chunk_arginfo(const struct printf_info *info, size_t n, int *argtypes)
-{
- if (n > 0)
- {
- argtypes[0] = PA_POINTER;
- }
- return 1;
-}
-
-/**
- * register printf() handlers for time_t
- */
-static void __attribute__ ((constructor))print_register()
-{
- register_printf_function(CHUNK_PRINTF_SPEC, print_chunk, print_chunk_arginfo);
- register_printf_function(BYTES_PRINTF_SPEC, print_bytes, print_bytes_arginfo);
- register_printf_function(TIME_PRINTF_SPEC, print_time, print_time_arginfo);
- register_printf_function(TIME_DELTA_PRINTF_SPEC, print_time_delta, print_time_delta_arginfo);
-}
+++ /dev/null
-/**
- * @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_*/
}
/**
- * 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);
}
/**
*/
static chunk_t get_address(private_host_t *this)
{
- chunk_t address = CHUNK_INITIALIZER;
+ chunk_t address = chunk_empty;
switch (this->address.sa_family)
{
#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
#include <ctype.h>
#include <printf.h>
-#include "definitions.h"
#include "identification.h"
#include <asn1/asn1.h>
*/
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)
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)
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;
break;
}
/* reset oid and change state */
- oid = CHUNK_INITIALIZER;
+ oid = chunk_empty;
state = SEARCH_NAME;
}
break;
status = OUT_OF_RES;
}
/* reset name and change state */
- name = CHUNK_INITIALIZER;
+ name = chunk_empty;
state = SEARCH_OID;
}
break;
if (status != SUCCESS)
{
free(dn->ptr);
- *dn = CHUNK_INITIALIZER;
+ *dn = chunk_empty;
}
return status;
}
}
/**
- * 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);
}
/**
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;
}
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.
#include "leak_detective.h"
-#include <types.h>
#include <library.h>
+#include <debug.h>
#ifdef LEAK_DETECTIVE
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 */
{
if (!eat_whitespace(line))
{
- *value = CHUNK_INITIALIZER;
+ *value = chunk_empty;
return NULL;
}
if (*line->ptr == '\'' || *line->ptr == '"')
* for more details.
*/
-#include <types.h>
+#include <library.h>
/**
* @brief Eats whitespace
{
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;
#include <pthread.h>
-#include <types.h>
+#include <library.h>
#include <utils/iterator.h>
/**
typedef struct randomizer_t randomizer_t;
-#include <types.h>
+#include <library.h>
#ifndef DEV_RANDOM
/**
#include <stdio.h>
#include <linux/stddef.h>
-#include <types.h>
-
#include "stroke.h"
#include "stroke_keywords.h"
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;
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;
LIST_ALL
};
-static int list(stroke_keyword_t kw, bool utc)
+static int list(stroke_keyword_t kw, int utc)
{
stroke_msg_t msg;
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:
char *subnet;
int subnet_mask;
int sendcert;
- bool hostaccess;
+ int hostaccess;
u_int8_t protocol;
u_int16_t port;
};
/* data for STR_ADD_CONN */
struct {
char *name;
- bool ikev2;
+ int ikev2;
int auth_method;
struct {
char *ike;
/* data for STR_LIST */
struct {
list_flag_t flags;
- bool utc;
+ int utc;
} list;
/* data for STR_REREAD */