diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml index 7e54f586da..570b67eea9 100644 --- a/.github/workflows/cmake-linux.yml +++ b/.github/workflows/cmake-linux.yml @@ -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 diff --git a/api/unittest/eptest.cpp b/api/unittest/eptest.cpp index aa3e52cf82..59f1f58675 100644 --- a/api/unittest/eptest.cpp +++ b/api/unittest/eptest.cpp @@ -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: @@ -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); @@ -267,10 +282,14 @@ TEST(OCEndpoints, StringToEndpoint) // test dns lookup when uri is NULL std::vector 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; @@ -281,7 +300,7 @@ TEST(OCEndpoints, StringToEndpoint) EXPECT_EQ(ret, 0) << "spu4[" << i << "] " << spu4[i]; oc_free_string(&s); } -#endif +#endif /* OC_TCP */ #ifdef _WIN32 WSACleanup(); #endif /* _WIN32 */ @@ -289,23 +308,23 @@ TEST(OCEndpoints, StringToEndpoint) 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 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: @@ -376,11 +395,11 @@ TEST(OCEndpoints, EndpointStringParsePath) } // paths with expected errors - const char *spu2[2] = { + std::vector 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; diff --git a/apps/server_certification_tests.c b/apps/server_certification_tests.c index 35c0e6f2f2..f9f5af61aa 100644 --- a/apps/server_certification_tests.c +++ b/apps/server_certification_tests.c @@ -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"; @@ -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(); @@ -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; } @@ -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 @@ -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) { @@ -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; @@ -850,7 +850,6 @@ 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)); @@ -858,6 +857,7 @@ post_switch(oc_request_t *request, oc_interface_mask_t iface_mask, 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(); @@ -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) { @@ -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); @@ -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) diff --git a/port/linux/ipadapter.c b/port/linux/ipadapter.c index 87654adc9d..f7016b1bcb 100644 --- a/port/linux/ipadapter.c +++ b/port/linux/ipadapter.c @@ -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) {