replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / src / resourcemanager.c
index 14f586d..6d7c8e1 100644 (file)
@@ -25,7 +25,6 @@
 #include "pstatresource.h"
 #include "doxmresource.h"
 #include "credresource.h"
-#include "svcresource.h"
 #include "amaclresource.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "dpairingresource.h"
 //#endif // DIRECT_PAIRING
 #include "verresource.h"
+#include "psinterface.h"
 
-#define TAG "SRM-RM"
+#define TAG "OIC_SRM_RM"
 
-#ifdef __WITH_X509__
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
 #include "crlresource.h"
-#endif // __WITH_X509__
+#endif // __WITH_DTLS__ || __WITH_TLS__
 
 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResult ehRet, const char *rspPayload)
-{
-    OIC_LOG (DEBUG, TAG, "SRM sending SRM response");
-    OCEntityHandlerResponse response = {.requestHandle = NULL};
-    if (ehRequest)
-    {
-        OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
-
-        response.requestHandle = ehRequest->requestHandle;
-        response.resourceHandle = ehRequest->resource;
-        response.ehResult = ehRet;
-        response.payload = (OCPayload*)(&ocPayload);
-        response.payload->type = PAYLOAD_TYPE_SECURITY;
-        ((OCSecurityPayload*)response.payload)->securityData = (char *)rspPayload;
-        response.persistentBufferFlag = 0;
-
-        return OCDoResponse(&response);
-    }
-    return OC_STACK_ERROR;
-}
-
-OCStackResult SendSRMCBORResponse(const OCEntityHandlerRequest *ehRequest,
         OCEntityHandlerResult ehRet, uint8_t *cborPayload, size_t size)
 {
     OIC_LOG(DEBUG, TAG, "SRM sending SRM response");
-    OCEntityHandlerResponse response = {.requestHandle = NULL};
     OCStackResult ret = OC_STACK_ERROR;
 
     if (ehRequest)
     {
+        OCEntityHandlerResponse response = {.requestHandle = 0};
         OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
 
         response.requestHandle = ehRequest->requestHandle;
@@ -82,7 +60,7 @@ OCStackResult SendSRMCBORResponse(const OCEntityHandlerRequest *ehRequest,
         response.ehResult = ehRet;
         response.payload = (OCPayload *)(&ocPayload);
         response.payload->type = PAYLOAD_TYPE_SECURITY;
-        ((OCSecurityPayload *)response.payload)->securityData1 = cborPayload;
+        ((OCSecurityPayload *)response.payload)->securityData = cborPayload;
         ((OCSecurityPayload *)response.payload)->payloadSize = size;
         response.persistentBufferFlag = 0;
 
@@ -95,13 +73,17 @@ OCStackResult InitSecureResources( )
 {
     OCStackResult ret;
 
+    ret = InitPersistentStorageInterface();
+
     /*
      * doxm resource should be initialized first as it contains the DeviceID
      * which MAY be used during initialization of other resources.
      */
 
-    ret = InitDoxmResource();
-
+    if(OC_STACK_OK == ret)
+    {
+        ret = InitDoxmResource();
+    }
     if(OC_STACK_OK == ret)
     {
         ret = InitPstatResource();
@@ -114,16 +96,12 @@ OCStackResult InitSecureResources( )
     {
         ret = InitCredResource();
     }
-#ifdef __WITH_X509__
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
     if(OC_STACK_OK == ret)
     {
         ret = InitCRLResource();
     }
-#endif // __WITH_X509__
-    if(OC_STACK_OK == ret)
-    {
-        ret = InitSVCResource();
-    }
+#endif // __WITH_DTLS__ || __WITH_TLS__
     if(OC_STACK_OK == ret)
     {
         ret = InitAmaclResource();
@@ -156,16 +134,16 @@ OCStackResult DestroySecureResources( )
     DeInitCredResource();
     DeInitDoxmResource();
     DeInitPstatResource();
-#ifdef __WITH_X509__
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
     DeInitCRLResource();
-#endif // __WITH_X509__
-    DeInitSVCResource();
+#endif // __WITH_DTLS__ || __WITH_TLS__
     DeInitAmaclResource();
 //#ifdef DIRECT_PAIRING
     DeInitPconfResource();
     DeInitDpairingResource();
 //#endif // DIRECT_PAIRING
     DeInitVerResource();
+    DeinitPersistentStorageInterface();
 
     return OC_STACK_OK;
 }