Merge branch '1.3-rel' (423eb833) 57/21557/3
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Thu, 20 Jul 2017 10:43:47 +0000 (12:43 +0200)
committerPhilippe Coval <philippe.coval@osg.samsung.com>
Thu, 20 Jul 2017 10:43:52 +0000 (12:43 +0200)
Relate-to:
https://gerrit.iotivity.org/gerrit/20829
https://gerrit.iotivity.org/gerrit/21387
https://gerrit.iotivity.org/gerrit/18679
https://gerrit.iotivity.org/gerrit/21139
https://gerrit.iotivity.org/gerrit/21403
https://gerrit.iotivity.org/gerrit/21433
https://gerrit.iotivity.org/gerrit/21503

Change-Id: I423eb833e348fe94b98793da7e226afd28ab0236
Bug: https://jira.iotivity.org/browse/IOT-2453
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
1  2 
resource/csdk/security/src/credresource.c
resource/csdk/stack/src/ocserverrequest.c

@@@ -217,103 -180,105 +217,102 @@@ static CAPayloadFormat_t OCToCAPayloadF
          return CA_FORMAT_UNSUPPORTED;
      }
  }
 -//-------------------------------------------------------------------------------------------------
 -// Internal APIs
 -//-------------------------------------------------------------------------------------------------
--
 -/**
 - * Get a server request from the server request list using the specified token.
 - *
 - * @param token - token of server request
 - * @param tokenLength - length of token
 - *
 - * @return
 - *     OCServerRequest*
 - */
 -OCServerRequest * GetServerRequestUsingToken (const CAToken_t token, uint8_t tokenLength)
 +static CAResponseResult_t ConvertEHResultToCAResult (OCEntityHandlerResult result, OCMethod method)
  {
 -    if(!token)
 -    {
 -        OIC_LOG(ERROR, TAG, "Invalid Parameter Token");
 -        return NULL;
 -    }
 -
 -    OIC_LOG(INFO, TAG,"Get server request with token");
 -    OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength);
 -
 -    OCServerRequest tmpFind, *out = NULL;
 -
 -    tmpFind.requestToken = token;
 -    tmpFind.tokenLength = tokenLength;
 -    out = RB_FIND(ServerRequestTree, &serverRequestTree, &tmpFind);
 -
 -    if (!out)
 -    {
 -        OIC_LOG(INFO, TAG, "Server Request not found!!");
 -        return NULL;
 -    }
 -
 -    OIC_LOG(INFO, TAG, "Found in server request list");
 -    return out;
 -}
 -
 -/**
 - * Get a server request from the server request list using the specified handle
 - *
 - * @param handle - handle of server request
 - * @return
 - *     OCServerRequest*
 - */
 -OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle)
 -{
 -    if (!handle)
 -    {
 -        OIC_LOG(ERROR, TAG, "Invalid Parameter handle");
 -        return NULL;
 -    }
 -
 -    return GetServerRequestUsingToken(handle->requestToken, handle->tokenLength);
 -}
 -
 -/**
 - * Get a server response from the server response list using the specified handle
 - *
 - * @param handle - handle of server response
 - *
 - * @return
 - *     OCServerResponse*
 - */
 -OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle)
 -{
 -    if (!handle)
 -    {
 -        OIC_LOG(ERROR, TAG, "Invalid Parameter handle");
 -        return NULL;
 -    }
 -
 -    OCServerResponse tmpFind, *out = NULL;
 -
 -    tmpFind.requestHandle = (OCRequestHandle)handle;
 -    out = RB_FIND(ServerResponseTree, &serverResponseTree, &tmpFind);
 +    CAResponseResult_t caResult = CA_BAD_REQ;
  
 -    if (!out)
 +    switch (result)
      {
 -        OIC_LOG(INFO, TAG, "Server Response not found!!");
 -        return NULL;
 +        // 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_RESOURCE_DELETED: // 2.02
 +            if (method == OC_REST_POST || method == OC_REST_DELETE)
 +            {
 +                caResult = CA_DELETED;
 +            }
 +            break;
 +        case OC_EH_SLOW: // 2.05
 +            caResult = CA_CONTENT;
 +            break;
 +        case OC_EH_OK:
 +        case OC_EH_CHANGED: // 2.04
 +        case OC_EH_CONTENT: // 2.05
 +            if (method == OC_REST_POST || method == OC_REST_PUT || method == OC_REST_DELETE)
 +            {
 +                caResult = CA_CHANGED;
 +            }
 +            else if (method == OC_REST_GET)
 +            {
 +                caResult = CA_CONTENT;
 +            }
 +            break;
 +        case OC_EH_VALID: // 2.03
 +            caResult = CA_VALID;
 +            break;
 +        // Unsuccessful Client Request
 +        case OC_EH_UNAUTHORIZED_REQ: // 4.01
 +            caResult = CA_UNAUTHORIZED_REQ;
 +            break;
 +        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_SERVICE_UNAVAILABLE: // 5.03
 +            caResult = CA_SERVICE_UNAVAILABLE;
 +            break;
 +        case OC_EH_RETRANSMIT_TIMEOUT: // 5.04
 +            caResult = CA_RETRANSMIT_TIMEOUT;
 +            break;
 +        default:
 +            caResult = CA_BAD_REQ;
 +            break;
      }
 -
 -    OIC_LOG(INFO, TAG, "Found in server response list");
 -    return out;
 +    return caResult;
  }
  
 -OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
 -        uint8_t delayedResNeeded, uint8_t notificationFlag, OCMethod method,
 -        uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
 -        OCQualityOfService qos, char * query,
 -        OCHeaderOption * rcvdVendorSpecificHeaderOptions,
 -        OCPayloadFormat payloadFormat, uint8_t * payload, CAToken_t requestToken,
 -        uint8_t tokenLength, char * resourceUrl, size_t reqTotalSize, OCPayloadFormat acceptFormat,
 -        uint16_t acceptVersion, const OCDevAddr *devAddr)
 +//-------------------------------------------------------------------------------------------------
 +// Internal APIs
 +//-------------------------------------------------------------------------------------------------
 +OCStackResult AddServerRequest (OCServerRequest ** request,
 +                                uint16_t coapMessageID,
 +                                uint8_t delayedResNeeded,
 +                                uint8_t notificationFlag,
 +                                OCMethod method,
 +                                uint8_t numRcvdVendorSpecificHeaderOptions,
 +                                uint32_t observationOption,
 +                                OCQualityOfService qos,
 +                                char * query,
 +                                OCHeaderOption * rcvdVendorSpecificHeaderOptions,
 +                                OCPayloadFormat payloadFormat,
 +                                uint8_t * payload,
 +                                CAToken_t requestToken,
 +                                uint8_t tokenLength,
 +                                char * resourceUrl,
 +                                size_t payloadSize,
 +                                OCPayloadFormat acceptFormat,
 +                                uint16_t acceptVersion,
 +                                const OCDevAddr *devAddr)
  {
 -    if (!request)
 +    if (!request || !devAddr)
      {
          return OC_STACK_INVALID_PARAM;
      }
@@@ -494,6 -413,106 +493,15 @@@ OCStackResult FormOCEntityHandlerReques
      return OC_STACK_INVALID_PARAM;
  }
  
 -/**
 - * Find a server request in the server request list and delete
 - *
 - * @param serverRequest - server request to find and delete
 - */
 -void FindAndDeleteServerRequest(OCServerRequest * serverRequest)
 -{
 -    if(serverRequest)
 -    {
 -        OCServerRequest* out = NULL;
 -        out = RB_FIND(ServerRequestTree, &serverRequestTree, serverRequest);
 -
 -        if (out)
 -        {
 -            DeleteServerRequest(out);
 -        }
 -    }
 -}
 -
 -CAResponseResult_t ConvertEHResultToCAResult (OCEntityHandlerResult result, OCMethod method)
 -{
 -    CAResponseResult_t caResult = CA_BAD_REQ;
 -
 -    switch (result)
 -    {
 -        // 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_RESOURCE_DELETED: // 2.02
 -            if (method == OC_REST_POST || method == OC_REST_DELETE)
 -            {
 -                caResult = CA_DELETED;
 -            }
 -            break;
 -        case OC_EH_SLOW: // 2.05
 -            caResult = CA_CONTENT;
 -            break;
 -        case OC_EH_OK:
 -        case OC_EH_CHANGED: // 2.04
 -        case OC_EH_CONTENT: // 2.05
 -            if (method == OC_REST_POST || method == OC_REST_PUT || method == OC_REST_DELETE)
 -            {
 -                caResult = CA_CHANGED;
 -            }
 -            else if (method == OC_REST_GET)
 -            {
 -                caResult = CA_CONTENT;
 -            }
 -            break;
 -        case OC_EH_VALID: // 2.03
 -            caResult = CA_VALID;
 -            break;
 -        // Unsuccessful Client Request
 -        case OC_EH_UNAUTHORIZED_REQ: // 4.01
 -            caResult = CA_UNAUTHORIZED_REQ;
 -            break;
 -        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_SERVICE_UNAVAILABLE: // 5.03
 -            caResult = CA_SERVICE_UNAVAILABLE;
 -            break;
 -        case OC_EH_RETRANSMIT_TIMEOUT: // 5.04
 -            caResult = CA_RETRANSMIT_TIMEOUT;
 -            break;
 -        default:
 -            caResult = CA_BAD_REQ;
 -            break;
 -    }
 -    return caResult;
 -}
 -
+ /**
+  * Handler function for sending a response from a single resource
+  *
+  * @param ehResponse - pointer to the response from the resource
+  *
+  * @return
+  *     OCStackResult
+  */
  OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
  {
      OCStackResult result = OC_STACK_ERROR;