mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 10:20:04 +00:00
Incorporated review comments on crud additional fields
This commit is contained in:
12
src/config.c
12
src/config.c
@@ -51,6 +51,16 @@ void set_parodus_cfg(ParodusCfg *cfg)
|
||||
memcpy(&parodusCfg, cfg, sizeof(ParodusCfg));
|
||||
}
|
||||
|
||||
void set_cloud_disconnect_reason(ParodusCfg *cfg, char *disconn_reason)
|
||||
{
|
||||
cfg->cloud_disconnect = strdup(disconn_reason);
|
||||
}
|
||||
|
||||
void reset_cloud_disconnect_reason(ParodusCfg *cfg)
|
||||
{
|
||||
cfg->cloud_disconnect = NULL;
|
||||
}
|
||||
|
||||
static void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum);
|
||||
|
||||
const char *get_tok (const char *src, int delim, char *result, int resultsize)
|
||||
@@ -639,7 +649,7 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
cfg->crud_config_file = strdup("parodus_cfg.json");
|
||||
ParodusPrint("Default crud_config_file is %s\n", cfg->crud_config_file);
|
||||
cfg->cloud_status = "offline";
|
||||
cfg->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("Default cloud_status is %s\n", cfg->cloud_status);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ extern "C" {
|
||||
#define CERT_PATH "ssl-cert-path"
|
||||
#define CLOUD_STATUS "cloud-status"
|
||||
#define CLOUD_DISCONNECT "cloud-disconnect"
|
||||
#define CLOUD_STATUS_ONLINE "online"
|
||||
#define CLOUD_STATUS_OFFLINE "offline"
|
||||
#define CLOUD_DISCONNECT_REASON "disconnection-reason"
|
||||
|
||||
#define PROTOCOL_VALUE "PARODUS-2.0"
|
||||
#define WEBPA_PATH_URL "/api/v2/device"
|
||||
@@ -128,7 +131,8 @@ void getAuthToken(ParodusCfg *cfg);
|
||||
ParodusCfg *get_parodus_cfg(void);
|
||||
void set_parodus_cfg(ParodusCfg *);
|
||||
char *get_token_application(void) ;
|
||||
|
||||
void set_cloud_disconnect_reason(ParodusCfg *cfg, char *disconn_reason);
|
||||
void reset_cloud_disconnect_reason(ParodusCfg *cfg);
|
||||
/**
|
||||
* parse a webpa url. Extract the server address, the port
|
||||
* and return whether it's secure or not
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define HEARTBEAT_RETRY_SEC 30 /* Heartbeat (ping/pong) timeout in seconds */
|
||||
#define CLOUD_RECONNECT_TIME 5 /* Cloud disconnect max time in minutes */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
@@ -155,18 +156,18 @@ void createSocketConnection(void (* initKeypress)())
|
||||
close_and_unref_connection(get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
|
||||
get_parodus_cfg()->cloud_status = "offline";
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_parodus_cfg()->cloud_status);
|
||||
if(get_parodus_cfg()->cloud_disconnect !=NULL)
|
||||
{
|
||||
ParodusPrint("get_parodus_cfg()->cloud_disconnect is %s\n", get_parodus_cfg()->cloud_disconnect);
|
||||
set_cloud_disconnect_time(5);
|
||||
set_cloud_disconnect_time(CLOUD_RECONNECT_TIME);
|
||||
ParodusInfo("Waiting for %d minutes for reconnecting .. \n", get_cloud_disconnect_time());
|
||||
|
||||
sleep( get_cloud_disconnect_time() * 60 );
|
||||
ParodusInfo("get_parodus_cfg()->cloud_disconnect reset after %d minutes\n", get_cloud_disconnect_time());
|
||||
ParodusInfo("cloud-disconnect reason reset after %d minutes\n", get_cloud_disconnect_time());
|
||||
free(get_parodus_cfg()->cloud_disconnect);
|
||||
get_parodus_cfg()->cloud_disconnect = NULL;
|
||||
reset_cloud_disconnect_reason(get_parodus_cfg());
|
||||
}
|
||||
createNopollConnection(ctx);
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusInfo("Connected to server\n");
|
||||
}
|
||||
|
||||
get_parodus_cfg()->cloud_status = "online";
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
|
||||
ParodusInfo("cloud_status set as %s after successful connection\n", get_parodus_cfg()->cloud_status);
|
||||
|
||||
if (NULL != jwt_server_url)
|
||||
|
||||
@@ -876,6 +876,7 @@ int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
int status =0, valid =0;
|
||||
int expireFlag = 0;
|
||||
int disconnStatus = 0;
|
||||
char *disconn_str = NULL;
|
||||
|
||||
status = readFromJSON(&jsonData);
|
||||
ParodusPrint("read status %d\n", status);
|
||||
@@ -1218,11 +1219,12 @@ int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
jsonPayload = cJSON_Parse( reqMsg->u.crud.payload );
|
||||
if(jsonPayload !=NULL)
|
||||
{
|
||||
if((cJSON_GetObjectItem( jsonPayload, "disconnection-reason" )) !=NULL)
|
||||
if((cJSON_GetObjectItem( jsonPayload, CLOUD_DISCONNECT_REASON )) !=NULL)
|
||||
{
|
||||
if (cJSON_String == cJSON_GetObjectItem( jsonPayload, "disconnection-reason" )->type)
|
||||
if (cJSON_String == cJSON_GetObjectItem( jsonPayload, CLOUD_DISCONNECT_REASON )->type)
|
||||
{
|
||||
if(cJSON_GetObjectItem( jsonPayload, "disconnection-reason" )->valuestring != NULL && strlen(cJSON_GetObjectItem( jsonPayload, "disconnection-reason" )->valuestring) == 0)
|
||||
disconn_str = cJSON_GetObjectItem( jsonPayload, CLOUD_DISCONNECT_REASON )->valuestring;
|
||||
if (disconn_str != NULL && strlen(disconn_str) == 0)
|
||||
{
|
||||
ParodusError("Invalid cloud-disconnect request. disconnect reason is NULL\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
@@ -1237,12 +1239,13 @@ int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
{
|
||||
//check disconnection reason is character string of [a-zA-Z0-9 ]*
|
||||
|
||||
valid = validateDisconnectString(cJSON_GetObjectItem( jsonPayload,"disconnection-reason" )->valuestring);
|
||||
valid = validateDisconnectString(disconn_str);
|
||||
if(valid >0)
|
||||
{
|
||||
//set the disconnection-reason value to in-memory
|
||||
get_parodus_cfg()->cloud_disconnect = strdup(cJSON_GetObjectItem( jsonPayload,"disconnection-reason" )->valuestring);
|
||||
ParodusInfo("get_parodus_cfg()->cloud_disconnect value set as %s\n", get_parodus_cfg()->cloud_disconnect);
|
||||
//set the disconnection reason value to in-memory
|
||||
set_cloud_disconnect_reason(get_parodus_cfg(), disconn_str);
|
||||
ParodusInfo("set cloud-disconnect reason as %s \n", get_parodus_cfg()->cloud_disconnect);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ pthread_mutex_t *get_global_nano_mut(void)
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char *get_src_dest_from_sub_req(char *upstreamDest);
|
||||
static char *get_src_dest_from_req(char *upstreamDest);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -337,9 +337,9 @@ void *processUpstreamMessage()
|
||||
if(WRP_MSG_TYPE__RETREIVE == msgType && msg->u.crud.dest !=NULL && msg->u.crud.source != NULL)
|
||||
{
|
||||
destVal = strdup(msg->u.crud.dest);
|
||||
upstreamDest = get_src_dest_from_sub_req(destVal);
|
||||
upstreamDest = get_src_dest_from_req(destVal);
|
||||
upstreamSrc = strdup(msg->u.crud.source);
|
||||
subsSource = get_src_dest_from_sub_req(upstreamSrc);
|
||||
subsSource = get_src_dest_from_req(upstreamSrc);
|
||||
|
||||
/* Handle cloud-status retrieve request here
|
||||
Expecting dest format as mac:xxxxxxxxxxxx/parodus/cloud-status
|
||||
@@ -362,7 +362,7 @@ void *processUpstreamMessage()
|
||||
Strip src field to get "parodus/cloud-status"
|
||||
*/
|
||||
crudDest = strdup(msg->u.crud.dest);
|
||||
serviceName = get_src_dest_from_sub_req(crudDest);
|
||||
serviceName = get_src_dest_from_req(crudDest);
|
||||
if ( serviceName != NULL)
|
||||
{
|
||||
//Send Client cloud-status response back to registered client
|
||||
@@ -463,17 +463,19 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
|
||||
/*
|
||||
Internal function to parse wrp src/dest
|
||||
(e.g parodus/cloud-status parsing from mac:44aaf59b18xx/parodus/cloud-status)
|
||||
*/
|
||||
static char *get_src_dest_from_sub_req(char *upstreamDest)
|
||||
static char *get_src_dest_from_req(char *upstreamDest)
|
||||
{
|
||||
char * endValue = NULL;
|
||||
char * tempValue = NULL;
|
||||
if(upstreamDest !=NULL)
|
||||
{
|
||||
tempValue = strtok(upstreamDest , "/");
|
||||
tempValue = strchr(upstreamDest , '/');
|
||||
if(tempValue !=NULL)
|
||||
{
|
||||
endValue = strtok(NULL , "");
|
||||
tempValue++;
|
||||
endValue = tempValue;
|
||||
}
|
||||
}
|
||||
return endValue;
|
||||
|
||||
@@ -413,7 +413,7 @@ void test_setDefaultValuesToCfg()
|
||||
assert_int_equal((int)cfg->flags, 0);
|
||||
assert_string_equal(cfg->webpa_path_url, WEBPA_PATH_URL);
|
||||
assert_string_equal(cfg->webpa_uuid, "1234567-345456546");
|
||||
assert_string_equal(cfg->cloud_status, "offline");
|
||||
assert_string_equal(cfg->cloud_status, CLOUD_STATUS_OFFLINE);
|
||||
}
|
||||
|
||||
void err_setDefaultValuesToCfg()
|
||||
|
||||
@@ -282,7 +282,7 @@ void test_createSocketConnection1()
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, "offline");
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_OFFLINE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -341,7 +341,7 @@ void test_createConnection()
|
||||
|
||||
int ret = createNopollConnection(ctx);
|
||||
assert_int_equal(ret, nopoll_true);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, "online");
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_ONLINE);
|
||||
free(cfg);
|
||||
if (g_jwt_server_ip !=NULL)
|
||||
{
|
||||
|
||||
@@ -1515,7 +1515,7 @@ void test_retrieveObject_cloud_status()
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.cloud_status = strdup("online");
|
||||
cfg.cloud_status = CLOUD_STATUS_ONLINE;
|
||||
cfg.crud_config_file = strdup("parodus_cfg.json");
|
||||
set_parodus_cfg(&cfg);
|
||||
testdata=strdup("{\"tags\":{\"test1\":{\"expires\":1522451870}}}");
|
||||
@@ -1528,7 +1528,7 @@ void test_retrieveObject_cloud_status()
|
||||
ret = retrieveObject(reqMsg, &respMsg);
|
||||
assert_int_equal (respMsg->u.crud.status, 200);
|
||||
assert_int_equal (ret, 0);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, "online");
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_ONLINE);
|
||||
assert_int_equal (respMsg->u.crud.payload_size, 25);
|
||||
|
||||
fp = fopen(cfg.crud_config_file, "r");
|
||||
@@ -3021,7 +3021,6 @@ int main(void)
|
||||
cmocka_unit_test(test_deleteObject_NonExistObj),
|
||||
cmocka_unit_test(test_deleteObject_withTagsEmpty),
|
||||
cmocka_unit_test(test_deleteObject_tagsFailure)
|
||||
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user