From ba6d6ccca69b89b6e3014eacdd681230d9ff736e Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Mon, 5 Feb 2024 09:32:33 +0100 Subject: [PATCH] cloud: remove private definitions from public API Remove oc_cloud_store_t and oc_cloud_context_t definitions from oc_cloud.h header. --- api/cloud/oc_cloud_context.c | 24 +++++ api/cloud/oc_cloud_context_internal.h | 46 ++++++++++ api/cloud/oc_cloud_rd.c | 5 +- api/cloud/oc_cloud_resource.c | 3 +- api/cloud/oc_cloud_store_internal.h | 16 ++++ api/cloud/unittest/cloud_manager_test.cpp | 1 + api/cloud/unittest/cloud_rd_test.cpp | 1 + api/cloud/unittest/cloud_store_test.cpp | 5 +- api/cloud/unittest/cloud_test.cpp | 1 + apps/cloud_proxy.c | 10 +-- include/oc_cloud.h | 104 ++++++++++------------ 11 files changed, 150 insertions(+), 66 deletions(-) diff --git a/api/cloud/oc_cloud_context.c b/api/cloud/oc_cloud_context.c index bd469847dc..df05aff3bc 100644 --- a/api/cloud/oc_cloud_context.c +++ b/api/cloud/oc_cloud_context.c @@ -118,6 +118,30 @@ oc_cloud_get_context(size_t device) return ctx; } +const char * +oc_cloud_get_apn(const oc_cloud_context_t *ctx) +{ + return oc_string(ctx->store.auth_provider); +} + +const char * +oc_cloud_get_at(const oc_cloud_context_t *ctx) +{ + return oc_string(ctx->store.access_token); +} + +const char * +oc_cloud_get_cis(const oc_cloud_context_t *ctx) +{ + return oc_string(ctx->store.ci_server); +} + +const char * +oc_cloud_get_sid(const oc_cloud_context_t *ctx) +{ + return oc_string(ctx->store.sid); +} + void cloud_context_iterate(cloud_context_iterator_cb_t cb, void *user_data) { diff --git a/api/cloud/oc_cloud_context_internal.h b/api/cloud/oc_cloud_context_internal.h index fc0bc5c815..45bc5eee8f 100644 --- a/api/cloud/oc_cloud_context_internal.h +++ b/api/cloud/oc_cloud_context_internal.h @@ -19,6 +19,7 @@ #ifndef OC_CLOUD_CONTEXT_INTERNAL_H #define OC_CLOUD_CONTEXT_INTERNAL_H +#include "api/cloud/oc_cloud_store_internal.h" #include "oc_cloud.h" #include @@ -26,6 +27,51 @@ extern "C" { #endif +/** + * @brief Cloud retry configuration structure. + */ +typedef struct oc_cloud_schedule_action_t +{ + oc_cloud_schedule_action_cb_t + on_schedule_action; /**< Callback invoked to set delay + and timeout for the action. */ + void *user_data; /**< User data provided to the schedule action callback. */ + uint16_t timeout; /**< Timeout for the action in seconds. */ +} oc_cloud_schedule_action_t; + +struct oc_cloud_context_t +{ + struct oc_cloud_context_t *next; + + size_t device; + + oc_cloud_cb_t callback; + void *user_data; + + oc_cloud_store_t store; + + oc_session_state_t cloud_ep_state; + oc_endpoint_t *cloud_ep; + uint8_t retry_count; + uint8_t retry_refresh_token_count; + oc_cloud_error_t last_error; + uint32_t time_to_live; /**< Time to live of published resources in seconds */ + + oc_link_t *rd_publish_resources; /**< Resource links to publish */ + oc_link_t *rd_published_resources; /**< Resource links already published */ + oc_link_t *rd_delete_resources; /**< Resource links to delete */ + + oc_resource_t *cloud_conf; + + int selected_identity_cred_id; /**< Selected identity cert chain. -1(default) + means any*/ + bool cloud_manager; + + oc_cloud_keepalive_t keepalive; /**< Keepalive configuration */ + oc_cloud_schedule_action_t + schedule_action; /**< Schedule action configuration */ +}; + /** * @brief Allocate and initialize cloud context for device * diff --git a/api/cloud/oc_cloud_rd.c b/api/cloud/oc_cloud_rd.c index 1cc439a89f..0fea49461a 100644 --- a/api/cloud/oc_cloud_rd.c +++ b/api/cloud/oc_cloud_rd.c @@ -17,11 +17,12 @@ ******************************************************************/ #ifdef OC_CLOUD +#include "api/cloud/oc_cloud_context_internal.h" +#include "api/cloud/oc_cloud_internal.h" +#include "api/cloud/oc_cloud_log_internal.h" #include "api/oc_link_internal.h" #include "api/oc_ri_internal.h" #include "oc_api.h" -#include "oc_cloud_internal.h" -#include "oc_cloud_log_internal.h" #include "oc_collection.h" #include "rd_client_internal.h" diff --git a/api/cloud/oc_cloud_resource.c b/api/cloud/oc_cloud_resource.c index cdc3d3b515..c43ca63e46 100644 --- a/api/cloud/oc_cloud_resource.c +++ b/api/cloud/oc_cloud_resource.c @@ -20,7 +20,8 @@ #ifdef OC_CLOUD -#include "oc_cloud_resource_internal.h" +#include "api/cloud/oc_cloud_context_internal.h" +#include "api/cloud/oc_cloud_resource_internal.h" #include "api/oc_core_res_internal.h" #include "oc_api.h" #include "oc_cloud_internal.h" diff --git a/api/cloud/oc_cloud_store_internal.h b/api/cloud/oc_cloud_store_internal.h index cd120232e0..d2006cf4d0 100644 --- a/api/cloud/oc_cloud_store_internal.h +++ b/api/cloud/oc_cloud_store_internal.h @@ -28,6 +28,22 @@ extern "C" { #endif +typedef struct oc_cloud_store_t +{ + oc_string_t ci_server; ///< URL of OCF Cloud. + oc_string_t auth_provider; ///< The name of the Authorisation Provider through + // which access token was obtained. + oc_string_t uid; + oc_string_t access_token; ///< Access token which is returned by an + ///< Authorisation Provider or OCF Cloud. + oc_string_t refresh_token; + oc_string_t sid; ///< The identity of the OCF Cloud + int64_t expires_in; + uint8_t status; + oc_cps_t cps; + size_t device; +} oc_cloud_store_t; + /** * @brief Load store data from storage * diff --git a/api/cloud/unittest/cloud_manager_test.cpp b/api/cloud/unittest/cloud_manager_test.cpp index 0f7c6d94b9..72ed6d1270 100644 --- a/api/cloud/unittest/cloud_manager_test.cpp +++ b/api/cloud/unittest/cloud_manager_test.cpp @@ -17,6 +17,7 @@ * ******************************************************************/ +#include "api/cloud/oc_cloud_context_internal.h" #include "api/cloud/oc_cloud_internal.h" #include "api/cloud/oc_cloud_manager_internal.h" #include "api/cloud/oc_cloud_store_internal.h" diff --git a/api/cloud/unittest/cloud_rd_test.cpp b/api/cloud/unittest/cloud_rd_test.cpp index c009dabd16..d9f143de6e 100644 --- a/api/cloud/unittest/cloud_rd_test.cpp +++ b/api/cloud/unittest/cloud_rd_test.cpp @@ -16,6 +16,7 @@ * ******************************************************************/ +#include "api/cloud/oc_cloud_context_internal.h" #include "api/cloud/oc_cloud_internal.h" #include "api/oc_link_internal.h" #include "oc_api.h" diff --git a/api/cloud/unittest/cloud_store_test.cpp b/api/cloud/unittest/cloud_store_test.cpp index 9d3f08e72d..f18e5dcaab 100644 --- a/api/cloud/unittest/cloud_store_test.cpp +++ b/api/cloud/unittest/cloud_store_test.cpp @@ -17,10 +17,11 @@ * ******************************************************************/ +#include "api/cloud/oc_cloud_context_internal.h" +#include "api/cloud/oc_cloud_internal.h" +#include "api/cloud/oc_cloud_store_internal.h" #include "oc_api.h" #include "oc_config.h" -#include "oc_cloud_internal.h" -#include "oc_cloud_store_internal.h" #include "oc_collection.h" #include "port/oc_storage.h" #include "port/oc_storage_internal.h" diff --git a/api/cloud/unittest/cloud_test.cpp b/api/cloud/unittest/cloud_test.cpp index ea10b63295..0cf4fb385c 100644 --- a/api/cloud/unittest/cloud_test.cpp +++ b/api/cloud/unittest/cloud_test.cpp @@ -16,6 +16,7 @@ * ******************************************************************/ +#include "api/cloud/oc_cloud_context_internal.h" #include "api/cloud/oc_cloud_internal.h" #include "oc_api.h" #include "oc_cloud.h" diff --git a/apps/cloud_proxy.c b/apps/cloud_proxy.c index 8be24c65db..9958914a8e 100644 --- a/apps/cloud_proxy.c +++ b/apps/cloud_proxy.c @@ -1680,14 +1680,14 @@ cloud_status_handler(oc_cloud_context_t *ctx, oc_cloud_status_t status, } if (ctx != NULL) { - const char *at = oc_string(ctx->store.access_token); + const char *at = oc_cloud_get_at(ctx); OC_PRINTF(" AC = %s\n", at != NULL ? at : ""); - const char *ap = oc_string(ctx->store.auth_provider); + const char *ap = oc_cloud_get_apn(ctx); OC_PRINTF(" AP = %s\n", ap != NULL ? ap : ""); - const char *ci = oc_string(ctx->store.ci_server); + const char *ci = oc_cloud_get_cis(ctx); OC_PRINTF(" CI = %s\n", ci != NULL ? ci : ""); - const char *uid = oc_string(ctx->store.uid); - OC_PRINTF(" UUID = %s\n", uid != NULL ? uid : ""); + const char *sid = oc_cloud_get_sid(ctx); + OC_PRINTF(" UUID = %s\n", sid != NULL ? sid : ""); } } #endif // OC_CLOUD diff --git a/include/oc_cloud.h b/include/oc_cloud.h index ef01db3fc7..8a3a185a84 100644 --- a/include/oc_cloud.h +++ b/include/oc_cloud.h @@ -56,20 +56,6 @@ typedef enum oc_cps_t { OC_CPS_DEREGISTERING } oc_cps_t; -typedef struct oc_cloud_store_t -{ - oc_string_t ci_server; - oc_string_t auth_provider; - oc_string_t uid; - oc_string_t access_token; - oc_string_t refresh_token; - oc_string_t sid; - int64_t expires_in; - uint8_t status; - oc_cps_t cps; - size_t device; -} oc_cloud_store_t; - typedef enum { CLOUD_OK = 0, CLOUD_ERROR_RESPONSE = 1, @@ -78,7 +64,7 @@ typedef enum { CLOUD_ERROR_UNAUTHORIZED = 4, } oc_cloud_error_t; -struct oc_cloud_context_t; +typedef struct oc_cloud_context_t oc_cloud_context_t; /** @brief A function pointer for handling the cloud status. @@ -158,55 +144,61 @@ typedef bool (*oc_cloud_schedule_action_cb_t)(oc_cloud_action_t action, void *user_data) OC_NONNULL(3, 4); /** - * @brief Cloud retry configuration structure. + * @brief Get cloud context for device. */ -typedef struct oc_cloud_schedule_action_t -{ - oc_cloud_schedule_action_cb_t - on_schedule_action; /**< Callback invoked to set delay - and timeout for the action. */ - void *user_data; /**< User data provided to the schedule action callback. */ - uint16_t timeout; /**< Timeout for the action in seconds. */ -} oc_cloud_schedule_action_t; - -typedef struct oc_cloud_context_t -{ - struct oc_cloud_context_t *next; - - size_t device; - - oc_cloud_cb_t callback; - void *user_data; - - oc_cloud_store_t store; - - oc_session_state_t cloud_ep_state; - oc_endpoint_t *cloud_ep; - uint8_t retry_count; - uint8_t retry_refresh_token_count; - oc_cloud_error_t last_error; - uint32_t time_to_live; /**< Time to live of published resources in seconds */ - - oc_link_t *rd_publish_resources; /**< Resource links to publish */ - oc_link_t *rd_published_resources; /**< Resource links already published */ - oc_link_t *rd_delete_resources; /**< Resource links to delete */ +OC_API +oc_cloud_context_t *oc_cloud_get_context(size_t device); - oc_resource_t *cloud_conf; +/** + * @brief Get authorization provider name. + * + * The name of the Authorisation Provider through which access token was + * obtained. + * + * @param ctx cloud context (cannot be NULL) + * @return auth provider ID + * + * @see `apn` property in the cloud configuration resource + */ +OC_API +const char *oc_cloud_get_apn(const oc_cloud_context_t *ctx) OC_NONNULL(); - int selected_identity_cred_id; /**< Selected identity cert chain. -1(default) - means any*/ - bool cloud_manager; +/** + * @brief Get the URL of the OCF Cloud. + * + * @param ctx cloud context (cannot be NULL) + * @return cloud interface server URL + * + * @see `cis` property in the cloud configuration resource + */ +OC_API +const char *oc_cloud_get_cis(const oc_cloud_context_t *ctx) OC_NONNULL(); - oc_cloud_keepalive_t keepalive; /**< Keepalive configuration */ - oc_cloud_schedule_action_t - schedule_action; /**< Schedule action configuration */ -} oc_cloud_context_t; +/** + * @brief Get the access token. + * + * Access token is returned by an Authorisation Provider or an OCF Cloud. + * + * @param ctx cloud context (cannot be NULL) + * @return access token + * + * @see `at` property in the cloud configuration resource + */ +OC_API +const char *oc_cloud_get_at(const oc_cloud_context_t *ctx) OC_NONNULL(); /** - * @brief Get cloud context for device. + * @brief Get the identity of the OCF Cloud. + * + * The ID is in the string form of a UUID. + * + * @param ctx cloud context (cannot be NULL) + * @return identity of the OCF Cloud + * + * @see `sid` property in the cloud configuration resource */ OC_API -oc_cloud_context_t *oc_cloud_get_context(size_t device); +const char *oc_cloud_get_sid(const oc_cloud_context_t *ctx) OC_NONNULL(); /** * @brief Start cloud registration process.