From 53479c7b40bdd9aaab737d53551b3ff89e1be000 Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Fri, 5 Aug 2016 16:40:09 +0900 Subject: [PATCH] Fix defects detected by SVACE system in easy setup 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/10021 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- service/easy-setup/enrollee/src/resourcehandler.c | 27 ++++++ .../enrollee/unittests/ESEnrolleeTest.cpp | 18 +++- .../enrollee/unittests/ESMediatorSimulator.h | 46 +++++---- .../easy-setup/mediator/richsdk/inc/ESRichCommon.h | 36 ++++++- .../mediator/richsdk/src/EnrolleeResource.cpp | 6 +- .../mediator/richsdk/src/EnrolleeSecurity.cpp | 8 +- .../sampleapp/enrollee/linux/easysetup_x.c | 2 + .../sampleapp/enrollee/linux/enrolleewifi.c | 107 +++++---------------- .../mediator/linux/richsdk_sample/mediator_cpp.cpp | 27 ++++-- 9 files changed, 151 insertions(+), 126 deletions(-) diff --git a/service/easy-setup/enrollee/src/resourcehandler.c b/service/easy-setup/enrollee/src/resourcehandler.c index ab24652..ed90ddf 100755 --- a/service/easy-setup/enrollee/src/resourcehandler.c +++ b/service/easy-setup/enrollee/src/resourcehandler.c @@ -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; + } } } diff --git a/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp b/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp index a4283e6..6232bce 100755 --- a/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp +++ b/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp @@ -49,9 +49,12 @@ public: MockRepository mocks; protected: - virtual ~TestWithMock() noexcept(noexcept(std::declval().~Test())) {} + virtual ~TestWithMock() noexcept(noexcept(std::declval().~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(); diff --git a/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h b/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h index e188ec3..938a43e 100755 --- a/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h +++ b/service/easy-setup/enrollee/unittests/ESMediatorSimulator.h @@ -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)> 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)> 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)> 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)> 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 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 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)); } } diff --git a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h index a5af75c..852aa6c 100755 --- a/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h +++ b/service/easy-setup/mediator/richsdk/inc/ESRichCommon.h @@ -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( m_rep.getValue(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( m_rep.getValue(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(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(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(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(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(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(m_rep.getValue(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(m_rep.getValue(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(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(OC_RSRVD_ES_COUNTRY); + } return std::string(""); } diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp index 13d1c9d..df9c15c 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp @@ -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( 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( std::bind(&EnrolleeResource::onGetConfigurationResponse, this, diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index f6a76a5..6e7bdf9 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -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*)); diff --git a/service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c b/service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c index 971fbbe..ca6ef58 100755 --- a/service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c +++ b/service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c @@ -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; diff --git a/service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c b/service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c index 749402e..792fe68 100755 --- a/service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c +++ b/service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c @@ -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) { diff --git a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp index c94bc05..7d0be0c 100755 --- a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp +++ b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp @@ -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: "<