cred = GetCredResourceData(&pTargetDev->doxm->deviceID);
if (cred == NULL)
{
- OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to get credential of remove device.");
+ OIC_LOG(ERROR, TAG, "RemoveDeviceInfoFromLocal : Failed to get credential of remove device.");
goto error;
}
res = RemoveCredential(&cred->subject);
if (res != OC_STACK_RESOURCE_DELETED)
{
- OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to remove credential.");
+ OIC_LOG(ERROR, TAG, "RemoveDeviceInfoFromLocal : Failed to remove credential.");
goto error;
}
OCProvisionResultCB resultCallback)
{
OIC_LOG(INFO, TAG, "IN OCRemoveDeviceWithUuid");
+
OCStackResult res = OC_STACK_ERROR;
+ OCProvisionDev_t* pTargetDev = NULL;
+ bool discoverdFlag = false;
+
if (!pTargetUuid || 0 == waitTimeForOwnedDeviceDiscovery)
{
OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Invalied parameters");
return OC_STACK_INVALID_CALLBACK;
}
+ char* strUuid = NULL;
+ if(OC_STACK_OK != ConvertUuidToStr(pTargetUuid, &strUuid))
+ {
+ OIC_LOG(WARNING, TAG, "Failed to covert UUID to String.");
+ goto error;
+ }
+
OCProvisionDev_t* pOwnedDevList = NULL;
//2. Find owned device from the network
res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
goto error;
}
- OCProvisionDev_t* pTargetDev = NULL;
LL_FOREACH(pOwnedDevList, pTargetDev)
{
if(memcmp(&pTargetDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id)) == 0)
}
}
- char* strUuid = NULL;
- if(OC_STACK_OK != ConvertUuidToStr(pTargetUuid, &strUuid))
- {
- OIC_LOG(WARNING, TAG, "Failed to covert UUID to String.");
- goto error;
- }
-
- if(pTargetDev)
+ if(NULL == pTargetDev)
{
- OIC_LOG_V(INFO, TAG, "[%s] is dectected on the network.", strUuid);
- OIC_LOG_V(INFO, TAG, "Trying [%s] revocation.", strUuid);
+ OIC_LOG_V(WARNING, TAG, "Can not find [%s] on the network.", strUuid);
+ OIC_LOG(WARNING, TAG, "Device information will be deleted from local and other devices.");
- // Send DELETE requests to linked devices
- OCStackResult resReq = OC_STACK_ERROR; // Check that we have to wait callback or not.
- resReq = SRPRemoveDeviceWithoutDiscovery(ctx, pOwnedDevList, pTargetDev, resultCallback);
- if (OC_STACK_OK != resReq)
+ pTargetDev = (OCProvisionDev_t*)OICCalloc(1, sizeof(OCProvisionDev_t));
+ if(NULL == pTargetDev)
{
- if (OC_STACK_CONTINUE == resReq)
- {
- OIC_LOG(DEBUG, TAG, "OCRemoveDeviceWithUuid : Revoked device has no linked device except PT.");
- }
- else
- {
- OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to invoke SRPRemoveDevice");
- res = resReq;
- OICFree(strUuid);
- goto error;
- }
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation.");
+ goto error;
}
- res = RemoveDeviceInfoFromLocal(pTargetDev);
- if(OC_STACK_OK != res)
+ pTargetDev->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
+ if(NULL == pTargetDev->doxm)
{
- OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Filed to remove the device information from local.");
- OICFree(strUuid);
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation.");
goto error;
}
- if(OC_STACK_CONTINUE == resReq)
+ //in case of can't find target device, the device id required only.
+ memcpy(pTargetDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id));
+ }
+ else
+ {
+ discoverdFlag = true;
+ OIC_LOG_V(INFO, TAG, "[%s] is dectected on the network.", strUuid);
+ }
+
+ OIC_LOG_V(INFO, TAG, "Trying [%s] revocation.", strUuid);
+
+ // Send DELETE requests to linked devices
+ OCStackResult resReq = OC_STACK_ERROR; // Check that we have to wait callback or not.
+ resReq = SRPRemoveDeviceWithoutDiscovery(ctx, pOwnedDevList, pTargetDev, resultCallback);
+ if (OC_STACK_OK != resReq)
+ {
+ if (OC_STACK_CONTINUE == resReq)
{
- /**
- * If there is no linked device, PM does not send any request.
- * So we should directly invoke the result callback to inform the result of OCRemoveDevice.
- */
- if(resultCallback)
- {
- resultCallback(ctx, 0, NULL, false);
- }
- res = OC_STACK_OK;
+ OIC_LOG(DEBUG, TAG, "OCRemoveDeviceWithUuid : Revoked device has no linked device except PT.");
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to invoke SRPRemoveDevice");
+ res = resReq;
+ goto error;
}
}
- else
+
+ res = RemoveDeviceInfoFromLocal(pTargetDev);
+ if(OC_STACK_OK != res)
{
- OIC_LOG_V(WARNING, TAG, "OCRemoveDeviceWithUuid : Failed to find the [%s] on the network.", strUuid);
- res = OC_STACK_ERROR;
+ OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Filed to remove the device information from local.");
+ goto error;
+ }
+
+ if(OC_STACK_CONTINUE == resReq)
+ {
+ /**
+ * If there is no linked device, PM does not send any request.
+ * So we should directly invoke the result callback to inform the result of OCRemoveDevice.
+ */
+ if(resultCallback)
+ {
+ resultCallback(ctx, 0, NULL, false);
+ }
+ res = OC_STACK_OK;
}
error:
OICFree(strUuid);
PMDeleteDeviceList(pOwnedDevList);
+ if(pTargetDev && false == discoverdFlag)
+ {
+ OICFree(pTargetDev->doxm);
+ OICFree(pTargetDev);
+ }
OIC_LOG(INFO, TAG, "OUT OCRemoveDeviceWithUuid");
return res;
}
{
OIC_LOG(INFO, TAG, "IN SRPRemoveDeviceWithoutDiscovery");
- if (!pTargetDev || !pOwnedDevList)
+ if (!pOwnedDevList)
+ {
+ OIC_LOG(WARNING, TAG, "SRPRemoveDeviceWithoutDiscovery : Owned Device List is empty");
+ return OC_STACK_CONTINUE;
+ }
+ if (!pTargetDev)
{
OIC_LOG(INFO, TAG, "SRPRemoveDeviceWithoutDiscovery : NULL parameters");
return OC_STACK_INVALID_PARAM;
res = PDMGetLinkedDevices(&pTargetDev->doxm->deviceID, &pLinkedUuidList, &numOfDevices);
if (OC_STACK_OK != res)
{
- OIC_LOG(ERROR, TAG, "SRPRemoveDeviceWithoutDiscovery : Failed to get linked devices information");
- return res;
+ OIC_LOG(WARNING, TAG, "SRPRemoveDeviceWithoutDiscovery : Failed to get linked devices information");
+ return OC_STACK_CONTINUE;
}
// if there is no related device, we can skip further process.
if (0 == numOfDevices)
{
- OIC_LOG(DEBUG, TAG, "SRPRemoveDeviceWithoutDiscovery : No linked device found.");
- res = OC_STACK_CONTINUE;
- goto error;
+ OIC_LOG(WARNING, TAG, "SRPRemoveDeviceWithoutDiscovery : No linked device found.");
+ return OC_STACK_CONTINUE;
}
//2. Make a list of devices to send DELETE credential request
if (0 == numOfLinkedDev) // This case means, there is linked device but it's not alive now.
{ // So we don't have to send request message.
OIC_LOG(DEBUG, TAG, "SRPRemoveDeviceWithoutDiscovery : No alived & linked device found.");
- res = OC_STACK_CONTINUE;
- goto error;
+ return OC_STACK_CONTINUE;
}
// 3. Prepare RemoveData Context data.