*/
void SRMRegisterProvisioningResponseHandler(SPResponseCallback respHandler);
+/**
+ * @brief Check the security resource URI.
+ * @param uri [IN] Pointers to security resource URI.
+ * @return true if the URI is one of security resources, otherwise false.
+ */
+bool SRMIsSecurityResourceURI(const char* uri);
+
#ifdef __cplusplus
}
#endif
}
OCProvisionDev_t** ppDevicesList = (OCProvisionDev_t**) ctx;
+ OC_LOG_V(INFO, TAG, "UpdateSecurePortOfDevice with %d", securePort);
OCStackResult res = UpdateSecurePortOfDevice(ppDevicesList, clientResponse->devAddr.addr,
clientResponse->devAddr.port, securePort);
cbData.cb = &SecurePortDiscoveryHandler;
cbData.context = ctx;
cbData.cd = NULL;
- OCStackResult ret = OCDoResource(NULL, OC_REST_GET, query, 0, 0,
+ OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
clientResponse->connType, OC_LOW_QOS, &cbData, NULL, 0);
// TODO: Should we use the default secure port in case of error?
if(OC_STACK_OK != ret)
*/
static OCEntityHandlerResult HandlePstatGetRequest (const OCEntityHandlerRequest * ehRequest)
{
- // Convert ACL data into JSON for transmission
+ OC_LOG (INFO, TAG, "HandlePstatGetRequest processing GET request");
+ // Convert ACL data into JSON for transmission
char* jsonStr = BinToPstatJSON(gPstat);
// A device should always have a default pstat. Therefore, jsonStr should never be NULL.
{
OCEntityHandlerResult ehRet = OC_EH_ERROR;
cJSON *postJson = NULL;
+ OC_LOG (INFO, TAG, "HandlePstatPutRequest processing PUT request");
if (ehRequest->resource)
{
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include <string.h>
#include "ocstack.h"
#include "logger.h"
#include "cainterface.h"
#include "credresource.h"
#include "policyengine.h"
#include "oic_string.h"
-#include <string.h>
+#include "srmresourcestrings.h"
#define TAG "SRM"
{
return DeInitPolicyEngine(&g_policyEngineContext);
}
+
+/**
+ * @brief Check the security resource URI.
+ * @param uri [IN] Pointers to security resource URI.
+ * @return true if the URI is one of security resources, otherwise false.
+ */
+bool SRMIsSecurityResourceURI(const char* uri)
+{
+ bool result = false;
+ if (!uri)
+ {
+ return result;
+ }
+
+ if (strcmp(uri, OIC_RSRC_AMACL_URI) == 0 || strcmp(uri, OIC_RSRC_ACL_URI) == 0
+ || strcmp(uri, OIC_RSRC_PSTAT_URI) == 0
+ || strncmp(OIC_RSRC_DOXM_URI, uri, sizeof(OIC_RSRC_DOXM_URI) - 1) == 0
+ || strcmp(uri, OIC_RSRC_CRED_URI) == 0 || strcmp(uri, OIC_RSRC_SVC_URI) == 0)
+ {
+ result = true;
+ }
+ return result;
+}
* OCStackResult
*/
OCStackResult FormOCEntityHandlerRequest(
- OCEntityHandlerRequest *entityHandlerRequest,
- OCRequestHandle request,
- OCMethod method,
- OCDevAddr *endpoint,
- OCResourceHandle resource,
- char *queryBuf,
- uint8_t *payload,
- size_t payloadSize,
- uint8_t numVendorOptions,
- OCHeaderOption *vendorOptions,
- OCObserveAction observeAction,
- OCObservationId observeID);
+ OCEntityHandlerRequest * entityHandlerRequest,
+ OCRequestHandle request,
+ OCMethod method,
+ OCDevAddr *endpoint,
+ OCResourceHandle resource,
+ char * queryBuf,
+ OCPayloadType payloadType,
+ uint8_t * payload,
+ size_t payloadSize,
+ uint8_t numVendorOptions,
+ OCHeaderOption * vendorOptions,
+ OCObserveAction observeAction,
+ OCObservationId observeID);
/**
* Find a server request in the server request list and delete
&request->devAddr,
(OCResourceHandle) resPtr,
request->query,
+ PAYLOAD_TYPE_REPRESENTATION,
request->payload,
request->payloadSize,
request->numRcvdVendorSpecificHeaderOptions,
// For POSIX.1-2001 base specification,
// Refer http://pubs.opengroup.org/onlinepubs/009695399/
#define _POSIX_C_SOURCE 200112L
-#include "ocresource.h"
#include <string.h>
+#include "ocresource.h"
#include "ocresourcehandler.h"
#include "ocobserve.h"
#include "occollection.h"
#include "logger.h"
#include "cJSON.h"
#include "ocpayload.h"
-
+#include "secureresourcemanager.h"
#include "cacommon.h"
#include "cainterface.h"
-
/// Module Name
#define TAG "ocresource"
#define VERIFY_SUCCESS(op, successCode) { if (op != successCode) \
request->method,
&request->devAddr,
(OCResourceHandle) NULL, request->query,
+ PAYLOAD_TYPE_REPRESENTATION,
request->payload,
request->payloadSize,
request->numRcvdVendorSpecificHeaderOptions,
OCEntityHandlerRequest ehRequest = {0};
OC_LOG(INFO, TAG, "Entering HandleResourceWithEntityHandler");
+ OCPayloadType type = PAYLOAD_TYPE_REPRESENTATION;
+ // check the security resource
+ if (request && request->resourceUrl && SRMIsSecurityResourceURI(request->resourceUrl))
+ {
+ type = PAYLOAD_TYPE_SECURITY;
+ }
result = FormOCEntityHandlerRequest(&ehRequest,
(OCRequestHandle)request,
request->method,
&request->devAddr,
(OCResourceHandle)resource,
request->query,
+ type,
request->payload,
request->payloadSize,
request->numRcvdVendorSpecificHeaderOptions,
&request->devAddr,
(OCResourceHandle)resource,
request->query,
+ PAYLOAD_TYPE_REPRESENTATION,
request->payload,
request->payloadSize,
request->numRcvdVendorSpecificHeaderOptions,
OCDevAddr *endpoint,
OCResourceHandle resource,
char * queryBuf,
+ OCPayloadType payloadType,
uint8_t * payload,
size_t payloadSize,
uint8_t numVendorOptions,
if(payload && payloadSize)
{
- if(OCParsePayload(&entityHandlerRequest->payload, PAYLOAD_TYPE_REPRESENTATION,
+ if(OCParsePayload(&entityHandlerRequest->payload, payloadType,
payload, payloadSize) != OC_STACK_OK)
{
return OC_STACK_ERROR;
OC_REST_NOMETHOD,
&observer->devAddr,
(OCResourceHandle)NULL,
- NULL, NULL, 0, 0, NULL,
+ NULL, PAYLOAD_TYPE_REPRESENTATION,
+ NULL, 0, 0, NULL,
OC_OBSERVE_DEREGISTER,
observer->observeId);
if(result != OC_STACK_OK)
OC_REST_NOMETHOD,
&observer->devAddr,
(OCResourceHandle)NULL,
- NULL, NULL, 0, 0, NULL,
+ NULL, PAYLOAD_TYPE_REPRESENTATION,
+ NULL, 0, 0, NULL,
OC_OBSERVE_DEREGISTER,
observer->observeId);
if(result != OC_STACK_OK)
responseInfo->info.payloadSize)
{
OCPayloadType type = PAYLOAD_TYPE_INVALID;
- if (cbNode->method == OC_REST_DISCOVER)
+ // check the security resource
+ if (SRMIsSecurityResourceURI(cbNode->requestUri))
+ {
+ type = PAYLOAD_TYPE_SECURITY;
+ }
+ else if (cbNode->method == OC_REST_DISCOVER)
{
if (strncmp(OC_RSRVD_WELL_KNOWN_URI,cbNode->requestUri,
sizeof(OC_RSRVD_WELL_KNOWN_URI) - 1) == 0)