OCEntityHandlerResponse response = {.ehResult = OC_EH_OK,
.payload = (OCPayload *)payload,
.persistentBufferFlag = 0,
- .requestHandle = (OCRequestHandle) request,
+ .requestHandle = (OCRequestHandle) request->requestId,
.resourceHandle = (OCResourceHandle) resource
};
OIC_LOG(DEBUG, TAG, "RMSendResponse OUT");
{
case SYMMETRIC_PAIR_WISE_KEY:
{
- OCServerRequest *request = (OCServerRequest *)ehRequest->requestHandle;
+ OCServerRequest *request = GetServerRequestUsingHandle(ehRequest->requestHandle);
if(FillPrivateDataOfOwnerPSK(cred, (CAEndpoint_t *)&request->devAddr, doxm))
{
if(OC_STACK_RESOURCE_DELETED == RemoveCredential(&cred->subject))
{
case SYMMETRIC_PAIR_WISE_KEY:
{
- OCServerRequest *request = (OCServerRequest *)ehRequest->requestHandle;
+ OCServerRequest *request = GetServerRequestUsingHandle(ehRequest->requestHandle);
if(FillPrivateDataOfSubOwnerPSK(cred, (CAEndpoint_t *)&request->devAddr, doxm, &cred->subject))
{
if(OC_STACK_RESOURCE_DELETED == RemoveCredential(&cred->subject))
VERIFY_NON_NULL(TAG, pconf, ERROR);
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
- OCServerRequest * request = (OCServerRequest *)ehRequest->requestHandle;
+ OCServerRequest *request = GetServerRequestUsingHandle(ehRequest->requestHandle);
VERIFY_SUCCESS(TAG, (request->devAddr.flags | OC_FLAG_SECURE), ERROR);
//Generate new credential
OCEntityHandlerResult ehRet, uint8_t *cborPayload, size_t size)
{
OIC_LOG(DEBUG, TAG, "SRM sending SRM response");
- OCEntityHandlerResponse response = {.requestHandle = NULL};
OCStackResult ret = OC_STACK_ERROR;
if (ehRequest)
{
+ OCEntityHandlerResponse response = {.requestHandle = 0};
OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
response.requestHandle = ehRequest->requestHandle;
OCQualityOfService qos;
/** Observe option field.*/
-
uint32_t observationOption;
/** Observe Result field.*/
/** payload is retrieved from the payload of the received request PDU.*/
uint8_t payload[1];
+ /** The ID of server request*/
+ uint32_t requestId;
+
// WARNING: Do NOT add attributes after payload as they get overwritten
// when payload content gets copied over!
* @return
* OCServerRequest*
*/
-OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
+OCServerRequest * GetServerRequestUsingHandle (const OCRequestHandle handle);
/**
* Get a server response from the server response list using the specified handle
* @return
* OCServerResponse*
*/
-OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
+OCServerResponse * GetServerResponseUsingHandle (const OCRequestHandle handle);
/**
* Add a server request to the server request list
/**
* Handle to an OCRequest object owned by the OCStack.
*/
-typedef void * OCRequestHandle;
+typedef uint32_t OCRequestHandle;
/**
* Unique identifier for each observation request. Used when observations are
if (ehResult == OC_EH_SLOW)
{
OIC_LOG(INFO, TAG, "This is a slow resource");
- ((OCServerRequest *)ehRequest->requestHandle)->slowFlag = 1;
+ OCServerRequest *request =
+ GetServerRequestUsingHandle(ehRequest->requestHandle);
+ if (request)
+ {
+ request->slowFlag = 1;
+ }
stackRet = EntityHandlerCodeToOCStackCode(ehResult);
}
}
return HandleLinkedListInterface(ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL);
case STACK_IF_BATCH:
+ {
OIC_LOG(INFO, TAG, "STACK_IF_BATCH");
- ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler =
- HandleAggregateResponse;
-
- ((OCServerRequest *)ehRequest->requestHandle)->numResponses =
+ OCServerRequest *request =
+ GetServerRequestUsingHandle(ehRequest->requestHandle);
+ if (request)
+ {
+ request->ehResponseHandler = HandleAggregateResponse;
+ request->numResponses =
GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1;
+ }
return HandleBatchInterface(ehRequest);
-
+ }
case STACK_IF_GROUP:
return BuildCollectionGroupActionCBORResponse(OC_REST_GET/*flag*/,
(OCResource *) ehRequest->resource, ehRequest);
return OC_STACK_ERROR;
case STACK_IF_BATCH:
- ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler =
- HandleAggregateResponse;
- ((OCServerRequest *)ehRequest->requestHandle)->numResponses =
+ {
+ OCServerRequest *request =
+ GetServerRequestUsingHandle(ehRequest->requestHandle);
+ if (request)
+ {
+ request->ehResponseHandler = HandleAggregateResponse;
+ request->numResponses =
GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1;
+ }
return HandleBatchInterface(ehRequest);
-
+ }
case STACK_IF_GROUP:
OIC_LOG(INFO, TAG, "IF_COLLECTION PUT with request ::\n");
OIC_LOG_PAYLOAD(INFO, ehRequest->payload);
return OC_STACK_ERROR;
case STACK_IF_BATCH:
- ((OCServerRequest *)ehRequest->requestHandle)->ehResponseHandler =
- HandleAggregateResponse;
- ((OCServerRequest *)ehRequest->requestHandle)->numResponses =
+ {
+ OCServerRequest *request =
+ GetServerRequestUsingHandle(ehRequest->requestHandle);
+ if (request)
+ {
+ request->ehResponseHandler = HandleAggregateResponse;
+ request->numResponses =
GetNumOfResourcesInCollection((OCResource *)ehRequest->resource) + 1;
+ }
return HandleBatchInterface(ehRequest);
+ }
case STACK_IF_GROUP:
OIC_LOG(INFO, TAG, "IF_COLLECTION POST with request ::\n");
{
result = FormOCEntityHandlerRequest(
&ehRequest,
- (OCRequestHandle) request,
+ (OCRequestHandle) request->requestId,
request->method,
&request->devAddr,
(OCResourceHandle) observer->resource,
ehResponse.ehResult = OC_EH_OK;
ehResponse.payload = (OCPayload*)presenceResBuf;
ehResponse.persistentBufferFlag = 0;
- ehResponse.requestHandle = (OCRequestHandle) request;
+ ehResponse.requestHandle = (OCRequestHandle) request->requestId;
ehResponse.resourceHandle = (OCResourceHandle) resPtr;
OICStrcpy(ehResponse.resourceUri, sizeof(ehResponse.resourceUri),
resourceObserver->resUri);
}
memcpy(ehResponse.payload, payload, sizeof(*payload));
ehResponse.persistentBufferFlag = 0;
- ehResponse.requestHandle = (OCRequestHandle) request;
+ ehResponse.requestHandle = (OCRequestHandle) request->requestId;
ehResponse.resourceHandle = (OCResourceHandle) resource;
result = OCDoResponse(&ehResponse);
if (result == OC_STACK_OK)
response.ehResult = ehResult;
response.payload = discoveryPayload;
response.persistentBufferFlag = 0;
- response.requestHandle = (OCRequestHandle) request;
+ response.requestHandle = (OCRequestHandle) request->requestId;
response.resourceHandle = (OCResourceHandle) resource;
return OCDoResponse(&response);
OIC_LOG(INFO, TAG, "Entering HandleResourceWithDefaultDeviceEntityHandler");
result = FormOCEntityHandlerRequest(&ehRequest,
- (OCRequestHandle) request,
+ (OCRequestHandle) request->requestId,
request->method,
&request->devAddr,
(OCResourceHandle) NULL, request->query,
if (request && request->resourceUrl && SRMIsSecurityResourceURI(request->resourceUrl))
{
type = PAYLOAD_TYPE_SECURITY;
-
}
result = FormOCEntityHandlerRequest(&ehRequest,
- (OCRequestHandle)request,
+ (OCRequestHandle)request->requestId,
request->method,
&request->devAddr,
(OCResourceHandle)resource,
OCEntityHandlerRequest ehRequest = {0};
result = FormOCEntityHandlerRequest(&ehRequest,
- (OCRequestHandle)request,
+ (OCRequestHandle)request->requestId,
request->method,
&request->devAddr,
(OCResourceHandle)resource,
* @return
* OCServerRequest*
*/
-OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle)
+OCServerRequest * GetServerRequestUsingHandle (const OCRequestHandle handle)
{
OCServerRequest * out = NULL;
LL_FOREACH (serverRequestList, out)
{
- if(out == handle)
+ if(out->requestId == handle)
{
return out;
}
* @return
* OCServerResponse*
*/
-OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle)
+OCServerResponse * GetServerResponseUsingHandle (const OCRequestHandle handle)
{
OCServerResponse * out = NULL;
LL_FOREACH (serverResponseList, out)
serverRequest->acceptFormat = acceptFormat;
serverRequest->ehResponseHandler = HandleSingleResponse;
serverRequest->numResponses = 1;
+ serverRequest->requestId = OCGetRandom();
if(query)
{
}
if(payload && reqTotalSize)
{
- // destination is at least 1 greater than the source, so a NULL always exists in the
+ // destination is at least 1 greater than the source, so a NULL always exists in the
// last character
memcpy(serverRequest->payload, payload, reqTotalSize);
serverRequest->payloadSize = reqTotalSize;
serverRequest->requestComplete = 0;
if(requestToken)
{
- // If tokenLength is zero, the return value depends on the
- // particular library implementation (it may or may not be a null pointer).
+ // If tokenLength is zero, the return value depends on the
+ // particular library implementation (it may or may not be a null pointer).
if (tokenLength)
{
serverRequest->requestToken = (CAToken_t) OICMalloc(tokenLength);
VERIFY_NON_NULL(serverRequest->requestToken);
memcpy(serverRequest->requestToken, requestToken, tokenLength);
}
-
}
serverRequest->tokenLength = tokenLength;
exit:
if (serverRequest)
{
+ OICFree(serverRequest->requestToken);
OICFree(serverRequest);
serverRequest = NULL;
}
return OC_STACK_ERROR;
}
- OCServerRequest *serverRequest = (OCServerRequest *)ehResponse->requestHandle;
+ OCServerRequest *serverRequest = GetServerRequestUsingHandle(ehResponse->requestHandle);
+ if (NULL == serverRequest)
+ {
+ OIC_LOG(ERROR, TAG, "No serverRequest matching with ehResponse");
+ return OC_STACK_ERROR;
+ }
CopyDevAddrToEndpoint(&serverRequest->devAddr, &responseEndpoint);
OIC_LOG(INFO, TAG, "Inside HandleAggregateResponse");
- OCServerRequest *serverRequest = GetServerRequestUsingHandle((OCServerRequest *)
- ehResponse->requestHandle);
- OCServerResponse *serverResponse = GetServerResponseUsingHandle((OCServerRequest *)
- ehResponse->requestHandle);
+ OCServerRequest *serverRequest = GetServerRequestUsingHandle(ehResponse->requestHandle);
+ OCServerResponse *serverResponse = GetServerResponseUsingHandle(ehResponse->requestHandle);
OCStackResult stackRet = OC_STACK_ERROR;
if(serverRequest)
if(observer)
{
result = FormOCEntityHandlerRequest(&ehRequest,
- (OCRequestHandle)NULL,
+ 0,
OC_REST_NOMETHOD,
&observer->devAddr,
(OCResourceHandle)NULL,
if(observer->failedCommCount >= MAX_OBSERVER_FAILED_COMM)
{
result = FormOCEntityHandlerRequest(&ehRequest,
- (OCRequestHandle)NULL,
+ 0,
OC_REST_NOMETHOD,
&observer->devAddr,
(OCResourceHandle)NULL,
// Normal response
// Get pointer to request info
- serverRequest = GetServerRequestUsingHandle((OCServerRequest *)ehResponse->requestHandle);
+ serverRequest = GetServerRequestUsingHandle(ehResponse->requestHandle);
if(serverRequest)
{
// response handler in ocserverrequest.c. Usually HandleSingleResponse.
}
// Format the response. Note this requires some info about the request
- response.requestHandle = info->ehRequest;
+ response.requestHandle = info->ehRequest->requestId;
response.resourceHandle = info->collResource;
response.payload = clientResponse->payload;
response.numSendVendorSpecificHeaderOptions = 0;
else
{
OIC_LOG(INFO, TAG, "Group Action[POST].");
+ OCServerRequest *request =
+ GetServerRequestUsingHandle(ehRequest->requestHandle);
+ if (NULL == request)
+ {
+ stackRet = OC_STACK_ERROR;
+ goto exit;
+ }
+
if (actionset->type == NONE)
{
OIC_LOG_V(INFO, TAG, "Execute ActionSet : %s",
unsigned int num = GetNumOfTargetResource(
actionset->head);
- ((OCServerRequest *) ehRequest->requestHandle)->ehResponseHandler =
- HandleAggregateResponse;
- ((OCServerRequest *) ehRequest->requestHandle)->numResponses =
- num + 1;
+ request->ehResponseHandler = HandleAggregateResponse;
+ request->numResponses = num + 1;
+
+ DoAction(resource, actionset, request);
- DoAction(resource, actionset,
- (OCServerRequest*) ehRequest->requestHandle);
stackRet = OC_STACK_OK;
}
else
MUTEX_LOCK(&g_scheduledResourceLock);
schedule->resource = resource;
schedule->actionset = actionset;
- schedule->ehRequest =
- (OCServerRequest*) ehRequest->requestHandle;
+ schedule->ehRequest = request;
+
MUTEX_UNLOCK(&g_scheduledResourceLock);
if (delay > 0)
{
AddResourceInterfaceNameToPayload(payload);
}
- OCEntityHandlerResponse ehResponse = { .ehResult = result,
- .payload = (OCPayload*) payload,
- .requestHandle = request,
+ OCEntityHandlerResponse ehResponse = { .ehResult = result,
+ .payload = (OCPayload*) payload,
+ .requestHandle = request->requestId,
.resourceHandle = g_keepAliveHandle };
OICStrcpy(ehResponse.resourceUri, sizeof(ehResponse.resourceUri), KEEPALIVE_RESOURCE_URI);
m_messageID(0),
m_representation(OCRepresentation()),
m_headerOptions(HeaderOptions()),
- m_requestHandle(nullptr),
+ m_requestHandle(0),
m_resourceHandle(nullptr)
{
m_observationInfo.action = ObserveAction::ObserveRegister;
m_headerOptions{},
m_interface{},
m_representation{},
- m_requestHandle{nullptr},
+ m_requestHandle{0},
m_resourceHandle{nullptr},
m_responseResult{}
{
request.qos = OC_LOW_QOS;
request.coapID = 0;
request.delayedResNeeded = 0;
+ request.requestId = 0x1234;
- OCRequestHandle handle = static_cast<OCRequestHandle>(&request);
- EXPECT_EQ(NULL, response.getRequestHandle());
+ OCRequestHandle handle = request.requestId;
+ EXPECT_EQ(0, response.getRequestHandle());
EXPECT_NO_THROW(response.setRequestHandle(handle));
- EXPECT_NE(static_cast<OCRequestHandle>(NULL), response.getRequestHandle());
+ EXPECT_NE(0, response.getRequestHandle());
}
TEST(RequestHandleTest, SetGetRequestHandleNullHandle)
{
OCResourceResponse response;
- OCRequestHandle handle = nullptr;
+ OCRequestHandle handle = 0;
EXPECT_EQ(NULL, response.getRequestHandle());
EXPECT_NO_THROW(response.setRequestHandle(handle));
}
};
-const OCRequestHandle ResourceObjectHandlingRequestTest::fakeRequestHandle =
- reinterpret_cast<OCRequestHandle>(0x1234);
+const OCRequestHandle ResourceObjectHandlingRequestTest::fakeRequestHandle = 0x1234;
const OCResourceHandle ResourceObjectHandlingRequestTest::fakeResourceHandle =
reinterpret_cast<OCResourceHandle>(0x4321);