From 0e634105dc2a8e171470fdac93418a9471db9ddf Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Fri, 6 May 2016 11:26:30 +0900 Subject: [PATCH] Update a logic for POST request in Enrollee implementation Updated logic/flow: (1) Parsing the requested attribute like tnn, cd, and tr (2) Check if the provisioning is completed (3) Check if the trigger is requested (4) If the trigger process fails due to some reason, revert an attribute tr to 0 Change-Id: I1db3bfcd3b0d5593516b7719d64ba23f831ba9bc Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/8075 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../enrollee/arduino/resourcehandler.cpp | 42 ++++++++++------------ service/easy-setup/enrollee/src/resourcehandler.c | 42 ++++++++++------------ 2 files changed, 38 insertions(+), 46 deletions(-) mode change 100644 => 100755 service/easy-setup/enrollee/arduino/resourcehandler.cpp mode change 100644 => 100755 service/easy-setup/enrollee/src/resourcehandler.c diff --git a/service/easy-setup/enrollee/arduino/resourcehandler.cpp b/service/easy-setup/enrollee/arduino/resourcehandler.cpp old mode 100644 new mode 100755 index 2181ec0..7f2fc8e --- a/service/easy-setup/enrollee/arduino/resourcehandler.cpp +++ b/service/easy-setup/enrollee/arduino/resourcehandler.cpp @@ -166,6 +166,24 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe return ehResult; } + char* tnn; + if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) + { + OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn); + OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn); + + gProvResource.ps = ES_PS_PROVISIONING_COMPLETED; + } + + char* cd; + if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) + { + OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd); + OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd); + } + + OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps); + int64_t tr; if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr)) { @@ -187,6 +205,7 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe } else { + gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE; OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL." "Network handler not registered. Failed to connect to the network"); ehResult = OC_EH_ERROR; @@ -204,29 +223,6 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee."); } - OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), ""); - OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), ""); - - char* tnn; - if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) - { - OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn); - OIC_LOG(INFO, ES_RH_TAG, "got ssid"); - } - - OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn); - - char* cd; - if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) - { - OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd); - OIC_LOG(INFO, ES_RH_TAG, "got password"); - }OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd); - - gProvResource.ps = ES_PS_PROVISIONING_COMPLETED; - - OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps); - OCRepPayload *getResp = constructResponse(ehRequest); if (!getResp) { diff --git a/service/easy-setup/enrollee/src/resourcehandler.c b/service/easy-setup/enrollee/src/resourcehandler.c old mode 100644 new mode 100755 index 0956410..f3856f2 --- a/service/easy-setup/enrollee/src/resourcehandler.c +++ b/service/easy-setup/enrollee/src/resourcehandler.c @@ -166,6 +166,24 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe return ehResult; } + char* tnn; + if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) + { + OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn); + OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn); + + gProvResource.ps = ES_PS_PROVISIONING_COMPLETED; + } + + char* cd; + if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) + { + OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd); + OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd); + } + + OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps); + int64_t tr; if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr)) { @@ -187,6 +205,7 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe } else { + gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE; OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL." "Network handler not registered. Failed to connect to the network"); ehResult = OC_EH_ERROR; @@ -204,29 +223,6 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee."); } - OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), ""); - OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), ""); - - char* tnn; - if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) - { - OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn); - OIC_LOG(INFO, ES_RH_TAG, "got ssid"); - } - - OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn); - - char* cd; - if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) - { - OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd); - OIC_LOG(INFO, ES_RH_TAG, "got password"); - }OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd); - - gProvResource.ps = ES_PS_PROVISIONING_COMPLETED; - - OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps); - OCRepPayload *getResp = constructResponse(ehRequest); if (!getResp) { -- 2.7.4