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 "amaclresource.h"
28 #include "oic_malloc.h"
33 #define TAG PCF("SRM-RM")
36 * This method is used by all secure resource modules to send responses to REST queries.
38 * @param ehRequest pointer to entity handler request data structure.
39 * @param ehRet result code from entity handler.
40 * @param rspPayload response payload in JSON.
42 * @retval OC_STACK_OK for Success, otherwise some error value
44 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
45 OCEntityHandlerResult ehRet, const char *rspPayload)
47 OC_LOG (INFO, TAG, PCF("SRM sending SRM response"));
48 OCEntityHandlerResponse response = {};
51 response.requestHandle = ehRequest->requestHandle;
52 response.resourceHandle = ehRequest->resource;
53 response.ehResult = ehRet;
54 response.payload = (char *)rspPayload;
55 response.payloadSize = (rspPayload ? strlen(rspPayload) : 0);
56 response.persistentBufferFlag = 0;
58 return OCDoResponse(&response);
60 return OC_STACK_ERROR;
64 * Initialize all secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc).
66 * @retval OC_STACK_OK for Success, otherwise some error value
68 OCStackResult InitSecureResources( )
73 * doxm resource should be initialized first as it contains the DeviceID
74 * which MAY be used during initialization of other resources.
77 ret = InitDoxmResource();
79 if(OC_STACK_OK == ret)
81 ret = InitPstatResource();
83 if(OC_STACK_OK == ret)
85 ret = InitACLResource();
87 if(OC_STACK_OK == ret)
89 ret = InitCredResource();
91 if(OC_STACK_OK == ret)
93 ret = InitAmaclResource();
95 if(OC_STACK_OK != ret)
97 //TODO: Update the default behavior if one of the SVR fails
98 DestroySecureResources();
104 * Perform cleanup for secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc).
106 * @retval OC_STACK_OK for Success, otherwise some error value
108 OCStackResult DestroySecureResources( )
111 DeInitCredResource();
112 DeInitDoxmResource();
113 DeInitPstatResource();