Commit 62c29f82 authored by Kishen Maloor's avatar Kishen Maloor

Merge branch 'master' into fargo

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parents 8a659eef 21fe3cb6
Pipeline #222 passed with stage
in 49 seconds
...@@ -21,43 +21,20 @@ ...@@ -21,43 +21,20 @@
#include "oc_api.h" #include "oc_api.h"
#include "oc_cloud_internal.h" #include "oc_cloud_internal.h"
#include "oc_rep.h" #include "oc_rep.h"
#include "oc_config.h"
#ifdef OC_DYNAMIC_ALLOCATION #ifdef OC_DYNAMIC_ALLOCATION
#include <stdlib.h> #include <stdlib.h>
#endif /* OC_DYNAMIC_ALLOCATION */ #endif /* OC_DYNAMIC_ALLOCATION */
#ifndef OC_STORAGE
#error Preprocessor macro OC_CLOUD is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_CLOUD is defined.
#endif
#define CLOUD_STORE_NAME "cloud" #define CLOUD_STORE_NAME "cloud"
#define CLOUD_TAG_MAX (32) #define CLOUD_TAG_MAX (32)
#ifndef OC_SECURITY
// dummy storage
int
oc_storage_config(const char *store)
{
(void)store;
return 0;
}
long
oc_storage_read(const char *store, uint8_t *buf, size_t size)
{
(void)store;
(void)buf;
(void)size;
return -1;
}
long
oc_storage_write(const char *store, uint8_t *buf, size_t size)
{
(void)store;
(void)buf;
(void)size;
return -1;
}
#endif
static int cloud_store_load_internal(const char *store_name, static int cloud_store_load_internal(const char *store_name,
oc_cloud_store_t *store); oc_cloud_store_t *store);
static void gen_cloud_tag(const char *name, size_t device, char *cloud_tag); static void gen_cloud_tag(const char *name, size_t device, char *cloud_tag);
......
...@@ -496,6 +496,52 @@ oc_string_to_endpoint(oc_string_t *endpoint_str, oc_endpoint_t *endpoint, ...@@ -496,6 +496,52 @@ oc_string_to_endpoint(oc_string_t *endpoint_str, oc_endpoint_t *endpoint,
return -1; return -1;
} }
int
oc_endpoint_string_parse_path(oc_string_t *endpoint_str, oc_string_t *path)
{
if (!endpoint_str) {
return -1;
}
if (!path) {
return -1;
}
const char *address = NULL;
address = strstr(oc_string(*endpoint_str), "://");
if(!address) {
return -1;
}
// 3 is string length of "://"
address += 3;
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) {
return -1;
}
/* Extract a uri path if available */
const char *path_start = NULL;
const char *query_start = NULL;
path_start = memchr(address, '/', len);
if (!path_start) {
// no path found return error
return -1;
}
query_start = memchr((address + (path_start - address)), '?',
(len - (path_start - address)));
if (query_start) {
oc_new_string(path, path_start, (query_start - path_start));
} else {
oc_new_string(path, path_start, (len - (path_start - address)));
}
return 0;
}
int int
oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint) oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint)
{ {
......
...@@ -22,14 +22,19 @@ ...@@ -22,14 +22,19 @@
#include "oc_introspection_internal.h" #include "oc_introspection_internal.h"
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include "oc_config.h"
#ifndef OC_IDD_API #ifndef OC_IDD_API
#include "server_introspection.dat.h" #include "server_introspection.dat.h"
#else /* OC_IDD_API */ #else /* OC_IDD_API */
#if !defined(OC_STORAGE) && defined(OC_IDD_API)
#error Preprocessor macro OC_IDD_API is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_IDD_API is defined.
#endif
#define MAX_TAG_LENGTH 20 #define MAX_TAG_LENGTH 20
#ifdef OC_SECURITY
static void static void
gen_idd_tag(const char *name, size_t device_index, char *idd_tag) gen_idd_tag(const char *name, size_t device_index, char *idd_tag)
{ {
...@@ -39,19 +44,13 @@ gen_idd_tag(const char *name, size_t device_index, char *idd_tag) ...@@ -39,19 +44,13 @@ gen_idd_tag(const char *name, size_t device_index, char *idd_tag)
(idd_tag_len < MAX_TAG_LENGTH) ? idd_tag_len + 1 : MAX_TAG_LENGTH; (idd_tag_len < MAX_TAG_LENGTH) ? idd_tag_len + 1 : MAX_TAG_LENGTH;
idd_tag[idd_tag_len] = '\0'; idd_tag[idd_tag_len] = '\0';
} }
#endif /* OC_SECURITY */
void void
oc_set_introspection_data(size_t device, uint8_t *IDD, size_t IDD_size) oc_set_introspection_data(size_t device, uint8_t *IDD, size_t IDD_size)
{ {
(void) device;
(void) IDD;
(void) IDD_size;
#ifdef OC_SECURITY
char idd_tag[MAX_TAG_LENGTH]; char idd_tag[MAX_TAG_LENGTH];
gen_idd_tag("IDD", device, idd_tag); gen_idd_tag("IDD", device, idd_tag);
oc_storage_write(idd_tag, IDD, IDD_size); oc_storage_write(idd_tag, IDD, IDD_size);
#endif /* OC_SECURITY */
} }
#endif /*OC_IDD_API*/ #endif /*OC_IDD_API*/
...@@ -73,13 +72,11 @@ oc_core_introspection_data_handler(oc_request_t *request, ...@@ -73,13 +72,11 @@ oc_core_introspection_data_handler(oc_request_t *request,
} else { } else {
IDD_size = -1; IDD_size = -1;
} }
#else /* OC_IDD_API */ #else /* OC_IDD_API */
#ifdef OC_SECURITY
char idd_tag[MAX_TAG_LENGTH]; char idd_tag[MAX_TAG_LENGTH];
gen_idd_tag("IDD", request->resource->device, idd_tag); gen_idd_tag("IDD", request->resource->device, idd_tag);
IDD_size = oc_storage_read( IDD_size = oc_storage_read(
idd_tag, request->response->response_buffer->buffer, OC_MAX_APP_DATA_SIZE); idd_tag, request->response->response_buffer->buffer, OC_MAX_APP_DATA_SIZE);
#endif /* OC_SECURITY */
#endif /* OC_IDD_API */ #endif /* OC_IDD_API */
if (IDD_size >= 0 && IDD_size < OC_MAX_APP_DATA_SIZE) { if (IDD_size >= 0 && IDD_size < OC_MAX_APP_DATA_SIZE) {
......
...@@ -1229,7 +1229,7 @@ oc_ri_find_client_cb_by_token(uint8_t *token, uint8_t token_len) ...@@ -1229,7 +1229,7 @@ oc_ri_find_client_cb_by_token(uint8_t *token, uint8_t token_len)
return cb; return cb;
} }
static bool bool
oc_ri_is_client_cb_valid(oc_client_cb_t *client_cb) oc_ri_is_client_cb_valid(oc_client_cb_t *client_cb)
{ {
oc_client_cb_t *cb = oc_list_head(client_cbs); oc_client_cb_t *cb = oc_list_head(client_cbs);
...@@ -1316,7 +1316,6 @@ oc_ri_invoke_client_cb(void *response, oc_client_cb_t *cb, ...@@ -1316,7 +1316,6 @@ oc_ri_invoke_client_cb(void *response, oc_client_cb_t *cb,
struct oc_memb rep_objects = { sizeof(oc_rep_t), 0, 0, 0, 0 }; struct oc_memb rep_objects = { sizeof(oc_rep_t), 0, 0, 0, 0 };
#endif /* OC_DYNAMIC_ALLOCATION */ #endif /* OC_DYNAMIC_ALLOCATION */
oc_rep_set_pool(&rep_objects); oc_rep_set_pool(&rep_objects);
if (payload_len) { if (payload_len) {
if (cb->discovery) { if (cb->discovery) {
if (oc_ri_process_discovery_payload(payload, payload_len, cb->handler, if (oc_ri_process_discovery_payload(payload, payload_len, cb->handler,
...@@ -1401,7 +1400,6 @@ oc_ri_invoke_client_cb(void *response, oc_client_cb_t *cb, ...@@ -1401,7 +1400,6 @@ oc_ri_invoke_client_cb(void *response, oc_client_cb_t *cb,
} }
} }
} }
return true; return true;
} }
......
...@@ -22,6 +22,11 @@ ...@@ -22,6 +22,11 @@
#include "oc_swupdate_internal.h" #include "oc_swupdate_internal.h"
#include "security/oc_pstat.h" #include "security/oc_pstat.h"
#ifndef OC_STORAGE
#error Preprocessor macro OC_SOFTWARE_UPDATE is defined but OC_STORAGE is not defined \
check oc_config.h and make sure OC_STORAGE is defined if OC_SOFTWARE_UPDATE is defined.
#endif
#ifdef OC_DYNAMIC_ALLOCATION #ifdef OC_DYNAMIC_ALLOCATION
#include "port/oc_assert.h" #include "port/oc_assert.h"
#include <stdlib.h> #include <stdlib.h>
......
This diff is collapsed.
...@@ -176,9 +176,9 @@ main(void) ...@@ -176,9 +176,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./client_block_linux_creds"); oc_storage_config("./client_block_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_mtu_size(300); oc_set_mtu_size(300);
oc_set_max_app_data_size(2048); oc_set_max_app_data_size(2048);
......
...@@ -427,9 +427,9 @@ main(void) ...@@ -427,9 +427,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./client_collections_linux_creds"); oc_storage_config("./client_collections_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -163,9 +163,9 @@ main(void) ...@@ -163,9 +163,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./client_creds"); oc_storage_config("./client_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_con_res_announced(false); oc_set_con_res_announced(false);
init = oc_main_init(&handler); init = oc_main_init(&handler);
......
...@@ -394,9 +394,9 @@ main(void) ...@@ -394,9 +394,9 @@ main(void)
.signal_event_loop = .signal_event_loop =
signal_event_loop }; signal_event_loop };
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./client_multithread_linux_creds"); oc_storage_config("./client_multithread_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
if (pthread_mutex_init(&mutex, NULL) < 0) { if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n"); printf("pthread_mutex_init failed!\n");
......
...@@ -565,7 +565,9 @@ ocf_event_thread(void *data) ...@@ -565,7 +565,9 @@ ocf_event_thread(void *data)
.register_resources = .register_resources =
register_resources }; register_resources };
#ifdef OC_STORAGE
oc_storage_config("./cloud_tests_creds"); oc_storage_config("./cloud_tests_creds");
#endif /* OC_STORAGE */
if (pthread_mutex_init(&mutex, NULL) < 0) { if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n"); printf("pthread_mutex_init failed!\n");
......
...@@ -296,7 +296,9 @@ main(void) ...@@ -296,7 +296,9 @@ main(void)
.signal_event_loop = signal_event_loop, .signal_event_loop = signal_event_loop,
.register_resources = .register_resources =
register_resources }; register_resources };
#ifdef OC_STORAGE
oc_storage_config("./cloud_server_creds/"); oc_storage_config("./cloud_server_creds/");
#endif /* OC_STORAGE */
ret = oc_main_init(&handler); ret = oc_main_init(&handler);
if (ret < 0) if (ret < 0)
......
...@@ -347,9 +347,9 @@ main(void) ...@@ -347,9 +347,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./multi_device_client_creds"); oc_storage_config("./multi_device_client_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -228,9 +228,9 @@ main(void) ...@@ -228,9 +228,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./multi_device_server_creds"); oc_storage_config("./multi_device_server_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -142,9 +142,9 @@ main(void) ...@@ -142,9 +142,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./server_block_linux_creds"); oc_storage_config("./server_block_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_mtu_size(200); oc_set_mtu_size(200);
oc_set_max_app_data_size(2048); oc_set_max_app_data_size(2048);
......
...@@ -338,9 +338,9 @@ main(void) ...@@ -338,9 +338,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./server_collections_linux_creds"); oc_storage_config("./server_collections_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -144,9 +144,9 @@ main(void) ...@@ -144,9 +144,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./server_creds"); oc_storage_config("./server_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -267,9 +267,9 @@ main(void) ...@@ -267,9 +267,9 @@ main(void)
.register_resources = .register_resources =
register_resources }; register_resources };
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./server_multithread_linux_creds"); oc_storage_config("./server_multithread_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
if (pthread_mutex_init(&mutex, NULL) < 0) { if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n"); printf("pthread_mutex_init failed!\n");
......
...@@ -261,9 +261,9 @@ main(void) ...@@ -261,9 +261,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./simpleclient_creds"); oc_storage_config("./simpleclient_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -260,9 +260,9 @@ main(void) ...@@ -260,9 +260,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./simpleclient_creds/"); oc_storage_config("./simpleclient_creds/");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -155,9 +155,9 @@ main(void) ...@@ -155,9 +155,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./simpleserver_creds"); oc_storage_config("./simpleserver_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
......
...@@ -391,9 +391,9 @@ main(void) ...@@ -391,9 +391,9 @@ main(void)
oc_set_mtu_size(16384); oc_set_mtu_size(16384);
oc_set_max_app_data_size(16384); oc_set_max_app_data_size(16384);
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./simpleserver_pki_creds"); oc_storage_config("./simpleserver_pki_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL); oc_set_factory_presets_cb(factory_presets_cb, NULL);
......
...@@ -151,9 +151,9 @@ main(void) ...@@ -151,9 +151,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./simpleserver_creds/"); oc_storage_config("./simpleserver_creds/");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
init = oc_main_init(&handler); init = oc_main_init(&handler);
if (init < 0) if (init < 0)
...@@ -174,4 +174,4 @@ main(void) ...@@ -174,4 +174,4 @@ main(void)
oc_main_shutdown(); oc_main_shutdown();
return 0; return 0;
} }
\ No newline at end of file
...@@ -696,9 +696,9 @@ main(void) ...@@ -696,9 +696,9 @@ main(void)
oc_set_con_res_announced(false); oc_set_con_res_announced(false);
oc_set_max_app_data_size(16384); oc_set_max_app_data_size(16384);
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./smart_home_server_linux_creds"); oc_storage_config("./smart_home_server_linux_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL); oc_set_factory_presets_cb(factory_presets_cb, NULL);
#ifdef OC_SECURITY #ifdef OC_SECURITY
......
...@@ -310,9 +310,9 @@ main(void) ...@@ -310,9 +310,9 @@ main(void)
oc_set_con_res_announced(false); oc_set_con_res_announced(false);
oc_set_max_app_data_size(16384); oc_set_max_app_data_size(16384);
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./smart_home_server_with_mock_swupdate_creds"); oc_storage_config("./smart_home_server_with_mock_swupdate_creds");
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_factory_presets_cb(factory_presets_cb, NULL); oc_set_factory_presets_cb(factory_presets_cb, NULL);
#ifdef OC_SECURITY #ifdef OC_SECURITY
......
...@@ -412,10 +412,10 @@ main(void) ...@@ -412,10 +412,10 @@ main(void)
.signal_event_loop = signal_event_loop, .signal_event_loop = signal_event_loop,
.requests_entry = issue_requests }; .requests_entry = issue_requests };
#ifdef OC_SECURITY #ifdef OC_STORAGE
oc_storage_config("./smart_lock_creds"); oc_storage_config("./smart_lock_creds");
oc_set_random_pin_callback(random_pin_cb, NULL); oc_set_random_pin_callback(random_pin_cb, NULL);
#endif /* OC_SECURITY */ #endif /* OC_STORAGE */
oc_set_con_res_announced(false); oc_set_con_res_announced(false);
init = oc_main_init(&handler); init = oc_main_init(&handler);
......
...@@ -141,9 +141,9 @@ main(void) ...@@ -141,9 +141,9 @@ main(void)
oc_clock_time_t next_event; oc_clock_time_t next_event;