Commit e5500cc5 authored by Kishen Maloor's avatar Kishen Maloor

Merge 'origin/master' into wes

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parents 469d7364 bdb0410e
Pipeline #938 failed with stage
in 6 minutes and 26 seconds
---
image: gcc
image: gcc:9.3.0
Linux_Secured_Test:
variables:
GIT_SUBMODULE_STRATEGY: normal
stage: build
before_script:
- apt update && apt -y install make autoconf
......@@ -13,6 +15,8 @@ Linux_Secured_Test:
- make DYNAMIC=1 IPV4=1 TCP=1 SECURE=1 test
Linux_Unsecured_Test:
variables:
GIT_SUBMODULE_STRATEGY: normal
stage: build
before_script:
- apt update && apt -y install make autoconf
......@@ -24,37 +28,37 @@ Linux_Unsecured_Test:
- make DYNAMIC=1 IPV4=1 TCP=1 SECURE=0 test
Android_build:
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
script:
- cd port/android
- make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
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
script:
- cd port/android
- make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
whitespace_and_doxygen:
doxygen:
variables:
GIT_SUBMODULE_STRATEGY: none
stage: build
before_script:
- apt update && apt -y install make autoconf doxygen clang-format
- apt update && apt -y install doxygen
script:
- clang-format --version
- doxygen --version
- cp tools/_clang-format _clang-format
- cp tools/whitespace_commit_checker.sh whitespace_commit_checker.sh
- ./whitespace_commit_checker.sh
- cd tools
- ./build_doc.sh
......@@ -113,7 +113,7 @@ cloud_deregister_on_reset_internal(oc_cloud_context_t *ctx,
cloud_store_initialize(&ctx->store);
cloud_manager_stop(ctx);
ctx->last_error = 0;
ctx->cps = 0;
ctx->store.cps = 0;
}
#endif /* OC_SECURITY */
......@@ -137,7 +137,7 @@ oc_cloud_reset_context(size_t device)
cloud_store_initialize(&ctx->store);
cloud_manager_stop(ctx);
ctx->last_error = 0;
ctx->cps = 0;
ctx->store.cps = 0;
return 0;
}
......@@ -168,7 +168,7 @@ oc_cloud_provision_conf_resource(oc_cloud_context_t *ctx, const char *server,
}
ctx->store.status = OC_CLOUD_INITIALIZED;
ctx->cps = OC_CPS_READYTOREGISTER;
ctx->store.cps = OC_CPS_READYTOREGISTER;
cloud_store_dump_async(&ctx->store);
......@@ -204,7 +204,7 @@ cloud_update_by_resource(oc_cloud_context_t *ctx,
cloud_set_string(&ctx->store.sid, data->sid, data->sid_len);
}
ctx->store.status = OC_CLOUD_INITIALIZED;
ctx->cps = OC_CPS_READYTOREGISTER;
ctx->store.cps = OC_CPS_READYTOREGISTER;
if (ctx->cloud_manager) {
cloud_reconnect(ctx);
}
......
......@@ -70,12 +70,16 @@ free_api_param(cloud_api_param_t *p)
int
conv_cloud_endpoint(oc_cloud_context_t *ctx)
{
int ret = 0;
oc_endpoint_t ep;
memset(&ep, 0, sizeof(oc_endpoint_t));
if (memcmp(&ep, ctx->cloud_ep, sizeof(oc_endpoint_t)) == 0) {
return oc_string_to_endpoint(&ctx->store.ci_server, ctx->cloud_ep, NULL);
ret = oc_string_to_endpoint(&ctx->store.ci_server, ctx->cloud_ep, NULL);
#ifdef OC_DNS_CACHE
oc_dns_clear_cache();
#endif /* OC_DNS_CACHE */
}
return 0;
return ret;
}
int
......@@ -105,7 +109,7 @@ oc_cloud_register(oc_cloud_context_t *ctx, oc_cloud_cb_t cb, void *data)
oc_string(ctx->store.uid), oc_string(ctx->store.access_token),
ctx->device, oc_cloud_register_handler, p)) {
cannotConnect = false;
ctx->cps = OC_CPS_REGISTERING;
ctx->store.cps = OC_CPS_REGISTERING;
}
if (cannotConnect) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
......@@ -227,17 +231,15 @@ cloud_deregistered_internal(oc_client_response_t *data)
{
cloud_api_param_t *p = (cloud_api_param_t *)data->user_data;
oc_cloud_context_t *ctx = p->ctx;
if (data->code >= OC_STATUS_SERVICE_UNAVAILABLE) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
ctx->store.status |= OC_CLOUD_FAILURE;
if (data->code < OC_STATUS_BAD_REQUEST ||
data->code >= OC_STATUS_SERVICE_UNAVAILABLE) {
ctx->store.status = OC_CLOUD_DEREGISTERED;
} else if (data->code >= OC_STATUS_BAD_REQUEST) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
ctx->store.status |= OC_CLOUD_FAILURE;
} else {
ctx->store.status = OC_CLOUD_DEREGISTERED;
}
ctx->cps = OC_CPS_READYTOREGISTER;
ctx->store.cps = OC_CPS_READYTOREGISTER;
if (p->cb) {
p->cb(ctx, ctx->store.status, p->data);
......@@ -245,6 +247,8 @@ cloud_deregistered_internal(oc_client_response_t *data)
free_api_param(p);
ctx->store.status &= ~(OC_CLOUD_FAILURE | OC_CLOUD_DEREGISTERED);
cloud_store_dump_async(&ctx->store);
}
int
......@@ -318,6 +322,25 @@ oc_cloud_refresh_token(oc_cloud_context_t *ctx, oc_cloud_cb_t cb, void *data)
return -1;
}
int
oc_cloud_discover_resources(oc_cloud_context_t *ctx,
oc_discovery_all_handler_t handler, void *user_data)
{
if (!ctx) {
return -1;
}
if (!(ctx->store.status & OC_CLOUD_LOGGED_IN)) {
return -1;
}
if (oc_do_ip_discovery_all_at_endpoint(handler, ctx->cloud_ep, user_data)) {
return 0;
}
return -1;
}
/* Internal APIs for accessing the OCF Cloud */
bool
cloud_access_register(oc_endpoint_t *endpoint, const char *auth_provider,
......@@ -339,7 +362,9 @@ cloud_access_register(oc_endpoint_t *endpoint, const char *auth_provider,
}
#ifdef OC_SECURITY
oc_tls_select_cloud_ciphersuite();
if (!oc_tls_connected(endpoint)) {
oc_tls_select_cloud_ciphersuite();
}
#endif /* OC_SECURITY */
if (oc_init_post(OC_RSRVD_ACCOUNT_URI, endpoint, NULL, handler, LOW_QOS,
......@@ -384,23 +409,32 @@ cloud_access_deregister(oc_endpoint_t *endpoint, const char *uid,
OC_ERR("Error of input parameters");
return false;
}
oc_string_t d;
(void)device;
oc_string_t at_uid;
oc_string_t at;
oc_concat_strings(&at, "accesstoken=", access_token);
oc_string_t u_id;
oc_concat_strings(&u_id, "&uid=", uid);
oc_concat_strings(&d, oc_string(at), oc_string(u_id));
oc_concat_strings(&at_uid, oc_string(at), oc_string(u_id));
char uuid[OC_UUID_LEN] = { 0 };
oc_uuid_to_str(oc_core_get_device_id(device), uuid, OC_UUID_LEN);
oc_string_t di;
oc_concat_strings(&di, "&di=", uuid);
oc_string_t at_uid_di;
oc_concat_strings(&at_uid_di, oc_string(at_uid), oc_string(di));
#ifdef OC_SECURITY
oc_tls_select_cloud_ciphersuite();
if (!oc_tls_connected(endpoint)) {
oc_tls_select_cloud_ciphersuite();
}
#endif /* OC_SECURITY */
bool s = oc_do_delete(OC_RSRVD_ACCOUNT_URI, endpoint, oc_string(d), handler,
HIGH_QOS, user_data);
oc_free_string(&d);
bool s = oc_do_delete(OC_RSRVD_ACCOUNT_URI, endpoint, oc_string(at_uid_di),
handler, HIGH_QOS, user_data);
oc_free_string(&at_uid);
oc_free_string(&at);
oc_free_string(&u_id);
oc_free_string(&di);
oc_free_string(&at_uid_di);
return s;
}
......@@ -422,7 +456,9 @@ cloud_access_login_out(oc_endpoint_t *endpoint, const char *uid,
}
#ifdef OC_SECURITY
oc_tls_select_cloud_ciphersuite();
if (!oc_tls_connected(endpoint)) {
oc_tls_select_cloud_ciphersuite();
}
#endif /* OC_SECURITY */
if (oc_init_post(OC_RSRVD_ACCOUNT_SESSION_URI, endpoint, NULL, handler,
......@@ -481,7 +517,9 @@ cloud_access_refresh_access_token(oc_endpoint_t *endpoint, const char *uid,
}
#ifdef OC_SECURITY
oc_tls_select_cloud_ciphersuite();
if (!oc_tls_connected(endpoint)) {
oc_tls_select_cloud_ciphersuite();
}
#endif /* OC_SECURITY */
if (oc_init_post(OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI, endpoint, NULL, handler,
......
......@@ -146,8 +146,6 @@ _register_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
oc_rep_t *payload = data->payload;
ctx->store.status = 0;
char *value = NULL;
size_t size = 0;
......@@ -195,12 +193,14 @@ _register_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
cloud_set_last_error(ctx, CLOUD_OK);
ctx->store.status |= OC_CLOUD_REGISTERED;
ctx->cps = OC_CPS_REGISTERED;
ctx->store.cps = OC_CPS_REGISTERED;
oc_notify_observers(ctx->cloud_conf);
return 0;
error:
ctx->cps = OC_CPS_FAILED;
ctx->store.cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
......@@ -259,7 +259,7 @@ cloud_register(void *data)
oc_string(ctx->store.uid), oc_string(ctx->store.access_token),
ctx->device, cloud_register_handler, data)) {
cannotConnect = false;
ctx->cps = OC_CPS_REGISTERING;
ctx->store.cps = OC_CPS_REGISTERING;
}
if (cannotConnect) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
......@@ -297,7 +297,7 @@ _login_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
return 0;
error:
ctx->cps = OC_CPS_FAILED;
ctx->store.cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
......@@ -430,7 +430,7 @@ error:
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_REFRESH_ACCESS_TOKEN);
}
ctx->cps = OC_CPS_FAILED;
ctx->store.cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
return -1;
}
......
......@@ -129,7 +129,7 @@ publish_resources_handler(oc_client_response_t *data)
if (l) {
l->ins = instance_id;
rd_link_remove(&ctx->rd_publish_resources, l);
rd_link_add(&ctx->rd_publish_resources, l);
rd_link_add(&ctx->rd_published_resources, l);
}
}
link = link->next;
......
......@@ -66,7 +66,7 @@ cloud_response(oc_cloud_context_t *ctx)
root, sid, (oc_string(ctx->store.sid) ? oc_string(ctx->store.sid) : ""));
oc_rep_set_int(root, clec, (int)ctx->last_error);
const char *cps = cps_to_str(ctx->cps);
const char *cps = cps_to_str(ctx->store.cps);
if (cps) {
oc_rep_set_text_string(root, cps, cps);
}
......@@ -145,7 +145,7 @@ post_cloud(oc_request_t *request, oc_interface_mask_t interface,
OC_DBG("POST request received");
(void)interface;
switch (ctx->cps) {
switch (ctx->store.cps) {
case OC_CPS_UNINITIALIZED:
case OC_CPS_READYTOREGISTER:
case OC_CPS_FAILED:
......
......@@ -64,10 +64,12 @@ encode_cloud_with_map(CborEncoder *object_map, const oc_cloud_store_t *store)
oc_rep_set_text_string(*object, auth_provider,
oc_string(store->auth_provider));
oc_rep_set_text_string(*object, uid, oc_string(store->uid));
oc_rep_set_text_string(*object, sid, oc_string(store->sid));
oc_rep_set_text_string(*object, access_token, oc_string(store->access_token));
oc_rep_set_text_string(*object, refresh_token,
oc_string(store->refresh_token));
oc_rep_set_int(*object, status, store->status);
oc_rep_set_int(*object, cps, store->cps);
}
static void
......@@ -145,6 +147,9 @@ cloud_store_decode(oc_rep_t *rep, oc_cloud_store_t *store)
if (len == 9 && memcmp(oc_string(t->name), "ci_server", 9) == 0) {
cloud_set_string(&store->ci_server, oc_string(t->value.string),
oc_string_len(t->value.string));
} else if (len == 3 && memcmp(oc_string(t->name), "sid", 3) == 0) {
cloud_set_string(&store->sid, oc_string(t->value.string),
oc_string_len(t->value.string));
} else if (len == 13 &&
memcmp(oc_string(t->name), "auth_provider", 13) == 0) {
cloud_set_string(&store->auth_provider, oc_string(t->value.string),
......@@ -168,6 +173,8 @@ cloud_store_decode(oc_rep_t *rep, oc_cloud_store_t *store)
case OC_REP_INT:
if (len == 6 && memcmp(oc_string(t->name), "status", 6) == 0) {
store->status = (uint8_t)t->value.integer;
} else if (len == 3 && memcmp(oc_string(t->name), "cps", 3) == 0) {
store->cps = (uint8_t)t->value.integer;
} else {
OC_ERR("[CLOUD_STORE] Unknown property %s", oc_string(t->name));
return -1;
......
......@@ -197,6 +197,37 @@ oc_free_server_endpoints(oc_endpoint_t *endpoint)
}
}
bool
oc_get_response_payload_raw(oc_client_response_t *response,
const uint8_t **payload, size_t *size,
oc_content_format_t *content_format)
{
if (!response || !payload || !size || !content_format) {
return false;
}
if (response->_payload && response->_payload_len > 0) {
*content_format = response->content_format;
*payload = response->_payload;
*size = response->_payload_len;
return true;
}
return false;
}
bool
oc_get_diagnostic_message(oc_client_response_t *response, const char **msg,
size_t *size)
{
oc_content_format_t cf = 0;
if (oc_get_response_payload_raw(response, (const uint8_t **)msg, size, &cf)) {
if (cf != TEXT_PLAIN) {
return false;
}
return true;
}
return false;
}
bool
oc_do_delete(const char *uri, oc_endpoint_t *endpoint, const char *query,
oc_response_handler_t handler, oc_qos_t qos, void *user_data)
......
......@@ -917,7 +917,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->response_length = (uint16_t)size;
request->response->response_buffer->code = code;
......
......@@ -447,7 +447,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;
if (matches && response_length) {
request->response->response_buffer->response_length =
(uint16_t)response_length;
......@@ -500,6 +500,7 @@ oc_core_discovery_handler(oc_request_t *request, oc_interface_mask_t iface_mask,
break;
}
int response_length = oc_rep_get_encoded_payload_size();
request->response->content_format = APPLICATION_VND_OCF_CBOR;
if (matches && response_length > 0) {
request->response->response_buffer->response_length =
(uint16_t)response_length;
......@@ -586,33 +587,12 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
rep = rep->next;
}
oc_rep_t *link = links->value.object;
while (link != NULL) {
switch (link->type) {
case OC_REP_STRING: {
if (oc_string_len(link->name) == 6 &&
memcmp(oc_string(link->name), "anchor", 6) == 0) {
anchor = &link->value.string;
}
} break;
default:
break;
}
if (anchor) {
break;
}
link = link->next;
}
oc_uuid_t di;
oc_str_to_uuid(oc_string(*anchor) + 6, &di);
while (links != NULL) {
/* Reset bm in every round as this can be omitted if 0. */
oc_uuid_t di;
oc_resource_properties_t bm = 0;
oc_endpoint_t *eps_list = NULL;
link = links->value.object;
oc_rep_t *link = links->value.object;
while (link != NULL) {
switch (link->type) {
......@@ -620,6 +600,7 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
if (oc_string_len(link->name) == 6 &&
memcmp(oc_string(link->name), "anchor", 6) == 0) {
anchor = &link->value.string;
oc_str_to_uuid(oc_string(*anchor) + 6, &di);
} else if (oc_string_len(link->name) == 4 &&
memcmp(oc_string(link->name), "href", 4) == 0) {
uri = &link->value.string;
......@@ -653,8 +634,9 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
memcmp(oc_string(ep->name), "ep", 2) == 0) {
if (oc_string_to_endpoint(&ep->value.string, &temp_ep, NULL) ==
0) {
if (((endpoint->flags & IPV4) && (temp_ep.flags & IPV6)) ||
((endpoint->flags & IPV6) && (temp_ep.flags & IPV4))) {
if (!(temp_ep.flags & TCP) &&
(((endpoint->flags & IPV4) && (temp_ep.flags & IPV6)) ||
((endpoint->flags & IPV6) && (temp_ep.flags & IPV4)))) {
goto next_ep;
}
if (eps_cur) {
......@@ -721,6 +703,9 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
done:
oc_free_rep(p);
#ifdef OC_DNS_CACHE
oc_dns_clear_cache();
#endif /* OC_DNS_CACHE */
return ret;
}
#endif /* OC_CLIENT */
......@@ -509,16 +509,17 @@ oc_endpoint_string_parse_path(oc_string_t *endpoint_str, oc_string_t *path)
const char *address = NULL;
address = strstr(oc_string(*endpoint_str), "://");
if(!address) {
if (!address) {
return -1;
}
// 3 is string length of "://"
address += 3;
size_t len = oc_string_len(*endpoint_str) - (address - oc_string(*endpoint_str));
size_t len =
oc_string_len(*endpoint_str) - (address - oc_string(*endpoint_str));
// the smallest possible address is '0' anything smaller is invalid.
if(len < 1) {
if (len < 1) {
return -1;
}
/* Extract a uri path if available */
......@@ -556,7 +557,7 @@ oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint)
}
int
oc_endpoint_compare_address(oc_endpoint_t *ep1, oc_endpoint_t *ep2)
oc_endpoint_compare_address(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2)
{
if (!ep1 || !ep2)
return -1;
......
......@@ -78,7 +78,7 @@ oc_core_introspection_data_handler(oc_request_t *request,
IDD_size = oc_storage_read(
idd_tag, request->response->response_buffer->buffer, OC_MAX_APP_DATA_SIZE);
#endif /* OC_IDD_API */
request->response->content_format = APPLICATION_VND_OCF_CBOR;
if (IDD_size >= 0 && IDD_size < OC_MAX_APP_DATA_SIZE) {
request->response->response_buffer->response_length = (uint16_t)IDD_size;
request->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
......
......@@ -17,6 +17,7 @@
#include <stdint.h>
#include <stdio.h>
#include "oc_config.h"
#include "port/oc_assert.h"
#include "port/oc_clock.h"
#include "port/oc_connectivity.h"
......