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"
35 //#ifdef DIRECT_PAIRING
36 #include "pconfresource.h"
37 #include "dpairingresource.h"
38 //#endif // DIRECT_PAIRING
43 #include "crlresource.h"
44 #endif // __WITH_X509__
47 * This method is used by all secure resource modules to send responses to REST queries.
49 * @param ehRequest pointer to entity handler request data structure.
50 * @param ehRet result code from entity handler.
51 * @param rspPayload response payload in JSON.
53 * @retval OC_STACK_OK for Success, otherwise some error value
55 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
56 OCEntityHandlerResult ehRet, const char *rspPayload)
58 OIC_LOG (DEBUG, TAG, "SRM sending SRM response");
59 OCEntityHandlerResponse response = {.requestHandle = NULL};
62 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
64 response.requestHandle = ehRequest->requestHandle;
65 response.resourceHandle = ehRequest->resource;
66 response.ehResult = ehRet;
67 response.payload = (OCPayload*)(&ocPayload);
68 response.payload->type = PAYLOAD_TYPE_SECURITY;
69 ((OCSecurityPayload*)response.payload)->securityData = (char *)rspPayload;
70 response.persistentBufferFlag = 0;
72 return OCDoResponse(&response);
74 return OC_STACK_ERROR;
78 * Initialize all secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc).
80 * @retval OC_STACK_OK for Success, otherwise some error value
82 OCStackResult InitSecureResources( )
87 * doxm resource should be initialized first as it contains the DeviceID
88 * which MAY be used during initialization of other resources.
91 ret = InitDoxmResource();
93 if(OC_STACK_OK == ret)
95 ret = InitPstatResource();
97 if(OC_STACK_OK == ret)
99 ret = InitACLResource();
101 if(OC_STACK_OK == ret)
103 ret = InitCredResource();
106 if(OC_STACK_OK == ret)
108 ret = InitCRLResource();
110 #endif // __WITH_X509__
111 if(OC_STACK_OK == ret)
113 ret = InitSVCResource();
115 if(OC_STACK_OK == ret)
117 ret = InitAmaclResource();
119 //#ifdef DIRECT_PAIRING
120 if(OC_STACK_OK == ret)
122 ret = InitPconfResource();
124 if(OC_STACK_OK == ret)
126 ret = InitDpairingResource();
128 //#endif // DIRECT_PAIRING
129 if(OC_STACK_OK != ret)
131 //TODO: Update the default behavior if one of the SVR fails
132 DestroySecureResources();
138 * Perform cleanup for secure resources ( /oic/sec/cred, /oic/sec/acl, /oic/sec/pstat etc).
140 * @retval OC_STACK_OK for Success, otherwise some error value
142 OCStackResult DestroySecureResources( )
145 DeInitCredResource();
146 DeInitDoxmResource();
147 DeInitPstatResource();
150 #endif // __WITH_X509__
152 DeInitAmaclResource();
153 //#ifdef DIRECT_PAIRING
154 DeInitPconfResource();
155 DeInitDpairingResource();
156 //#endif // DIRECT_PAIRING