X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fstack%2Fsrc%2Foccollection.c;h=66b5dce9e2749662a664ef00ace13de495c1feef;hb=8229635f6d207516ccbbdf23b13be164e0fc1787;hp=3ac8af035f708716e723b3f947a4d36ac7a12771;hpb=b2b9c7d9e130e14c07d42f2b2f07baa90108c336;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/src/occollection.c b/resource/csdk/stack/src/occollection.c old mode 100644 new mode 100755 index 3ac8af0..66b5dce --- a/resource/csdk/stack/src/occollection.c +++ b/resource/csdk/stack/src/occollection.c @@ -25,386 +25,211 @@ // For POSIX.1-2001 base specification, // Refer http://pubs.opengroup.org/onlinepubs/009695399/ #define _POSIX_C_SOURCE 200112L -#include -#include "ocstack.h" -#include "ocstackinternal.h" -#include "ocresourcehandler.h" -#include "logger.h" -#include "ocmalloc.h" -#include "cJSON.h" -#include "ocmalloc.h" - -/// Module Name -#include - -#define WITH_GROUPACTION 1 +#include "occollection.h" +#include "ocpayload.h" +#include "ocstack.h" #include "oicgroup.h" +#include "oic_string.h" +#include "payload_logging.h" -#define TAG PCF("occollection") - -#define NUM_PARAM_IN_QUERY 2 // The expected number of parameters in a query -#define NUM_FIELDS_IN_QUERY 2 // The expected number of fields in a query +#define TAG "OIC_RI_COLLECTION" -static OCStackResult CheckRTParamSupport(const OCResource* resource, const char* rtPtr) +static bool AddRTSBaslinePayload(OCRepPayload **linkArray, int size, OCRepPayload **colPayload) { - if(!resource || !rtPtr) - { - return OC_STACK_INVALID_PARAM; - } - - OCResourceType* rTPointer = resource->rsrcType; - while (rTPointer) - { - if( strcmp (rTPointer->resourcetypename, rtPtr) == 0) + size_t arraySize = 0; + for (int j = 0; j < size; j++) + { + size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0}; + char **rt = NULL; + OCRepPayloadGetStringArray(linkArray[j], OC_RSRVD_RESOURCE_TYPE, &rt, rtDim); + arraySize += rtDim[0]; + for (size_t l = 0; l < rtDim[0]; l++) { - return OC_STACK_OK; + OICFree(rt[l]); } - - rTPointer = rTPointer->next; + OICFree(rt); } - return OC_STACK_ERROR; -} -static OCStackResult CheckIFParamSupport(const OCResource* resource, const char* ifPtr) -{ - if(!resource || !ifPtr) - { - return OC_STACK_INVALID_PARAM; - } + for (OCStringLL *rsrcType = (*colPayload)->types; rsrcType; rsrcType = rsrcType->next, arraySize++); - OCResourceInterface* iFPointer = resource->rsrcInterface; - while (iFPointer) + OIC_LOG_V(DEBUG, TAG, "Number of RTS elements : %zd", arraySize); + size_t dim[MAX_REP_ARRAY_DEPTH] = {arraySize, 0, 0}; + char **rts = (char **)OICMalloc(sizeof(char *) * arraySize); + if (!rts) { - if( strcmp (iFPointer->name, ifPtr) == 0) - { - return OC_STACK_OK; - } - - iFPointer = iFPointer->next; + OIC_LOG(ERROR, TAG, "Memory allocation failed!"); + return OC_STACK_NO_MEMORY; } - return OC_STACK_ERROR; -} - -static OCStackResult -ValidateQuery (const char *query, OCResourceHandle resource, - OCStackIfTypes *ifParam, char **rtParam) -{ - uint8_t numFields = 0; - uint8_t numParam; - - //TODO: Query and URL validation is being done for virtual resource case - // using ValidateUrlQuery function. We should be able to merge it with this - // function. - OC_LOG(INFO, TAG, PCF("Entering ValidateQuery")); - - if (!query) - return OC_STACK_ERROR; - - if(!ifParam || !rtParam) + int k = 0; + for (int j = 0; j < size; j++) { - return OC_STACK_INVALID_PARAM; - } - - if (!(*query)) - { - // Query string is empty - OC_LOG_V(INFO, TAG, PCF("Empty query string, use default IF and RT")); - *ifParam = STACK_IF_DEFAULT; - *rtParam = (char *) OCGetResourceTypeName (resource, 0); - return OC_STACK_OK; - } - - // Break the query string to validate it and determine IF and RT parameters - // Validate there are atmost 2 parameters in string and that one is 'if' and other 'rt' - char *endStr, *ifPtr = NULL, *rtPtr = NULL; - char *token = strtok_r ((char *)query, "&", &endStr); - - // External loop breaks query string into fields using the & separator - while (token != NULL) - { - numFields++; - char *endToken; - char *innerToken = strtok_r (token, "=", &endToken); - numParam = 0; - - // Internal loop parses the field to extract values (parameters) assigned to each field - while (innerToken != NULL) + size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0}; + char **rt = NULL; + OCRepPayloadGetStringArray(linkArray[j], OC_RSRVD_RESOURCE_TYPE, &rt, rtDim); + for (size_t l = 0; l < rtDim[0]; l++) { - numParam++; - if (strncmp (innerToken, OC_RSRVD_INTERFACE, sizeof(OC_RSRVD_INTERFACE)) == 0) - { - // Determine the value of IF parameter - innerToken = strtok_r (NULL, "=", &endToken); - ifPtr = innerToken; - } - else if (strcmp (innerToken, OC_RSRVD_RESOURCE_TYPE) == 0) - { - // Determine the value of RT parameter - innerToken = strtok_r (NULL, "=", &endToken); - rtPtr = innerToken; - } - else - { - innerToken = strtok_r (NULL, "=", &endToken); - } + rts[k++] = OICStrdup(rt[l]); + OICFree(rt[l]); } - if (numParam != NUM_PARAM_IN_QUERY) - { - // Query parameter should be of the form if=. String should not have & or = - return OC_STACK_INVALID_QUERY; - } - token = strtok_r (NULL, "&", &endStr); - } - if (numFields > NUM_FIELDS_IN_QUERY) - { - // current release supports one IF value, one RT value and no other params - return OC_STACK_INVALID_QUERY; - } - - if (ifPtr) - { - if(CheckIFParamSupport((OCResource *)resource, ifPtr) != OC_STACK_OK) - { - return OC_STACK_INVALID_QUERY; - } - if (strcmp (ifPtr, OC_RSRVD_INTERFACE_DEFAULT) == 0) - { - *ifParam = STACK_IF_DEFAULT; - } - else if (strcmp (ifPtr, OC_RSRVD_INTERFACE_LL) == 0) - { - *ifParam = STACK_IF_LL; - } - else if (strcmp (ifPtr, OC_RSRVD_INTERFACE_BATCH) == 0) - { - *ifParam = STACK_IF_BATCH; - } - else if(strcmp (ifPtr, OC_RSRVD_INTERFACE_GROUP) == 0) - { - *ifParam = STACK_IF_GROUP; - } - else - { - return OC_STACK_ERROR; - } - } - else - { - // IF not specified in query, use default IF - *ifParam = STACK_IF_DEFAULT; + OICFree(rt); } - - if (rtPtr) + for (OCStringLL *rsrcType = (*colPayload)->types; rsrcType; rsrcType = rsrcType->next, size++) { - if (CheckRTParamSupport((OCResource *)resource, rtPtr) == OC_STACK_OK) - { - *rtParam = rtPtr; - } - else - { - return OC_STACK_INVALID_QUERY; - } + rts[k++] = OICStrdup(rsrcType->value); } - else - { - // RT not specified in query. Use the first resource type for the resource as default. - *rtParam = (char *) OCGetResourceTypeName (resource, 0); - } - OC_LOG_V(INFO, TAG, "Query params: IF = %d, RT = %s", *ifParam, *rtParam); - return OC_STACK_OK; + return OCRepPayloadSetStringArrayAsOwner(*colPayload, OC_RSRVD_RTS, rts, dim); } - -static OCStackResult BuildRootResourceJSON(OCResource *resource, - char * bufferPtr, uint16_t *remaining) +static OCStackResult SendResponse(const OCRepPayload *payload, const OCEntityHandlerRequest *ehRequest, + const OCResource* collResource, OCEntityHandlerResult ehResult) { - OCStackResult ret = OC_STACK_ERROR; - cJSON *resObj = NULL; - char *jsonStr = NULL; - uint16_t jsonLen; - - OC_LOG(INFO, TAG, PCF("Entering BuildRootResourceJSON")); - resObj = cJSON_CreateObject(); + OCEntityHandlerResponse response = {0}; + response.ehResult = ehResult; + response.payload = (OCPayload*)payload; + response.persistentBufferFlag = 0; + response.requestHandle = (OCRequestHandle) ehRequest->requestHandle; + response.resourceHandle = (OCResourceHandle) collResource; + return OCDoResponse(&response); +} - if ( ! resObj) - { - ret = OC_STACK_NO_MEMORY; - } - else if (resource) - { - cJSON_AddItemToObject (resObj, OC_RSRVD_HREF, cJSON_CreateString(resource->uri)); - jsonStr = cJSON_PrintUnformatted (resObj); - jsonLen = strlen(jsonStr); - if (jsonLen < *remaining) - { - strncpy(bufferPtr, jsonStr, jsonLen); - *remaining -= jsonLen; - bufferPtr += jsonLen; - ret = OC_STACK_OK; - } - } - else +uint8_t GetNumOfResourcesInCollection(const OCResource *collResource) +{ + uint8_t size = 0; + for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead; + tempChildResource; tempChildResource = tempChildResource->next) { - ret = OC_STACK_INVALID_PARAM; + size++; } - - cJSON_Delete (resObj); - OCFree(jsonStr); - - return ret; + return size; } - -static OCStackResult -HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest, - uint8_t filterOn, char *filterValue) +static OCStackResult HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest, char *ifQueryParam) { - if(!ehRequest) + if (!ehRequest) { return OC_STACK_INVALID_PARAM; } - OCStackResult ret = OC_STACK_ERROR; - char jsonbuffer[MAX_RESPONSE_LENGTH] = {}; - size_t jsonbufferLength = 0; - uint16_t remaining = 0; - char * ptr = NULL; - OCResource * collResource = (OCResource *) ehRequest->resource; - - ptr = jsonbuffer; - remaining = MAX_RESPONSE_LENGTH; - - ret = BuildRootResourceJSON(collResource, ptr, &remaining); - - if (ret == OC_STACK_OK && remaining >= (sizeof(OC_JSON_SEPARATOR) + 1)) + OCResource *collResource = (OCResource *)ehRequest->resource; + if (!collResource) { - ptr += strlen((char*)ptr); - *ptr = OC_JSON_SEPARATOR; - ptr++; - remaining--; + return OC_STACK_INVALID_PARAM; } - else + + uint8_t size = GetNumOfResourcesInCollection(collResource); + OCRepPayload *colPayload = NULL; + OCEntityHandlerResult ehResult = OC_EH_ERROR; + int i = 0; + OCStackResult ret = OC_STACK_OK; + size_t dim[MAX_REP_ARRAY_DEPTH] = {size, 0, 0}; + OCRepPayload **linkArr = (OCRepPayload **)OICCalloc(size, sizeof(OCRepPayload *)); + VERIFY_PARAM_NON_NULL(TAG, linkArr, "Failed creating LinkArray"); + + for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead; + tempChildResource && ret == OC_STACK_OK; tempChildResource = tempChildResource->next) { - ret = OC_STACK_ERROR; + OCResource* temp = tempChildResource->rsrcResource; + if (temp) + { + ret = BuildResponseRepresentation(temp, &linkArr[i++], &ehRequest->devAddr); + } } if (ret == OC_STACK_OK) { - for (int i = 0; i < MAX_CONTAINED_RESOURCES; i++) + colPayload = OCRepPayloadCreate(); + if (colPayload) { - OCResource* temp = collResource->rsrcResources[i]; - if (temp) + if (0 == strcmp(OC_RSRVD_INTERFACE_DEFAULT, ifQueryParam)) { - //TODO : Update needed here to get correct connectivity type - //from ServerRequest data structure. - - // Function will return error if not enough space in buffer. - ret = BuildVirtualResourceResponse(temp, filterOn, filterValue, - (char*)ptr, &remaining, CA_IPV4 ); - if (ret != OC_STACK_OK) + //TODO : Add resource type filtering once collections + // start supporting queries. + OCRepPayloadAddResourceType(colPayload, OC_RSRVD_RESOURCE_TYPE_COLLECTION); + for (OCResourceType *types = collResource->rsrcType; types; types = types->next) { - break; + if (0 != strcmp(OC_RSRVD_RESOURCE_TYPE_COLLECTION, types->resourcetypename)) + { + OCRepPayloadAddResourceType(colPayload, types->resourcetypename); + } } - ptr += strlen((char*)ptr); - - // Check if we have added all resources. - if ((i + 1) == MAX_CONTAINED_RESOURCES) + for (OCResourceInterface *itf = collResource->rsrcInterface; itf; itf = itf->next) { - break; - } - // Add separator if more resources and enough space present. - if (collResource->rsrcResources[i+1] && remaining > sizeof(OC_JSON_SEPARATOR)) - { - *ptr = OC_JSON_SEPARATOR; - ptr++; - remaining--; - } - // No point continuing as no more space on buffer - // and/or no more resources. - else - { - break; + OCRepPayloadAddInterface(colPayload, itf->name); } + AddRTSBaslinePayload(linkArr, i, &colPayload); } - else - { - break; - } + OCRepPayloadSetPropObjectArrayAsOwner(colPayload, OC_RSRVD_LINKS, linkArr, dim); } } - jsonbufferLength = strlen((const char *)jsonbuffer); - if(ret == OC_STACK_OK && jsonbufferLength) +exit: + if (ret == OC_STACK_OK) + { + ehResult = OC_EH_OK; + } + else { - OCEntityHandlerResponse response = {}; - response.ehResult = OC_EH_OK; - response.payload = jsonbuffer; - response.payloadSize = jsonbufferLength + 1; - response.persistentBufferFlag = 0; - response.requestHandle = (OCRequestHandle) ehRequest->requestHandle; - response.resourceHandle = (OCResourceHandle) collResource; - ret = OCDoResponse(&response); + ehResult = (ret == OC_STACK_NO_RESOURCE) ? OC_EH_RESOURCE_NOT_FOUND : OC_EH_ERROR; } + ret = SendResponse(colPayload, ehRequest, collResource, ehResult); + OIC_LOG_PAYLOAD(DEBUG, (OCPayload *)colPayload); + OCRepPayloadDestroy(colPayload); return ret; } -static OCStackResult -HandleBatchInterface(OCEntityHandlerRequest *ehRequest) +static OCStackResult HandleBatchInterface(OCEntityHandlerRequest *ehRequest) { - OCStackResult stackRet = OC_STACK_ERROR; - OCEntityHandlerResult ehResult = OC_EH_ERROR; - char jsonbuffer[MAX_RESPONSE_LENGTH] = {0}; - size_t jsonbufferLength = 0; - uint16_t remaining = 0; - char * ptr = NULL; - OCResource * collResource = (OCResource *) ehRequest->resource; - - ptr = jsonbuffer; - remaining = MAX_RESPONSE_LENGTH; - - stackRet = BuildRootResourceJSON(collResource, ptr, &remaining); - ptr += strlen((char*)ptr); - - jsonbufferLength = strlen((const char *)jsonbuffer); - if(jsonbufferLength) + if (!ehRequest) { - OCEntityHandlerResponse response = {}; - response.ehResult = OC_EH_OK; - response.payload = jsonbuffer; - response.payloadSize = jsonbufferLength + 1; - response.persistentBufferFlag = 0; - response.requestHandle = (OCRequestHandle) ehRequest->requestHandle; - response.resourceHandle = (OCResourceHandle) collResource; - stackRet = OCDoResponse(&response); + return OC_STACK_INVALID_PARAM; } + OCStackResult stackRet = OC_STACK_OK; + char *storeQuery = NULL; + OCResource *collResource = (OCResource *)ehRequest->resource; + if (stackRet == OC_STACK_OK) { - for (int i = 0; i < MAX_CONTAINED_RESOURCES; i++) + + if (collResource->rsrcChildResourcesHead) + { + storeQuery = ehRequest->query; + ehRequest->query = NULL; + OIC_LOG_V(DEBUG, TAG, "Query : %s", ehRequest->query); + } + + uint8_t numRes = 0; + for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead; + tempChildResource; tempChildResource = tempChildResource->next, numRes++) { - OCResource* temp = collResource->rsrcResources[i]; - if (temp) + OCResource* tempRsrcResource = tempChildResource->rsrcResource; + if (tempRsrcResource) { // Note that all entity handlers called through a collection // will get the same pointer to ehRequest, the only difference // is ehRequest->resource - ehRequest->resource = (OCResourceHandle) temp; - - ehResult = temp->entityHandler(OC_REQUEST_FLAG, ehRequest); + ehRequest->resource = (OCResourceHandle) tempRsrcResource; + OCEntityHandlerResult ehResult = tempRsrcResource->entityHandler(OC_REQUEST_FLAG, + ehRequest, tempRsrcResource->entityHandlerCallbackParam); // The default collection handler is returning as OK - if(stackRet != OC_STACK_SLOW_RESOURCE) + if (stackRet != OC_STACK_SLOW_RESOURCE) { stackRet = OC_STACK_OK; } // if a single resource is slow, then entire response will be treated // as slow response - if(ehResult == OC_EH_SLOW) + if (ehResult == OC_EH_SLOW) { - OC_LOG(INFO, TAG, PCF("This is a slow resource")); - ((OCServerRequest *)ehRequest->requestHandle)->slowFlag = 1; + OIC_LOG(INFO, TAG, "This is a slow resource"); + OCServerRequest *request = + GetServerRequestUsingHandle(ehRequest->requestHandle); + if (request) + { + request->slowFlag = 1; + } stackRet = EntityHandlerCodeToOCStackCode(ehResult); } } @@ -415,155 +240,71 @@ HandleBatchInterface(OCEntityHandlerRequest *ehRequest) } ehRequest->resource = (OCResourceHandle) collResource; } + ehRequest->query = storeQuery; return stackRet; } -uint8_t GetNumOfResourcesInCollection (OCResource *resource) +OCStackResult DefaultCollectionEntityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest) { - if(resource) - { - uint8_t num = 0; - for (int i = 0; i < MAX_CONTAINED_RESOURCES; i++) - { - if (resource->rsrcResources[i]) - { - num++; - } - } - return num; - } - else - { - return -1; - } -} - - -OCStackResult DefaultCollectionEntityHandler (OCEntityHandlerFlag flag, - OCEntityHandlerRequest *ehRequest) -{ - if(!ehRequest || !ehRequest->query) + if (!ehRequest || !ehRequest->query) { return OC_STACK_INVALID_PARAM; } - - OCStackResult result = OC_STACK_ERROR; - OCStackIfTypes ifQueryParam = STACK_IF_INVALID; - char *rtQueryParam = NULL; - - OC_LOG_V(INFO, TAG, "DefaultCollectionEntityHandler with query %s", ehRequest->query); - - if (flag != OC_REQUEST_FLAG) + // Delete is not supported for any interface query method. + if (ehRequest->method == OC_REST_DELETE || flag != OC_REQUEST_FLAG) { return OC_STACK_ERROR; } + OIC_LOG_V(INFO, TAG, "DefaultCollectionEntityHandler with query %s", ehRequest->query); - result = ValidateQuery (ehRequest->query, - ehRequest->resource, &ifQueryParam, &rtQueryParam); - + char *ifQueryParam = NULL; + char *rtQueryParam = NULL; + OCStackResult result = ExtractFiltersFromQuery(ehRequest->query, &ifQueryParam, &rtQueryParam); if (result != OC_STACK_OK) { - return result; + result = OC_STACK_NO_RESOURCE; + goto exit; } - - if(!((ehRequest->method == OC_REST_GET) || - (ehRequest->method == OC_REST_PUT) || - (ehRequest->method == OC_REST_POST))) + if (!ifQueryParam) { - return OC_STACK_ERROR; + ifQueryParam = OICStrdup(OC_RSRVD_INTERFACE_LL); } - if (ehRequest->method == OC_REST_GET) + VERIFY_PARAM_NON_NULL(TAG, ifQueryParam, "Invalid Parameter root"); + + if (0 == strcmp(ifQueryParam, OC_RSRVD_INTERFACE_LL) || 0 == strcmp (ifQueryParam, OC_RSRVD_INTERFACE_DEFAULT)) { - switch (ifQueryParam) + if (ehRequest->method == OC_REST_PUT || ehRequest->method == OC_REST_POST) { - case STACK_IF_DEFAULT: - // Get attributes of collection resource and properties of contined resource - // M1 release does not support attributes for collection resource, so the GET - // operation is same as the GET on LL interface. - OC_LOG(INFO, TAG, PCF("STACK_IF_DEFAULT")); - return HandleLinkedListInterface(ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL); - - case STACK_IF_LL: - OC_LOG(INFO, TAG, PCF("STACK_IF_LL")); - return HandleLinkedListInterface(ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL); - - case STACK_IF_BATCH: - OC_LOG(INFO, TAG, PCF("STACK_IF_BATCH")); - ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler = - HandleAggregateResponse; - ((OCServerRequest *)ehRequest->requestHandle)->numResponses = - GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1; - return HandleBatchInterface(ehRequest); - case STACK_IF_GROUP: - return BuildCollectionGroupActionJSONResponse(OC_REST_GET/*flag*/, - (OCResource *) ehRequest->resource, ehRequest); - default: - return OC_STACK_ERROR; + result = OC_STACK_ERROR; } - } - else if (ehRequest->method == OC_REST_PUT) - { - switch (ifQueryParam) + else { - case STACK_IF_DEFAULT: - // M1 release does not support PUT on default interface - return OC_STACK_ERROR; - - case STACK_IF_LL: - // LL interface only supports GET - return OC_STACK_ERROR; - - case STACK_IF_BATCH: - ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler = - HandleAggregateResponse; - ((OCServerRequest *)ehRequest->requestHandle)->numResponses = - GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1; - return HandleBatchInterface(ehRequest); - - case STACK_IF_GROUP: - { - OC_LOG_V(INFO, TAG, "IF_COLLECTION PUT with request ::\n%s\n ", - ehRequest->reqJSONPayload); - return BuildCollectionGroupActionJSONResponse(OC_REST_PUT/*flag*/, - (OCResource *) ehRequest->resource, ehRequest); - } - default: - return OC_STACK_ERROR; + result = HandleLinkedListInterface(ehRequest, ifQueryParam); } } - else if (ehRequest->method == OC_REST_POST) + else if (0 == strcmp(ifQueryParam, OC_RSRVD_INTERFACE_BATCH)) { - - switch (ifQueryParam) + OCServerRequest *request = GetServerRequestUsingHandle(ehRequest->requestHandle); + if (request) { - case STACK_IF_GROUP: - { - OC_LOG_V(INFO, TAG, "IF_COLLECTION POST with request :: \n%s\n ", - ehRequest->reqJSONPayload); - return BuildCollectionGroupActionJSONResponse(OC_REST_POST/*flag*/, - (OCResource *) ehRequest->resource, ehRequest); - } - default: - return OC_STACK_ERROR; + request->numResponses = GetNumOfResourcesInCollection((OCResource *)ehRequest->resource); + request->ehResponseHandler = HandleAggregateResponse; + result = HandleBatchInterface(ehRequest); } } - else if (ehRequest->method == OC_REST_POST) + else if (0 == strcmp(ifQueryParam, OC_RSRVD_INTERFACE_GROUP)) { - - if(ifQueryParam == STACK_IF_GROUP) - { - OC_LOG_V(INFO, TAG, "IF_COLLECTION POST with request :: \n%s\n ", - ehRequest->reqJSONPayload); - return BuildCollectionGroupActionJSONResponse(OC_REST_POST/*flag*/, - (OCResource *) ehRequest->resource, ehRequest); - } - else - { - return OC_STACK_ERROR; - } + OIC_LOG_V(INFO, TAG, "IF_COLLECTION %d with request ::\n", ehRequest->method); + OIC_LOG_PAYLOAD(INFO, ehRequest->payload); + result = BuildCollectionGroupActionCBORResponse(ehRequest->method, (OCResource *) ehRequest->resource, ehRequest); } +exit: + if (result != OC_STACK_OK) + { + result = SendResponse(NULL, ehRequest, (OCResource *)ehRequest->resource, OC_EH_BAD_REQ); + } + OICFree(ifQueryParam); + OICFree(rtQueryParam); return result; } - -