From 27e432056b0d3eaaf5e938b3df9be2169e421275 Mon Sep 17 00:00:00 2001 From: Jan Hutter Date: Mon, 28 Nov 2005 16:55:46 +0000 Subject: [PATCH] - memory allocation checks removed --- Source/charon/config/configuration_manager.h | 4 + Source/charon/encoding/generator.c | 80 +++----- Source/charon/encoding/generator.h | 7 +- Source/charon/encoding/message.c | 258 ++++++++++-------------- Source/charon/encoding/message.h | 59 +++--- Source/charon/sa/ike_sa.c | 10 +- Source/charon/sa/states/ike_sa_init_requested.c | 7 +- Source/charon/sa/states/initiator_init.c | 27 +-- Source/charon/sa/states/responder_init.c | 28 +-- 9 files changed, 173 insertions(+), 307 deletions(-) diff --git a/Source/charon/config/configuration_manager.h b/Source/charon/config/configuration_manager.h index e15f6a5..787286a 100644 --- a/Source/charon/config/configuration_manager.h +++ b/Source/charon/config/configuration_manager.h @@ -41,6 +41,8 @@ typedef struct configuration_manager_t configuration_manager_t; * It is expected, that in future different configurations are stored in a linked list * or a hash map and are managed by this class. * + * @ingroup config + * */ struct configuration_manager_t { @@ -184,6 +186,8 @@ struct configuration_manager_t { * @return * - pointer to created manager object if succeeded * - NULL if memory allocation failed + * + * @ingroup config */ configuration_manager_t *configuration_manager_create(); diff --git a/Source/charon/encoding/generator.c b/Source/charon/encoding/generator.c index e1da403..f4ae722 100644 --- a/Source/charon/encoding/generator.c +++ b/Source/charon/encoding/generator.c @@ -1,7 +1,7 @@ /** * @file generator.c * - * @brief Generic generator class used to generate IKEv2-header and payloads. + * @brief Implementation of generator_t. * */ @@ -113,7 +113,7 @@ struct private_generator_t { void (*generate_reserved_field) (private_generator_t *this,int bits); /** - * Generates a FLAG field + * Generates a FLAG field. * * @param this private_generator_t object * @param generator_contexts generator_contexts_t object where the context is written or read from @@ -122,7 +122,7 @@ struct private_generator_t { void (*generate_flag) (private_generator_t *this,u_int32_t offset); /** - * Writes the current buffer content into a chunk_t + * Writes the current buffer content into a chunk_t. * * Memory of specific chunk_t gets allocated. * @@ -132,7 +132,7 @@ struct private_generator_t { void (*write_chunk) (private_generator_t *this,chunk_t *data); /** - * Generates a bytestream from a chunk_t + * Generates a bytestream from a chunk_t. * * @param this private_generator_t object * @param offset offset of chunk_t value in data struct @@ -201,22 +201,22 @@ struct private_generator_t { void * data_struct; /* - * Last payload length position offset in the buffer + * Last payload length position offset in the buffer. */ u_int32_t last_payload_length_position_offset; /** - * Offset of the header length field in the buffer + * Offset of the header length field in the buffer. */ u_int32_t header_length_position_offset; /** - * Last SPI size + * Last SPI size. */ u_int8_t last_spi_size; /* - * Attribute format of the last generated transform attribute + * Attribute format of the last generated transform attribute. * * Used to check if a variable value field is used or not for * the transform attribute value. @@ -225,19 +225,18 @@ struct private_generator_t { /* * Depending on the value of attribute_format this field is used - * to hold the length of the transform attribute in bytes + * to hold the length of the transform attribute in bytes. */ u_int16_t attribute_length; /** - * Associated Logger + * Associated Logger. */ logger_t *logger; }; /** - * Implements private_generator_t's get_current_buffer_size function. - * See #private_generator_s.get_current_buffer_size. + * Implementation of private_generator_t.get_current_buffer_size. */ static size_t get_current_buffer_size (private_generator_t *this) { @@ -245,8 +244,7 @@ static size_t get_current_buffer_size (private_generator_t *this) } /** - * Implements private_generator_t's get_current_buffer_space function. - * See #private_generator_s.get_current_buffer_space. + * Implementation of private_generator_t.get_current_buffer_space. */ static size_t get_current_buffer_space (private_generator_t *this) { @@ -256,8 +254,7 @@ static size_t get_current_buffer_space (private_generator_t *this) } /** - * Implements private_generator_t's get_current_buffer_space function. - * See #private_generator_s.get_current_buffer_space. + * Implementation of private_generator_t.get_current_data_length. */ static size_t get_current_data_length (private_generator_t *this) { @@ -265,18 +262,15 @@ static size_t get_current_data_length (private_generator_t *this) } /** - * Implements private_generator_t's get_current_buffer_offset function. - * See #private_generator_s.get_current_buffer_offset. + * Implementation of private_generator_t.get_current_buffer_offset. */ static u_int32_t get_current_buffer_offset (private_generator_t *this) { return (this->out_position - this->buffer); } - /** - * Implements private_generator_t's generate_u_int_type function. - * See #private_generator_s.generate_u_int_type. + * Implementation of private_generator_t.generate_u_int_type. */ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_type,u_int32_t offset) { @@ -438,8 +432,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t } /** - * Implements private_generator_t's generate_reserved_field function. - * See #private_generator_s.generate_reserved_field. + * Implementation of private_generator_t.generate_reserved_field. */ static void generate_reserved_field(private_generator_t *this,int bits) { @@ -487,8 +480,7 @@ static void generate_reserved_field(private_generator_t *this,int bits) } /** - * Implements private_generator_t's generate_flag function. - * See #private_generator_s.generate_flag. + * Implementation of private_generator_t.generate_flag. */ static void generate_flag (private_generator_t *this,u_int32_t offset) { @@ -524,8 +516,7 @@ static void generate_flag (private_generator_t *this,u_int32_t offset) } /** - * Implements private_generator_t's generate_from_chunk function. - * See #private_generator_s.generate_from_chunk. + * Implementation of private_generator_t.generate_from_chunk. */ static void generate_from_chunk (private_generator_t *this,u_int32_t offset) { @@ -545,8 +536,7 @@ static void generate_from_chunk (private_generator_t *this,u_int32_t offset) } /** - * Implements private_generator_t's generator_context_make_space_available function. - * See #private_generator_s.generator_context_make_space_available. + * Implementation of private_generator_t.make_space_available. */ static void make_space_available (private_generator_t *this, size_t bits) { @@ -576,8 +566,7 @@ static void make_space_available (private_generator_t *this, size_t bits) } /** - * Implements private_generator_t's write_bytes_to_buffer function. - * See #private_generator_s.write_bytes_to_buffer. + * Implementation of private_generator_t.write_bytes_to_buffer. */ static void write_bytes_to_buffer (private_generator_t *this,void * bytes, size_t number_of_bytes) { @@ -595,8 +584,7 @@ static void write_bytes_to_buffer (private_generator_t *this,void * bytes, size_ } /** - * Implements private_generator_t's write_bytes_to_buffer_at_offset function. - * See #private_generator_s.write_bytes_to_buffer_at_offset. + * Implementation of private_generator_t.write_bytes_to_buffer_at_offset. */ static void write_bytes_to_buffer_at_offset (private_generator_t *this,void * bytes,size_t number_of_bytes,u_int32_t offset) { @@ -622,8 +610,7 @@ static void write_bytes_to_buffer_at_offset (private_generator_t *this,void * by } /** - * Implements generator_t's write_chunk function. - * See #generator_s.write_chunk. + * Implementation of private_generator_t.write_to_chunk. */ static void write_to_chunk (private_generator_t *this,chunk_t *data) { @@ -647,8 +634,7 @@ static void write_to_chunk (private_generator_t *this,chunk_t *data) } /** - * Implements generator_t's generate_payload function. - * See #generator_s.generate_payload. + * Implementation of private_generator_t.generate_payload. */ static void generate_payload (private_generator_t *this,payload_t *payload) { @@ -928,8 +914,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload) } /** - * Implements generator_t's destroy function. - * See #generator_s.destroy. + * Implementation of generator_t.destroy. */ static status_t destroy(private_generator_t *this) { @@ -947,10 +932,6 @@ generator_t * generator_create() private_generator_t *this; this = allocator_alloc_thing(private_generator_t); - if (this == NULL) - { - return NULL; - } /* initiate public functions */ this->public.generate_payload = (void(*)(generator_t*, payload_t *)) generate_payload; @@ -974,11 +955,6 @@ generator_t * generator_create() /* allocate memory for buffer */ this->buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE); - if (this->buffer == NULL) - { - allocator_free(this); - return NULL; - } /* initiate private variables */ this->out_position = this->buffer; @@ -988,12 +964,6 @@ generator_t * generator_create() this->last_payload_length_position_offset = 0; this->header_length_position_offset = 0; this->logger = global_logger_manager->create_logger(global_logger_manager,GENERATOR,NULL); - - if (this->logger == NULL) - { - allocator_free(this->buffer); - allocator_free(this); - return NULL; - } + return &(this->public); } diff --git a/Source/charon/encoding/generator.h b/Source/charon/encoding/generator.h index 7637f49..1db9570 100644 --- a/Source/charon/encoding/generator.h +++ b/Source/charon/encoding/generator.h @@ -1,7 +1,7 @@ /** * @file generator.h * - * @brief Generic generator class used to generate IKEv2-header and payloads. + * @brief Interface of generator_t. * */ @@ -42,6 +42,8 @@ typedef struct generator_t generator_t; /** *A generator_t object which generates payloads of specific type. + * + * @ingroup encoding */ struct generator_t { @@ -75,7 +77,8 @@ struct generator_t { * Constructor to create a generator. * * Returns a new generator_t object. - * + * + * @ingroup encoding */ generator_t * generator_create(); diff --git a/Source/charon/encoding/message.c b/Source/charon/encoding/message.c index 5fb6fa3..5f949df 100644 --- a/Source/charon/encoding/message.c +++ b/Source/charon/encoding/message.c @@ -1,7 +1,7 @@ /** * @file message.c * - * @brief Class message_t. Object of this type represents an IKEv2-Message. + * @brief Implementation of message_t. * */ @@ -40,22 +40,22 @@ typedef struct supported_payload_entry_t supported_payload_entry_t; /** - * Supported payload entry used in message_rule_t + * Supported payload entry used in message_rule_t. * */ struct supported_payload_entry_t { /** - * Payload type + * Payload type. */ payload_type_t payload_type; /** - * Minimal occurence of this payload + * Minimal occurence of this payload. */ size_t min_occurence; /** - * Max occurence of this payload + * Max occurence of this payload. */ size_t max_occurence; }; @@ -63,31 +63,32 @@ struct supported_payload_entry_t { typedef struct message_rule_t message_rule_t; /** - * Message Rule used to find out which payloads are supported by each message type + * Message Rule used to find out which payloads + * are supported by each message type. * */ struct message_rule_t { /** - * Type of message + * Type of message. */ exchange_type_t exchange_type; /** - * Is message a request or response + * Is message a request or response. */ bool is_request; /** - * Number of supported payloads + * Number of supported payloads. */ size_t supported_payloads_count; /** - * Pointer to first supported payload entry + * Pointer to first supported payload entry. */ supported_payload_entry_t *supported_payloads; }; /** - * message rule for ike_sa_init from initiator + * Message rule for IKE_SA_INIT from initiator. */ static supported_payload_entry_t supported_ike_sa_init_i_payloads[] = { @@ -97,7 +98,7 @@ static supported_payload_entry_t supported_ike_sa_init_i_payloads[] = }; /** - * message rule for ike_sa_init from responder + * Message rule for IKE_SA_INIT from responder. */ static supported_payload_entry_t supported_ike_sa_init_r_payloads[] = { @@ -108,7 +109,7 @@ static supported_payload_entry_t supported_ike_sa_init_r_payloads[] = /** - * message rules, defines allowed payloads + * Message rules, defines allowed payloads. */ static message_rule_t message_rules[] = { {IKE_SA_INIT,TRUE,(sizeof(supported_ike_sa_init_i_payloads)/sizeof(supported_payload_entry_t)),supported_ike_sa_init_i_payloads}, @@ -118,16 +119,16 @@ static message_rule_t message_rules[] = { typedef struct payload_entry_t payload_entry_t; /** - * Entry for a payload in the internal used linked list + * Entry for a payload in the internal used linked list. * */ struct payload_entry_t { /** - * Type of payload + * Type of payload. */ payload_type_t payload_type; /** - * Data struct holding the data of given payload + * Data struct holding the data of given payload. */ void *data_struct; }; @@ -136,33 +137,32 @@ struct payload_entry_t { typedef struct private_message_t private_message_t; /** - * Private data of an message_t object + * Private data of an message_t object. */ struct private_message_t { /** - * Public part of a message_t object + * Public part of a message_t object. */ message_t public; - /** - * Minor version of message + * Minor version of message. */ u_int8_t major_version; /** - * Major version of message + * Major version of message. */ u_int8_t minor_version; /** - * First Payload in message + * First Payload in message. */ payload_type_t first_payload; /** - * Assigned exchange type + * Assigned exchange type. */ exchange_type_t exchange_type; @@ -174,12 +174,12 @@ struct private_message_t { bool is_request; /** - * Message ID of this message + * Message ID of this message. */ u_int32_t message_id; /** - * ID of assigned IKE_SA + * ID of assigned IKE_SA. */ ike_sa_id_t *ike_sa_id; @@ -191,17 +191,17 @@ struct private_message_t { packet_t *packet; /** - * Linked List where payload data are stored in + * Linked List where payload data are stored in. */ linked_list_t *payloads; /** - * Assigned parser to parse Header and Body of this message + * Assigned parser to parse Header and Body of this message. */ parser_t *parser; /** - * logger for this message + * Assigned logger. */ logger_t *logger; @@ -212,16 +212,16 @@ struct private_message_t { * @param[out] supported_payloads first entry of supported payloads * @param[out] supported_payloads_count number of supported payload entries * - * @return SUCCESS - * NOT_FOUND if no supported payload definition could be found + * @return + * - SUCCESS + * - NOT_FOUND if no supported payload definition could be found */ status_t (*get_supported_payloads) (private_message_t *this, supported_payload_entry_t **supported_payloads,size_t *supported_payloads_count); }; /** - * Implements private_message_t's get_supported_payloads function. - * See #private_message_t.get_supported_payloads. + * Implementation of private_message_t.get_supported_payloads. */ status_t get_supported_payloads (private_message_t *this, supported_payload_entry_t **supported_payloads,size_t *supported_payloads_count) { @@ -250,46 +250,36 @@ status_t get_supported_payloads (private_message_t *this, supported_payload_entr } /** - * Implements message_t's set_ike_sa_id function. - * See #message_s.set_ike_sa_id. + * Implementation of message_t.set_ike_sa_id. */ -static status_t set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id) +static void set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id) { - status_t status; - status = ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)); - return status; + ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)); } /** - * Implements message_t's get_ike_sa_id function. - * See #message_s.get_ike_sa_id. + * Implementation of message_t.get_ike_sa_id. */ static status_t get_ike_sa_id (private_message_t *this,ike_sa_id_t **ike_sa_id) { - status_t status; if (this->ike_sa_id == NULL) { return FAILED; } - status = this->ike_sa_id->clone(this->ike_sa_id,ike_sa_id); - return status; + this->ike_sa_id->clone(this->ike_sa_id,ike_sa_id); + return SUCCESS; } - /** - * Implements message_t's set_message_id function. - * See #message_s.set_message_id. + * Implementation of message_t.set_message_id. */ -static status_t set_message_id (private_message_t *this,u_int32_t message_id) +static void set_message_id (private_message_t *this,u_int32_t message_id) { this->message_id = message_id; - return SUCCESS; } - /** - * Implements message_t's set_message_id function. - * See #message_s.set_message_id. + * Implementation of message_t.get_message_id. */ static u_int32_t get_message_id (private_message_t *this) { @@ -297,8 +287,7 @@ static u_int32_t get_message_id (private_message_t *this) } /** - * Implements message_t's get_responder_spi function. - * See #message_s.get_responder_spi. + * Implementation of message_t.get_responder_spi. */ static u_int64_t get_responder_spi (private_message_t *this) { @@ -306,19 +295,16 @@ static u_int64_t get_responder_spi (private_message_t *this) } /** - * Implements message_t's set_major_version function. - * See #message_s.set_major_version. + * Implementation of message_t.set_major_version. */ -static status_t set_major_version (private_message_t *this,u_int8_t major_version) +static void set_major_version (private_message_t *this,u_int8_t major_version) { this->major_version = major_version; - return SUCCESS; } /** - * Implements message_t's get_major_version function. - * See #message_s.get_major_version. + * Implementation of message_t.set_major_version. */ static u_int8_t get_major_version (private_message_t *this) { @@ -326,19 +312,15 @@ static u_int8_t get_major_version (private_message_t *this) } /** - * Implements message_t's set_minor_version function. - * See #message_s.set_minor_version. + * Implementation of message_t.set_minor_version. */ -static status_t set_minor_version (private_message_t *this,u_int8_t minor_version) +static void set_minor_version (private_message_t *this,u_int8_t minor_version) { this->minor_version = minor_version; - return SUCCESS; } - /** - * Implements message_t's get_minor_version function. - * See #message_s.get_minor_version. + * Implementation of message_t.get_minor_version. */ static u_int8_t get_minor_version (private_message_t *this) { @@ -346,58 +328,50 @@ static u_int8_t get_minor_version (private_message_t *this) } /** - * Implements message_t's set_exchange_type function. - * See #message_s.set_exchange_type. + * Implementation of message_t.set_exchange_type. */ -static status_t set_exchange_type (private_message_t *this,exchange_type_t exchange_type) +static void set_exchange_type (private_message_t *this,exchange_type_t exchange_type) { this->exchange_type = exchange_type; - return SUCCESS; } - /** - * Implements message_t's get_exchange_type function. - * See #message_s.get_exchange_type. + * Implementation of message_t.get_exchange_type. */ static exchange_type_t get_exchange_type (private_message_t *this) { return this->exchange_type; } - /** - * Implements message_t's set_request function. - * See #message_s.set_request. + * Implementation of message_t.set_request. */ -static status_t set_request (private_message_t *this,bool request) +static void set_request (private_message_t *this,bool request) { this->is_request = request; - return SUCCESS; } /** - * Implements message_t's get_request function. - * See #message_s.get_request. + * Implementation of message_t.get_request. */ static exchange_type_t get_request (private_message_t *this) { return this->is_request; } -static status_t add_payload(private_message_t *this, payload_t *payload) +/** + * Implementation of message_t.add_payload. + */ +static void add_payload(private_message_t *this, payload_t *payload) { payload_t *last_payload; - if ((this->payloads->get_count(this->payloads) > 0) && - (this->payloads->get_last(this->payloads,(void **) &last_payload) != SUCCESS)) + if (this->payloads->get_count(this->payloads) > 0) { - return OUT_OF_RES; + this->payloads->get_last(this->payloads,(void **) &last_payload); } - if (this->payloads->insert_last(this->payloads, payload) != SUCCESS) - { - return OUT_OF_RES; - } + this->payloads->insert_last(this->payloads, payload); + if (this->payloads->get_count(this->payloads) == 1) { this->first_payload = payload->get_type(payload); @@ -410,51 +384,59 @@ static status_t add_payload(private_message_t *this, payload_t *payload) this->logger->log(this->logger, CONTROL|MORE, "added payload of type %s to message", mapping_find(payload_type_m, payload->get_type(payload))); - return SUCCESS; } -static status_t set_source(private_message_t *this, host_t *host) +/** + * Implementation of message_t.set_source. + */ +static void set_source(private_message_t *this, host_t *host) { if (this->packet->source != NULL) { this->packet->source->destroy(this->packet->source); } this->packet->source = host; - return SUCCESS; } -static status_t set_destination(private_message_t *this, host_t *host) +/** + * Implementation of message_t.set_destination. + */ +static void set_destination(private_message_t *this, host_t *host) { if (this->packet->destination != NULL) { this->packet->destination->destroy(this->packet->destination); } this->packet->destination = host; - return SUCCESS; } -static status_t get_source(private_message_t *this, host_t **host) +/** + * Implementation of message_t.get_source. + */ +static void get_source(private_message_t *this, host_t **host) { *host = this->packet->source; - return SUCCESS; } -static status_t get_destination(private_message_t *this, host_t **host) +/** + * Implementation of message_t.get_destination. + */ +static void get_destination(private_message_t *this, host_t **host) { *host = this->packet->destination; - return SUCCESS; } - -static status_t get_payload_iterator(private_message_t *this, iterator_t **iterator) +/** + * Implementation of message_t.get_destination. + */ +static void get_payload_iterator(private_message_t *this, iterator_t **iterator) { - return this->payloads->create_iterator(this->payloads, iterator, TRUE); + this->payloads->create_iterator(this->payloads, iterator, TRUE); } /** - * Implements message_t's generate function. - * See #message_s.generate. + * Implementation of message_t.generate. */ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* signer, packet_t **packet) { @@ -483,11 +465,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* /* build ike header */ ike_header = ike_header_create(); - if (ike_header == NULL) - { - return OUT_OF_RES; - } - + ike_header->set_exchange_type(ike_header, this->exchange_type); ike_header->set_message_id(ike_header, this->message_id); ike_header->set_response_flag(ike_header, !this->is_request); @@ -496,19 +474,11 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* ike_header->set_responder_spi(ike_header, this->ike_sa_id->get_responder_spi(this->ike_sa_id)); generator = generator_create(); - if (generator == NULL) - { - return OUT_OF_RES; - } payload = (payload_t*)ike_header; - if (this->payloads->create_iterator(this->payloads, &iterator, TRUE) != SUCCESS) - { - generator->destroy(generator); - ike_header->destroy(ike_header); - return OUT_OF_RES; - } + this->payloads->create_iterator(this->payloads, &iterator, TRUE); + /* generate every payload, except last one */ while(iterator->has_next(iterator)) { @@ -602,12 +572,7 @@ static status_t parse_header(private_message_t *this) this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header), ike_header->get_responder_spi(ike_header), ike_header->get_initiator_flag(ike_header)); - if (this->ike_sa_id == NULL) - { - this->logger->log(this->logger, ERROR, "could not create ike_sa_id object"); - ike_header->destroy(ike_header); - return OUT_OF_RES; - } + this->exchange_type = ike_header->get_exchange_type(ike_header); this->message_id = ike_header->get_message_id(ike_header); this->is_request = (!(ike_header->get_response_flag(ike_header))); @@ -708,13 +673,8 @@ static status_t verify(private_message_t *this) return status; } - status = this->payloads->create_iterator(this->payloads,&iterator,TRUE); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not create iterator to check supported payloads"); - return status; - } - + this->payloads->create_iterator(this->payloads,&iterator,TRUE); + /* check for payloads with wrong count*/ for (i = 0; i < supported_payloads_count;i++) { @@ -728,13 +688,8 @@ static status_t verify(private_message_t *this) while(iterator->has_next(iterator)) { payload_t *current_payload; - status = iterator->current(iterator,(void **)¤t_payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not get payload from internal list"); - iterator->destroy(iterator); - return OUT_OF_RES; - } + iterator->current(iterator,(void **)¤t_payload); + if (current_payload->get_type(current_payload) == payload_type) { found_payloads++; @@ -765,7 +720,7 @@ static status_t verify(private_message_t *this) * Implements message_t's destroy function. * See #message_s.destroy. */ -static status_t destroy (private_message_t *this) +static void destroy (private_message_t *this) { iterator_t *iterator; @@ -791,7 +746,6 @@ static status_t destroy (private_message_t *this) global_logger_manager->destroy_logger(global_logger_manager, this->logger); allocator_free(this); - return SUCCESS; } /* @@ -806,30 +760,30 @@ message_t *message_create_from_packet(packet_t *packet) } /* public functions */ - this->public.set_major_version = (status_t(*)(message_t*, u_int8_t))set_major_version; + this->public.set_major_version = (void(*)(message_t*, u_int8_t))set_major_version; this->public.get_major_version = (u_int8_t(*)(message_t*))get_major_version; - this->public.set_minor_version = (status_t(*)(message_t*, u_int8_t))set_minor_version; + this->public.set_minor_version = (void(*)(message_t*, u_int8_t))set_minor_version; this->public.get_minor_version = (u_int8_t(*)(message_t*))get_minor_version; - this->public.set_message_id = (status_t(*)(message_t*, u_int32_t))set_message_id; + this->public.set_message_id = (void(*)(message_t*, u_int32_t))set_message_id; this->public.get_message_id = (u_int32_t(*)(message_t*))get_message_id; this->public.get_responder_spi = (u_int64_t(*)(message_t*))get_responder_spi; - this->public.set_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t *))set_ike_sa_id; + this->public.set_ike_sa_id = (void(*)(message_t*, ike_sa_id_t *))set_ike_sa_id; this->public.get_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t **))get_ike_sa_id; - this->public.set_exchange_type = (status_t(*)(message_t*, exchange_type_t))set_exchange_type; + this->public.set_exchange_type = (void(*)(message_t*, exchange_type_t))set_exchange_type; this->public.get_exchange_type = (exchange_type_t(*)(message_t*))get_exchange_type; - this->public.set_request = (status_t(*)(message_t*, bool))set_request; + this->public.set_request = (void(*)(message_t*, bool))set_request; this->public.get_request = (bool(*)(message_t*))get_request; - this->public.add_payload = (status_t(*)(message_t*,payload_t*))add_payload; + this->public.add_payload = (void(*)(message_t*,payload_t*))add_payload; this->public.generate = (status_t (*) (message_t *,crypter_t*,signer_t*,packet_t**)) generate; - this->public.set_source = (status_t (*) (message_t*,host_t*)) set_source; - this->public.get_source = (status_t (*) (message_t*,host_t**)) get_source; - this->public.set_destination = (status_t (*) (message_t*,host_t*)) set_destination; - this->public.get_destination = (status_t (*) (message_t*,host_t**)) get_destination; - this->public.get_payload_iterator = (status_t (*) (message_t *, iterator_t **)) get_payload_iterator; + this->public.set_source = (void (*) (message_t*,host_t*)) set_source; + this->public.get_source = (void (*) (message_t*,host_t**)) get_source; + this->public.set_destination = (void (*) (message_t*,host_t*)) set_destination; + this->public.get_destination = (void (*) (message_t*,host_t**)) get_destination; + this->public.get_payload_iterator = (void (*) (message_t *, iterator_t **)) get_payload_iterator; this->public.parse_header = (status_t (*) (message_t *)) parse_header; this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body; this->public.verify = (status_t (*) (message_t*)) verify; - this->public.destroy = (status_t(*)(message_t*))destroy; + this->public.destroy = (void(*)(message_t*))destroy; /* public values */ this->exchange_type = EXCHANGE_TYPE_UNDEFINED; diff --git a/Source/charon/encoding/message.h b/Source/charon/encoding/message.h index 19c00bb..8ee0695 100644 --- a/Source/charon/encoding/message.h +++ b/Source/charon/encoding/message.h @@ -1,7 +1,7 @@ /** * @file message.h * - * @brief Class message_t. Object of this type represents an IKEv2-Message. + * @brief Interface of message_t. * */ @@ -38,6 +38,8 @@ typedef struct message_t message_t; * @brief This class is used to represent an IKEv2-Message. * * An IKEv2-Message is either a request or response. + * + * @ingroup encoding */ struct message_t { @@ -46,9 +48,8 @@ struct message_t { * * @param this message_t object * @param major_version major version to set - * @return SUCCESS */ - status_t (*set_major_version) (message_t *this,u_int8_t major_version); + void (*set_major_version) (message_t *this,u_int8_t major_version); /** * @brief Gets the IKE major version of the message. @@ -63,9 +64,8 @@ struct message_t { * * @param this message_t object * @param minor_version minor version to set - * @return SUCCESS */ - status_t (*set_minor_version) (message_t *this,u_int8_t minor_version); + void (*set_minor_version) (message_t *this,u_int8_t minor_version); /** * @brief Gets the IKE minor version of the message. @@ -80,9 +80,8 @@ struct message_t { * * @param this message_t object * @param message_id message_id to set - * @return SUCCESS */ - status_t (*set_message_id) (message_t *this,u_int32_t message_id); + void (*set_message_id) (message_t *this,u_int32_t message_id); /** * @brief Gets the Message ID of the message. @@ -108,12 +107,8 @@ struct message_t { * * @param this message_t object * @param ike_sa_id ike_sa_id to set - * @return - * - SUCCESS - * - OUT_OF_RES - * @return SUCCESS */ - status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id); + void (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id); /** * @brief Gets the IKE_SA ID of the message. @@ -125,7 +120,6 @@ struct message_t { * @param ike_sa_id pointer to ike_sa_id pointer which will be set * @return * - SUCCESS - * - OUT_OF_RES * - FAILED if no ike_sa_id is set */ status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id); @@ -135,9 +129,8 @@ struct message_t { * * @param this message_t object * @param exchange_type exchange_type to set - * @return SUCCESS */ - status_t (*set_exchange_type) (message_t *this,exchange_type_t exchange_type); + void (*set_exchange_type) (message_t *this,exchange_type_t exchange_type); /** * @brief Gets the exchange type of the message. @@ -152,9 +145,8 @@ struct message_t { * * @param this message_t object * @param original_initiator TRUE if message is from original initiator - * @return SUCCESS */ - status_t (*set_original_initiator) (message_t *this,bool original_initiator); + void (*set_original_initiator) (message_t *this,bool original_initiator); /** * @brief Gets original initiator flag. @@ -169,9 +161,8 @@ struct message_t { * * @param this message_t object * @param original_initiator TRUE if message is a request, FALSE if it is a reply - * @return SUCCESS */ - status_t (*set_request) (message_t *this,bool request); + void (*set_request) (message_t *this,bool request); /** * @brief Gets request flag. @@ -188,9 +179,8 @@ struct message_t { * @param payload payload to append * @return * - SUCCESS or - * - OUT_OF_RES */ - status_t (*add_payload) (message_t *this, payload_t *payload); + void (*add_payload) (message_t *this, payload_t *payload); /** * @brief Parses header of message @@ -198,7 +188,6 @@ struct message_t { * @param this message_t object * @return * - SUCCESS if header could be parsed - * - OUT_OF_RES if out of ressources * - PARSE_ERROR if corrupted/invalid data found * - FAILED if consistence check of header failed */ @@ -215,7 +204,6 @@ struct message_t { * @return * - SUCCESS if header could be parsed * - NOT_SUPPORTED if unsupported payload are contained in body - * - OUT_OF_RES if out of ressources * - FAILED if message type is not suppported! * - PARSE_ERROR if corrupted/invalid data found * - VERIFY_ERROR if verification of some payload failed @@ -234,19 +222,18 @@ struct message_t { status_t (*generate) (message_t *this, crypter_t *crypter, signer_t *signer, packet_t **packet); status_t (*verify) (message_t *this); - status_t (*get_source) (message_t *this, host_t **host); - status_t (*set_source) (message_t *this, host_t *host); - status_t (*get_destination) (message_t *this, host_t **host); - status_t (*set_destination) (message_t *this, host_t *host); - status_t (*get_payload_iterator) (message_t *this, iterator_t **iterator); + void (*get_source) (message_t *this, host_t **host); + void (*set_source) (message_t *this, host_t *host); + void (*get_destination) (message_t *this, host_t **host); + void (*set_destination) (message_t *this, host_t *host); + void (*get_payload_iterator) (message_t *this, iterator_t **iterator); /** * @brief Destroys a message and all including objects * * @param this message_t object - * @return SUCCESS */ - status_t (*destroy) (message_t *this); + void (*destroy) (message_t *this); }; /** @@ -263,9 +250,9 @@ struct message_t { * * @param packet packet_t object which is assigned to message * - * @return - * - created message_t object - * - NULL if out of ressources + * @return created message_t object + * + * @ingroup encoding */ message_t * message_create_from_packet(packet_t *packet); @@ -277,9 +264,9 @@ message_t * message_create_from_packet(packet_t *packet); * - original_initiator is set to TRUE * - is_request is set to TRUE * - * @return - * - created message_t object - * - NULL if out of ressources + * @return created message_t object + * + * @ingroup encoding */ message_t * message_create(); diff --git a/Source/charon/sa/ike_sa.c b/Source/charon/sa/ike_sa.c index cd2a666..2b1fe94 100644 --- a/Source/charon/sa/ike_sa.c +++ b/Source/charon/sa/ike_sa.c @@ -303,14 +303,8 @@ static status_t build_message(private_ike_sa_t *this, exchange_type_t type, bool new_message->set_message_id(new_message, (request) ? this->message_id_out : this->message_id_in); - status = new_message->set_ike_sa_id(new_message, this->ike_sa_id); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Fatal error: could not set ike_sa_id of message"); - new_message->destroy(new_message); - return status; - } - + new_message->set_ike_sa_id(new_message, this->ike_sa_id); + *message = new_message; return SUCCESS; diff --git a/Source/charon/sa/states/ike_sa_init_requested.c b/Source/charon/sa/states/ike_sa_init_requested.c index 2db9336..4f79143 100644 --- a/Source/charon/sa/states/ike_sa_init_requested.c +++ b/Source/charon/sa/states/ike_sa_init_requested.c @@ -120,12 +120,7 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t ike_sa_id->set_responder_spi(ike_sa_id,responder_spi); /* iterate over incoming payloads */ - status = message->get_payload_iterator(message, &payloads); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not create payload interator"); - return status; - } + message->get_payload_iterator(message, &payloads); while (payloads->has_next(payloads)) { payload_t *payload; diff --git a/Source/charon/sa/states/initiator_init.c b/Source/charon/sa/states/initiator_init.c index 68413c1..1ffc324 100644 --- a/Source/charon/sa/states/initiator_init.c +++ b/Source/charon/sa/states/initiator_init.c @@ -318,14 +318,7 @@ static status_t build_ike_sa_init_request (private_initiator_init_t *this, messa } this ->logger->log(this->logger, CONTROL|MOST, "add SA payload to message"); - status = message->add_payload(message, payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not add SA payload to message"); - payload->destroy(payload); - message->destroy(message); - return status; - } + message->add_payload(message, payload); /* build KE payload */ status = this->build_ke_payload(this, &payload); @@ -337,14 +330,7 @@ static status_t build_ike_sa_init_request (private_initiator_init_t *this, messa } this ->logger->log(this->logger, CONTROL|MOST, "add KE payload to message"); - status = message->add_payload(message, payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not add KE payload to message"); - payload->destroy(payload); - message->destroy(message); - return status; - } + message->add_payload(message, payload); /* build Nonce payload */ status = this->build_nonce_payload(this, &payload); @@ -356,14 +342,7 @@ static status_t build_ike_sa_init_request (private_initiator_init_t *this, messa } this ->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message"); - status = message->add_payload(message, payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not add nonce payload to message"); - payload->destroy(payload); - message->destroy(message); - return status; - } + message->add_payload(message, payload); *request = message; return SUCCESS; diff --git a/Source/charon/sa/states/responder_init.c b/Source/charon/sa/states/responder_init.c index 03fd08a..0d93a5b 100644 --- a/Source/charon/sa/states/responder_init.c +++ b/Source/charon/sa/states/responder_init.c @@ -202,12 +202,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa } /* iterate over incoming payloads. We can be sure, the message contains only accepted payloads! */ - status = message->get_payload_iterator(message, &payloads); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Fatal error: Could not get payload interator"); - return status; - } + message->get_payload_iterator(message, &payloads); while (payloads->has_next(payloads)) { @@ -412,12 +407,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa } this->logger->log(this->logger, CONTROL|MOST, "add SA payload to message"); - status = response->add_payload(response, payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not add SA payload to message"); - return status; - } + response->add_payload(response, payload); /* build KE payload */ status = this->build_ke_payload(this,&payload); @@ -428,12 +418,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa } this->logger->log(this->logger, CONTROL|MOST, "add KE payload to message"); - status = response->add_payload(response, payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not add KE payload to message"); - return status; - } + response->add_payload(response, payload); /* build Nonce payload */ status = this->build_nonce_payload(this, &payload); @@ -444,12 +429,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa } this->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message"); - status = response->add_payload(response, payload); - if (status != SUCCESS) - { - this->logger->log(this->logger, ERROR, "Could not add nonce payload to message"); - return status; - } + response->add_payload(response, payload); /* generate packet */ this->logger->log(this->logger, CONTROL|MOST, "generate packet from message"); -- 2.7.4