+
+OCStackResult MOTRemoveSubOwner(void* ctx,
+ const OCProvisionDev_t *targetDeviceInfo,
+ const OicUuid_t* subOwner,
+ OCProvisionResultCB resultCallback)
+{
+ OCStackResult deleteSubOwnerRes = OC_STACK_INVALID_CALLBACK;
+ OTMContext_t *motCtx = NULL;
+ char* strUuid = NULL;
+
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+ VERIFY_NON_NULL(TAG, resultCallback, ERROR);
+ deleteSubOwnerRes = OC_STACK_INVALID_PARAM;
+ VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR);
+ VERIFY_NON_NULL(TAG, subOwner, ERROR);
+
+ deleteSubOwnerRes = OC_STACK_NO_MEMORY;
+ //Generate the qurey to delete sub-owner
+ if (memcmp(subOwner->id, WILDCARD_SUBJECT_ID.id, sizeof(WILDCARD_SUBJECT_ID.id)) == 0)
+ {
+ strUuid = OICStrdup(WILDCARD_RESOURCE_URI);
+ VERIFY_NON_NULL(TAG, strUuid, ERROR);
+ }
+ else
+ {
+ VERIFY_SUCCESS(TAG, (OC_STACK_OK == ConvertUuidToStr(subOwner, &strUuid)), ERROR);
+ }
+ char url[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
+ snprintf(url, sizeof(url), "%s?%s=%s", OIC_RSRC_DOXM_URI, OIC_JSON_SUBOWNERID_NAME, strUuid);
+
+ char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
+ bool queryGenRes = PMGenerateQuery(true,
+ targetDeviceInfo->endpoint.addr,
+ targetDeviceInfo->securePort,
+ targetDeviceInfo->connType,
+ query, sizeof(query), url);
+ VERIFY_SUCCESS(TAG, (true == queryGenRes), ERROR);
+
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
+
+ //Create the MOT Context to handle the response message
+ motCtx = (OTMContext_t*)OICCalloc(1, sizeof(OTMContext_t));
+ VERIFY_NON_NULL(TAG, motCtx, ERROR);
+ motCtx->selectedDeviceInfo= targetDeviceInfo;
+ motCtx->ctxResultCallback = resultCallback;
+ motCtx->ctxResultArraySize =1;
+ motCtx->ctxHasError = false;
+ motCtx->userCtx = ctx;
+ motCtx->ctxResultArray = (OCProvisionResult_t*)OICCalloc(1, sizeof(OCProvisionResult_t));
+ VERIFY_NON_NULL(TAG, motCtx->ctxResultArray, ERROR);
+
+ //Send POST request
+ OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
+ cbData.cb = &MOTDeleteSecurityResourceCB;
+ cbData.context = (void *)motCtx;
+ OIC_LOG(DEBUG, TAG, "Sending DELETE sub-owner request to resource server");
+ deleteSubOwnerRes = OCDoResource(NULL, OC_REST_DELETE, query,
+ &targetDeviceInfo->endpoint, NULL,
+ targetDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
+ VERIFY_SUCCESS(TAG, (OC_STACK_OK == deleteSubOwnerRes), ERROR);
+
+ OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+
+ OICFree(strUuid);
+
+ return deleteSubOwnerRes;
+
+exit:
+ //If DELETE request successfully sent, motCtx will be cleaned from response handler.
+ OICFree(strUuid);
+ if (motCtx)
+ {
+ OICFree(motCtx->ctxResultArray);
+ OICFree(motCtx);
+ }
+ OIC_LOG_V(DEBUG, TAG, "Out %s : %d", __func__, deleteSubOwnerRes);
+ return deleteSubOwnerRes;
+}
+