Removed warnings from provisioning module
authorSachin Agrawal <sachin.agrawal@intel.com>
Fri, 21 Aug 2015 16:00:42 +0000 (09:00 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Fri, 21 Aug 2015 16:53:05 +0000 (16:53 +0000)
Removed all unused variable warnings coming from provisioning module

Change-Id: I6183c9413ea495d2969d0e94aa6152a53eeb4b38
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2226
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/provisioning/sample/sampleserver_justworks.cpp
resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
resource/csdk/security/provisioning/src/ocprovisioningmanager.c
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/oxmjustworks.c
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp

index 9607e1b..ee16b58 100644 (file)
@@ -155,7 +155,7 @@ static int CalculateAclPermission(const char *temp_pms, uint16_t *pms)
  */
 static int InputACL(OicSecAcl_t *acl)
 {
-    int unused __attribute__((unused));
+    int ret;
     char temp_id [UUID_LENGTH + 4] = {0,};
     char temp_rsc[MAX_URI_LENGTH + 1] = {0,};
     char temp_pms[MAX_PERMISSION_LENGTH + 1] = {0,};
@@ -166,20 +166,38 @@ static int InputACL(OicSecAcl_t *acl)
     printf("-URN identifying the subject\n");
     printf("ex) 1111-1111-1111-1111 (16 Numbers except to '-')\n");
     printf("Subject : ");
-    unused = scanf("%19s", temp_id);
+    char *ptr = NULL;
+    ret = scanf("%19ms", &ptr);
+    if(1==ret)
+    {
+        OICStrcpy(temp_id, sizeof(temp_id), ptr);
+        OICFree(ptr);
+    }
+    else
+    {
+         printf("Error while input\n");
+         return -1;
+    }
     int j = 0;
     for (int i = 0; temp_id[i] != '\0'; i++)
     {
         if (DASH != temp_id[i])
+        {
+            if(j>UUID_LENGTH)
+            {
+                printf("Invalid input\n");
+                return -1;
+            }
             acl->subject.id[j++] = temp_id[i];
+        }
     }
 
     //Set Resource.
-    printf("Num. of Resource : ");
-    unused = scanf("%zu", &acl->resourcesLen);
+    printf("Num. of Resource : \n");
+    ret = scanf("%zu", &acl->resourcesLen);
     printf("-URI of resource\n");
     printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n");
-    acl->resources = (char **)OICMalloc(acl->resourcesLen * sizeof(char *));
+    acl->resources = (char **)OICCalloc(acl->resourcesLen, sizeof(char *));
     if (NULL == acl->resources)
     {
         OC_LOG(ERROR, TAG, "Error while memory allocation");
@@ -188,7 +206,18 @@ static int InputACL(OicSecAcl_t *acl)
     for (size_t i = 0; i < acl->resourcesLen; i++)
     {
         printf("[%zu]Resource : ", i + 1);
-        unused = scanf("%64s", temp_rsc);
+        char *ptr_tempRsc = NULL;
+        ret = scanf("%64ms", &ptr_tempRsc);
+        if (1==ret)
+        {
+            OICStrcpy(temp_rsc, sizeof(temp_rsc), ptr_tempRsc);
+            OICFree(ptr_tempRsc);
+        }
+        else
+        {
+            printf("Error while input\n");
+            return -1;
+        }
         acl->resources[i] = OICStrdup(temp_rsc);
 
         if (NULL == acl->resources[i])
@@ -196,8 +225,6 @@ static int InputACL(OicSecAcl_t *acl)
             OC_LOG(ERROR, TAG, "Error while memory allocation");
             return -1;
         }
-        strncpy(acl->resources[i], temp_rsc, strlen(temp_rsc));
-        acl->resources[i][strlen(temp_rsc)] = '\0';
     }
     // Set Permission
     do
@@ -205,12 +232,24 @@ static int InputACL(OicSecAcl_t *acl)
         printf("-Set the permission(C,R,U,D,N)\n");
         printf("ex) CRUDN, CRU_N,..(5 Charaters)\n");
         printf("Permission : ");
-        unused = scanf("%5s", temp_pms);
+        char *ptr_temp_pms = NULL;
+        ret = scanf("%5ms", &ptr_temp_pms);
+        if(1 == ret)
+        {
+            OICStrcpy(temp_pms, sizeof(temp_pms), ptr_temp_pms);
+            OICFree(ptr_temp_pms);
+
+        }
+        else
+        {
+            printf("Error while input\n");
+            return -1;
+        }
     }
     while (0 != CalculateAclPermission(temp_pms, &(acl->permission)) );
     // Set Rowner
     printf("Num. of Rowner : ");
-    unused = scanf("%zu", &acl->ownersLen);
+    ret = scanf("%zu", &acl->ownersLen);
     printf("-URN identifying the rowner\n");
     printf("ex) 1111-1111-1111-1111 (16 Numbers except to '-')\n");
     acl->owners = (OicUuid_t *)OICCalloc(acl->ownersLen, sizeof(OicUuid_t));
@@ -222,7 +261,18 @@ static int InputACL(OicSecAcl_t *acl)
     for (size_t i = 0; i < acl->ownersLen; i++)
     {
         printf("[%zu]Rowner : ", i + 1);
-        unused = scanf("%19s", temp_id);
+        char *ptr_temp_id = NULL;
+        ret = scanf("%19ms", &ptr_temp_id);
+        if (1 == ret)
+        {
+            OICStrcpy(temp_id, sizeof(temp_id), ptr_temp_id);
+            OICFree(ptr_temp_id);
+        }
+        else
+        {
+            printf("Error while input\n");
+            return -1;
+        }
         j = 0;
         for (int k = 0; temp_id[k] != '\0'; k++)
         {
@@ -237,8 +287,9 @@ static int InputACL(OicSecAcl_t *acl)
 
 
 //FILE *client_fopen(const char *path, const char *mode)
-FILE *client_fopen(const char *UNUSED_PARAM, const char *mode)
+FILE *client_fopen(const char* UNUSED_PARAM , const char *mode)
 {
+    (void)UNUSED_PARAM;
     return fopen(CRED_FILE, mode);
 }
 
@@ -311,25 +362,29 @@ void InputPinCB(char* pinBuf, size_t bufSize)
     if(pinBuf)
     {
         printf("INPUT PIN : ");
-        int unused = scanf("%s", pinBuf);
-        pinBuf[bufSize - 1] = '\0';
+        char *ptr = NULL;
+        int ret = scanf("%ms", &ptr);
+        if(1 == ret)
+        {
+            OICStrcpy(pinBuf, bufSize, ptr);
+            OICFree(ptr);
+        }
+        else
+        {
+             printf("Error in input\n");
+             return;
+        }
     }
 }
 
 /**
  * Provisioning client sample using ProvisioningAPI
  */
-int main(int argc, char **argv)
+int main()
 {
     OCStackResult res = OC_STACK_OK;
-    int unused __attribute__((unused));
-
-    gAcl1 = (OicSecAcl_t *)OICMalloc(sizeof(OicSecAcl_t));
-    if (NULL == gAcl1)
-    {
-        OC_LOG(ERROR, TAG, "Error while memory allocation");
-        goto error;
-    }
+    int unused;
+    (void)unused;
 
     // Initialize Persistent Storage for SVR database
     OCPersistentStorage ps = { .open = NULL,
@@ -452,21 +507,19 @@ int main(int argc, char **argv)
     unused = scanf("%d", &Device2);
 
 
-    gAcl1 = (OicSecAcl_t *)OICMalloc(sizeof(OicSecAcl_t));
+    gAcl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
     if (NULL == gAcl1)
     {
         OC_LOG(ERROR, TAG, "Error while memory allocation");
         goto error;
     }
-    memset(gAcl1, 0x00, sizeof(OicSecAcl_t));
 
-    gAcl2 = (OicSecAcl_t *)OICMalloc(sizeof(OicSecAcl_t));
+    gAcl2 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
     if (NULL == gAcl2)
     {
         OC_LOG(ERROR, TAG, "Error while memory allocation");
         goto error;
     }
-    memset(gAcl2, 0x00, sizeof(OicSecAcl_t));
 
     printf("Input ACL for Device1\n");
     if ( 0 == InputACL(gAcl1))
index 35db3e5..10971e8 100644 (file)
@@ -310,7 +310,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
         void* callbackParam)
 {
     OC_LOG_V (INFO, TAG, "Inside entity handler - flags: 0x%x", flag);
-
+    (void)callbackParam;
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     OCEntityHandlerResponse response = {};
 
@@ -393,7 +393,7 @@ FILE* server_fopen(const char *path, const char *mode)
     return fopen(CRED_FILE, mode);
 }
 
-int main(int argc, char* argv[])
+int main()
 {
     struct timespec timeout;
 
index 25e84f8..7051a52 100644 (file)
@@ -311,7 +311,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
         void* callbackParam)
 {
     OC_LOG_V (INFO, TAG, "Inside entity handler - flags: 0x%x", flag);
-
+    (void)callbackParam;
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     OCEntityHandlerResponse response = {};
 
@@ -407,7 +407,7 @@ void GeneratePinCB(char* pin, size_t pinSize)
     OC_LOG(INFO, TAG, "============================");
 }
 
-int main(int argc, char* argv[])
+int main()
 {
     struct timespec timeout;
 
index fa26f36..cdef12d 100644 (file)
@@ -190,6 +190,7 @@ static void AclProv2CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool has
         OC_LOG(ERROR,TAG,"Context is Null in ACLProv 2");
         return;
     }
+    (void)nOfRes;
     Linkdata_t *link = (Linkdata_t*)ctx;
     OCProvisionResultCB resultCallback = link->resultCallback;
 
@@ -225,6 +226,7 @@ static void AclProv1CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool has
         OC_LOG(ERROR,TAG,"Context is Null in ACLProv1");
         return;
     }
+    (void)nOfRes;
     Linkdata_t *link = (Linkdata_t*)ctx;
     OCProvisionResultCB resultCallback = link->resultCallback;
 
index 2510a9d..e1f69f0 100644 (file)
@@ -403,7 +403,7 @@ exit:
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult OwnerTransferModeHandler(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                         OCClientResponse *clientResponse)
 {
     OC_LOG(DEBUG, TAG, "IN OwnerTransferModeHandler");
 
@@ -411,7 +411,7 @@ static OCStackApplicationResult OwnerTransferModeHandler(void *ctx, OCDoHandle U
     VERIFY_NON_NULL(TAG, ctx, WARNING);
 
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
-
+    (void)UNUSED;
     if(clientResponse->result == OC_STACK_OK)
     {
         OC_LOG(INFO, TAG, "OwnerTransferModeHandler : response result = OC_STACK_OK");
@@ -446,7 +446,7 @@ exit:
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult ListMethodsHandler(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                    OCClientResponse *clientResponse)
 {
     OC_LOG(DEBUG, TAG, "IN ListMethodsHandler");
 
@@ -454,7 +454,7 @@ static OCStackApplicationResult ListMethodsHandler(void *ctx, OCDoHandle UNUSED,
     VERIFY_NON_NULL(TAG, ctx, WARNING);
 
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
-
+    (void)UNUSED;
     if  (OC_STACK_OK == clientResponse->result)
     {
         if  (NULL == clientResponse->payload)
@@ -514,14 +514,14 @@ exit:
  * @return  OC_STACK_DELETE_TRANSACTION to delete the transaction
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
-static OCStackApplicationResult OwnershipInformationHandler(void *ctx,
-                                OCDoHandle UNUSED, OCClientResponse *clientResponse)
+static OCStackApplicationResult OwnershipInformationHandler(void *ctx, OCDoHandle UNUSED,
+                                OCClientResponse *clientResponse)
 {
     VERIFY_NON_NULL(TAG, clientResponse, WARNING);
     VERIFY_NON_NULL(TAG, ctx, WARNING);
 
     OC_LOG(DEBUG, TAG, "IN OwnershipInformationHandler");
-
+    (void)UNUSED;
     OCStackResult res = OC_STACK_OK;
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
     if  (OC_STACK_OK == clientResponse->result)
@@ -583,8 +583,8 @@ exit:
  * @return  OC_STACK_DELETE_TRANSACTION to delete the transaction
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
-static OCStackApplicationResult OperationModeUpdateHandler(void *ctx,
-                                OCDoHandle UNUSED, OCClientResponse *clientResponse)
+static OCStackApplicationResult OperationModeUpdateHandler(void *ctx, OCDoHandle UNUSED,
+                                OCClientResponse *clientResponse)
 {
     OC_LOG(DEBUG, TAG, "IN OperationModeUpdateHandler");
 
@@ -592,6 +592,7 @@ static OCStackApplicationResult OperationModeUpdateHandler(void *ctx,
     VERIFY_NON_NULL(TAG, ctx, WARNING);
 
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
+    (void) UNUSED;
     if  (OC_STACK_OK == clientResponse->result)
     {
         OCStackResult res = OC_STACK_ERROR;
@@ -956,7 +957,7 @@ OCStackResult OTMDoOwnershipTransfer(void* ctx,
  *          and OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult FinalizeProvisioningCB(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                       OCClientResponse *clientResponse)
 {
     OC_LOG_V(INFO, TAG, "IN FinalizeProvisioningCB.");
 
@@ -964,7 +965,7 @@ static OCStackApplicationResult FinalizeProvisioningCB(void *ctx, OCDoHandle UNU
     VERIFY_NON_NULL(TAG, ctx, ERROR);
 
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
-
+    (void)UNUSED;
     if(OC_STACK_OK == clientResponse->result)
     {
         SetResult(otmCtx, OC_STACK_OK);
@@ -983,7 +984,7 @@ exit:
  *          and OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult ProvisionDefaultACLCB(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                       OCClientResponse *clientResponse)
 {
     OC_LOG_V(INFO, TAG, "IN ProvisionDefaultACLCB.");
 
@@ -991,6 +992,7 @@ static OCStackApplicationResult ProvisionDefaultACLCB(void *ctx, OCDoHandle UNUS
     VERIFY_NON_NULL(TAG, ctx, ERROR);
 
     OTMContext_t* otmCtx = (OTMContext_t*) ctx;
+    (void)UNUSED;
 
     if (OC_STACK_RESOURCE_CREATED == clientResponse->result)
     {
index ea595c5..2d1988c 100644 (file)
@@ -66,6 +66,7 @@ char* CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx)
 OCStackResult LoadSecretJustWorksCallback(OTMContext_t* UNUSED_PARAM)
 {
     //In case of 'just works', secret data not required
+    (void)UNUSED_PARAM;
     return OC_STACK_OK;
 }
 
index 22c205d..0f46c36 100644 (file)
@@ -267,15 +267,15 @@ uint16_t GetSecurePortFromJSON(char* jsonStr)
  * @return OC_STACK_KEEP_TRANSACTION to keep transaction and
  *         OC_STACK_DELETE_TRANSACTION to delete it.
  */
-static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx,
-                                OCDoHandle UNUSED, OCClientResponse *clientResponse)
+static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
+                                 OCClientResponse *clientResponse)
 {
     if (ctx == NULL)
     {
         OC_LOG(ERROR, TAG, "Lost List of device information");
         return OC_STACK_KEEP_TRANSACTION;
     }
-
+    (void)UNUSED;
     if (clientResponse)
     {
         if  (NULL == clientResponse->payload)
@@ -333,14 +333,15 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx,
  * @return OC_STACK_KEEP_TRANSACTION to keep transaction and
  *         OC_STACK_DELETE_TRANSACTION to delete it.
  */
-static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx,
-                                OCDoHandle UNUSED, OCClientResponse *clientResponse)
+static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
+                                OCClientResponse *clientResponse)
 {
     if (ctx == NULL)
     {
         OC_LOG(ERROR, TAG, "Lost List of device information");
         return OC_STACK_KEEP_TRANSACTION;
     }
+    (void)UNUSED;
     if (clientResponse)
     {
         if  (NULL == clientResponse->payload)
index a0f4120..4ac8e32 100644 (file)
@@ -123,10 +123,11 @@ static void registerResultForCredProvisioning(CredentialData_t *credData,
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult provisionCredentialCB2(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                       OCClientResponse *clientResponse)
 {
     VERIFY_NON_NULL(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
     CredentialData_t *credData = (CredentialData_t *) ctx;
+    (void)UNUSED;
 
     OCProvisionResultCB resultCallback = credData->resultCallback;
     OC_LOG(INFO, TAG, "provisionCredentialCB2 called");
@@ -164,9 +165,10 @@ static OCStackApplicationResult provisionCredentialCB2(void *ctx, OCDoHandle UNU
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult provisionCredentialCB1(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                       OCClientResponse *clientResponse)
 {
     VERIFY_NON_NULL(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
+    (void)UNUSED;
     CredentialData_t* credData = (CredentialData_t*) ctx;
     OICFree(credData->credInfoFirst);
     const OCProvisionDev_t *deviceInfo = credData->deviceInfo2;
@@ -383,9 +385,10 @@ static void registerResultForACLProvisioning(ACLData_t *aclData,
  *          and  OC_STACK_KEEP_TRANSACTION to keep it.
  */
 static OCStackApplicationResult SRPProvisionACLCB(void *ctx, OCDoHandle UNUSED,
-        OCClientResponse *clientResponse)
+                                                  OCClientResponse *clientResponse)
 {
     OC_LOG_V(INFO, TAG, "Inside SRPProvisionACLCB.");
+    (void)UNUSED;
     VERIFY_NON_NULL(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
     ACLData_t *aclData = (ACLData_t*)ctx;
     OCProvisionResultCB resultCallback = aclData->resultCallback;
index bbf365b..6c8e3d6 100644 (file)
  * *****************************************************************/
 #include "gtest/gtest.h"
 #include "secureresourceprovider.h"
-//#include "provisioningmanager.h"
+
 
 static OicSecAcl_t acl;
 static OCProvisionDev_t pDev1;
 static OCProvisionDev_t pDev2;
 static OicSecCredType_t credType;
 
-static void provisioningCB (void* UNUSED1, int UNUSED2,
-                            OCProvisionResult_t *UNUSED3, bool UNUSED4)
+static void provisioningCB (void* UNUSED1, int UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4)
 {
     //dummy callback
+    (void) UNUSED1;
+    (void) UNUSED2;
+    (void) UNUSED3;
+    (void) UNUSED4;
 }
 
 TEST(SRPProvisionACLTest, NullDeviceInfo)