Skip to content

Commit

Permalink
cloud: remove private definitions from public API
Browse files Browse the repository at this point in the history
Remove oc_cloud_store_t and oc_cloud_context_t definitions from
oc_cloud.h header.
  • Loading branch information
Danielius1922 committed Feb 5, 2024
1 parent 67ebdb1 commit ba6d6cc
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 66 deletions.
24 changes: 24 additions & 0 deletions api/cloud/oc_cloud_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
46 changes: 46 additions & 0 deletions api/cloud/oc_cloud_context_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,59 @@
#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 <stddef.h>

#ifdef __cplusplus
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
*
Expand Down
5 changes: 3 additions & 2 deletions api/cloud/oc_cloud_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion api/cloud/oc_cloud_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions api/cloud/oc_cloud_store_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions api/cloud/unittest/cloud_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions api/cloud/unittest/cloud_rd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions api/cloud/unittest/cloud_store_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions api/cloud/unittest/cloud_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions apps/cloud_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 48 additions & 56 deletions include/oc_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ba6d6cc

Please sign in to comment.