diff --git a/api/oc_discovery.c b/api/oc_discovery.c index e826ce5e4..1f7fb339c 100644 --- a/api/oc_discovery.c +++ b/api/oc_discovery.c @@ -1082,43 +1082,16 @@ discovery_check_sduuid(oc_request_t *request, const char *query, } #endif /* OC_SECURITY */ -// static void discovery_encode(oc_request_t *request, oc_interface_mask_t -// iface) -// { - -// } - -static void -discovery_resource_get(oc_request_t *request, oc_interface_mask_t iface, - void *data) +static int +discovery_encode(oc_request_t *request, oc_interface_mask_t iface) { - (void)data; - -#ifdef OC_SPEC_VER_OIC - if (request->origin && request->origin->version == OIC_VER_1_1_0) { - oc_core_1_1_discovery_handler(request, iface, data); - return; - } -#endif /* OC_SPEC_VER_OIC */ - - // for dev without SVRs, ignore queries for backward compatibility -#ifdef OC_SECURITY - const char *q; - int ql = oc_get_query_value_v1(request, OCF_RES_QUERY_SDUUID, - OC_CHAR_ARRAY_LEN(OCF_RES_QUERY_SDUUID), &q); - if (ql > 0 && !discovery_check_sduuid(request, q, (size_t)ql)) { - return; - } -#endif /* OC_SECURITY */ - - oc_status_t code = OC_STATUS_OK; - int matches = 0; switch (iface) { case OC_IF_LL: { oc_rep_start_links_array(); - matches = process_device_resources(oc_rep_array(links), request); + int matches = process_device_resources(oc_rep_array(links), request); oc_rep_end_links_array(); - } break; + return matches > 0 ? OC_STATUS_OK : OC_IGNORE; + } #ifdef OC_RES_BATCH_SUPPORT case OC_IF_B: { if (request->origin == NULL @@ -1127,22 +1100,22 @@ discovery_resource_get(oc_request_t *request, oc_interface_mask_t iface, #endif /* OC_SECURITY */ ) { OC_ERR("oc_discovery: insecure batch interface requests are unsupported"); - break; + return -1; } oc_rep_start_links_array(); - code = discovery_process_batch_request(oc_rep_array(links), request); + int code = discovery_process_batch_request(oc_rep_array(links), request); oc_rep_end_links_array(); - if (code != OC_STATUS_NOT_MODIFIED) { - ++matches; - } - } break; + return code; + } #endif /* OC_RES_BATCH_SUPPORT */ case OC_IF_BASELINE: #ifdef OC_HAS_FEATURE_ETAG_INTERFACE case PLGD_IF_ETAG: #endif /* OC_HAS_FEATURE_ETAG_INTERFACE */ { + int matches; size_t device = request->resource->device; + // oc_rep_begin_array(oc_rep_get_encoder(), root); oc_rep_start_links_array(); oc_rep_start_object(oc_rep_array(links), props); memcpy(&root_map, &props_map, sizeof(CborEncoder)); @@ -1165,13 +1138,44 @@ discovery_resource_get(oc_request_t *request, oc_interface_mask_t iface, memcpy(&props_map, &root_map, sizeof(CborEncoder)); oc_rep_end_object(oc_rep_array(links), props); oc_rep_end_links_array(); + + // oc_rep_end_array(oc_rep_get_encoder(), root); + return matches > 0 ? OC_STATUS_OK : OC_STATUS_NOT_MODIFIED; } break; default: break; } + return -1; +} + +static void +discovery_resource_get(oc_request_t *request, oc_interface_mask_t iface, + void *data) +{ + (void)data; + +#ifdef OC_SPEC_VER_OIC + if (request->origin && request->origin->version == OIC_VER_1_1_0) { + oc_core_1_1_discovery_handler(request, iface, data); + return; + } +#endif /* OC_SPEC_VER_OIC */ + + // for dev without SVRs, ignore queries for backward compatibility +#ifdef OC_SECURITY + const char *q; + int ql = oc_get_query_value_v1(request, OCF_RES_QUERY_SDUUID, + OC_CHAR_ARRAY_LEN(OCF_RES_QUERY_SDUUID), &q); + if (ql > 0 && !discovery_check_sduuid(request, q, (size_t)ql)) { + return; + } +#endif /* OC_SECURITY */ + + oc_status_t code = discovery_encode(request, iface); int response_length = oc_rep_get_encoded_payload_size(); - send_response(request, APPLICATION_VND_OCF_CBOR, matches == 0, code, + bool has_data = (code == OC_STATUS_OK); + send_response(request, APPLICATION_VND_OCF_CBOR, !has_data, code, response_length < 0 ? 0 : (size_t)response_length); } diff --git a/api/oc_etag.c b/api/oc_etag.c index a03d0a311..205d1dae2 100644 --- a/api/oc_etag.c +++ b/api/oc_etag.c @@ -56,9 +56,9 @@ #include #include -#ifndef OC_HAS_FEATURE_CRC_ENCODER -#error "CRC encoder must be enabled to use the ETag feature" -#endif /* !OC_HAS_FEATURE_CRC_ENCODER */ +#if defined(OC_STORAGE) && !defined(OC_HAS_FEATURE_CRC_ENCODER) +#error "CRC encoder must be enabled to use the ETag feature with storage" +#endif /* OC_STORAGE && !OC_HAS_FEATURE_CRC_ENCODER */ static uint64_t g_etag = 0; diff --git a/api/plgd/plgd_time_internal.h b/api/plgd/plgd_time_internal.h index c9c96c1a8..0b62098ce 100644 --- a/api/plgd/plgd_time_internal.h +++ b/api/plgd/plgd_time_internal.h @@ -103,7 +103,7 @@ typedef enum plgd_time_encode_flag_t { * @brief Encode plgd time properties to the global encoder. * * @param pt plgd time to encode - * @param iface_mask encoding interface + * @param iface encoding interface * @param flags mask of encoding flags * @return 0 on success * @return -1 on error diff --git a/api/unittest/discoverytest.cpp b/api/unittest/discoverytest.cpp index 546862b44..a49653bee 100644 --- a/api/unittest/discoverytest.cpp +++ b/api/unittest/discoverytest.cpp @@ -110,6 +110,9 @@ class TestDiscoveryWithServer : public ::testing::Test { public: static void SetUpTestCase() { + // TODO: rm + oc_log_set_level(OC_LOG_LEVEL_DEBUG); + #if defined(OC_DYNAMIC_ALLOCATION) && !defined(OC_APP_DATA_BUFFER_SIZE) oc_set_max_app_data_size(16384); #endif /* OC_DYNAMIC_ALLOCATION && !OC_APP_DATA_BUFFER_SIZE */ @@ -142,6 +145,9 @@ class TestDiscoveryWithServer : public ::testing::Test { #if defined(OC_DYNAMIC_ALLOCATION) && !defined(OC_APP_DATA_BUFFER_SIZE) oc_set_max_app_data_size(g_max_app_data_size); #endif /* OC_DYNAMIC_ALLOCATION && !OC_APP_DATA_BUFFER_SIZE */ + + // TODO: rm + oc_log_set_level(OC_LOG_LEVEL_INFO); } void SetUp() override diff --git a/util/oc_features.h b/util/oc_features.h index 4699378f6..4638fcd01 100644 --- a/util/oc_features.h +++ b/util/oc_features.h @@ -63,11 +63,8 @@ #endif /* OC_ETAG && OC_SERVER */ #if defined(OC_HAS_FEATURE_ETAG) && defined(OC_STORAGE) -#define OC_HAS_FEATURE_ETAG_INTERFACE -#endif /* OC_HAS_FEATURE_ETAG && OC_STORAGE */ - -#ifdef OC_HAS_FEATURE_ETAG_INTERFACE #define OC_HAS_FEATURE_CRC_ENCODER -#endif /* OC_HAS_FEATURE_ETAG_INTERFACE */ +// #define OC_HAS_FEATURE_ETAG_INTERFACE +#endif /* OC_HAS_FEATURE_ETAG && OC_STORAGE */ #endif /* OC_FEATURES_H */