OCDoHandle handle;
OCStackResult result;
- result = OCDoResource(handle,
+ result = OCDoResource(&handle,
method,
uri,
addr,
static void retreiveRDDetails(OCClientResponse *clientResponse, OCRDBiasFactorCB clientCB)
{
- OC_LOG_V(DEBUG, TAG, "\tAddress of the RD: %s : %d", clientResponse->devAddr.addr,
+ OC_LOG_V(DEBUG, TAG, "\tAddress of the RD: %s:%d", clientResponse->devAddr.addr,
clientResponse->devAddr.port);
OCRDPayload *payload = (OCRDPayload *) clientResponse->payload;
// needs to cache here detail
// and after certain timeout then decide based on the biasFactor.
//if (biasFactor > 75)
- clientCB(clientResponse->devAddr.addr, clientResponse->devAddr.port);
-
+ if (clientCB)
+ {
+ clientCB(clientResponse->devAddr.addr, clientResponse->devAddr.port);
+ }
}
static OCStackApplicationResult handleDiscoverCB(void *ctx,
OC_LOG(DEBUG, TAG, "Found Resource Directory");
OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
- OCRDClientContextCB *cb = (OCRDClientContextCB *) ctx;
+ OCRDClientContextCB *cb = (OCRDClientContextCB *)ctx;
if (!cb)
{
OC_LOG(ERROR, TAG, "RD Context Invalid Parameters.");
OC_LOG(ERROR, TAG, "Discovery of RD Failed");
}
+ OICFree(cb);
+
return ret;
}
OC_LOG_V(DEBUG, TAG, "Querying RD: %s\n", queryUri);
- OCRDClientContextCB cbContext;
- cbContext.context = (void *)DEFAULT_CONTEXT_VALUE;
- cbContext.cbFunc = cbBiasFactor;
+ OCRDClientContextCB *cbContext = OICCalloc(1, sizeof(OCRDClientContextCB));
+ if (!cbContext)
+ {
+ OC_LOG(ERROR, TAG, "Failed allocating memory.");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ cbContext->context = (void *)DEFAULT_CONTEXT_VALUE;
+ cbContext->cbFunc = cbBiasFactor;
OCCallbackData cbData;
cbData.cb = handleDiscoverCB;
- cbData.context = (void *)(&cbContext);
+ cbData.context = (void *)(cbContext);
cbData.cd = NULL;
return sendRequest(OC_REST_DISCOVER, queryUri, NULL, NULL, cbData);
*size = MAX_REQUEST_LENGTH;
+ OCRDPayloadLog(DEBUG, TAG, rdPayload);
+
CborEncoder encoder;
int flags = 0;
cbor_encoder_init(&encoder, *outPayload, *size, flags);
- OC_LOG_V(DEBUG, TAG, "RD Payload : %d", rdPayload->base.type);
- OC_LOG_V(DEBUG, TAG, "RD Payload Type: %d", rdPayload->payloadType);
-
CborEncoder rootArray;
CborError cborEncoderResult;
cborEncoderResult = cbor_encoder_create_array(&encoder, &rootArray, CBOR_ROOT_ARRAY_LENGTH);
OC_LOG_V(ERROR, TAG, "Failed setting discovery sel value.");
goto exit;
}
- OC_LOG_V(DEBUG, TAG, "RD Payload bias factor: %d", rdPayload->rdDiscovery->sel);
}
else
{
}
*outPayload = tempPayload;
-
return OC_STACK_OK;
no_memory:
goto exit;
}
- OCRDLinksPayloadCreate(href, itf, rt, &links);
+ OCRDLinksPayloadCreate(href, rt, itf, &links);
if (!links)
{
goto no_memory;
{
goto no_memory;
}
+ }
- OCRDPayloadLog(DEBUG, TAG, rdPayload);
- cborFindResult = cbor_value_advance(rdCBORPayload);
- if (CborNoError != cborFindResult)
- {
- OC_LOG_V(ERROR, TAG, "Failed advancing the payload.");
- goto exit;
- }
+ OCRDPayloadLog(DEBUG, TAG, rdPayload);
+ cborFindResult = cbor_value_advance(rdCBORPayload);
+ if (CborNoError != cborFindResult)
+ {
+ OC_LOG_V(ERROR, TAG, "Failed advancing the payload.");
+ goto exit;
}
*outPayload = (OCPayload *)rdPayload;
}
{
if (rdPublish)
{
- if (payload->rdPublish->deviceName.deviceName)
+ if (rdPublish->deviceName.deviceName)
{
- OC_LOG_V(level, tag, "RD Payload Pulish Name : %s", payload->rdPublish->deviceName.deviceName);
+ OC_LOG_V(level, tag, "RD Payload Pulish Name : %s", rdPublish->deviceName.deviceName);
}
- if (payload->rdPublish->deviceId.id)
+ if (rdPublish->deviceId.id)
{
- OC_LOG_V(level, tag, "RD Payload Publish ID : %s", payload->rdPublish->deviceId.id);
+ OC_LOG_V(level, tag, "RD Payload Publish ID : %s", rdPublish->deviceId.id);
}
OC_LOG_V(level, tag, "RD Payload Publish TTL : %d", rdPublish->ttl);
if (rdPublish->links)
{
- for (OCRDLinksPayload *temp = payload->rdPublish->links; temp; temp = temp->next)
+ for (OCRDLinksPayload *temp = rdPublish->links; temp; temp = temp->next)
{
+ OC_LOG_V(level, tag, "RD Payload Publish Link HREF : %s", temp->href);
OC_LOG_V(level, tag, "RD Payload Publish Link RT : %s", temp->rt);
OC_LOG_V(level, tag, "RD Payload Publish Link ITF : %s", temp->itf);
- OC_LOG_V(level, tag, "RD Payload Publish Link HREF : %s", temp->href);
}
}
}
response.requestHandle = ehRequest->requestHandle;
response.resourceHandle = ehRequest->resource;
response.ehResult = OC_EH_OK;
- response.payload = (OCPayload*)(&rdPayload);
+ response.payload = (OCPayload*)(rdPayload);
response.payload->type = PAYLOAD_TYPE_RD;
return OCDoResponse(&response);
OCRDStorePublishedResources(payload->rdPublish);
}
- OC_LOG_V(DEBUG, TAG, "Sending success response");
- OCRDPayload *rdPayload = OCRDPayloadCreate(RD_PAYLOAD_TYPE_PUBLISH);
- if (sendResponse(ehRequest, rdPayload) != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "Sending response failed.");
- ehResult = OC_EH_ERROR;
- }
-
- OCRDPayloadDestroy(rdPayload);
-
return ehResult;
}