[easysetup] Bug fix, code cleanup and function name changes for better readability
authorlankamadan <lanka.madan@samsung.com>
Fri, 11 Dec 2015 10:39:52 +0000 (19:39 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 16 Dec 2015 05:45:31 +0000 (05:45 +0000)
- Provisioning status 0 was considered for checking success. Now changed to 2.
- PUT is retained based on the spec.
  PUT request is appropriate for provisioning information to the enrollee.
  When an enrollee receives the put request, the entire resource information should be overwritten.

Change-Id: Ib001c19c8a8ed74a967251c1be4219fd9cc70cdf
Signed-off-by: lankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4527
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/easy-setup/sdk/common/escommon.h
service/easy-setup/sdk/enrollee/src/resourceHandler.cpp
service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp
service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h

index 1e94983..67d628f 100755 (executable)
 #define OC_RSRVD_ES_URI_PROV               "/oic/prov"
 #define OC_RSRVD_ES_URI_NET                "/oic/net"
 
-
+/**
+ * @brief Defines for Provisioning status accepted values
+ */
+#define ES_PS_NEED_PROVISIONING 1
+#define ES_PS_PROVISIONING_COMPLETED 2
 
 typedef enum
 {
index 74efd8b..f066367 100755 (executable)
@@ -169,6 +169,23 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
         return ehResult;
     }
 
+    //TODO : ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
+    // A new request for provisioning means overriding existing network provisioning information.
+    // Metadata to indicate that it is override is needed. The metadata can be a new attribute
+    // should be added to the /oic/prov resource indicating to override the existing network
+    // information.
+    if (g_prov.ps == ES_PS_PROVISIONING_COMPLETED)
+    {
+        OC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
+                "This a request to override the existing the network provisioning information");
+    }
+
+    // PUT request is appropriate for provisioning information to the enrollee.
+    // When an enrollee receives the put request, the entire resource information should
+    // be overwritten.
+    sprintf(g_prov.tnn, "%s", "");
+    sprintf(g_prov.cd, "%s", "");
+
     char* tnn;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
     {
@@ -193,6 +210,9 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
 
     OC_LOG_V(INFO, ES_RH_TAG, "g_prov.cd %s", g_prov.cd);
 
+    g_prov.ps = 2;
+    OC_LOG_V(INFO, ES_RH_TAG, "g_prov.ps %d", g_prov.ps);
+
     g_flag = 1;
 
     OCRepPayload *getResp = constructResponse(ehRequest);
@@ -232,7 +252,6 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
     char* tr;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr))
     {
-
         // Triggering
         ehResult = OC_EH_OK;
     }
index 9284ea8..7fc4180 100755 (executable)
@@ -40,17 +40,17 @@ namespace OIC
             m_enrolleeNWProvInfo = enrolleeNWProvInfo;\r
         }\r
 \r
-        void RemoteEnrolleeResource::onProvPostResource(const HeaderOptions& /*headerOptions*/,\r
+        void RemoteEnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,\r
                 const OCRepresentation& rep, const int eCode)\r
         {\r
-            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvPostResource : %s, eCode = %d",\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "checkProvInformationCb : %s, eCode = %d",\r
                     rep.getUri().c_str(),\r
                     eCode);\r
 \r
             if(eCode != 0)\r
             {\r
                 OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
-                        "onProvPostResource : Provisioning is failed ");\r
+                        "checkProvInformationCb : Provisioning is failed ");\r
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
                 m_provStatusCb(provStatus);\r
@@ -65,39 +65,48 @@ namespace OIC
             rep.getValue(OC_RSRVD_ES_TNN, tnn);\r
             rep.getValue(OC_RSRVD_ES_CD, cd);\r
 \r
-            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvPostResource : ps - %d",\r
-                    ps);OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : tnn - %s",\r
-                    tnn.c_str());OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : cd - %s",\r
-                    cd.c_str());\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "checkProvInformationCb : ps - %d", ps);\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "checkProvInformationCb : tnn - %s", tnn.c_str());\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "checkProvInformationCb : cd - %s", cd.c_str());\r
 \r
             //Provisioning status check\r
-            if (ps == 0)\r
+            if (ps == ES_PS_PROVISIONING_COMPLETED)\r
             {\r
-                OC::QueryParamsMap query;\r
-                OC::OCRepresentation rep;\r
-\r
-                OCStackResult result = m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
-                        m_ocResource->getResourceInterfaces().at(0), query,\r
-                        std::function<\r
-                                void(const HeaderOptions& headerOptions,\r
-                                        const OCRepresentation& rep, const int eCode) >(\r
-                                std::bind(&RemoteEnrolleeResource::onProvResource, this,\r
-                                        std::placeholders::_1, std::placeholders::_2,\r
-                                        std::placeholders::_3)));\r
+                if(tnn != std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid))\r
+                {\r
+                    OC_LOG_V (ERROR, ES_REMOTE_ENROLLEE_TAG,\r
+                            "checkProvInformationCb : Network SSID is not the same as the "\r
+                            "SSID provisioned");\r
+                    std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                            ProvisioningStatus >(ESResult::ES_ERROR,\r
+                            ESState::ES_PROVISIONING_ERROR);\r
+                            m_provStatusCb(provStatus);\r
+                    return;\r
+                }\r
 \r
-                if(result != OCStackResult::OC_STACK_OK)\r
+                if(cd != std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd))\r
                 {\r
+                    OC_LOG_V (ERROR, ES_REMOTE_ENROLLEE_TAG,\r
+                            "checkProvInformationCb : Network PWD is not the same as the "\r
+                            "PWD provisioned");\r
                     std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
                             ProvisioningStatus >(ESResult::ES_ERROR,\r
                             ESState::ES_PROVISIONING_ERROR);\r
                     m_provStatusCb(provStatus);\r
                     return;\r
                 }\r
+\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+                        "checkProvInformationCb : Provisioning is success ");\r
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);\r
+                m_provStatusCb(provStatus);\r
+                return;\r
             }\r
             else\r
             {\r
                 OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
-                        "onProvResource : Provisioning is failed ");\r
+                        "checkProvInformationCb : Provisioning is failed ");\r
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
                 m_provStatusCb(provStatus);\r
@@ -105,18 +114,18 @@ namespace OIC
             }\r
         }\r
 \r
-        void RemoteEnrolleeResource::onProvResource(const HeaderOptions& /*headerOptions*/,\r
+        void RemoteEnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/,\r
                                                     const OCRepresentation& rep,\r
                                                     const int eCode)\r
         {\r
-            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : %s, eCode = %d",\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "getProvStatusResponse : %s, eCode = %d",\r
                     rep.getUri().c_str(),\r
                     eCode);\r
 \r
             if (eCode != 0)\r
             {\r
                 OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
-                                            "onProvResource : Provisioning is failed ");\r
+                                            "getProvStatusResponse : Provisioning is failed ");\r
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
                 m_provStatusCb(provStatus);\r
@@ -131,14 +140,14 @@ namespace OIC
             rep.getValue(OC_RSRVD_ES_TNN, tnn);\r
             rep.getValue(OC_RSRVD_ES_CD, cd);\r
 \r
-            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : ps - %d",\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "getProvStatusResponse : ps - %d",\r
                                 ps);\r
-            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : tnn - %s",\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "getProvStatusResponse : tnn - %s",\r
                                             tnn.c_str());\r
-            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : cd - %s",\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "getProvStatusResponse : cd - %s",\r
                                             cd.c_str());\r
 \r
-            if (ps == 1) //ps == 1 indicates the need for provisioning\r
+            if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning\r
             {\r
                 OCRepresentation provisioningRepresentation;\r
 \r
@@ -147,23 +156,23 @@ namespace OIC
                 provisioningRepresentation.setValue(OC_RSRVD_ES_CD,\r
                         std::string(m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd));\r
 \r
-                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : ssid - %s",\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "getProvStatusResponse : ssid - %s",\r
                         m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid);\r
-                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : pwd - %s",\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "getProvStatusResponse : pwd - %s",\r
                         m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd);\r
 \r
                 m_ocResource->put(provisioningRepresentation, QueryParamsMap(),\r
                         std::function<\r
                                 void(const HeaderOptions& headerOptions,\r
                                         const OCRepresentation& rep, const int eCode) >(\r
-                                std::bind(&RemoteEnrolleeResource::onProvPostResource, this,\r
+                                std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,\r
                                         std::placeholders::_1, std::placeholders::_2,\r
                                         std::placeholders::_3)));\r
             }\r
-            else if(ps == 0) //ps == 1 indicates that provisioning is completed\r
+            else if(ps == ES_PS_PROVISIONING_COMPLETED) //Indicates that provisioning is completed\r
             {\r
                 OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
-                        "onProvResource : Provisioning is successful");\r
+                        "getProvStatusResponse : Provisioning is successful");\r
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
                         ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);\r
                 m_provStatusCb(provStatus);\r
@@ -252,14 +261,18 @@ namespace OIC
             OC::QueryParamsMap query;\r
             OC::OCRepresentation rep;\r
 \r
-            OCStackResult result = m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
-                    m_ocResource->getResourceInterfaces().at(0), query,\r
-                    std::function<\r
-                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
-                                    const int eCode) >(\r
-                            std::bind(&RemoteEnrolleeResource::onProvResource, this,\r
-                                    std::placeholders::_1, std::placeholders::_2,\r
-                                    std::placeholders::_3)));\r
+            std::function <OCStackResult(void)> getProvisioingStatus = [&]\r
+            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
+                        m_ocResource->getResourceInterfaces().at(0), query,\r
+                        std::function<\r
+                        void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+                                const int eCode) >(\r
+                                std::bind(&RemoteEnrolleeResource::getProvStatusResponse, this,\r
+                                        std::placeholders::_1, std::placeholders::_2,\r
+                                        std::placeholders::_3)));\r
+            };\r
+\r
+            OCStackResult result = getProvisioingStatus();\r
 \r
             if (result != OCStackResult::OC_STACK_OK)\r
             {\r
@@ -286,7 +299,7 @@ namespace OIC
                     std::function<\r
                             void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
                                     const int eCode) >(\r
-                            std::bind(&RemoteEnrolleeResource::onProvPostResource, this,\r
+                            std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,\r
                                     std::placeholders::_1, std::placeholders::_2,\r
                                     std::placeholders::_3)));\r
         }\r
index cc520ec..8e41c28 100755 (executable)
@@ -107,10 +107,10 @@ namespace OIC
             ProvStatusCb m_provStatusCb;\r
             EnrolleeNWProvInfo m_enrolleeNWProvInfo;\r
 \r
-            void onProvResource(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+            void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
                     const int eCode);\r
 \r
-            void onProvPostResource(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+            void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
                     const int eCode);\r
         };\r
     }\r