Commit 07ee66c6 authored by Kishen Maloor's avatar Kishen Maloor

Merge branch 'gaborone+' into hollywood

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parents 507da634 a268abe9
Pipeline #1131 passed with stage
in 4 minutes and 47 seconds
......@@ -76,9 +76,7 @@ oc_blockwise_free_buffer(oc_list_t list, struct oc_memb *pool,
return;
}
if (oc_string_len(buffer->uri_query) > 0) {
oc_free_string(&buffer->uri_query);
}
oc_free_string(&buffer->uri_query);
oc_free_string(&buffer->href);
oc_list_remove(list, buffer);
#ifdef OC_DYNAMIC_ALLOCATION
......
......@@ -134,9 +134,9 @@ prepare_coap_request(oc_client_cb_t *cb)
return false;
}
#ifndef OC_BLOCK_WISE
oc_rep_new(transaction->message->data + COAP_MAX_HEADER_SIZE, OC_BLOCK_SIZE);
#else /* !OC_BLOCK_WISE */
#ifdef OC_BLOCK_WISE
if (cb->method == OC_PUT || cb->method == OC_POST) {
request_buffer = oc_blockwise_alloc_request_buffer(
oc_string(cb->uri) + 1, oc_string_len(cb->uri) - 1, &cb->endpoint,
......@@ -603,9 +603,8 @@ oc_do_site_local_ipv6_discovery(const char *rt, oc_discovery_handler_t handler,
}
bool status = multi_scope_ipv6_discovery(NULL, 0x05, oc_string(uri_query),
handlers, user_data);
if (oc_string_len(uri_query) > 0) {
oc_free_string(&uri_query);
}
oc_free_string(&uri_query);
return status;
}
......@@ -633,9 +632,8 @@ oc_do_realm_local_ipv6_discovery(const char *rt, oc_discovery_handler_t handler,
}
bool status = multi_scope_ipv6_discovery(NULL, 0x03, oc_string(uri_query),
handlers, user_data);
if (oc_string_len(uri_query) > 0) {
oc_free_string(&uri_query);
}
oc_free_string(&uri_query);
return status;
}
......@@ -657,9 +655,8 @@ oc_do_ip_discovery(const char *rt, oc_discovery_handler_t handler,
#endif
bool status = multi_scope_ipv6_discovery(cb4, 0x02, oc_string(uri_query),
handlers, user_data);
if (oc_string_len(uri_query) > 0) {
oc_free_string(&uri_query);
}
oc_free_string(&uri_query);
return status;
}
......@@ -700,9 +697,8 @@ oc_do_ip_discovery_at_endpoint(const char *rt, oc_discovery_handler_t handler,
}
bool status = dispatch_ip_discovery(NULL, oc_string(uri_query), handlers,
endpoint, user_data);
if (oc_string_len(uri_query) > 0) {
oc_free_string(&uri_query);
}
oc_free_string(&uri_query);
return status;
}
......
......@@ -77,12 +77,9 @@ oc_core_free_device_info_properties(oc_device_info_t *oc_device_info_item)
{
if (oc_device_info_item) {
if (oc_string_len(oc_device_info_item->name))
oc_free_string(&(oc_device_info_item->name));
if (oc_string_len(oc_device_info_item->icv))
oc_free_string(&(oc_device_info_item->icv));
if (oc_string_len(oc_device_info_item->dmv))
oc_free_string(&(oc_device_info_item->dmv));
oc_free_string(&(oc_device_info_item->name));
oc_free_string(&(oc_device_info_item->icv));
oc_free_string(&(oc_device_info_item->dmv));
}
}
......@@ -90,8 +87,7 @@ void
oc_core_shutdown(void)
{
size_t i;
if (oc_string_len(oc_platform_info.mfg_name))
oc_free_string(&(oc_platform_info.mfg_name));
oc_free_string(&(oc_platform_info.mfg_name));
#ifdef OC_DYNAMIC_ALLOCATION
if (oc_device_info) {
......
......@@ -472,15 +472,13 @@ oc_parse_endpoint_string(oc_string_t *endpoint_str, oc_endpoint_t *endpoint,
#else /* OC_IPV4 */
else {
#ifdef OC_DNS_LOOKUP
if (oc_string_len(ipaddress) > 0)
oc_free_string(&ipaddress);
oc_free_string(&ipaddress);
#endif /* OC_DNS_LOOKUP */
return -1;
}
#endif /* !OC_IPV4 */
#ifdef OC_DNS_LOOKUP
if (oc_string_len(ipaddress) > 0)
oc_free_string(&ipaddress);
oc_free_string(&ipaddress);
#endif /* OC_DNS_LOOKUP */
return 0;
}
......
......@@ -95,11 +95,13 @@ _oc_free_string(
#endif
oc_string_t *ocstring)
{
oc_free(
if (ocstring && ocstring->size > 0) {
oc_free(
#ifdef OC_MEMORY_TRACE
func,
func,
#endif
ocstring, BYTE_POOL);
ocstring, BYTE_POOL);
}
}
void
......
......@@ -381,12 +381,8 @@ void
oc_ri_free_resource_properties(oc_resource_t *resource)
{
if (resource) {
if (oc_string_len(resource->name) > 0) {
oc_free_string(&(resource->name));
}
if (oc_string_len(resource->uri) > 0) {
oc_free_string(&(resource->uri));
}
oc_free_string(&(resource->name));
oc_free_string(&(resource->uri));
if (oc_string_array_get_allocated_size(resource->types) > 0) {
oc_free_string_array(&(resource->types));
}
......@@ -1202,9 +1198,7 @@ free_client_cb(oc_client_cb_t *cb)
oc_blockwise_scrub_buffers_for_client_cb(cb);
#endif /* OC_BLOCK_WISE */
oc_free_string(&cb->uri);
if (oc_string_len(cb->query)) {
oc_free_string(&cb->query);
}
oc_free_string(&cb->query);
oc_memb_free(&client_cbs_s, cb);
}
......
......@@ -132,15 +132,9 @@ oc_swupdate_free(void)
for (i = 0; i < oc_core_get_num_devices(); i++) {
oc_swupdate_t *s = &sw[i];
oc_dump_sw(i);
if (oc_string_len(s->purl) > 0) {
oc_free_string(&s->purl);
}
if (oc_string_len(s->nv) > 0) {
oc_free_string(&s->nv);
}
if (oc_string_len(s->signage) > 0) {
oc_free_string(&s->signage);
}
oc_free_string(&s->purl);
oc_free_string(&s->nv);
oc_free_string(&s->signage);
}
#ifdef OC_DYNAMIC_ALLOCATION
if (sw) {
......@@ -218,10 +212,8 @@ oc_swupdate_notify_upgrading(size_t device, const char *version,
oc_swupdate_t *s = &sw[device];
s->swupdatestate = OC_SWUPDATE_STATE_UPGRADING;
s->swupdateresult = result;
if (oc_string_len(s->nv) > 0) {
oc_free_string(&s->nv);
oc_new_string(&s->nv, version, strlen(version));
}
oc_free_string(&s->nv);
oc_new_string(&s->nv, version, strlen(version));
s->lastupdate = timestamp;
#ifdef OC_SERVER
oc_notify_observers(oc_core_get_resource_by_index(OCF_SW_UPDATE, device));
......@@ -404,9 +396,7 @@ oc_swupdate_decode(oc_rep_t *rep, size_t device)
}
if (oc_string_len(rep->name) == 2 &&
memcmp(oc_string(rep->name), "nv", 2) == 0) {
if (oc_string_len(s->nv) > 0) {
oc_free_string(&s->nv);
}
oc_free_string(&s->nv);
if (oc_string_len(rep->value.string) > 0) {
oc_new_string(&s->nv, oc_string(rep->value.string),
oc_string_len(rep->value.string));
......@@ -414,9 +404,7 @@ oc_swupdate_decode(oc_rep_t *rep, size_t device)
}
if (oc_string_len(rep->name) == 4 &&
memcmp(oc_string(rep->name), "purl", 4) == 0) {
if (oc_string_len(s->purl) > 0) {
oc_free_string(&s->purl);
}
oc_free_string(&s->purl);
if (oc_string_len(rep->value.string) > 0) {
oc_new_string(&s->purl, oc_string(rep->value.string),
oc_string_len(rep->value.string));
......@@ -424,9 +412,7 @@ oc_swupdate_decode(oc_rep_t *rep, size_t device)
}
if (oc_string_len(rep->name) == 6 &&
memcmp(oc_string(rep->name), "signed", 6) == 0) {
if (oc_string_len(s->signage) > 0) {
oc_free_string(&s->signage);
}
oc_free_string(&s->signage);
if (oc_string_len(rep->value.string) > 0) {
oc_new_string(&s->signage, oc_string(rep->value.string),
oc_string_len(rep->value.string));
......@@ -466,16 +452,16 @@ oc_swupdate_decode(oc_rep_t *rep, size_t device)
/**
* post method for "/sw" resource.
* The function has as input the request body, which are the input values of the
* POST method.
* The input values (as a set) are checked if all supplied values are correct.
* If the input values are correct, they will be assigned to the global property
* values.
* Resource Description:
* Mechanism to schedule a start of the software update.
*
* @param requestRep the request representation.
*/
* The function has as input the request body, which are the input values of the
* POST method.
* The input values (as a set) are checked if all supplied values are correct.
* If the input values are correct, they will be assigned to the global property
* values.
* Resource Description:
* Mechanism to schedule a start of the software update.
*
* @param requestRep the request representation.
*/
static void
post_sw(oc_request_t *request, oc_interface_mask_t interfaces, void *user_data)
{
......@@ -587,17 +573,17 @@ post_sw(oc_request_t *request, oc_interface_mask_t interfaces, void *user_data)
}
/**
* get method for "/sw" resource.
* function is called to intialize the return values of the GET method.
* initialisation of the returned values are done from the global property
* values.
* Resource Description:
* The Resource performing scheduled software update.
*
* @param request the request representation.
* @param interfaces the interface used for this call
* @param user_data the user data.
*/
* get method for "/sw" resource.
* function is called to intialize the return values of the GET method.
* initialisation of the returned values are done from the global property
* values.
* Resource Description:
* The Resource performing scheduled software update.
*
* @param request the request representation.
* @param interfaces the interface used for this call
* @param user_data the user data.
*/
static void
get_sw(oc_request_t *request, oc_interface_mask_t interfaces, void *user_data)
......
......@@ -10,13 +10,15 @@
#ifdef __AVR__
#ifdef OC_XMEM
void extRAMinit(void)__attribute__ ((used, naked, section (".init3")));
void extRAMinit(void) {
// set up the xmem registers
XMCRB=0;
XMCRA=1<<SRE;
DDRD|=_BV(PD7);
DDRL|=(_BV(PL6)|_BV(PL7));
void extRAMinit(void) __attribute__((used, naked, section(".init3")));
void
extRAMinit(void)
{
// set up the xmem registers
XMCRB = 0;
XMCRA = 1 << SRE;
DDRD |= _BV(PD7);
DDRL |= (_BV(PL6) | _BV(PL7));
}
#endif
#endif
......@@ -66,8 +68,7 @@ observe_light(oc_client_response_t *data)
break;
case OC_REP_STRING:
OC_DBG("%s", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......@@ -159,8 +160,7 @@ get_light(oc_client_response_t *data)
break;
case OC_REP_STRING:
OC_DBG("%s", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......@@ -244,9 +244,9 @@ OC_PROCESS_THREAD(sample_client_process, ev, data)
{
(void)data;
static struct oc_etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
static const oc_handler_t handler = { .init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
static oc_clock_time_t next_event;
oc_set_mtu_size(1024);
oc_set_max_app_data_size(1024);
......@@ -255,32 +255,31 @@ OC_PROCESS_THREAD(sample_client_process, ev, data)
while (ev != OC_PROCESS_EVENT_EXIT) {
oc_etimer_set(&et, (oc_clock_time_t)next_event);
if(ev == OC_PROCESS_EVENT_INIT){
if (ev == OC_PROCESS_EVENT_INIT) {
int init = oc_main_init(&handler);
if (init < 0){
if (init < 0) {
OC_DBG("Client Init failed!");
return init;
}
OC_DBG("Client process init!");
}
else if(ev == OC_PROCESS_EVENT_TIMER){
} else if (ev == OC_PROCESS_EVENT_TIMER) {
next_event = oc_main_poll();
next_event -= oc_clock_time();
}
OC_PROCESS_WAIT_EVENT();
}
OC_PROCESS_END();
OC_PROCESS_END();
}
// Arduino Ethernet Shield
uint8_t ConnectToNetwork()
uint8_t
ConnectToNetwork()
{
// Note: ****Update the MAC address here with your shield's MAC address****
uint8_t ETHERNET_MAC[] = {0x90, 0xA2, 0xDA, 0x11, 0x44, 0xA9};
uint8_t ETHERNET_MAC[] = { 0x90, 0xA2, 0xDA, 0x11, 0x44, 0xA9 };
Ethernet.init(5); // CS Pin for MKRZERO
uint8_t error = Ethernet.begin(ETHERNET_MAC);
if (error == 0)
{
if (error == 0) {
OC_ERR("Error connecting to Network: %d", error);
return -1;
}
......@@ -289,18 +288,19 @@ uint8_t ConnectToNetwork()
return 0;
}
void setup() {
void
setup()
{
#if defined(__arm__) && defined(__SAMD21G18A__) || defined(__SAM3X8E__)
Serial.begin(250000);
Serial.begin(250000);
#else
Serial.begin(115200);
Serial.begin(115200);
#endif
#if defined(__SAMD21G18A__)
while (!Serial) {
}
#endif
if (ConnectToNetwork() != 0)
{
if (ConnectToNetwork() != 0) {
OC_ERR("Unable to connect to network");
return;
}
......@@ -312,7 +312,9 @@ void setup() {
delay(200);
}
void loop() {
void
loop()
{
oc_process_run();
}
......@@ -157,8 +157,7 @@ parse_payload(oc_client_response_t *data)
break;
case OC_REP_STRING:
printf("%s\n", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......
......@@ -70,8 +70,7 @@ observe_light(oc_client_response_t *data)
break;
case OC_REP_STRING:
PRINT("%s\n", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......@@ -163,8 +162,7 @@ get_light(oc_client_response_t *data)
break;
case OC_REP_STRING:
PRINT("%s\n", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......
......@@ -68,8 +68,7 @@ observe_light(oc_client_response_t *data)
break;
case OC_REP_STRING:
PRINT("%s\n", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......@@ -161,8 +160,7 @@ get_light(oc_client_response_t *data)
break;
case OC_REP_STRING:
PRINT("%s\n", oc_string(rep->value.string));
if (oc_string_len(name))
oc_free_string(&name);
oc_free_string(&name);
oc_new_string(&name, oc_string(rep->value.string),
oc_string_len(rep->value.string));
break;
......
......@@ -1271,7 +1271,7 @@ coap_set_token(void *packet, const uint8_t *token, size_t token_len)
}
int
coap_get_header_content_format(void *packet, unsigned int *format)
coap_get_header_content_format(void *packet, oc_content_format_t *format)
{
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
......@@ -1283,11 +1283,11 @@ coap_get_header_content_format(void *packet, unsigned int *format)
}
int
coap_set_header_content_format(void *packet, unsigned int format)
coap_set_header_content_format(void *packet, oc_content_format_t format)
{
coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
coap_pkt->content_format = (uint16_t)format;
coap_pkt->content_format = format;
SET_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT);
return 1;
}
......
......@@ -58,6 +58,7 @@
#include "port/oc_connectivity.h"
#include "port/oc_log.h"
#include "port/oc_random.h"
#include "oc_ri.h"
#ifdef __cplusplus
extern "C"
......@@ -240,8 +241,8 @@ int coap_set_status_code(void *packet, unsigned int code);
int coap_set_token(void *packet, const uint8_t *token, size_t token_len);
int coap_get_header_content_format(void *packet, unsigned int *format);
int coap_set_header_content_format(void *packet, unsigned int format);
int coap_get_header_content_format(void *packet, oc_content_format_t *format);
int coap_set_header_content_format(void *packet, oc_content_format_t format);
int coap_get_header_accept(void *packet, unsigned int *accept);
int coap_set_header_accept(void *packet, unsigned int accept);
......
......@@ -190,8 +190,7 @@ coap_separate_clear(oc_separate_response_t *separate_response,
coap_separate_t *separate_store)
{
#ifdef OC_BLOCK_WISE
if (oc_string_len(separate_store->uri) > 0)
oc_free_string(&separate_store->uri);
oc_free_string(&separate_store->uri);
#endif /* OC_BLOCK_WISE */
oc_list_remove(separate_response->requests, separate_store);
oc_memb_free(&separate_requests, separate_store);
......
......@@ -1050,6 +1050,10 @@ oc_send_buffer(oc_message_t *message)
ip_context_t *dev = get_ip_context_for_device(message->endpoint.device);
if (!dev) {
return -1;
}
#ifdef OC_TCP
if (message->endpoint.flags & TCP) {
return oc_tcp_send_buffer(dev, message, &receiver);
......
......@@ -1048,6 +1048,10 @@ oc_send_buffer(oc_message_t *message)
ip_context_t *dev = get_ip_context_for_device(message->endpoint.device);
if (!dev) {
return -1;
}
#ifdef OC_TCP
if (message->endpoint.flags & TCP) {
return oc_tcp_send_buffer(dev, message, &receiver);
......
......@@ -687,9 +687,7 @@ oc_ace_free_resources(size_t device, oc_sec_ace_t **ace, const char *href)
if (href == NULL ||
(oc_string_len(res->href) == strlen(href) &&
memcmp(href, oc_string(res->href), strlen(href)) == 0)) {
if (oc_string_len(res->href) > 0) {
oc_free_string(&res->href);
}
oc_free_string(&res->href);
oc_list_remove((*ace)->resources, res);
oc_memb_free(&res_l, res);
}
......@@ -749,9 +747,7 @@ oc_acl_remove_ace(int aceid, size_t device)
oc_ace_free_resources(device, &ace, NULL);
if (ace->subject_type == OC_SUBJECT_ROLE) {
oc_free_string(&ace->subject.role.role);
if (oc_string_len(ace->subject.role.authority) > 0) {
oc_free_string(&ace->subject.role.authority);
}
oc_free_string(&ace->subject.role.authority);
}
oc_memb_free(&ace_l, ace);
removed = true;
......@@ -771,9 +767,7 @@ oc_sec_clear_acl(size_t device)
oc_ace_free_resources(device, &ace, NULL);
if (ace->subject_type == OC_SUBJECT_ROLE) {
oc_free_string(&ace->subject.role.role);
if (oc_string_len(ace->subject.role.authority) > 0) {
oc_free_string(&ace->subject.role.authority);
}
oc_free_string(&ace->subject.role.authority);
}
oc_memb_free(&ace_l, ace);
ace = (oc_sec_ace_t *)oc_list_pop(acl_d->subjects);
......@@ -1055,9 +1049,7 @@ oc_sec_decode_acl(oc_rep_t *rep, bool from_storage, size_t device)
if (subject_type == OC_SUBJECT_ROLE) {
oc_free_string(&subject.role.role);
if (oc_string_len(subject.role.authority) > 0) {
oc_free_string(&subject.role.authority);
}
oc_free_string(&subject.role.authority);
}
aclist2 = aclist2->next;
......
......@@ -158,18 +158,12 @@ oc_sec_remove_cred(oc_sec_cred_t *cred, size_t device)
oc_sec_remove_role_cred(oc_string(cred->role.role),
oc_string(cred->role.authority));
#endif /* OC_PKI && OC_CLIENT */
oc_free_string(&cred->role.role);
if (oc_string_len(cred->role.authority) > 0) {
oc_free_string(&cred->role.authority);
}
}
if (oc_string_len(cred->privatedata.data) > 0) {
oc_free_string(&cred->privatedata.data);
}
oc_free_string(&cred->role.role);
oc_free_string(&cred->role.authority);
oc_free_string(&cred->privatedata.data);
#ifdef OC_PKI
if (oc_string_len(cred->publicdata.data) > 0) {
oc_free_string(&cred->publicdata.data);
}
oc_free_string(&cred->publicdata.data);
if (cred->credtype == OC_CREDTYPE_CERT) {
if (cred->credusage != OC_CREDUSAGE_TRUSTCA &&
......@@ -440,9 +434,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
#endif /* OC_PKI */
) {
#ifdef OC_PKI
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
oc_free_string(&public_key);
#endif /* OC_PKI */
return credid;
} else {
......@@ -475,9 +467,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
publicdata_size == oc_string_len(cred->publicdata.data) &&
memcmp(publicdata, oc_string(cred->publicdata.data),
publicdata_size) == 0) {
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
oc_free_string(&public_key);
return cred->credid;
}
}
......@@ -494,9 +484,7 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
if ((oc_string_len(roles->publicdata.data) == publicdata_size) &&
memcmp(oc_string(roles->publicdata.data), publicdata,
publicdata_size) == 0) {
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
oc_free_string(&public_key);
return roles->credid;
}
roles = roles->next;
......@@ -616,16 +604,12 @@ oc_sec_add_new_cred(size_t device, bool roles_resource, oc_tls_peer_t *client,
}
#endif /* OC_PKI */
#ifdef OC_PKI
if (oc_string_len(public_key) > 0) {
oc_free_string(&public_key);
}
oc_free_string(&public_key);
#endif /* OC_PKI */