diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-28 16:55:46 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-28 16:55:46 +0000 |
commit | 27e432056b0d3eaaf5e938b3df9be2169e421275 (patch) | |
tree | 37611d89808c874aa3f3feaf3e965d6f16e9db5a /Source/charon/encoding/message.c | |
parent | 0f30f5686a8baace9da905071c32e2575913e33e (diff) | |
download | strongswan-27e432056b0d3eaaf5e938b3df9be2169e421275.tar.bz2 strongswan-27e432056b0d3eaaf5e938b3df9be2169e421275.tar.xz |
- memory allocation checks removed
Diffstat (limited to 'Source/charon/encoding/message.c')
-rw-r--r-- | Source/charon/encoding/message.c | 258 |
1 files changed, 106 insertions, 152 deletions
diff --git a/Source/charon/encoding/message.c b/Source/charon/encoding/message.c index 5fb6fa33d..5f949dfa8 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; |