[IOT-2912]cloud sample 73/23473/6
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Mon, 27 Nov 2017 14:30:52 +0000 (16:30 +0200)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 2 Jan 2018 05:45:10 +0000 (05:45 +0000)
cloud sample refactoring

Bug: https://jira.iotivity.org/browse/IOT-2912
Change-Id: I5b229f56dcd21efb823e2663e418cfaee99f6ab5
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
resource/provisioning/examples/cloudAuth.cpp
resource/provisioning/examples/cloudWrapper.cpp

index 7c8182c..110fc5d 100644 (file)
@@ -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;
index 6fbc5c8..2fa36c2 100644 (file)
@@ -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;