From 1ee5b8d93173f469c061dfa0c6cc8d88aa3f2242 Mon Sep 17 00:00:00 2001 From: Habib Virji Date: Tue, 28 Jun 2016 11:09:09 +0100 Subject: [PATCH] Jira Issue-964: Add more types for OCEntityHandlerResult OCEntityHandlerResult includes more type that matches with CAResponseResult_t. This patch does not modify the return value of the exisitng code and neither changes the enum value of the existing code. It appends to the existing list based on the CoAP return values. Change-Id: I2be12bb5f80ab751c9afc4e89c48446479c8f565 Signed-off-by: Habib Virji Reviewed-on: https://gerrit.iotivity.org/gerrit/8991 Tested-by: jenkins-iotivity Reviewed-by: Phil Coval Reviewed-by: Dwarkaprasad Dayama Reviewed-by: Ziran Sun --- resource/csdk/stack/include/octypes.h | 20 +++++-- resource/csdk/stack/src/ocserverrequest.c | 82 ++++++++++++++++----------- resource/unittests/OCResourceResponseTest.cpp | 6 ++ 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/resource/csdk/stack/include/octypes.h b/resource/csdk/stack/include/octypes.h index 96b8177..3428b35 100644 --- a/resource/csdk/stack/include/octypes.h +++ b/resource/csdk/stack/include/octypes.h @@ -849,11 +849,21 @@ typedef enum { OC_EH_OK = 0, OC_EH_ERROR, - OC_EH_RESOURCE_CREATED, - OC_EH_RESOURCE_DELETED, - OC_EH_SLOW, - OC_EH_FORBIDDEN, - OC_EH_RESOURCE_NOT_FOUND + OC_EH_RESOURCE_CREATED, // 2.01 + OC_EH_RESOURCE_DELETED, // 2.02 + OC_EH_SLOW, // 2.05 + OC_EH_FORBIDDEN, // 4.03 + OC_EH_RESOURCE_NOT_FOUND, // 4.04 + OC_EH_VALID, // 2.03 + OC_EH_CHANGED, // 2.04 + OC_EH_CONTENT, // 2.05 + OC_EH_BAD_REQ, // 4.00 + OC_EH_UNAUTHORIZED_REQ, // 4.01 + OC_EH_BAD_OPT, // 4.02 + OC_EH_METHOD_NOT_ALLOWED, // 4.05 + OC_EH_NOT_ACCEPTABLE, // 4.06 + OC_EH_INTERNAL_SERVER_ERROR, // 5.00 + OC_EH_RETRANSMIT_TIMEOUT // 5.04 } OCEntityHandlerResult; /** diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index 0526e9d..9ee0395 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -421,49 +421,67 @@ void FindAndDeleteServerRequest(OCServerRequest * serverRequest) CAResponseResult_t ConvertEHResultToCAResult (OCEntityHandlerResult result, OCMethod method) { - CAResponseResult_t caResult; + CAResponseResult_t caResult = CA_BAD_REQ; switch (result) { - case OC_EH_OK: - switch (method) - { - case OC_REST_PUT: - case OC_REST_POST: - // This Response Code is like HTTP 204 "No Content" but only used in - // response to POST and PUT requests. - caResult = CA_CHANGED; - break; - case OC_REST_GET: - // This Response Code is like HTTP 200 "OK" but only used in response to - // GET requests. - caResult = CA_CONTENT; - break; - default: - // This should not happen but, - // give it a value just in case but output an error - caResult = CA_CONTENT; - OIC_LOG_V(ERROR, TAG, "Unexpected OC_EH_OK return code for method [%d].", method); - } + // Successful Client Request + case OC_EH_RESOURCE_CREATED: // 2.01 + if (method == OC_REST_POST || method == OC_REST_PUT) + { + caResult = CA_CREATED; + } break; - case OC_EH_ERROR: - caResult = CA_BAD_REQ; + case OC_EH_RESOURCE_DELETED: // 2.02 + if (method == OC_REST_POST || method == OC_REST_DELETE) + { + caResult = CA_DELETED; + } break; - case OC_EH_RESOURCE_CREATED: - caResult = CA_CREATED; + case OC_EH_SLOW: // 2.05 + caResult = CA_CONTENT; + break; + case OC_EH_OK: // 2.04/2.05 + if (method == OC_REST_POST || method == OC_REST_PUT) + { + caResult = CA_CHANGED; + } + else if (method == OC_REST_GET) + { + caResult = CA_CONTENT; + } break; - case OC_EH_RESOURCE_DELETED: - caResult = CA_DELETED; + case OC_EH_VALID: // 2.03 + caResult = CA_VALID; break; - case OC_EH_SLOW: - caResult = CA_CONTENT; + case OC_EH_CHANGED: // 2.04 + caResult = CA_CHANGED; break; - case OC_EH_FORBIDDEN: + // Unsuccessful Client Request + case OC_EH_UNAUTHORIZED_REQ: // 4.01 caResult = CA_UNAUTHORIZED_REQ; break; - case OC_EH_RESOURCE_NOT_FOUND: + case OC_EH_BAD_OPT: // 4.02 + caResult = CA_BAD_OPT; + break; + case OC_EH_FORBIDDEN: // 4.03 + caResult = CA_FORBIDDEN_REQ; + break; + case OC_EH_RESOURCE_NOT_FOUND: // 4.04 caResult = CA_NOT_FOUND; break; + case OC_EH_METHOD_NOT_ALLOWED: // 4.05 + caResult = CA_METHOD_NOT_ALLOWED; + break; + case OC_EH_NOT_ACCEPTABLE: // 4.06 + caResult = CA_NOT_ACCEPTABLE; + break; + case OC_EH_INTERNAL_SERVER_ERROR: // 5.00 + caResult = CA_INTERNAL_SERVER_ERROR; + break; + case OC_EH_RETRANSMIT_TIMEOUT: // 5.04 + caResult = CA_RETRANSMIT_TIMEOUT; + break; default: caResult = CA_BAD_REQ; break; @@ -756,7 +774,6 @@ OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse) (OCRepPayload*)newPayload); } - (serverRequest->numResponses)--; if(serverRequest->numResponses == 0) @@ -777,4 +794,3 @@ OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse) exit: return stackRet; } - diff --git a/resource/unittests/OCResourceResponseTest.cpp b/resource/unittests/OCResourceResponseTest.cpp index 3b9e711..ca6a9f1 100644 --- a/resource/unittests/OCResourceResponseTest.cpp +++ b/resource/unittests/OCResourceResponseTest.cpp @@ -37,6 +37,12 @@ namespace OCResourceResponseTest int setCode = 200; EXPECT_NO_THROW(response.setErrorCode(setCode)); EXPECT_EQ(setCode, response.getErrorCode()); + setCode = 500; + EXPECT_NO_THROW(response.setErrorCode(setCode)); + EXPECT_EQ(setCode, response.getErrorCode()); + setCode = 400; + EXPECT_NO_THROW(response.setErrorCode(setCode)); + EXPECT_EQ(setCode, response.getErrorCode()); } TEST(NewResourceUriTest, SetGetNewResourceUriValidUri) -- 2.7.4