New CoAP changes updated to this library

Unittests updated also
pull/3240/head
Antti Kauppila 2016-09-08 18:13:26 +03:00
parent 70447c3e35
commit 73d5163e4e
4 changed files with 20 additions and 54 deletions

View File

@ -294,7 +294,6 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
data_len = sn_coap_builder_calc_needed_packet_data_size(&request);
data_ptr = own_alloc(data_len);
if(data_len > 0 && !data_ptr){
own_free(request.content_type_ptr);
transaction_delete(transaction_ptr);
return 0;
}
@ -303,7 +302,6 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
handle->sn_coap_tx_callback(data_ptr, data_len, &dst_addr, transaction_ptr);
// Free allocated data
own_free(request.content_type_ptr);
own_free(data_ptr);
if(request_response_cb == NULL){
//No response expected
@ -373,26 +371,19 @@ int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_ti
static void coap_service_build_content_format(sn_coap_hdr_s *header, sn_coap_content_format_e format)
{
if (format == COAP_CT_NONE) {
return;
}
header->content_format = format;
/* Always alloc - CoAP library needs a non-NULL pointer to trigger writing
* of a zero-length option, and it will free the pointer later.
*/
header->content_type_ptr = own_alloc(2);
if (!header->content_type_ptr) {
return;
}
if (format == 0) { /* text/plain */
header->content_type_len = 0;
} else if (format <= 0xff) {
header->content_type_ptr[0] = format;
header->content_type_len = 1;
} else {
header->content_type_ptr[0] = format >> 8;
header->content_type_ptr[1] = format & 0xff;
header->content_type_len = 2;
}
// if (format == COAP_CT_NONE) {
// return;
// }
// if (format == 0) { /* text/plain */
// header->content_type_len = 0;
// } else if (format <= 0xff) {
// header->content_type_ptr[0] = format;
// header->content_type_len = 1;
// } else {
// header->content_type_ptr[0] = format >> 8;
// header->content_type_ptr[1] = format & 0xff;
// header->content_type_len = 2;
// }
}

View File

@ -39,7 +39,7 @@ int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr){
int16_t process_cb(int8_t a, sn_coap_hdr_s *b, coap_transaction_t *c)
{
return retValue;
}
bool test_coap_message_handler_init()
@ -140,11 +140,12 @@ bool test_coap_message_handler_coap_msg_process()
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
sn_coap_protocol_stub.expectedHeader->coap_status = COAP_STATUS_OK;
sn_coap_protocol_stub.expectedHeader->msg_code = 1;
retValue = -1;
retValue = 0;
if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb))
return false;
nsdynmemlib_stub.returnCounter = 1;
retValue = -1;
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb))
return false;
@ -265,13 +266,13 @@ bool test_coap_message_handler_response_send()
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
nsdynmemlib_stub.returnCounter = 1;
nsdynmemlib_stub.returnCounter = 0;
if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
return false;
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
nsdynmemlib_stub.returnCounter = 2;
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
return false;

View File

@ -23,6 +23,7 @@ extern "C" {
#endif
#include <inttypes.h>
#include <stdbool.h>
#include "coap_message_handler.h"
typedef struct {

View File

@ -34,15 +34,7 @@ void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coa
free(freed_coap_msg_ptr->token_ptr);
}
if (freed_coap_msg_ptr->content_type_ptr != NULL) {
free(freed_coap_msg_ptr->content_type_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr != NULL) {
if (freed_coap_msg_ptr->options_list_ptr->max_age_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->max_age_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr);
}
@ -59,33 +51,14 @@ void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coa
free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->uri_port_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->uri_port_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->observe_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->observe_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->block2_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->block2_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->block1_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->block1_ptr);
}
if (freed_coap_msg_ptr->options_list_ptr->accept_ptr != NULL) {
free(freed_coap_msg_ptr->options_list_ptr->accept_ptr);
}
free(freed_coap_msg_ptr->options_list_ptr);
}