Skip to content

Commit

Permalink
fixup! Fix issues reported by SonarCloud and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Apr 13, 2024
1 parent 6587bcc commit 2882829
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 161 deletions.
15 changes: 9 additions & 6 deletions api/oc_core_res.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ static oc_device_info_t g_oc_device_info[OC_MAX_NUM_DEVICES] = { 0 };
static int g_res_latency = 0;
static OC_ATOMIC_UINT32_T g_device_count = 0;

bool
oc_is_device_resource_uri(oc_string_view_t uri)
{
return oc_resource_match_uri(OC_STRING_VIEW(OCF_D_URI), uri);
}

void
oc_core_init(void)
{
Expand Down Expand Up @@ -688,8 +694,7 @@ oc_core_get_resource_type_by_uri(const char *uri, size_t uri_len)
if (oc_is_platform_resource_uri(oc_string_view(uri, uri_len))) {
return OCF_P;
}
if (core_is_resource_uri(uri, uri_len, OCF_D_URI,
OC_CHAR_ARRAY_LEN(OCF_D_URI))) {
if (oc_is_device_resource_uri(oc_string_view(uri, uri_len))) {
return OCF_D;
}
if (oc_is_discovery_resource_uri(oc_string_view(uri, uri_len))) {
Expand All @@ -711,14 +716,12 @@ oc_core_get_resource_type_by_uri(const char *uri, size_t uri_len)
}
#endif /* OC_INTROSPECTION */
#ifdef OC_HAS_FEATURE_PLGD_TIME
if (core_is_resource_uri(uri, uri_len, PLGD_TIME_URI,
OC_CHAR_ARRAY_LEN(PLGD_TIME_URI))) {
if (plgd_is_time_resource_uri(oc_string_view(uri, uri_len))) {
return PLGD_TIME;
}
#endif /* OC_HAS_FEATURE_PLGD_TIME */
#ifdef OC_WKCORE
if (core_is_resource_uri(uri, uri_len, OC_WELLKNOWNCORE_URI,
OC_CHAR_ARRAY_LEN(OC_WELLKNOWNCORE_URI))) {
if (oc_is_wkcore_resource_uri(oc_string_view(uri, uri_len))) {
return WELLKNOWNCORE;
}
#endif /* OC_WKCORE */
Expand Down
6 changes: 6 additions & 0 deletions api/oc_core_res_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef OC_CORE_RES_INTERNAL_H
#define OC_CORE_RES_INTERNAL_H

#include "api/oc_helpers_internal.h"
#include "oc_api.h"
#include "oc_core_res.h"
#include "oc_helpers.h"
Expand All @@ -37,6 +38,11 @@ extern "C" {
#define OCF_D_URI "/oic/d"
#define OCF_D_RT "oic.wk.d"

/** @brief Check if the URI matches the device resource URI (with or without
* the leading slash)
*/
bool oc_is_device_resource_uri(oc_string_view_t uri);

/**
* @brief initialize the core functionality
*/
Expand Down
6 changes: 6 additions & 0 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,12 @@ oc_create_wkcore_resource(size_t device)
OC_WELLKNOWNCORE_RT);
}

bool
oc_is_wkcore_resource_uri(oc_string_view_t uri)
{
return oc_resource_match_uri(OC_STRING_VIEW(OC_WELLKNOWNCORE_URI), uri);
}

#endif /* OC_WKCORE */

void
Expand Down
6 changes: 6 additions & 0 deletions api/oc_discovery_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ uint64_t oc_discovery_get_batch_etag(const oc_endpoint_t *endpoint,
#define OC_WELLKNOWNCORE_URI "/.well-known/core"
#define OC_WELLKNOWNCORE_RT "wk"

/** @brief Create /.well-known/core resource */
void oc_create_wkcore_resource(size_t device);

/** @brief Check if the URI matches the wkcore resource URI (with or without
* the leading slash)
*/
bool oc_is_wkcore_resource_uri(oc_string_view_t uri);

#endif /* OC_WKCORE */

#ifdef __cplusplus
Expand Down
3 changes: 1 addition & 2 deletions api/oc_etag.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ bool
oc_etag_dump_ignore_resource(const char *uri, size_t uri_len)
{
#ifdef OC_WKCORE
if (uri_len == OC_CHAR_ARRAY_LEN(OC_WELLKNOWNCORE_URI) &&
memcmp(uri, OC_WELLKNOWNCORE_URI, uri_len) == 0) {
if (oc_is_wkcore_resource_uri(oc_string_view(uri, uri_len))) {
return true;
}
#endif /* OC_WKCORE */
Expand Down
6 changes: 6 additions & 0 deletions api/plgd/plgd_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,12 @@ plgd_time_create_resource(void)
/*delete*/ NULL, 1, PLGD_TIME_RT);
}

bool
plgd_is_time_resource_uri(oc_string_view_t uri)
{
return oc_resource_match_uri(OC_STRING_VIEW(PLGD_TIME_URI), uri);
}

void
plgd_time_configure(bool use_in_mbedtls,
plgd_set_system_time_fn_t set_system_time,
Expand Down
6 changes: 6 additions & 0 deletions api/plgd/plgd_time_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#ifdef OC_HAS_FEATURE_PLGD_TIME

#include "api/oc_helpers_internal.h"
#include "oc_rep.h"
#include "oc_ri.h"
#include "plgd/plgd_time.h"
Expand Down Expand Up @@ -56,6 +57,11 @@ extern "C" {
*/
void plgd_time_create_resource(void);

/** @brief Check if the URI matches the plgd time resource URI (with or without
* the leading slash)
*/
bool plgd_is_time_resource_uri(oc_string_view_t uri);

typedef struct plgd_time_store_t
{
oc_clock_time_t last_synced_time;
Expand Down
Loading

0 comments on commit 2882829

Please sign in to comment.