Commit bf1ea55f authored by Oleksandr Dmytrenko's avatar Oleksandr Dmytrenko Committed by Randeep

[IOT-2912]cloud sample

cloud sample refactoring

Bug: https://jira.iotivity.org/browse/IOT-2912
Change-Id: I5b229f56dcd21efb823e2663e418cfaee99f6ab5
Signed-off-by: default avatarOleksandr Dmytrenko <o.dmytrenko@samsung.com>
parent cf212ed4
......@@ -166,17 +166,10 @@ OCStackApplicationResult handleCloudSignUpResponse(void *ctx,
OC_UNUSED(ctx);
OC_UNUSED(handle);
if (!response)
{
OIC_LOG(ERROR, TAG, "Received NULL response!");
goto exit;
}
VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
VERIFY_NOT_NULL(TAG, response->payload, ERROR);
if (response->payload)
{
OIC_LOG(ERROR, TAG, "Payload received");
OIC_LOG_PAYLOAD(DEBUG, response->payload);
}
OIC_LOG_PAYLOAD(DEBUG, response->payload);
if (response->result != LOGIN_OK)
{
......@@ -264,19 +257,12 @@ OCStackApplicationResult handleCloudSignInResponse(void *ctx,
OC_UNUSED(ctx);
OC_UNUSED(handle);
if (!response)
{
OIC_LOG(ERROR, TAG, "Received NULL response!");
goto exit;
}
VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
VERIFY_NOT_NULL(TAG, response->payload, ERROR);
if (response->payload)
{
OIC_LOG(ERROR, TAG, "Payload received");
OIC_LOG_PAYLOAD(DEBUG, response->payload);
}
OIC_LOG_PAYLOAD(DEBUG, response->payload);
if (response->result < 4 && response->payload)
if (response->result < 4)
{
OIC_LOG_V(ERROR, TAG, "Sign In error: result: %d, payload exist: %s",
response->result, response->payload ? "yes" : "no");
......@@ -381,19 +367,12 @@ OCStackApplicationResult handleCloudSignOutResponse(void *ctx,
OC_UNUSED(ctx);
OC_UNUSED(handle);
if (!response)
{
OIC_LOG(ERROR, TAG, "Received NULL response!");
goto exit;
}
VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
VERIFY_NOT_NULL(TAG, response->payload, ERROR);
if (response->payload)
{
OIC_LOG(ERROR, TAG, "Payload received");
OIC_LOG_PAYLOAD(DEBUG, response->payload);
}
OIC_LOG_PAYLOAD(DEBUG, response->payload);
if (response->result < 4 && response->payload)
if (response->result < 4)
{
OIC_LOG_V(ERROR, TAG, "Sign Out error");
return OC_STACK_DELETE_TRANSACTION;
......
......@@ -130,6 +130,22 @@ void readInteger(int* item, const char* description, const char* example)
getchar();
}
}
/**
* Read user input (expect integer value)
*
* @param[out] item size_t item to fill
* @param[in] description item description
* @param[in] example item example
*/
void readSize(size_t* item, const char* description, const char* example)
{
printf("Enter %s (f.e. %s):\n", description, example);
if (scanf("%zd", item))
{
getchar();
}
}
/**
* Read user input (expect array of strings)
......@@ -141,16 +157,16 @@ void readInteger(int* item, const char* description, const char* example)
*/
static void readStringArray(stringArray_t *list, int length, const char* description, const char* example)
{
int i = 0;
int count = 0;
size_t i = 0;
size_t count = 0;
char hint[MAX_STRING_LENGTH] = { 0 };
snprintf(hint, sizeof(hint), "%s items count", description);
readInteger(&count, hint, "2");
readSize(&count, hint, "2");
char **item = NULL;
if (0 >= count)
if (0 == count || 10 * 1024 < count)
{
return;
}
......@@ -171,16 +187,16 @@ static void readStringArray(stringArray_t *list, int length, const char* descrip
goto no_memory;
}
snprintf(hint, sizeof(hint), "%s %d item", description, i + 1);
snprintf(hint, sizeof(hint), "%s %zd item", description, i + 1);
readString(item[i], length, hint, example);
}
list->array = item;
list->length = (size_t)count;
list->length = count;
return;
no_memory:
//free already allocated memory here
for (int k = 0; k < i; k++)
for (size_t k = 0; k < i; k++)
{
OICFree(item[k]);
}
......@@ -371,7 +387,7 @@ OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloud
int acllist_count = 0;
readInteger(&acllist_count, "acl list count", "1");
if (0 >= acllist_count)
if (0 >= acllist_count || 1024 < acllist_count)
{
OIC_LOG(ERROR, TAG, "Wrong number of aclList");
goto exit;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment