Commit b6f46e32 authored by Kishen Maloor's avatar Kishen Maloor

Merge branch 'origin/master' into fargo

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parents c3e52ee3 e47f40d0
Pipeline #281 passed with stage
in 51 seconds
......@@ -76,8 +76,9 @@ oc_blockwise_free_buffer(oc_list_t list, struct oc_memb *pool,
return;
}
if (oc_string_len(buffer->uri_query))
if (oc_string_len(buffer->uri_query) > 0) {
oc_free_string(&buffer->uri_query);
}
oc_free_string(&buffer->href);
oc_list_remove(list, buffer);
#ifdef OC_DYNAMIC_ALLOCATION
......
......@@ -682,7 +682,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
request_obj.origin = endpoint;
/* Initialize OCF interface selector. */
oc_interface_mask_t iface_mask = 0;
oc_interface_mask_t iface_query = 0, iface_mask = 0;
/* Obtain request uri from the CoAP packet. */
const char *uri_path;
......@@ -701,7 +701,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
int if_len =
oc_ri_get_query_value(uri_query, (int)uri_query_len, "if", &iface);
if (if_len != -1) {
iface_mask |= oc_ri_get_interface_mask(iface, (size_t)if_len);
iface_query |= oc_ri_get_interface_mask(iface, (size_t)if_len);
}
}
......@@ -792,6 +792,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
if (cur_resource) {
/* If there was no interface selection, pick the "default interface". */
iface_mask = iface_query;
if (iface_mask == 0)
iface_mask = cur_resource->default_interface;
......@@ -949,10 +950,10 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
if (observe == 0) {
#ifdef OC_BLOCK_WISE
if (coap_observe_handler(request, response, cur_resource, block2_size,
endpoint, iface_mask) >= 0) {
endpoint, iface_query) >= 0) {
#else /* OC_BLOCK_WISE */
if (coap_observe_handler(request, response, cur_resource, endpoint,
iface_mask) >= 0) {
iface_query) >= 0) {
#endif /* !OC_BLOCK_WISE */
/* If the resource is marked as periodic observable it means
* it must be polled internally for updates (which would lead to
......@@ -983,7 +984,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
}
#endif /* OC_SECURITY */
if (set_observe_option) {
if (iface_mask == OC_IF_B) {
if (iface_query == OC_IF_B) {
links = (oc_link_t *)oc_list_head(collection->links);
while (links) {
if (links->resource &&
......@@ -1011,10 +1012,10 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
else if (observe == 1) {
#ifdef OC_BLOCK_WISE
if (coap_observe_handler(request, response, cur_resource, block2_size,
endpoint, iface_mask) > 0) {
endpoint, iface_query) > 0) {
#else /* OC_BLOCK_WISE */
if (coap_observe_handler(request, response, cur_resource, endpoint,
iface_mask) > 0) {
iface_query) > 0) {
#endif /* !OC_BLOCK_WISE */
if (cur_resource->properties & OC_PERIODIC) {
remove_periodic_observe_callback(cur_resource);
......
This diff is collapsed.
......@@ -414,8 +414,10 @@ main(void)
#ifdef OC_STORAGE
oc_storage_config("./smart_lock_creds");
oc_set_random_pin_callback(random_pin_cb, NULL);
#endif /* OC_STORAGE */
#ifdef OC_SECURITY
oc_set_random_pin_callback(random_pin_cb, NULL);
#endif
oc_set_con_res_announced(false);
init = oc_main_init(&handler);
......
......@@ -720,12 +720,15 @@ coap_receive(oc_message_t *msg)
* signal from the server. In this case, the client_cb continues
* to live until the response arrives (or it times out).
*/
if (oc_ri_is_client_cb_valid(client_cb)) {
if (client_cb->separate == 0) {
if (response_buffer) {
response_buffer->ref_count = 0;
}
}
} else {
client_cb->separate = 0;
}
}
goto send_message;
#else /* OC_BLOCK_WISE */
oc_ri_invoke_client_cb(message, client_cb, &msg->endpoint);
......
......@@ -153,6 +153,32 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
/*---------------------------------------------------------------------------*/
/*- Removal -----------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
static const char *
get_iface_query(oc_interface_mask_t iface_mask)
{
switch (iface_mask) {
case OC_IF_BASELINE:
return "if=oic.if.baseline";
case OC_IF_LL:
return "if=oic.if.ll";
case OC_IF_B:
return "if=oic.if.b";
case OC_IF_R:
return "if=oic.if.r";
case OC_IF_RW:
return "if=oic.if.rw";
case OC_IF_A:
return "if=oic.if.a";
case OC_IF_S:
return "if=oic.if.s";
case OC_IF_CREATE:
return "if=oic.if.create";
default:
break;
}
return NULL;
}
void
coap_remove_observer(coap_observer_t *o)
{
......@@ -160,9 +186,11 @@ coap_remove_observer(coap_observer_t *o)
o->token[0], o->token[1]);
#ifdef OC_BLOCK_WISE
const char *query = get_iface_query(o->iface_mask);
oc_blockwise_state_t *response_state = oc_blockwise_find_response_buffer(
oc_string(o->resource->uri) + 1, oc_string_len(o->resource->uri) - 1,
&o->endpoint, OC_GET, NULL, 0, OC_BLOCKWISE_SERVER);
&o->endpoint, OC_GET, query, (query) ? strlen(query) : 0,
OC_BLOCKWISE_SERVER);
if (response_state) {
response_state->ref_count = 0;
}
......@@ -285,10 +313,15 @@ coap_notify_collection_observers(oc_resource_t *resource,
/* iterate over observers */
for (obs = (coap_observer_t *)oc_list_head(observers_list); obs;
obs = obs->next) {
if (obs->resource != resource || obs->iface_mask != iface_mask) {
if (obs->resource != resource) {
continue;
}
OC_DBG("coap_notify_collections: notifying observer");
if (obs->iface_mask != iface_mask) {
if ((obs->iface_mask | iface_mask) != OC_IF_LL) {
continue;
}
}
OC_DBG("coap_notify_collection_observers: notifying observer");
coap_transaction_t *transaction = NULL;
coap_packet_t notification[1];
......@@ -309,10 +342,11 @@ coap_notify_collection_observers(oc_resource_t *resource,
if (response_buf->response_length > obs->block2_size) {
#endif /* !OC_TCP */
notification->type = COAP_TYPE_CON;
const char *query = get_iface_query(obs->iface_mask);
response_state = oc_blockwise_find_response_buffer(
oc_string(obs->resource->uri) + 1,
oc_string_len(obs->resource->uri) - 1, &obs->endpoint, OC_GET, NULL, 0,
OC_BLOCKWISE_SERVER);
oc_string_len(obs->resource->uri) - 1, &obs->endpoint, OC_GET, query,
(query) ? strlen(query) : 0, OC_BLOCKWISE_SERVER);
if (response_state) {
if (response_state->payload_size == response_state->next_block_offset) {
oc_blockwise_free_response_buffer(response_state);
......@@ -330,6 +364,9 @@ coap_notify_collection_observers(oc_resource_t *resource,
goto leave_notify_collections;
}
if (query) {
oc_new_string(&response_state->uri_query, query, strlen(query));
}
memcpy(response_state->buffer, response_buf->buffer,
response_buf->response_length);
response_state->payload_size = response_buf->response_length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment