Skip to content

Commit 078bd0d

Browse files
author
Antti Kauppila
authored
Merge pull request #32 from ARMmbed/coap-option-tidy
Coap option tidy
2 parents 70447c3 + bc636c0 commit 078bd0d

File tree

5 files changed

+22
-56
lines changed

5 files changed

+22
-56
lines changed

module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"dependencies": {
2121
"nanostack-libservice": "^3.0.0",
22-
"mbed-client-c": "^2.0.0",
22+
"mbed-client-c": "^3.0.0",
2323
"sal-stack-nanostack": "^5.0.0",
2424
"mbedtls": "^2.0.0"
2525
},

source/coap_message_handler.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
294294
data_len = sn_coap_builder_calc_needed_packet_data_size(&request);
295295
data_ptr = own_alloc(data_len);
296296
if(data_len > 0 && !data_ptr){
297-
own_free(request.content_type_ptr);
298297
transaction_delete(transaction_ptr);
299298
return 0;
300299
}
@@ -303,7 +302,6 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
303302
handle->sn_coap_tx_callback(data_ptr, data_len, &dst_addr, transaction_ptr);
304303

305304
// Free allocated data
306-
own_free(request.content_type_ptr);
307305
own_free(data_ptr);
308306
if(request_response_cb == NULL){
309307
//No response expected
@@ -373,26 +371,19 @@ int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_ti
373371

374372
static void coap_service_build_content_format(sn_coap_hdr_s *header, sn_coap_content_format_e format)
375373
{
376-
if (format == COAP_CT_NONE) {
377-
return;
378-
}
379-
380-
/* Always alloc - CoAP library needs a non-NULL pointer to trigger writing
381-
* of a zero-length option, and it will free the pointer later.
382-
*/
383-
header->content_type_ptr = own_alloc(2);
384-
if (!header->content_type_ptr) {
385-
return;
386-
}
387-
388-
if (format == 0) { /* text/plain */
389-
header->content_type_len = 0;
390-
} else if (format <= 0xff) {
391-
header->content_type_ptr[0] = format;
392-
header->content_type_len = 1;
393-
} else {
394-
header->content_type_ptr[0] = format >> 8;
395-
header->content_type_ptr[1] = format & 0xff;
396-
header->content_type_len = 2;
397-
}
374+
header->content_format = format;
375+
376+
// if (format == COAP_CT_NONE) {
377+
// return;
378+
// }
379+
// if (format == 0) { /* text/plain */
380+
// header->content_type_len = 0;
381+
// } else if (format <= 0xff) {
382+
// header->content_type_ptr[0] = format;
383+
// header->content_type_len = 1;
384+
// } else {
385+
// header->content_type_ptr[0] = format >> 8;
386+
// header->content_type_ptr[1] = format & 0xff;
387+
// header->content_type_len = 2;
388+
// }
398389
}

test/coap-service/unittest/coap_message_handler/test_coap_message_handler.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr){
3939

4040
int16_t process_cb(int8_t a, sn_coap_hdr_s *b, coap_transaction_t *c)
4141
{
42-
42+
return retValue;
4343
}
4444

4545
bool test_coap_message_handler_init()
@@ -140,11 +140,12 @@ bool test_coap_message_handler_coap_msg_process()
140140
memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
141141
sn_coap_protocol_stub.expectedHeader->coap_status = COAP_STATUS_OK;
142142
sn_coap_protocol_stub.expectedHeader->msg_code = 1;
143-
retValue = -1;
143+
retValue = 0;
144144
if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb))
145145
return false;
146146

147147
nsdynmemlib_stub.returnCounter = 1;
148+
retValue = -1;
148149
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb))
149150
return false;
150151

@@ -265,13 +266,13 @@ bool test_coap_message_handler_response_send()
265266

266267
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
267268
memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
268-
nsdynmemlib_stub.returnCounter = 1;
269+
nsdynmemlib_stub.returnCounter = 0;
269270
if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
270271
return false;
271272

272273
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
273274
memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
274-
nsdynmemlib_stub.returnCounter = 2;
275+
nsdynmemlib_stub.returnCounter = 1;
275276
if( 0 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
276277
return false;
277278

test/coap-service/unittest/stub/coap_message_handler_stub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" {
2323
#endif
2424

2525
#include <inttypes.h>
26+
#include <stdbool.h>
2627
#include "coap_message_handler.h"
2728

2829
typedef struct {

test/coap-service/unittest/stub/sn_coap_parser_stub.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@ void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coa
3434
free(freed_coap_msg_ptr->token_ptr);
3535
}
3636

37-
if (freed_coap_msg_ptr->content_type_ptr != NULL) {
38-
free(freed_coap_msg_ptr->content_type_ptr);
39-
}
40-
4137
if (freed_coap_msg_ptr->options_list_ptr != NULL) {
42-
if (freed_coap_msg_ptr->options_list_ptr->max_age_ptr != NULL) {
43-
free(freed_coap_msg_ptr->options_list_ptr->max_age_ptr);
44-
}
45-
4638
if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) {
4739
free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr);
4840
}
@@ -59,33 +51,14 @@ void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coa
5951
free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr);
6052
}
6153

62-
if (freed_coap_msg_ptr->options_list_ptr->uri_port_ptr != NULL) {
63-
free(freed_coap_msg_ptr->options_list_ptr->uri_port_ptr);
64-
}
65-
6654
if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) {
6755
free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr);
6856
}
6957

70-
if (freed_coap_msg_ptr->options_list_ptr->observe_ptr != NULL) {
71-
free(freed_coap_msg_ptr->options_list_ptr->observe_ptr);
72-
}
73-
7458
if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) {
7559
free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr);
7660
}
7761

78-
if (freed_coap_msg_ptr->options_list_ptr->block2_ptr != NULL) {
79-
free(freed_coap_msg_ptr->options_list_ptr->block2_ptr);
80-
}
81-
82-
if (freed_coap_msg_ptr->options_list_ptr->block1_ptr != NULL) {
83-
free(freed_coap_msg_ptr->options_list_ptr->block1_ptr);
84-
}
85-
if (freed_coap_msg_ptr->options_list_ptr->accept_ptr != NULL) {
86-
free(freed_coap_msg_ptr->options_list_ptr->accept_ptr);
87-
}
88-
8962
free(freed_coap_msg_ptr->options_list_ptr);
9063
}
9164

0 commit comments

Comments
 (0)