From 10ac37501a95a2ebbeb4e16a873b45d2c8a9a3b4 Mon Sep 17 00:00:00 2001 From: Habib Virji Date: Tue, 5 Apr 2016 19:58:01 +0100 Subject: [PATCH] IOT-1075 PUT/POST/DELETE for /oic/res, /oic/d, /oic/p returns error /oic/res. /oic/d and /oic/p returns error when PUT/POST/DELETE is performed on the resource. Change-Id: Ib40c4d2b5e9263bc4252e3553fa7e30ef21c2a51 Signed-off-by: Habib Virji Reviewed-on: https://gerrit.iotivity.org/gerrit/7625 Tested-by: jenkins-iotivity Reviewed-by: Mushfiqul Islam Reviewed-by: Markus Jung Reviewed-by: Uze Choi --- resource/csdk/stack/src/ocresource.c | 18 ++++++++++++++++++ resource/csdk/stack/src/ocstack.c | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index 3272862..3c0ee58 100755 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -680,6 +680,12 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource // Step 1: Generate the response to discovery request if (virtualUriInRequest == OC_WELL_KNOWN_URI) { + if (request->method == OC_REST_PUT || request->method == OC_REST_POST || request->method == OC_REST_DELETE) + { + OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d", request->resourceUrl, request->method); + return OC_STACK_UNAUTHORIZED_REQ; + } + char *interfaceQuery = NULL; char *resourceTypeQuery = NULL; @@ -812,6 +818,12 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource } else if (virtualUriInRequest == OC_DEVICE_URI) { + if (request->method == OC_REST_PUT || request->method == OC_REST_POST || request->method == OC_REST_DELETE) + { + OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d", request->resourceUrl, request->method); + return OC_STACK_UNAUTHORIZED_REQ; + } + const char* deviceId = OCGetServerInstanceIDString(); if (!deviceId) { @@ -833,6 +845,12 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource } else if (virtualUriInRequest == OC_PLATFORM_URI) { + if (request->method == OC_REST_PUT || request->method == OC_REST_POST || request->method == OC_REST_DELETE) + { + OIC_LOG_V(ERROR, TAG, "Resource : %s not permitted for method: %d", request->resourceUrl, request->method); + return OC_STACK_UNAUTHORIZED_REQ; + } + payload = (OCPayload*)OCPlatformPayloadCreate(&savedPlatformInfo); if (!payload) { diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 5f66cd5..7fe2254 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1193,8 +1193,8 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp cbNode->method == OC_REST_DELETE) { char targetUri[MAX_URI_LENGTH]; - snprintf(targetUri, MAX_URI_LENGTH, "%s?rt=%s", - OC_RSRVD_RD_URI, OC_RSRVD_RESOURCE_TYPE_RDPUBLISH); + snprintf(targetUri, MAX_URI_LENGTH, "%s?rt=%s", OC_RSRVD_RD_URI, + OC_RSRVD_RESOURCE_TYPE_RDPUBLISH); if (strcmp(targetUri, cbNode->requestUri) == 0) { type = PAYLOAD_TYPE_RD; -- 2.7.4