#include "oicgroup.h"
#include "cJSON.h"
+#include "cbor.h"
+#include "ocpayload.h"
#include "oic_malloc.h"
#include "oic_string.h"
#include "occollection.h"
#define DO_ACTION "DoAction"
#define GET_ACTIONSET "GetActionSet"
#define ACTIONSET "ActionSet"
+#define CANCEL_ACTIONSET "CancelAction"
#define DELETE_ACTIONSET "DelActionSet"
-#define OIC_ACTION_PREFIX "{\"oic\":[{\"rep\":{"
+#define DEFAULT_CONTEXT_VALUE 0x99
+
#define VARIFY_POINTER_NULL(pointer, result, toExit) \
if(pointer == NULL) \
{\
}
-OCStackResult ExtractKeyValueFromRequest(char *request, char **key,
- char **value)
+OCStackResult ExtractKeyValueFromRequest(OCEntityHandlerRequest *ehRequest,
+ char **key, char **value)
{
OCStackResult result = OC_STACK_OK;
- size_t length = 0;
- char* pRequest = (char *) request + strlen(OIC_ACTION_PREFIX);
- char* iterToken, *iterTokenPtr;
+ char *actionSetStr;
+
+ if( NULL == ehRequest->payload )
+ {
+ result = OC_STACK_ERROR;
+ goto exit;
+ }
+
+ OCRepPayload* input;
- iterToken = (char *) strtok_r(pRequest, ":", &iterTokenPtr);
- VARIFY_POINTER_NULL(iterToken, result, exit);
- length = strlen(iterToken) + 1;
+ input = (OCRepPayload*)(ehRequest->payload);
- *key = (char *) OICMalloc(length);
- VARIFY_POINTER_NULL(*key, result, exit)
+ if(OCRepPayloadGetPropString(input, ACTIONSET, &actionSetStr))
+ {
+ *key = OICStrdup(ACTIONSET);
+ VARIFY_POINTER_NULL(*key, result, exit);
- strncpy(*key, iterToken + 1, length);
- ((*key)[((length - 1) - 2)]) = '\0';
+ *value = OICStrdup(actionSetStr);
+ VARIFY_POINTER_NULL(*value, result, exit);
+ }
+ else if(OCRepPayloadGetPropString(input, DO_ACTION, &actionSetStr))
+ {
+ *key = OICStrdup(DO_ACTION);
+ VARIFY_POINTER_NULL(*key, result, exit);
- iterToken = (char *) strtok_r(NULL, "}", &iterTokenPtr);
- VARIFY_POINTER_NULL(iterToken, result, exit);
- length = strlen(iterToken) + 1;
+ *value = OICStrdup(actionSetStr);
+ VARIFY_POINTER_NULL(*value, result, exit);
+ }
+ else if(OCRepPayloadGetPropString(input, GET_ACTIONSET, &actionSetStr))
+ {
+ *key = OICStrdup(GET_ACTIONSET);
+ VARIFY_POINTER_NULL(*key, result, exit);
- *value = (char *) OICMalloc(length);
- VARIFY_POINTER_NULL(*value, result, exit)
+ *value = OICStrdup(actionSetStr);
+ VARIFY_POINTER_NULL(*value, result, exit);
+ }
+ else if(OCRepPayloadGetPropString(input, DELETE_ACTIONSET, &actionSetStr))
+ {
+ *key = OICStrdup(DELETE_ACTIONSET);
+ VARIFY_POINTER_NULL(*key, result, exit);
- strncpy(*value, iterToken + 1, length);
- ((*value)[((length - 1) - 2)]) = '\0';
+ *value = OICStrdup(actionSetStr);
+ VARIFY_POINTER_NULL(*value, result, exit);
+ }
+ else if(OCRepPayloadGetPropString(input, CANCEL_ACTIONSET, &actionSetStr))
+ {
+ *key = OICStrdup(CANCEL_ACTIONSET);
+ VARIFY_POINTER_NULL(*key, result, exit);
+
+ *value = OICStrdup(actionSetStr);
+ VARIFY_POINTER_NULL(*value, result, exit);
+ }
+ else
+ {
+ result = OC_STACK_ERROR;
+ }
exit:
if (result != OC_STACK_OK)
{
(void)context;
(void)clientResponse;
- OC_LOG(INFO, TAG, PCF("Entering BuildActionJSON"));
+ OC_LOG(INFO, TAG, PCF("Entering ActionSetCB"));
ClientRequestInfo *info = GetClientRequestInfo(clientRequstList, handle);
if (info)
{
- int idx;
+ OCEntityHandlerResponse response = { 0 };
- unsigned char *responseJson = NULL;
- // TODO: Figure out what this does, change implementation
- //responseJson = (unsigned char *) OICMalloc(
- // (unsigned int) (strlen((char *) clientResponse->resJSONPayload)
- // + 1));
+ response.ehResult = OC_EH_OK;
- if( responseJson == NULL )
+ if(NULL == clientResponse->payload)
+ {
+ OC_LOG(ERROR, TAG, "Error sending response");
return OC_STACK_DELETE_TRANSACTION;
+ }
- // We need the body of response.
- // Copy the body from the response
- // TODO: Taken out
- //strcpy((char *) responseJson,
- // ((char *) clientResponse->resJSONPayload + OC_JSON_PREFIX_LEN));
- //idx = strlen((char *) responseJson) - OC_JSON_SUFFIX_LEN;
- // And insert NULL at the end of body.
- (responseJson[idx]) = 0;
-
- OCEntityHandlerResponse response = { 0 };
- response.ehResult = OC_EH_OK;
- // TODO: Removing payload size, waht goes here?
- // response.payload = (char*)responseJson;
- //response.payloadSize = (unsigned int) strlen((char *) responseJson) + 1;
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = info->ehRequest;
+ response.resourceHandle = info->collResource;
+ response.payload = clientResponse->payload;
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof response.sendVendorSpecificHeaderOptions);
+ memset(response.resourceUri, 0, sizeof response.resourceUri);
+ // Indicate that response is NOT in a persistent buffer
response.persistentBufferFlag = 0;
- response.requestHandle = (OCRequestHandle) info->ehRequest;
- response.resourceHandle = (OCResourceHandle) info->collResource;
- OCDoResponse(&response);
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Error sending response");
+ return OC_STACK_DELETE_TRANSACTION;
+ }
RemoveClientRequestInfo(&clientRequstList, info);
OCFREE(info)
- OCFREE(responseJson)
}
return OC_STACK_KEEP_TRANSACTION;
return ret;
}
+OCPayload* BuildActionCBOR(OCAction* action)
+{
+ OCRepPayload* payload = OCRepPayloadCreate();
+
+ if (!payload)
+ {
+ OC_LOG(INFO, TAG, PCF("Failed to create put payload object"));
+ return NULL;
+ }
+
+ OCCapability* pointerCapa = action->head;
+ while (pointerCapa)
+ {
+ OCRepPayloadSetPropString(payload, pointerCapa->capability, pointerCapa->status);
+ pointerCapa = pointerCapa->next;
+ }
+
+ return (OCPayload*) payload;
+}
+
unsigned int GetNumOfTargetResource(OCAction *actionset)
{
int numOfResource = 0;
return numOfResource;
}
+OCStackResult SendAction(OCDoHandle *handle, OCServerRequest* requestHandle, const char *targetUri,
+ OCPayload *payload)
+{
-#define DEFAULT_CONTEXT_VALUE 0x99
+ OCCallbackData cbData;
+ cbData.cb = &ActionSetCB;
+ cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
+ cbData.cd = NULL;
-OCStackResult SendAction(OCDoHandle *handle, const char *targetUri,
- const unsigned char *action)
-{
- (void)handle;
- (void)targetUri;
- (void)action;
- // TODO: disabled since this is no longer compatible
- return OC_STACK_NOTIMPL;
+ return OCDoResource(handle, OC_REST_PUT, targetUri, &requestHandle->devAddr,
+ payload, CT_ADAPTER_IP, OC_NA_QOS, &cbData, NULL, 0);
}
OCStackResult DoAction(OCResource* resource, OCActionSet* actionset,
OCServerRequest* requestHandle)
{
OCStackResult result = OC_STACK_ERROR;
+
+ if( NULL == actionset->head)
+ {
+ return result;
+ }
+
OCAction *pointerAction = actionset->head;
while (pointerAction != NULL)
{
- unsigned char actionDesc[MAX_RESPONSE_LENGTH] = { 0 };
- unsigned char* actionDescPtr = actionDesc;
- uint16_t remaining = MAX_RESPONSE_LENGTH;
+ OCPayload* payload;
+ payload = BuildActionCBOR(pointerAction);
- strncpy((char *) actionDescPtr, (const char *) OC_JSON_PREFIX,
- strlen((const char *) OC_JSON_PREFIX) + 1);
- BuildActionJSON(pointerAction, actionDescPtr, &remaining);
- strncat((char *) actionDescPtr, (const char *) OC_JSON_SUFFIX,
- strlen((const char *) OC_JSON_SUFFIX));
+ if(payload == NULL)
+ {
+ return result;
+ }
ClientRequestInfo *info = (ClientRequestInfo *) OICMalloc(
sizeof(ClientRequestInfo));
info->collResource = resource;
info->ehRequest = requestHandle;
- result = SendAction(&info->required, pointerAction->resourceUri,
- actionDescPtr);
+ result = SendAction(&info->required, info->ehRequest, pointerAction->resourceUri,
+ payload);
+
if (result != OC_STACK_OK)
{
OICFree(info);
return;
}
-OCStackResult BuildCollectionGroupActionJSONResponse(
+OCStackResult BuildCollectionGroupActionCBORResponse(
OCMethod method/*OCEntityHandlerFlag flag*/, OCResource *resource,
OCEntityHandlerRequest *ehRequest)
{
OCStackResult stackRet = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Group Action is requested."));
- // if (stackRet == OC_STACK_OK)
- {
- char *doWhat = NULL;
- char *details = NULL;
-
- size_t bufferLength = 0;
- unsigned char buffer[MAX_RESPONSE_LENGTH] = { 0 };
- OCResource * collResource = (OCResource *) ehRequest->resource;
+ char *doWhat = NULL;
+ char *details = NULL;
- char *jsonResponse;
+ stackRet = ExtractKeyValueFromRequest(ehRequest, &doWhat, &details);
- stackRet = OC_STACK_NOTIMPL;
- // TODO: Fix?
- //stackRet = ExtractKeyValueFromRequest((char *) ehRequest->reqJSONPayload,
- // &doWhat, &details);
-
- if(stackRet != OC_STACK_OK)
- {
- OC_LOG_V(ERROR, TAG, "ExtractKeyValueFromRequest failed: %d", stackRet);
- return stackRet;
- }
+ if(stackRet != OC_STACK_OK)
+ {
+ OC_LOG_V(ERROR, TAG, "ExtractKeyValueFromRequest failed: %d", stackRet);
+ return stackRet;
+ }
- stackRet = OC_STACK_ERROR;
+ stackRet = OC_STACK_ERROR;
- cJSON *json;
- cJSON *format;
+ if (method == OC_REST_PUT)
+ {
+ OC_LOG(INFO, TAG, PCF("Group Action[PUT]."));
- if (method == OC_REST_PUT)
+ if (strcmp(doWhat, ACTIONSET) == 0)
{
- json = cJSON_CreateObject();
- cJSON_AddStringToObject(json, "href", resource->uri);
- cJSON_AddItemToObject(json, "rep", format = cJSON_CreateObject());
-
- OC_LOG(INFO, TAG, PCF("Group Action[PUT]."));
+ OCActionSet *actionSet = NULL;
+ stackRet = BuildActionSetFromString(&actionSet, details);
- if (strcmp(doWhat, ACTIONSET) == 0)
+ if(stackRet == OC_STACK_OK)
{
- OCActionSet *actionSet = NULL;
- stackRet = BuildActionSetFromString(&actionSet, details);
-
- if(stackRet == OC_STACK_OK)
+ if (actionSet != NULL)
{
- if (actionSet != NULL)
+ stackRet = AddActionSet(&resource->actionsetHead,
+ actionSet);
+ if (stackRet == OC_STACK_ERROR)
{
- stackRet = AddActionSet(&resource->actionsetHead,
- actionSet);
- if (stackRet == OC_STACK_ERROR)
+ if(actionSet != NULL)
{
- if(actionSet != NULL)
- {
- DeleteActionSet( &actionSet );
- }
- OC_LOG(INFO, TAG, PCF("Duplicated ActionSet "));
+ DeleteActionSet( &actionSet );
}
+ OC_LOG(INFO, TAG, PCF("Duplicated ActionSet "));
}
}
else
{
stackRet = OC_STACK_ERROR;
+ goto exit;
}
+ }
+ else
+ {
+ stackRet = OC_STACK_ERROR;
+ }
+ }
+ else if (strcmp(doWhat, DELETE_ACTIONSET) == 0)
+ {
+ if (FindAndDeleteActionSet(&resource, details) == OC_STACK_OK)
+ {
+ stackRet = OC_STACK_OK;
}
- else if (strcmp(doWhat, DELETE_ACTIONSET) == 0)
+ else
{
- if (FindAndDeleteActionSet(&resource, details) == OC_STACK_OK)
- {
- stackRet = OC_STACK_OK;
- }
- else
- {
- stackRet = OC_STACK_ERROR;
- }
+ stackRet = OC_STACK_ERROR;
}
+ }
- jsonResponse = cJSON_Print(json);
- cJSON_Delete(json);
+ OCRepPayload* payload = OCRepPayloadCreate();
- OICStrcat((char*)buffer, sizeof(buffer), jsonResponse);
+ if(!payload)
+ {
+ OC_LOG(ERROR, TAG, PCF("Failed to allocate Payload"));
+ stackRet = OC_STACK_ERROR;
+ }
+ else
+ {
+ OCEntityHandlerResponse response = { 0 };
- bufferLength = strlen((const char *) buffer);
- if (bufferLength > 0)
+ if(stackRet == OC_STACK_OK)
+ response.ehResult = OC_EH_OK;
+ else
+ response.ehResult = OC_EH_ERROR;
+
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = ehRequest->requestHandle;
+ response.resourceHandle = ehRequest->resource;
+ response.payload = (OCPayload*) payload;
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof response.sendVendorSpecificHeaderOptions);
+ memset(response.resourceUri, 0, sizeof response. resourceUri);
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+ response.ehResult = (stackRet == OC_STACK_OK)?OC_EH_OK:OC_EH_ERROR;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
{
- OCEntityHandlerResponse response = { 0 };
- if(stackRet == OC_STACK_OK)
- response.ehResult = OC_EH_OK;
- else
- response.ehResult = OC_EH_ERROR;
- // TODO: Fix
- //response.payload = (char*)buffer;
- //response.payloadSize = bufferLength + 1;
- response.persistentBufferFlag = 0;
- response.requestHandle =
- (OCRequestHandle) ehRequest->requestHandle;
- response.resourceHandle = (OCResourceHandle) collResource;
- stackRet = OCDoResponse(&response);
+ OC_LOG(ERROR, TAG, "Error sending response");
+ stackRet = OC_STACK_ERROR;
}
}
+ }
+ else if (method == OC_REST_POST)
+ {
+ OCActionSet *actionset = NULL;
- if (method == OC_REST_POST)
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadSetUri(payload, resource->uri);
+
+ if ((strcmp(doWhat, DO_ACTION) == 0)
+ || (strcmp(doWhat, "DoScheduledAction") == 0))
{
- OCActionSet *actionset = NULL;
+ char *pActionsetName = NULL;
+ long int delay = -1;
- json = cJSON_CreateObject();
- cJSON_AddStringToObject(json, "href", resource->uri);
+ if (strcmp(doWhat, "DoScheduledAction") == 0)
+ {
+ stackRet = ExtractActionSetNameAndDelaytime(details,
+ &pActionsetName, &delay);
- if ((strcmp(doWhat, DO_ACTION) == 0)
- || (strcmp(doWhat, "DoScheduledAction") == 0))
+ OCFREE(details)
+ details = pActionsetName;
+ }
+ else
{
- char *pActionsetName = NULL;
- long int delay = -1;
+ stackRet = OC_STACK_OK;
+ }
- if (strcmp(doWhat, "DoScheduledAction") == 0)
+ if (stackRet == OC_STACK_OK)
+ {
+ if (GetActionSet(details, resource->actionsetHead,
+ &actionset) != OC_STACK_OK)
{
- stackRet = ExtractActionSetNameAndDelaytime(details,
- &pActionsetName, &delay);
-
- OCFREE(details)
- details = pActionsetName;
+ OC_LOG(INFO, TAG, PCF("ERROR"));
+ stackRet = OC_STACK_ERROR;
}
- else
+
+ if (actionset == NULL)
{
- stackRet = OC_STACK_OK;
+ OC_LOG(INFO, TAG, PCF("Cannot Find ActionSet"));
+ stackRet = OC_STACK_ERROR;
}
-
- if (stackRet == OC_STACK_OK)
+ else
{
- if (GetActionSet(details, resource->actionsetHead,
- &actionset) != OC_STACK_OK)
+ OC_LOG(INFO, TAG, PCF("Group Action[POST]."));
+ if (actionset->type == NONE)
{
- OC_LOG(INFO, TAG, PCF("ERROR"));
- stackRet = OC_STACK_ERROR;
- }
-
- if (actionset == NULL)
- {
- OC_LOG(INFO, TAG, PCF("Cannot Find ActionSet"));
- stackRet = OC_STACK_ERROR;
+ OC_LOG_V(INFO, TAG, "Execute ActionSet : %s",
+ actionset->actionsetName);
+ unsigned int num = GetNumOfTargetResource(
+ actionset->head);
+
+ ((OCServerRequest *) ehRequest->requestHandle)->ehResponseHandler =
+ HandleAggregateResponse;
+ ((OCServerRequest *) ehRequest->requestHandle)->numResponses =
+ num + 1;
+
+ DoAction(resource, actionset,
+ (OCServerRequest*) ehRequest->requestHandle);
+ stackRet = OC_STACK_OK;
}
else
{
- OC_LOG(INFO, TAG, PCF("Group Action[POST]."));
- if (actionset->type == NONE)
- {
- OC_LOG_V(INFO, TAG, "Execute ActionSet : %s",
- actionset->actionsetName);
- unsigned int num = GetNumOfTargetResource(
- actionset->head);
-
- ((OCServerRequest *) ehRequest->requestHandle)->ehResponseHandler =
- HandleAggregateResponse;
- ((OCServerRequest *) ehRequest->requestHandle)->numResponses =
- num + 1;
-
- DoAction(resource, actionset,
- (OCServerRequest*) ehRequest->requestHandle);
- stackRet = OC_STACK_OK;
- }
- else
- {
- OC_LOG_V(INFO, TAG, "Execute Scheduled ActionSet : %s",
- actionset->actionsetName);
+ OC_LOG_V(INFO, TAG, "Execute Scheduled ActionSet : %s",
+ actionset->actionsetName);
- delay =
- (delay == -1 ? actionset->timesteps : delay);
+ delay =
+ (delay == -1 ? actionset->timesteps : delay);
- ScheduledResourceInfo *schedule;
- schedule = (ScheduledResourceInfo *) OICMalloc(
+ ScheduledResourceInfo *schedule;
+ schedule = (ScheduledResourceInfo *) OICMalloc(
+ sizeof(ScheduledResourceInfo));
+
+ if (schedule)
+ {
+ OC_LOG(INFO, TAG, PCF("Building New Call Info."));
+ memset(schedule, 0,
sizeof(ScheduledResourceInfo));
- if (schedule)
+ schedule->resource = resource;
+ schedule->actionset = actionset;
+ schedule->ehRequest =
+ (OCServerRequest*) ehRequest->requestHandle;
+
+ if (delay > 0)
{
- OC_LOG(INFO, TAG, PCF("Building New Call Info."));
- memset(schedule, 0,
- sizeof(ScheduledResourceInfo));
-
- schedule->resource = resource;
- schedule->actionset = actionset;
- schedule->ehRequest =
- (OCServerRequest*) ehRequest->requestHandle;
-
- if (delay > 0)
- {
- OC_LOG_V(INFO, TAG, "delay_time is %lf seconds.",
- actionset->timesteps);
-
- schedule->time = registerTimer(delay,
- &schedule->timer_id,
- &DoScheduledGroupAction);
-
- AddScheduledResource(&scheduleResourceList,
- schedule);
- stackRet = OC_STACK_OK;
- }
- else
- {
- stackRet = OC_STACK_ERROR;
- }
+ OC_LOG_V(INFO, TAG, "delay_time is %lf seconds.",
+ actionset->timesteps);
+
+ schedule->time = registerTimer(delay,
+ &schedule->timer_id,
+ &DoScheduledGroupAction);
+
+ AddScheduledResource(&scheduleResourceList,
+ schedule);
+ stackRet = OC_STACK_OK;
+ }
+ else
+ {
+ stackRet = OC_STACK_ERROR;
}
}
}
}
}
- else if (strcmp(doWhat, "CancelAction") == 0)
- {
- ScheduledResourceInfo *info =
- GetScheduledResourceByActionSetName(scheduleResourceList, details);
+ }
+ else if (strcmp(doWhat, "CancelAction") == 0)
+ {
+ ScheduledResourceInfo *info =
+ GetScheduledResourceByActionSetName(scheduleResourceList, details);
- if(info != NULL)
- {
- unregisterTimer(info->timer_id);
+ if(info != NULL)
+ {
+ unregisterTimer(info->timer_id);
- RemoveScheduledResource(&scheduleResourceList, info);
- stackRet = OC_STACK_OK;
- }
- else
- {
- stackRet = OC_STACK_ERROR;
- }
+ RemoveScheduledResource(&scheduleResourceList, info);
+ stackRet = OC_STACK_OK;
}
+ else
+ {
+ stackRet = OC_STACK_ERROR;
+ }
+ }
+
+ else if (strcmp(doWhat, GET_ACTIONSET) == 0)
+ {
+ char *plainText = NULL;
+ OCActionSet *actionset = NULL;
- else if (strcmp(doWhat, GET_ACTIONSET) == 0)
+ GetActionSet(details, resource->actionsetHead, &actionset);
+ if (actionset != NULL)
{
- char *plainText = NULL;
- OCActionSet *actionset = NULL;
+ BuildStringFromActionSet(actionset, &plainText);
- cJSON_AddItemToObject(json, "rep", format =
- cJSON_CreateObject());
- GetActionSet(details, resource->actionsetHead, &actionset);
- if (actionset != NULL)
+ if (plainText != NULL)
{
- BuildStringFromActionSet(actionset, &plainText);
-
- if (plainText != NULL)
- {
- cJSON_AddStringToObject(format, ACTIONSET, plainText);
- }
- OICFree(plainText);
- stackRet = OC_STACK_OK;
+ OCRepPayloadSetPropString(payload, ACTIONSET, plainText);
}
+ OICFree(plainText);
+ stackRet = OC_STACK_OK;
}
+ }
-
- jsonResponse = cJSON_Print(json);
- cJSON_Delete(json);
-
- OICStrcat((char*)buffer, sizeof(buffer), jsonResponse);
-
- bufferLength = strlen((const char *) buffer);
- if (bufferLength > 0)
+ if(!payload)
+ {
+ OC_LOG(ERROR, TAG, PCF("Failed to allocate Payload"));
+ stackRet = OC_STACK_ERROR;
+ }
+ else
+ {
+ OCEntityHandlerResponse response = { 0 };
+ if(stackRet == OC_STACK_OK)
+ response.ehResult = OC_EH_OK;
+ else
+ response.ehResult = OC_EH_ERROR;
+
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = ehRequest->requestHandle;
+ response.resourceHandle = ehRequest->resource;
+ response.payload = (OCPayload*) payload;
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof response.sendVendorSpecificHeaderOptions);
+ memset(response.resourceUri, 0, sizeof response.resourceUri);
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+ response.ehResult = (stackRet == OC_STACK_OK)?OC_EH_OK:OC_EH_ERROR;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
{
- OCEntityHandlerResponse response = { 0 };
- if(stackRet == OC_STACK_OK)
- response.ehResult = OC_EH_OK;
- else
- response.ehResult = OC_EH_ERROR;
- // TODO: Implement
- //response.payload = (char *)buffer;
- //response.payloadSize = bufferLength + 1;
- response.persistentBufferFlag = 0;
- response.requestHandle =
- (OCRequestHandle) ehRequest->requestHandle;
- response.resourceHandle = (OCResourceHandle) collResource;
- stackRet = OCDoResponse(&response);
+ OC_LOG(ERROR, TAG, "Error sending response");
+ stackRet = OC_STACK_ERROR;
}
}
-
- OCFREE(doWhat)
- OCFREE(details)
}
+exit:
+
+ OCFREE(doWhat)
+ OCFREE(details)
+
return stackRet;
}
+