1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "resourcemanager.h"
22 #include "securevirtualresourcetypes.h"
23 #include "aclresource.h"
24 #include "pstatresource.h"
25 #include "doxmresource.h"
26 #include "credresource.h"
27 #include "svcresource.h"
28 #include "amaclresource.h"
29 #include "oic_malloc.h"
30 #include "oic_string.h"
38 #include "crlresource.h"
39 #endif // __WITH_X509__
42 * This method is used by all secure resource modules to send responses to REST queries.
44 * @param ehRequest pointer to entity handler request data structure.
45 * @param ehRet result code from entity handler.
46 * @param rspPayload response payload in JSON.
48 * @retval OC_STACK_OK for Success, otherwise some error value
50 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
51 OCEntityHandlerResult ehRet, const char *rspPayload)
53 OC_LOG (DEBUG, TAG, "SRM sending SRM response");
54 OCEntityHandlerResponse response = {.requestHandle = NULL};
57 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
59 response.requestHandle = ehRequest->requestHandle;
60 response.resourceHandle = ehRequest->resource;
61 response.ehResult = ehRet;
62 response.payload = (OCPayload*)(&ocPayload);
63 response.payload->type = PAYLOAD_TYPE_SECURITY;
64 ((OCSecurityPayload*)response.payload)->securityData = (char *)rspPayload;
65 response.persistentBufferFlag = 0;
67 return OCDoResponse(&response);
69 return OC_STACK_ERROR;
73 * Initialize all secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc).
75 * @retval OC_STACK_OK for Success, otherwise some error value
77 OCStackResult InitSecureResources( )
82 * doxm resource should be initialized first as it contains the DeviceID
83 * which MAY be used during initialization of other resources.
86 ret = InitDoxmResource();
88 if(OC_STACK_OK == ret)
90 ret = InitPstatResource();
92 if(OC_STACK_OK == ret)
94 ret = InitACLResource();
96 if(OC_STACK_OK == ret)
98 ret = InitCredResource();
101 if(OC_STACK_OK == ret)
103 ret = InitCRLResource();
105 #endif // __WITH_X509__
106 if(OC_STACK_OK == ret)
108 ret = InitSVCResource();
110 if(OC_STACK_OK == ret)
112 ret = InitAmaclResource();
114 if(OC_STACK_OK != ret)
116 //TODO: Update the default behavior if one of the SVR fails
117 DestroySecureResources();
123 * Perform cleanup for secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc).
125 * @retval OC_STACK_OK for Success, otherwise some error value
127 OCStackResult DestroySecureResources( )
130 DeInitCredResource();
131 DeInitDoxmResource();
132 DeInitPstatResource();
135 #endif // __WITH_X509__
137 DeInitAmaclResource();