Skip to content

Commit

Permalink
Fix compilation when OC_STORAGE is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 authored Oct 17, 2022
1 parent d4e4ec9 commit 95365df
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
- args: "-DOC_SECURITY_ENABLED=OFF -DOC_TCP_ENABLED=ON -DOC_IPV4_ENABLED=ON"
# collection create if on, push notification on, tcp off
- args: "-DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_PUSH_ENABLED=ON"
# everything off (dynamic allocation off, secure off, pki off, idd off, oscore off)
- args: "-DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_SECURITY_ENABLED=OFF -DOC_PKI_ENABLED=OFF -DOC_IDD_API_ENABLED=OFF -DOC_OSCORE_ENABLED=OFF"

steps:
- name: Checkout repository
Expand Down
61 changes: 40 additions & 21 deletions api/unittest/eptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ TEST(OCEndpoints, StringToEndpoint)
#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */
return;
#endif /* OC_IPV4 */
oc_free_string(&s);
oc_free_string(&uri);
continue;
#endif /* OC_IPV4 || OC_DNS_LOOKUP_IPV6 */

switch (i) {
case 0:
Expand Down Expand Up @@ -218,15 +220,28 @@ TEST(OCEndpoints, StringToEndpoint)
memset(&uri, 0, sizeof(oc_string_t));

int ret = oc_string_to_endpoint(&s, &ep, &uri);
EXPECT_EQ(ret, 0) << "spu3[" << i << "] " << spu3[i];
switch (i) {
case 0:
#if defined(OC_IPV4) || defined(OC_DNS_LOOKUP_IPV6)
EXPECT_EQ(ret, 0) << "spu3[" << i << "] " << spu3[i];
#else
EXPECT_EQ(ret, -1) << "spu3[" << i << "] " << spu3[i];
#endif /* OC_IPV4 || OC_DNS_LOOKUP_IPV6 */
break;
default:
EXPECT_EQ(ret, 0) << "spu3[" << i << "] " << spu3[i];
break;
}

switch (i) {
case 0:
#if defined(OC_IPV4) || defined(OC_DNS_LOOKUP_IPV6)
ASSERT_TRUE((ep.flags & IPV4) || (ep.flags & IPV6));
ASSERT_TRUE(ep.flags & SECURED);
ASSERT_TRUE(ep.flags & TCP);
EXPECT_EQ(ep.addr.ipv4.port, 3456);
EXPECT_EQ(oc_string_len(uri), 0);
#endif /* OC_IPV4 || OC_DNS_LOOKUP_IPV6 */
break;
case 1: {
ASSERT_TRUE(ep.flags & IPV6);
Expand Down Expand Up @@ -267,10 +282,14 @@ TEST(OCEndpoints, StringToEndpoint)

// test dns lookup when uri is NULL
std::vector<const char *> spu4 = {
#ifdef OC_IPV4
"coap://10.211.55.3:56789/a/light",
"coaps+tcp://10.211.55.3/a/light",
#endif /* OC_IPV4 */
#if defined(OC_IPV4) || defined(OC_DNS_LOOKUP_IPV6)
"coap://openconnectivity.org/alpha",
"coaps://openconnectivity.org:3456/alpha",
#endif /* OC_IPV4 || OC_DNS_LOOKUP_IPV6 */
};
for (size_t i = 0; i < spu4.size(); i++) {
oc_string_t s;
Expand All @@ -281,31 +300,31 @@ TEST(OCEndpoints, StringToEndpoint)
EXPECT_EQ(ret, 0) << "spu4[" << i << "] " << spu4[i];
oc_free_string(&s);
}
#endif
#endif /* OC_TCP */
#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */
}

TEST(OCEndpoints, EndpointStringParsePath)
{
const char *spu[12] = { "coaps://10.211.55.3:56789/a/light",
"coap://openconnectivity.org",
"coap://openconnectivity.org/alpha",
"coaps://openconnectivity.org:3456/alpha",
"coaps+tcp://10.211.55.3/a/light",
"coap+tcp://1.2.3.4:2568",
"coaps+tcp://openconnectivity.org:3456",
"coap+tcp://[ff02::158]",
"coaps+tcp://[ff02::158]/a/light",
"coaps+tcp://[fe80::12]:2439/a/light",
"coaps+tcp://[fe80::12]:2439/a/light?s=100",
"coap://0/foo" };
for (int i = 0; i < 12; i++) {
oc_string_t s;
oc_string_t path;
std::vector<const char *> spu = { "coaps://10.211.55.3:56789/a/light",
"coap://openconnectivity.org",
"coap://openconnectivity.org/alpha",
"coaps://openconnectivity.org:3456/alpha",
"coaps+tcp://10.211.55.3/a/light",
"coap+tcp://1.2.3.4:2568",
"coaps+tcp://openconnectivity.org:3456",
"coap+tcp://[ff02::158]",
"coaps+tcp://[ff02::158]/a/light",
"coaps+tcp://[fe80::12]:2439/a/light",
"coaps+tcp://[fe80::12]:2439/a/light?s=100",
"coap://0/foo" };
for (size_t i = 0; i < spu.size(); i++) {
int ret = -1;
oc_string_t s;
oc_new_string(&s, spu[i], strlen(spu[i]));
oc_string_t path;
memset(&path, 0, sizeof(oc_string_t));
switch (i) {
case 0:
Expand Down Expand Up @@ -376,11 +395,11 @@ TEST(OCEndpoints, EndpointStringParsePath)
}

// paths with expected errors
const char *spu2[2] = {
std::vector<const char *> spu2 = {
"coaps://", // no address
"coaps:/10.211.55.3:56789/a/light" // missing ://
};
for (int i = 0; i < 2; i++) {
for (size_t i = 0; i < spu2.size(); i++) {
oc_string_t s;
oc_new_string(&s, spu2[i], strlen(spu2[i]));
oc_string_t path;
Expand Down
59 changes: 35 additions & 24 deletions apps/server_certification_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ static double temp = 5.0, temp_K = (5.0 + 273.15), temp_F = (5.0 * 9 / 5 + 32),
typedef enum { C = 100, F, K } units_t;
units_t temp_units = C;

int g_switch_storage_status = 0; /* 0=no storage, 1=startup, 2=startup.revert */
bool g_switch_value =
#ifdef OC_STORAGE
static int g_switch_storage_status =
0; // 0=no storage, 1=startup, 2=startup.revert
#endif /* OC_STORAGE */
static bool g_switch_value =
false; /* current value of property "value" The status of the switch. */

const char *mfg_persistent_uuid = "f6e10d9c-a1c9-43ba-a800-f1b0aad2a889";
Expand Down Expand Up @@ -748,7 +751,6 @@ get_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
{
(void)user_data;
PRINT("GET_switch:\n");
bool error_state = false;
int oc_status_code = OC_STATUS_OK;

oc_rep_start_root_object();
Expand All @@ -759,9 +761,10 @@ get_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
case OC_IF_A:
oc_rep_set_boolean(root, value, g_switch_value);
break;
#ifdef OC_STORAGE
case OC_IF_STARTUP:
if (g_switch_storage_status != 1) {
error_state = true;
oc_status_code = OC_STATUS_BAD_OPTION;
break;
}

Expand All @@ -775,22 +778,20 @@ get_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
break;
case OC_IF_STARTUP_REVERT:
if (g_switch_storage_status != 2) {
error_state = true;
oc_status_code = OC_STATUS_BAD_OPTION;
break;
}

oc_status_code = OC_STATUS_NOT_MODIFIED;
break;
#endif /* OC_STORAGE */

default:
break;
}
oc_rep_end_root_object();

if (error_state == false) {
oc_send_response(request, oc_status_code);
} else {
oc_send_response(request, OC_STATUS_BAD_OPTION);
}
oc_send_response(request, oc_status_code);
}

static void
Expand All @@ -800,11 +801,12 @@ post_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
(void)iface_mask;
(void)user_data;

bool error_state = false;
int oc_status_code = OC_STATUS_CHANGED;

PRINT("POST_switch:\n");
bool state = false, bad_request = false, var_in_request = false;
bool state = false;
bool bad_request = false;
bool var_in_request = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
switch (rep->type) {
Expand All @@ -828,11 +830,9 @@ post_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
if (!var_in_request) {
bad_request = true;
}
if (bad_request) {
error_state = true;
}
long tmp_size;
if (error_state == false) {
if (!bad_request) {
#ifdef OC_STORAGE
switch (iface_mask) {
case OC_IF_STARTUP: {
g_switch_storage_status = 1;
Expand All @@ -850,14 +850,14 @@ post_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
}
case OC_IF_STARTUP_REVERT: {
g_switch_storage_status = 2;
g_switch_value = state;
oc_storage_write("g_switch_storage_status",
(uint8_t *)&g_switch_storage_status,
sizeof(g_switch_storage_status));
tmp_size =
oc_storage_write("g_switch_value", (uint8_t *)&state, sizeof(state));
PRINT("storage (startup.revert) property 'value' : %s (%ld)\n",
btoa(state), tmp_size);
g_switch_value = state;
oc_rep_start_root_object();
oc_rep_set_boolean(root, value, g_switch_value);
oc_rep_end_root_object();
Expand All @@ -877,6 +877,12 @@ post_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
break;
}
}
#else /* !OC_STORAGE */
g_switch_value = state;
oc_rep_start_root_object();
oc_rep_set_boolean(root, value, g_switch_value);
oc_rep_end_root_object();
#endif /* OC_STORAGE */
}

if (!bad_request) {
Expand Down Expand Up @@ -1690,9 +1696,11 @@ register_resources(void)
bswitch = oc_new_resource(NULL, "/switch", 1, 0);
oc_resource_bind_resource_type(bswitch, "oic.r.switch.binary");
oc_resource_bind_resource_interface(bswitch, OC_IF_A);
#ifdef OC_STORAGE
oc_resource_bind_resource_interface(bswitch, OC_IF_STARTUP);
oc_resource_bind_resource_interface(
bswitch, OC_IF_STARTUP_REVERT); /* oic.if.startup.revert */
bswitch, OC_IF_STARTUP_REVERT); // oic.if.startup.revert
#endif /* OC_STORAGE */
oc_resource_set_default_interface(bswitch, OC_IF_A);
oc_resource_set_observable(bswitch, true);
oc_resource_set_discoverable(bswitch, true);
Expand Down Expand Up @@ -1957,17 +1965,20 @@ display_device_uuid(void)
void
initialize_variables(void)
{
int ret_size = 0;
g_switch_value =
false; /* current value of property "value" The status of the switch. */

#ifdef OC_STORAGE
/* initialize global variables for resource "/switch" */
oc_storage_read("g_switch_storage_status",
(uint8_t *)&g_switch_storage_status,
sizeof(g_switch_storage_status));
g_switch_value =
false; /* current value of property "value" The status of the switch. */
ret_size = oc_storage_read("g_switch_value", (uint8_t *)&g_switch_value,
sizeof(g_switch_value));
if (ret_size != sizeof(g_switch_value))
int ret_size = oc_storage_read("g_switch_value", (uint8_t *)&g_switch_value,
sizeof(g_switch_value));
if (ret_size != sizeof(g_switch_value)) {
PRINT(" could not read store g_switch_value : %d\n", ret_size);
}
#endif /* OC_STORAGE */
}
int
main(void)
Expand Down
2 changes: 1 addition & 1 deletion port/linux/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ send_msg(int sock, struct sockaddr_storage *receiver,

int bytes_sent = 0, x;
while (bytes_sent < (int)message->length) {
iovec[0].iov_base = message->data + bytes_sent;
iovec[0].iov_base = (void *)(message->data + bytes_sent);
iovec[0].iov_len = message->length - (size_t)bytes_sent;
x = sendmsg(sock, &msg, 0);
if (x < 0) {
Expand Down

0 comments on commit 95365df

Please sign in to comment.