Commit b6269c94 authored by Omkar Hegde's avatar Omkar Hegde Committed by Erich Keane

Fixing collections

The result status was set incorrectly. Also, wrong type
of payload was being created in HandleBatchInterface()
and HandleLinkedListInterface(). Added a function to
create representation payload from resource pointer.
Also, changing HandleAggregateResponse() to handle
collections correctly. Some bug fixes for CBOR parsing
which affected collections.

Change-Id: Ia3c1fb4d144ead24e7efad0d915a01dad16d15e5
Signed-off-by: default avatarOmkar Hegde <omkar.m.hegde@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1700Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent 312c5a47
......@@ -144,8 +144,14 @@ void DeletePlatformInfo();
*/
void DeleteDeviceInfo();
/*
* Prepare payload for resource representation.
*/
OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
OCRepPayload** payload);
/**
* Prepares a JSON string for response.
* Prepares a Payload for response.
*/
OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
OCDiscoveryPayload* payload,
......
......@@ -231,15 +231,11 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest, uint8_t filterOn, c
OCStackResult ret = OC_STACK_OK;
OCResource *collResource = (OCResource *)ehRequest->resource;
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
if(!payload)
{
ret = OC_STACK_NO_MEMORY;
}
OCRepPayload* payload = NULL;
if(ret == OC_STACK_OK)
{
ret = BuildVirtualResourceResponse(collResource, payload, &ehRequest->devAddr);
ret = BuildResponseRepresentation(collResource, &payload);
}
if (ret == OC_STACK_OK)
......@@ -251,7 +247,7 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest, uint8_t filterOn, c
{
//TODO : Add resource type filtering once collections
// start supporting queries.
ret = BuildVirtualResourceResponse(temp, payload, &ehRequest->devAddr);
ret = BuildResponseRepresentation(temp, &payload);
}
}
}
......@@ -266,18 +262,18 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest, uint8_t filterOn, c
response.resourceHandle = (OCResourceHandle) collResource;
ret = OCDoResponse(&response);
}
OCDiscoveryPayloadDestroy(payload);
OCRepPayloadDestroy(payload);
return ret;
}
static OCStackResult
HandleBatchInterface(OCEntityHandlerRequest *ehRequest)
{
OCStackResult stackRet = OC_STACK_ERROR;
OCStackResult stackRet = OC_STACK_OK;
OCEntityHandlerResult ehResult = OC_EH_ERROR;
OCResource * collResource = (OCResource *) ehRequest->resource;
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
OCRepPayload* payload = OCRepPayloadCreate();
if(!payload)
{
stackRet = OC_STACK_NO_MEMORY;
......@@ -285,7 +281,7 @@ HandleBatchInterface(OCEntityHandlerRequest *ehRequest)
if(stackRet == OC_STACK_OK)
{
stackRet = BuildVirtualResourceResponse(collResource, payload, &ehRequest->devAddr);
OCRepPayloadSetUri(payload, collResource->uri);
}
if(stackRet == OC_STACK_OK)
......@@ -298,7 +294,6 @@ HandleBatchInterface(OCEntityHandlerRequest *ehRequest)
response.resourceHandle = (OCResourceHandle) collResource;
stackRet = OCDoResponse(&response);
}
OCDiscoveryPayloadDestroy(payload);
if (stackRet == OC_STACK_OK)
{
......
......@@ -91,6 +91,7 @@ void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child)
}
parent->next= child;
child->next = NULL;
}
static OCRepPayloadValue* OCRepPayloadFindValue(const OCRepPayload* payload, const char* name)
......
......@@ -676,7 +676,8 @@ static bool OCParseSingleRepPayload(OCRepPayload** outPayload, CborValue* repPar
while(!err && cbor_value_is_valid(&rtArray))
{
char* curRt;
cbor_value_dup_text_string(&rtArray, &curRt, &len, NULL);
err = err || cbor_value_dup_text_string(&rtArray, &curRt, &len, NULL);
err = err || cbor_value_advance(&rtArray);
OCRepPayloadAddResourceTypeAsOwner(curPayload, curRt);
}
......@@ -694,6 +695,7 @@ static bool OCParseSingleRepPayload(OCRepPayload** outPayload, CborValue* repPar
{
char* curIf;
err = err || cbor_value_dup_text_string(&ifArray, &curIf, &len, NULL);
err = err || cbor_value_advance(&ifArray);
OCRepPayloadAddInterfaceAsOwner(curPayload, curIf);
}
......
......@@ -202,6 +202,58 @@ static OCStackResult getQueryParamsForFiltering (OCVirtualResources uri, char *q
return result;
}
OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
OCRepPayload** payload)
{
OCRepPayload *tempPayload = OCRepPayloadCreate();
if (!resourcePtr)
{
OCRepPayloadDestroy(tempPayload);
return OC_STACK_INVALID_PARAM;
}
if(!tempPayload)
{
return OC_STACK_NO_MEMORY;
}
OCRepPayloadSetUri(tempPayload, resourcePtr->uri);
OCResourceType *resType = resourcePtr->rsrcType;
while(resType)
{
OCRepPayloadAddResourceType(tempPayload, resType->resourcetypename);
resType = resType->next;
}
OCResourceInterface *resInterface = resourcePtr->rsrcInterface;
while(resInterface)
{
OCRepPayloadAddInterface(tempPayload, resInterface->name);
resInterface = resInterface->next;
}
OCAttribute *resAttrib = resourcePtr->rsrcAttributes;
while(resAttrib)
{
OCRepPayloadSetPropString(tempPayload, resAttrib->attrName,
resAttrib->attrValue);
resAttrib = resAttrib->next;
}
if(!*payload)
{
*payload = tempPayload;
}
else
{
OCRepPayloadAppend(*payload, tempPayload);
}
return OC_STACK_OK;
}
OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
OCDiscoveryPayload *payload, OCDevAddr *devAddr)
{
......
......@@ -658,16 +658,24 @@ OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse)
VERIFY_NON_NULL(serverResponse);
}
if(serverResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION ||
ehResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION)
if(ehResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
stackRet = OC_STACK_ERROR;
OC_LOG(ERROR, TAG, PCF("Error adding payload, as it was the incorrect type"));
goto exit;
}
if(!serverResponse->payload)
{
serverResponse->payload = (OCPayload*)OCRepPayloadCreate();
serverResponse->payload = ehResponse->payload;
}
else
{
OCRepPayloadAppend((OCRepPayload*)serverResponse->payload,
(OCRepPayload*)ehResponse->payload);
}
(serverRequest->numResponses)--;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment