Commit a3f8a508 authored by Kishen Maloor's avatar Kishen Maloor

Merge 'origin/master' into ocfbridging

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parents a2b88033 07ee66c6
Pipeline #1132 passed with stage
in 3 minutes and 37 seconds
......@@ -31,26 +31,13 @@ Android_build:
variables:
GIT_SUBMODULE_STRATEGY: normal
stage: build
image: openjdk:8-jdk
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 make autoconf swig patch
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "ndk-bundle" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-28" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;28.0.2" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
- ./android-sdk-linux/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --api 23 --install-dir ~/android-arm-23
image: gitlab.iotivity.org:5050/iotivity/iotivity-lite
script:
- cd port/android
- make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
retry:
max: 2
when: runner_system_failure
doxygen:
variables:
......@@ -62,3 +49,4 @@ doxygen:
- doxygen --version
- cd tools
- ./build_doc.sh
......@@ -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;
}
......
......@@ -100,6 +100,7 @@ oc_new_link(oc_resource_t *resource)
oc_new_string_array(&link->rel, 3);
oc_string_array_add_item(link->rel, "hosts");
link->resource = resource;
link->interfaces = resource->interfaces;
resource->num_links++;
link->next = 0;
link->ins = (int64_t)oc_random_value();
......@@ -203,6 +204,12 @@ oc_link_add_link_param(oc_link_t *link, const char *key, const char *value)
}
}
void
oc_link_set_interfaces(oc_link_t *link, oc_interface_mask_t new_interfaces)
{
link->interfaces = new_interfaces;
}
oc_collection_t *
oc_get_collection_by_uri(const char *uri_path, size_t uri_path_len,
size_t device)
......@@ -577,23 +584,27 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
oc_rep_start_root_object();
oc_process_baseline_interface(request->resource);
/* rts */
oc_rep_open_array(root, rts);
oc_rt_t *rtt = (oc_rt_t *)oc_list_head(collection->supported_rts);
while (rtt) {
oc_rep_add_text_string(rts, oc_string(rtt->rt));
rtt = rtt->next;
if (oc_list_length(collection->supported_rts) > 0) {
oc_rep_open_array(root, rts);
oc_rt_t *rtt = (oc_rt_t *)oc_list_head(collection->supported_rts);
while (rtt) {
oc_rep_add_text_string(rts, oc_string(rtt->rt));
rtt = rtt->next;
}
oc_rep_close_array(root, rts);
}
oc_rep_close_array(root, rts);
/* rts-m */
const char *rtsm_key = "rts-m";
oc_rep_set_key(oc_rep_object(root), rtsm_key);
oc_rep_start_array(oc_rep_object(root), rtsm);
oc_rt_t *rtt = (oc_rt_t *)oc_list_head(collection->mandatory_rts);
while (rtt) {
oc_rep_add_text_string(rtsm, oc_string(rtt->rt));
rtt = rtt->next;
if (oc_list_length(collection->mandatory_rts) > 0) {
const char *rtsm_key = "rts-m";
oc_rep_set_key(oc_rep_object(root), rtsm_key);
oc_rep_start_array(oc_rep_object(root), rtsm);
oc_rt_t *rtt = (oc_rt_t *)oc_list_head(collection->mandatory_rts);
while (rtt) {
oc_rep_add_text_string(rtsm, oc_string(rtt->rt));
rtt = rtt->next;
}
oc_rep_end_array(oc_rep_object(root), rtsm);
}
oc_rep_end_array(oc_rep_object(root), rtsm);
oc_rep_set_array(root, links);
while (link != NULL) {
if (oc_filter_resource_by_rt(link->resource, request)) {
......@@ -601,7 +612,7 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
oc_rep_set_text_string(links, href, oc_string(link->resource->uri));
oc_rep_set_string_array(links, rt, link->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links),
link->resource->interfaces);
link->interfaces);
oc_rep_set_string_array(links, rel, link->rel);
oc_rep_set_int(links, ins, link->ins);
oc_link_params_t *p = (oc_link_params_t *)oc_list_head(link->params);
......@@ -616,6 +627,34 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
(uint8_t)(link->resource->properties & ~(OC_PERIODIC | OC_SECURE)));
oc_rep_close_object(links, p);
// tag-pos-desc
if (link->resource->tag_pos_desc > 0) {
const char *desc =
oc_enum_pos_desc_to_str(link->resource->tag_pos_desc);
if (desc) {
oc_rep_set_text_string(links, tag-pos-desc, desc);
}
}
// tag-func-desc
if (link->resource->tag_func_desc > 0) {
const char *func = oc_enum_to_str(link->resource->tag_func_desc);
if (func) {
oc_rep_set_text_string(links, tag-func-desc, func);
}
}
// tag-pos-rel
double *pos = link->resource->tag_pos_rel;
if (pos[0] != 0 || pos[1] != 0 || pos[2] != 0) {
oc_rep_set_key(oc_rep_object(links), "tag-pos-rel");
oc_rep_start_array(oc_rep_object(links), tag_pos_rel);
oc_rep_add_double(tag_pos_rel, pos[0]);
oc_rep_add_double(tag_pos_rel, pos[1]);
oc_rep_add_double(tag_pos_rel, pos[2]);
oc_rep_end_array(oc_rep_object(links), tag_pos_rel);
}
// eps
oc_rep_set_array(links, eps);
oc_endpoint_t *eps =
......@@ -674,8 +713,7 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
oc_rep_object_array_start_item(links);
oc_rep_set_text_string(links, href, oc_string(link->resource->uri));
oc_rep_set_string_array(links, rt, link->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links),
link->resource->interfaces);
oc_core_encode_interfaces_mask(oc_rep_object(links), link->interfaces);
oc_rep_set_string_array(links, rel, link->rel);
oc_rep_set_int(links, ins, link->ins);
oc_link_params_t *p = (oc_link_params_t *)oc_list_head(link->params);
......@@ -690,6 +728,34 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
(uint8_t)(link->resource->properties & ~(OC_PERIODIC | OC_SECURE)));
oc_rep_close_object(links, p);
// tag-pos-desc
if (link->resource->tag_pos_desc > 0) {
const char *desc =
oc_enum_pos_desc_to_str(link->resource->tag_pos_desc);
if (desc) {
oc_rep_set_text_string(links, tag-pos-desc, desc);
}
}
// tag-func-desc
if (link->resource->tag_func_desc > 0) {
const char *func = oc_enum_to_str(link->resource->tag_func_desc);
if (func) {
oc_rep_set_text_string(links, tag-func-desc, func);
}
}
// tag-pos-rel
double *pos = link->resource->tag_pos_rel;
if (pos[0] != 0 || pos[1] != 0 || pos[2] != 0) {
oc_rep_set_key(oc_rep_object(links), "tag-pos-rel");
oc_rep_start_array(oc_rep_object(links), tag_pos_rel);
oc_rep_add_double(tag_pos_rel, pos[0]);
oc_rep_add_double(tag_pos_rel, pos[1]);
oc_rep_add_double(tag_pos_rel, pos[2]);
oc_rep_end_array(oc_rep_object(links), tag_pos_rel);
}
// eps
oc_rep_set_array(links, eps);
oc_endpoint_t *eps =
......@@ -769,6 +835,10 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
}
pay = pay->next;
}
if (!href || (href && oc_string_len(*href) == 0)) {
ecode = oc_status_code(OC_STATUS_BAD_REQUEST);
goto processed_request;
}
process_request:
link = oc_list_head(collection->links);
while (link != NULL) {
......@@ -804,52 +874,56 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
} else
#endif /* OC_SECURITY */
{
oc_interface_mask_t req_iface =
link->resource->default_interface;
if (link->resource == (oc_resource_t *)collection) {
req_iface = OC_IF_BASELINE;
}
switch (method) {
case OC_GET:
if (link->resource->get_handler.cb)
link->resource->get_handler.cb(
&rest_request, req_iface,
link->resource->get_handler.user_data);
else
method_not_found = true;
break;
case OC_PUT:
if (link->resource->put_handler.cb)
link->resource->put_handler.cb(
&rest_request, req_iface,
link->resource->put_handler.user_data);
else
method_not_found = true;
break;
case OC_POST:
if (link->resource->post_handler.cb)
link->resource->post_handler.cb(
&rest_request, req_iface,
link->resource->post_handler.user_data);
else
method_not_found = true;
break;
case OC_DELETE:
if (link->resource->delete_handler.cb)
link->resource->delete_handler.cb(
&rest_request, req_iface,
link->resource->delete_handler.user_data);
else
method_not_found = true;
break;
if ((link->resource != (oc_resource_t *)collection) &&
oc_check_if_collection(link->resource)) {
request->resource = link->resource;
oc_handle_collection_request(
method, request, link->resource->default_interface, NULL);
request->resource = (oc_resource_t *)collection;
} else {
oc_interface_mask_t req_iface =
link->resource->default_interface;
if (link->resource == (oc_resource_t *)collection) {
req_iface = OC_IF_BASELINE;
}
switch (method) {
case OC_GET:
if (link->resource->get_handler.cb)
link->resource->get_handler.cb(
&rest_request, req_iface,
link->resource->get_handler.user_data);
else
method_not_found = true;
break;
case OC_PUT:
if (link->resource->put_handler.cb)
link->resource->put_handler.cb(
&rest_request, req_iface,
link->resource->put_handler.user_data);
else
method_not_found = true;
break;
case OC_POST:
if (link->resource->post_handler.cb)
link->resource->post_handler.cb(
&rest_request, req_iface,
link->resource->post_handler.user_data);
else
method_not_found = true;
break;
case OC_DELETE:
if (link->resource->delete_handler.cb)
link->resource->delete_handler.cb(
&rest_request, req_iface,
link->resource->delete_handler.user_data);
else
method_not_found = true;
break;
}
}
}
if (method_not_found ||
(href && oc_string_len(*href) > 0 &&
response_buffer.code >=
oc_status_code(OC_STATUS_BAD_REQUEST))) {
ecode = response_buffer.code;
if (method_not_found) {
ecode = oc_status_code(OC_STATUS_METHOD_NOT_ALLOWED);
memcpy(&links_array, &prev_link, sizeof(CborEncoder));
goto next;
} else {
......@@ -918,7 +992,7 @@ oc_handle_collection_request(oc_method_t method, oc_request_t *request,
break;
}
}
request->response->content_format = APPLICATION_VND_OCF_CBOR;
request->response->response_buffer->content_format = APPLICATION_VND_OCF_CBOR;
request->response->response_buffer->response_length = (uint16_t)size;
request->response->response_buffer->code = code;
......
......@@ -49,6 +49,7 @@ static oc_device_info_t oc_device_info[OC_MAX_NUM_DEVICES];
static oc_platform_info_t oc_platform_info;
static bool announce_con_res = false;
static int res_latency = 0;
static size_t device_count = 0;
/* Although used several times in the OCF spec, "/oic/con" is not
......@@ -79,12 +80,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));
}
}
......@@ -92,8 +90,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) {
......@@ -275,6 +272,18 @@ oc_get_con_res_announced(void)
return announce_con_res;
}
void
oc_core_set_latency(int latency)
{
res_latency = latency;
}
int
oc_core_get_latency(void)
{
return res_latency;
}
void
oc_set_con_res_announced(bool announce)
{
......@@ -678,6 +687,8 @@ oc_core_get_resource_by_uri(const char *uri, size_t device)
type = OCF_SEC_PSTAT;
} else if (memcmp(uri + skip, "oic/sec/acl2", 12) == 0) {
type = OCF_SEC_ACL;
} else if (memcmp(uri + skip, "oic/sec/ael", 11) == 0) {
type = OCF_SEC_AEL;
} else if (memcmp(uri + skip, "oic/sec/cred", 12) == 0) {
type = OCF_SEC_CRED;
}
......@@ -694,6 +705,10 @@ oc_core_get_resource_by_uri(const char *uri, size_t device)
type = OCF_SEC_ROLES;
}
#endif /* OC_PKI */
else if ((strlen(uri) - skip) == 11 &&
memcmp(uri + skip, "oic/sec/sdi", 11) == 0) {
type = OCF_SEC_SDI;
}
#endif /* OC_SECURITY */
#ifdef OC_SOFTWARE_UPDATE
else if ((strlen(uri) - skip) == 2 && memcmp(uri + skip, "sw", 2) == 0) {
......
......@@ -21,14 +21,25 @@
#include "messaging/coap/oc_coap.h"
#include "oc_api.h"
#include "oc_discovery.h"
#include "oc_enums.h"
#ifdef OC_RES_BATCH_SUPPORT
#ifdef OC_SECURITY
#include "security/oc_acl_internal.h"
#endif /* OC_SECURITY */
#endif /* OC_RES_BATCH_SUPPORT */
#if defined(OC_COLLECTIONS) && defined(OC_SERVER)
#include "oc_collection.h"
#endif /* OC_COLLECTIONS && OC_SERVER */
#endif /* OC_COLLECTIONS && OC_SERVER */
#include "oc_core_res.h"
#include "oc_endpoint.h"
#ifdef OC_SECURITY
#include "security/oc_sdi.h"
#endif
static bool
filter_resource(oc_resource_t *resource, oc_request_t *request,
const char *anchor, CborEncoder *links, size_t device_index)
......@@ -43,6 +54,13 @@ filter_resource(oc_resource_t *resource, oc_request_t *request,
oc_rep_start_object(links, link);
// rel
if (oc_core_get_resource_by_index(OCF_RES, resource->device) == resource) {
oc_rep_set_array(link, rel);
oc_rep_add_text_string(rel, "self");
oc_rep_close_array(link, rel);
}
// anchor
oc_rep_set_text_string(link, anchor, anchor);
......@@ -97,12 +115,41 @@ filter_resource(oc_resource_t *resource, oc_request_t *request,
oc_rep_set_text_string(eps, ep, oc_string(ep));
oc_free_string(&ep);
}
if (oc_core_get_latency() > 0)
oc_rep_set_uint(eps, lat, oc_core_get_latency());
oc_rep_object_array_end_item(eps);
next_eps:
eps = eps->next;
}
oc_rep_close_array(link, eps);
// tag-pos-desc
if (resource->tag_pos_desc > 0) {
const char *desc = oc_enum_pos_desc_to_str(resource->tag_pos_desc);
if (desc) {
oc_rep_set_text_string(link, tag-pos-desc, desc);
}
}
// tag-func-desc
if (resource->tag_func_desc > 0) {
const char *func = oc_enum_to_str(resource->tag_func_desc);
if (func) {
oc_rep_set_text_string(link, tag-func-desc, func);
}
}
// tag-pos-rel
double *pos = resource->tag_pos_rel;
if (pos[0] != 0 || pos[1] != 0 || pos[2] != 0) {
oc_rep_set_key(oc_rep_object(link), "tag-pos-rel");
oc_rep_start_array(oc_rep_object(link), tag_pos_rel);
oc_rep_add_double(tag_pos_rel, pos[0]);
oc_rep_add_double(tag_pos_rel, pos[1]);
oc_rep_add_double(tag_pos_rel, pos[2]);
oc_rep_end_array(oc_rep_object(link), tag_pos_rel);
}
oc_rep_end_object(links, link);
return true;
......@@ -122,6 +169,10 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
oc_string(anchor), links, device_index))
matches++;
if (filter_resource(oc_core_get_resource_by_index(OCF_RES, device_index),
request, oc_string(anchor), links, device_index))
matches++;
if (filter_resource(oc_core_get_resource_by_index(OCF_D, device_index),
request, oc_string(anchor), links, device_index))
matches++;
......@@ -161,6 +212,10 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
request, oc_string(anchor), links, device_index))
matches++;
if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_AEL, device_index),
request, oc_string(anchor), links, device_index))
matches++;
if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_CRED, device_index),
request, oc_string(anchor), links, device_index))
matches++;
......@@ -179,6 +234,11 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
oc_string(anchor), links, device_index))
matches++;
#endif /* OC_PKI */
if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_SDI, device_index),
request, oc_string(anchor), links, device_index))
matches++;
#endif /* OC_SECURITY */
#if defined(OC_CLIENT) && defined(OC_SERVER) && defined(OC_CLOUD)
......@@ -389,6 +449,10 @@ process_oic_1_1_device_object(CborEncoder *device, oc_request_t *request,
oc_core_get_resource_by_index(OCF_SEC_ACL, device_num), request,
oc_rep_array(links)))
matches++;
if (filter_oic_1_1_resource(
oc_core_get_resource_by_index(OCF_SEC_AEL, device_num), request,
oc_rep_array(links)))
matches++;
if (filter_oic_1_1_resource(
oc_core_get_resource_by_index(OCF_SEC_SP, device_num), request,
......@@ -447,7 +511,7 @@ oc_core_1_1_discovery_handler(oc_request_t *request,
}
int response_length = oc_rep_get_encoded_payload_size();
request->response->content_format = APPLICATION_CBOR;
request->response->response_buffer->content_format = APPLICATION_CBOR;
if (matches && response_length) {
request->response->response_buffer->response_length =
(uint16_t)response_length;
......@@ -461,6 +525,126 @@ oc_core_1_1_discovery_handler(oc_request_t *request,
}
#endif /* OC_SPEC_VER_OIC */
#ifdef OC_RES_BATCH_SUPPORT
static void
process_batch_response(CborEncoder *links_array, oc_resource_t *resource,
oc_endpoint_t *endpoint)
{
if (!(resource->properties & OC_DISCOVERABLE)) {
return;
}
oc_request_t rest_request = { 0 };
oc_response_t response = { 0 };
oc_response_buffer_t response_buffer;
response.response_buffer = &response_buffer;
rest_request.response = &response;
rest_request.origin = endpoint;
rest_request.query = 0;
rest_request.query_len = 0;
#ifdef OC_SECURITY
if (oc_sec_check_acl(OC_GET, resource, endpoint)) {
#endif /* OC_SECURITY */
oc_rep_start_object((links_array), links);
char href[OC_UUID_LEN + 6 + 256];