Fix defects detected by SVACE system in easy setup
authorJihun Ha <jihun.ha@samsung.com>
Fri, 5 Aug 2016 07:40:09 +0000 (16:40 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 5 Aug 2016 12:14:32 +0000 (12:14 +0000)
SVACE which is one of static code analysis tools detects several defects
in easy setup. This patch fixes them.

Change-Id: Ie7e3eb692c58c586b6d0964cf6af24829c39eb11
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10021
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp
service/easy-setup/enrollee/unittests/ESMediatorSimulator.h
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp

index ab246526d6e8bbf528050599b7eb6e5cf4878d2c..ed90ddf7feae53f7a974274357ec569716f99a51 100755 (executable)
@@ -266,10 +266,17 @@ void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
 void updateWiFiResource(OCRepPayload* input)
 {
     ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
+
     if(wiFiData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
+        return ;
     }
+
+    memset(wiFiData->ssid, 0, MAX_SSIDLEN);
+    memset(wiFiData->pwd, 0, MAX_CREDLEN);
+    wiFiData->authtype = NONE_AUTH;
+    wiFiData->enctype = NONE_AUTH;
     wiFiData->userdata = NULL;
 
     char* ssid = NULL;
@@ -330,10 +337,16 @@ void updateWiFiResource(OCRepPayload* input)
 void updateCloudResource(OCRepPayload* input)
 {
     ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
+
     if(cloudData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
+        return;
     }
+
+    memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
+    memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
+    memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
     cloudData->userdata = NULL;
 
     char *authCode = NULL;
@@ -386,10 +399,14 @@ void updateCloudResource(OCRepPayload* input)
 void updateDevConfResource(OCRepPayload* input)
 {
     ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
+
     if(devConfData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
+        return;
     }
+    memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
+    memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
     devConfData->userdata = NULL;
 
     char *country = NULL;
@@ -446,7 +463,9 @@ OCRepPayload* constructResponseOfWiFi()
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
     int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
     for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
+    {
         modes_64[i] = gWiFiResource.supportedMode[i];
+    }
     OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
 
     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
@@ -536,14 +555,22 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
             payload->next = constructResponseOfWiFi();
 
             if(payload->next)
+            {
                 payload->next->next = constructResponseOfCloud();
+            }
             else
+            {
                 return payload;
+            }
 
             if(payload->next->next)
+            {
                 payload->next->next->next = constructResponseOfDevConf();
+            }
             else
+            {
                 return payload;
+            }
         }
     }
 
index a4283e648270c79fec6e87d62082559791c5af8f..6232bcea32c29bcb140db9bb7927b500699f4f95 100755 (executable)
@@ -49,9 +49,12 @@ public:
     MockRepository mocks;
 
 protected:
-    virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
+    virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test()))
+    {
+    }
 
-    virtual void TearDown() {
+    virtual void TearDown()
+    {
         try
         {
             mocks.VerifyAll();
@@ -303,9 +306,12 @@ TEST_F(EasysetupEnrolleeTest, ProvisioningPropertiesIsWellConstructedInResponseP
             {
                 EnrolleeStatus enrolleeStatus = status->getEnrolleeStatus();
 
+
                 if(enrolleeStatus.getProvStatus() == ES_STATE_CONNECTED_TO_ENROLLER &&
                    enrolleeStatus.getLastErrCode() == ES_ERRCODE_NO_INTERNETCONNECTION)
+                {
                     isWellConstructed = true;
+                }
             }
         });
     ESResult ret = startEnrollee();
@@ -341,14 +347,18 @@ TEST_F(EasysetupEnrolleeTest, WiFiAndDevConfProperiesProvisionedWithSuccess)
                 !strcmp(data->pwd, "Iotivity_PWD") &&
                 data->authtype == WPA2_PSK &&
                 data->enctype == TKIP_AES)
+            {
                 cntForReceivedCallbackWithSuccess++;
+            }
         });
     mocks.OnCallFunc(DevConfProvCbInApp).Do(
         [& cntForReceivedCallbackWithSuccess](ESDevConfProvData *data)
         {
             if(!strcmp(data->language, "korean") &&
                 !strcmp(data->country, "Korea"))
+            {
                 cntForReceivedCallbackWithSuccess++;
+            }
         });
 
     startEnrollee();
@@ -372,7 +382,9 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
         {
             // Will called twice
             if(status->getESResult() == ES_OK)
+            {
                cntForReceivedCallbackWithSuccess++;
+            }
         });
 
     mocks.OnCallFunc(CloudDataCbInApp).Do(
@@ -381,7 +393,9 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
             if(!strcmp(data->authCode, "authCode") &&
                 !strcmp(data->authProvider, "authProvider") &&
                 !strcmp(data->ciServer, "ciServer"))
+            {
                 cntForReceivedCallbackWithSuccess++;
+            }
         });
 
     startEnrollee();
index e188ec34cac0171fc4c1f9c54409b5619b96c726..938a43e2c5f727309177db20d815b008a5d0299b 100755 (executable)
@@ -48,9 +48,11 @@ private:
 public:
     ESMediatorSimulator()
     : m_remoteEnrollee(), m_discoveryCb(), m_getConfigurationCb(), m_getStatusCb(),
-    m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb() { };
+    m_DevicePropProvisioningCb(), m_CloudPropProvisioningCb()
+    {
+    };
     ~ESMediatorSimulator() = default;
-    
+
     ESMediatorSimulator(const ESMediatorSimulator &) = delete;
     ESMediatorSimulator & operator = (const ESMediatorSimulator &) = delete;
 
@@ -65,7 +67,7 @@ public:
                 OCConnectivityType::CT_DEFAULT,
                 std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCb,
                                                                     this, std::placeholders::_1));
-        
+
     }
 
     void getConfiguration(std::function<void(std::shared_ptr< GetConfigurationStatus >)> cb)
@@ -76,7 +78,7 @@ public:
         OC::OCPlatform::findResource("", uri,
                 OCConnectivityType::CT_DEFAULT,
                 std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetConfiguration,
-                                                                    this, std::placeholders::_1));        
+                                                                    this, std::placeholders::_1));
     }
 
     void getStatus(std::function<void(std::shared_ptr< GetEnrolleeStatus >)> cb)
@@ -87,7 +89,7 @@ public:
         OC::OCPlatform::findResource("", uri,
                 OCConnectivityType::CT_DEFAULT,
                 std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToGetStatus,
-                                                                    this, std::placeholders::_1));        
+                                                                    this, std::placeholders::_1));
     }
 
     void provisionDeviceProperties(std::function<void(std::shared_ptr< DevicePropProvisioningStatus >)> cb)
@@ -98,7 +100,7 @@ public:
         OC::OCPlatform::findResource("", uri,
                 OCConnectivityType::CT_DEFAULT,
                 std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionDeviceProperties,
-                                                                    this, std::placeholders::_1));        
+                                                                    this, std::placeholders::_1));
     }
 
     void provisionCloudProperties(std::function<void(std::shared_ptr< CloudPropProvisioningStatus >)> cb)
@@ -109,7 +111,7 @@ public:
         OC::OCPlatform::findResource("", uri,
                 OCConnectivityType::CT_DEFAULT,
                 std::bind(&ESMediatorSimulator::discoverRemoteEnrolleeCbToProvisionCloudProperties,
-                                                                    this, std::placeholders::_1));        
+                                                                    this, std::placeholders::_1));
     }
 
 private:
@@ -121,19 +123,19 @@ private:
             m_discoveryCb(resource);
             m_discoveryCb = NULL;
         }
-    }   
+    }
 
     void getConfigurationCallback(std::shared_ptr< GetConfigurationStatus > getConfigurationStatus)
     {
         if(m_getConfigurationCb != NULL)
         {
             m_getConfigurationCb(getConfigurationStatus);
-            m_getConfigurationCb = NULL;            
+            m_getConfigurationCb = NULL;
         }
     }
 
     void discoverRemoteEnrolleeCbToGetConfiguration(std::shared_ptr<OC::OCResource> resource)
-    {        
+    {
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) && m_getConfigurationCb
                                                                            && !m_remoteEnrollee)
         {
@@ -142,7 +144,7 @@ private:
             if(m_remoteEnrollee != NULL)
             {
               m_remoteEnrollee->getConfiguration(std::bind(
-                    &ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));                
+                    &ESMediatorSimulator::getConfigurationCallback, this, std::placeholders::_1));
             }
         }
     }
@@ -166,7 +168,7 @@ private:
             if(m_remoteEnrollee != NULL)
             {
                 m_remoteEnrollee->getStatus(std::bind(
-                    &ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));               
+                    &ESMediatorSimulator::getStatusCallback, this, std::placeholders::_1));
             }
         }
     }
@@ -193,9 +195,9 @@ private:
                 DeviceProp devProp;
                 devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
                 devProp.setDevConfProp("korean", "Korea");
-                                 
-                m_remoteEnrollee->provisionDeviceProperties(devProp, 
-                    std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback, 
+
+                m_remoteEnrollee->provisionDeviceProperties(devProp,
+                    std::bind(&ESMediatorSimulator::deviceProvisioningStatusCallback,
                                                             this, std::placeholders::_1));
             }
         }
@@ -203,29 +205,31 @@ private:
 
     void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatus >
                                                                     cloudPropProvisioningStatus)
-    {    
+    {
         if(m_CloudPropProvisioningCb != NULL)
         {
             m_CloudPropProvisioningCb(cloudPropProvisioningStatus);
-            if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)            
+            if(cloudPropProvisioningStatus->getESCloudState() == ES_CLOUD_PROVISIONING_SUCCESS)
+            {
                 m_CloudPropProvisioningCb = NULL;
+            }
         }
     }
 
     void discoverRemoteEnrolleeCbToProvisionCloudProperties(std::shared_ptr<OC::OCResource> resource)
-    {       
+    {
         if(!resource->getResourceTypes().at(0).compare(PROV_RESOURCE_TYPE) &&
                                                 m_CloudPropProvisioningCb && !m_remoteEnrollee)
         {
             m_remoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee(resource);
 
             if(m_remoteEnrollee != NULL)
-            {                
+            {
                 CloudProp cloudProp;
                 cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
 
-                m_remoteEnrollee->provisionCloudProperties(cloudProp, 
-                    std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback, 
+                m_remoteEnrollee->provisionCloudProperties(cloudProp,
+                    std::bind(&ESMediatorSimulator::cloudProvisioningStatusCallback,
                                                             this, std::placeholders::_1));
             }
         }
index a5af75c48dd42a5385ec6cf7a0f07653db387fc7..852aa6c2db23d4177be8d95912efeaacd54607e9 100755 (executable)
@@ -53,7 +53,10 @@ namespace OIC
             /**
              * Constructor
              */
-            EnrolleeStatus(const OCRepresentation& rep) { m_rep = rep; }
+            EnrolleeStatus(const OCRepresentation& rep)
+            {
+                m_rep = rep;
+            }
 
             EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
                 m_rep(enrolleeStatus.getRepresentation())
@@ -73,8 +76,10 @@ namespace OIC
             ProvStatus getProvStatus()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
+                {
                     return static_cast<ProvStatus>(
                                         m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
+                }
                 return ES_STATE_INIT;
             }
 
@@ -86,8 +91,10 @@ namespace OIC
             ESErrorCode getLastErrCode()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
+                {
                     return static_cast<ESErrorCode>(
                                         m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
+                }
                 return ES_ERRCODE_NO_ERROR;
             }
 
@@ -114,7 +121,9 @@ namespace OIC
             /**
              * Constructor
              */
-            CloudProp() {};
+            CloudProp()
+            {
+            };
 
             /**
              * Constructor with OCRepresentation object. This is used for JNI communication.
@@ -157,7 +166,9 @@ namespace OIC
             std::string getAuthCode()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
+                }
                 return std::string("");
             }
 
@@ -169,7 +180,9 @@ namespace OIC
             std::string getAuthProvider()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
+                }
                 return std::string("");
             }
 
@@ -181,7 +194,9 @@ namespace OIC
             std::string getCiServer()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
+                }
                 return std::string("");
             }
 
@@ -225,7 +240,10 @@ namespace OIC
             /**
              * Constructor with OCRepresentation object. This is used for JNI communication.
              */
-            DeviceProp(const OCRepresentation &rep) { m_rep = rep; }
+            DeviceProp(const OCRepresentation &rep)
+            {
+                m_rep = rep;
+            }
 
             /**
              * Set WiFi resource properties to be delivered to Enrollee
@@ -266,7 +284,9 @@ namespace OIC
             std::string getSsid()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
+                }
                 return std::string("");
             }
 
@@ -278,7 +298,9 @@ namespace OIC
             std::string getPassword()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
+                }
                 return std::string("");
             }
 
@@ -292,7 +314,9 @@ namespace OIC
             WIFI_AUTHTYPE getAuthType()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
+                {
                     return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
+                }
                 return NONE_AUTH;
             }
 
@@ -306,7 +330,9 @@ namespace OIC
             WIFI_ENCTYPE getEncType()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
+                {
                     return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
+                }
                 return NONE_ENC;
             }
 
@@ -319,7 +345,9 @@ namespace OIC
             std::string getLanguage()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
+                }
                 return std::string("");
             }
 
@@ -332,7 +360,9 @@ namespace OIC
             std::string getCountry()
             {
                 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
+                {
                     return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
+                }
                 return std::string("");
             }
 
index 13d1c9d6db15f0921826f2775fec2a3513ba67ff..df9c15ce1b9deb0b8b664cbc363bb0618c85fe74 100755 (executable)
@@ -160,7 +160,8 @@ namespace OIC
             OC::OCRepresentation rep;
 
             std::function< OCStackResult(void) > getStatus = [&]
-            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+            {
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
                         DEFAULT_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
                         const OCRepresentation& rep, const int eCode) >(
                                 std::bind(&EnrolleeResource::onGetStatusResponse, this,
@@ -193,7 +194,8 @@ namespace OIC
             OC::OCRepresentation rep;
 
             std::function< OCStackResult(void) > getConfigurationStatus = [&]
-            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+            {
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
                         BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
                         const OCRepresentation& rep, const int eCode) >(
                                 std::bind(&EnrolleeResource::onGetConfigurationResponse, this,
index f6a76a5689cdfd9e43a04495654cc51823d0edaf..6e7bdf9aa35c7ebb26ad3c930f7776ae2c72e0a5 100755 (executable)
@@ -101,7 +101,7 @@ namespace OIC
         {
             size_t outBufSize = B64DECODE_OUT_SAFESIZE((uuidString.length() + 1));
             uint8_t* outKey = (uint8_t*)OICCalloc(1, outBufSize);
-            uint32_t outKeySize;
+            uint32_t outKeySize = 0;
             if(NULL == outKey)
             {
                 OIC_LOG (ERROR, ENROLEE_SECURITY_TAG, "Failed to memoray allocation.");
@@ -165,7 +165,7 @@ namespace OIC
             pOwnedDevList.clear();
             pUnownedDevList.clear();
 
-            OCStackResult result;
+            OCStackResult result = OC_STACK_ERROR;
 
             result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
                     pOwnedDevList);
@@ -346,7 +346,7 @@ namespace OIC
             char href[] = "*";
             size_t len = strlen(href)+1;  // '1' for null termination
             rsrc->href = (char*) OICCalloc(len, sizeof(char));
-            if(!rsrc)
+            if(!rsrc->href)
             {
                 OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,  "createAcl: OICCalloc error return");
                 OCDeleteACLList(acl);
@@ -354,7 +354,7 @@ namespace OIC
             }
             OICStrcpy(rsrc->href, len, href);
 
-            int arrLen = 1;
+            size_t arrLen = 1;
             rsrc->typeLen = arrLen;
             rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
             rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
index 971fbbec5bdfaf0124d1d16644f61a0826383f2e..ca6ef587c07fcf027066ddd0d637beae3eda5895 100755 (executable)
@@ -53,7 +53,9 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
             if (OCRepPayloadGetPropInt(payload, USERPROPERTY_KEY_INT, &value))
             {
                 if(*userdata != NULL)
+                {
                     *userdata = (void*)OICMalloc(sizeof(UserProperties));
+                }
                 OIC_LOG_V(INFO, ESX_ENROLLEE_TAG, "[User specific property] %s : %ld",
                                                                             USERPROPERTY_KEY_INT, value);
                 ((UserProperties*)(*userdata))->userValue_int = value;
index 749402e376c15fb2c75a632182e52314abe89079..792fe68c79c58c4f41c15fa4ab3fb303a69715c3 100755 (executable)
@@ -66,48 +66,16 @@ void WiFiProvCbInApp(ESWiFiProvData *eventData)
 {
     printf("WiFiProvCbInApp IN\n");
 
-    if(eventData->ssid != NULL)
+    if(eventData == NULL)
     {
-        printf("SSID : %s\n", eventData->ssid);
-    }
-    else
-    {
-        printf("ERROR! SSID IS NULL\n");
-        return;
-    }
-
-    if(eventData->pwd != NULL)
-    {
-        printf("Password : %s\n", eventData->pwd);
-    }
-    else
-    {
-        printf("ERROR! Password IS NULL\n");
-        return;
-    }
-
-    if(eventData->authtype == NONE_AUTH || eventData->authtype == WEP || \
-        eventData->authtype == WPA_PSK || eventData->authtype == WPA2_PSK)
-    {
-        printf("AuthType : %d\n", eventData->authtype);
-    }
-    else
-    {
-        printf("ERROR! AuthType IS NULL\n");
-        return;
+        printf("ESWiFiProvData is NULL\n");
+        return ;
     }
 
-    if(eventData->enctype == NONE_ENC || eventData->enctype == WEP_64 || \
-        eventData->enctype == WEP_128 || eventData->enctype == TKIP || \
-        eventData->enctype == AES || eventData->enctype == TKIP_AES)
-    {
-        printf("EncType : %d\n", eventData->enctype);
-    }
-    else
-    {
-        printf("ERROR! EncType IS NULL\n");
-        return;
-    }
+    printf("SSID : %s\n", eventData->ssid);
+    printf("Password : %s\n", eventData->pwd);
+    printf("AuthType : %d\n", eventData->authtype);
+    printf("EncType : %d\n", eventData->enctype);
 
     if(eventData->userdata != NULL)
     {
@@ -121,25 +89,14 @@ void DevConfProvCbInApp(ESDevConfProvData *eventData)
 {
     printf("DevConfProvCbInApp IN\n");
 
-    if(eventData->language != NULL)
-    {
-        printf("Language : %s\n", eventData->language);
-    }
-    else
+    if(eventData == NULL)
     {
-        printf("ERROR! Language IS NULL\n");
-        return;
+        printf("ESDevConfProvData is NULL\n");
+        return ;
     }
 
-    if(eventData->country != NULL)
-    {
-        printf("Country : %s\n", eventData->country);
-    }
-    else
-    {
-        printf("ERROR! Country IS NULL\n");
-        return;
-    }
+    printf("Language : %s\n", eventData->language);
+    printf("Country : %s\n", eventData->country);
 
     printf("DevConfProvCbInApp OUT\n");
 }
@@ -148,35 +105,15 @@ void CloudDataProvCbInApp(ESCloudProvData *eventData)
 {
     printf("CloudDataProvCbInApp IN\n");
 
-    if(eventData->authCode != NULL)
-    {
-        printf("AuthCode : %s\n", eventData->authCode);
-    }
-    else
-    {
-        printf("ERROR! AuthCode IS NULL\n");
-        return;
-    }
-
-    if(eventData->authProvider != NULL)
-    {
-        printf("AuthProvider : %s\n", eventData->authProvider);
-    }
-    else
+    if(eventData == NULL)
     {
-        printf("ERROR! AuthProvider IS NULL\n");
-        return;
+        printf("ESCloudProvData is NULL\n");
+        return ;
     }
 
-    if(eventData->ciServer != NULL)
-    {
-        printf("CI Server : %s\n", eventData->ciServer);
-    }
-    else
-    {
-        printf("ERROR! CI Server IS NULL\n");
-        return;
-    }
+    printf("AuthCode : %s\n", eventData->authCode);
+    printf("AuthProvider : %s\n", eventData->authProvider);
+    printf("CI Server : %s\n", eventData->ciServer);
 
     printf("CloudDataProvCbInApp OUT\n");
 }
@@ -222,7 +159,7 @@ void StartEasySetup()
     }
     printf("ESInitEnrollee Success\n");
 
-    pthread_t thread_handle;
+    pthread_t thread_handle = NULL;
     if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
     {
         printf("Thread creation failed\n");
@@ -246,7 +183,9 @@ void SetDeviceInfo()
     SetUserProperties(&g_userProperties);
 
     if(ESSetDeviceProperty(&deviceProperty) == ES_ERROR)
+    {
         printf("ESSetDeviceProperty Error\n");
+    }
 
     printf("SetDeviceInfo OUT\n");
 }
@@ -339,7 +278,7 @@ int main()
                     PrintMenu();
                     break;
             }
-            if (option == 'Q' || option == 'q') break;
+            if (option == 'Q' || option == 'q') { break; }
         }
     }
     return 0;
@@ -348,7 +287,7 @@ int main()
 void *listeningFunc(void * data)
 {
     (void)data;
-    OCStackResult result;
+    OCStackResult result = OC_STACK_ERROR;
 
     while (true)
     {
index c94bc053e38c6a9010ebd1fd66a86349d6e9ca78..7d0be0caf8e9092ec575493a8262fed6a2be35da 100755 (executable)
@@ -126,7 +126,9 @@ void getStatusCallback(std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus)
 void getStatus()
 {
     if(!remoteEnrollee)
+    {
         return;
+    }
 
     try
     {
@@ -156,7 +158,9 @@ void getConfigurationCallback(std::shared_ptr< GetConfigurationStatus > getConfi
 void getConfiguration()
 {
     if(!remoteEnrollee)
+    {
         return;
+    }
 
     try
     {
@@ -185,7 +189,9 @@ void deviceProvisioningStatusCallback(std::shared_ptr< DevicePropProvisioningSta
 void provisionDeviceProperty()
 {
     if(!remoteEnrollee)
+    {
         return;
+    }
 
     DeviceProp devProp;
     devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
@@ -225,7 +231,9 @@ void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatu
 void provisionCloudProperty()
 {
     if(!remoteEnrollee)
+    {
         return;
+    }
 
     CloudProp cloudProp;
     cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
@@ -357,18 +365,17 @@ int main()
 
     OCPlatform::Configure(config);
 
+    try
+    {
 #ifdef __WITH_DTLS__
-    //Initializing the provisioning client stack using the db path provided by the application.
-    OCStackResult result = OCSecure::provisionInit("");
+        //Initializing the provisioning client stack using the db path provided by the application.
+        OCStackResult result = OCSecure::provisionInit("");
 
-    if (result != OC_STACK_OK)
-    {
-        return -1;
-    }
+        if (result != OC_STACK_OK)
+        {
+            return -1;
+        }
 #endif
-
-    try
-    {
         requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=" << PROV_RESOURCE_TYPE;
 
         OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, &foundResource);
@@ -379,7 +386,7 @@ int main()
 
     }catch(OCException& e)
     {
-        oclog() << "Exception in main: "<<e.what();
+        std::cout << "Exception in main: "<<e.what();
     }
 
     while (true)