Skip to content

Commit

Permalink
fixup! Calcuate crc64 for a resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Oct 20, 2023
1 parent fc46b62 commit 4a50340
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 48 deletions.
82 changes: 43 additions & 39 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions api/oc_etag.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
#include <stdint.h>
#include <stdlib.h>

#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;

Expand Down
2 changes: 1 addition & 1 deletion api/plgd/plgd_time_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions api/unittest/discoverytest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions util/oc_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 4a50340

Please sign in to comment.