replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / include / OCCloudProvisioning.hpp
1 //****************************************************************\r
2 //\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.\r
4 //\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
6 //\r
7 // Licensed under the Apache License, Version 2.0 (the "License");\r
8 // you may not use this file except in compliance with the License.\r
9 // You may obtain a copy of the License at\r
10 //\r
11 //     http://www.apache.org/licenses/LICENSE-2.0\r
12 //\r
13 // Unless required by applicable law or agreed to in writing, software\r
14 // distributed under the License is distributed on an "AS IS" BASIS,\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16 // See the License for the specific language governing permissions and\r
17 // limitations under the License.\r
18 //\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
20 \r
21 #ifndef OC_CLOUD_PROVISIONING_CXX_H_\r
22 #define OC_CLOUD_PROVISIONING_CXX_H_\r
23 \r
24 #include <thread>\r
25 \r
26 #ifndef __APPLE__\r
27 #include "occloudprovisioning.h"\r
28 #else\r
29 #include "../csdk/security/provisioning/include/cloud/occloudprovisioning.h"\r
30 #endif\r
31 #include "OCApi.h"\r
32 #include "OCPlatform_impl.h"\r
33 #include "CAManager.h"\r
34 \r
35 namespace OC\r
36 {\r
37     typedef std::function<void(OCStackResult result, void *data)> ResponseCallBack;\r
38     typedef std::function<void(OCStackResult result, std::string aclId)> AclIdResponseCallBack;\r
39 \r
40     /**\r
41      * Context to be passed to the underlying stack. This is passed back as argument\r
42      * to the callback function\r
43      */\r
44     struct CloudProvisionContext\r
45     {\r
46         ResponseCallBack callback;\r
47         CloudProvisionContext(ResponseCallBack cb) : callback(cb){}\r
48     };\r
49 \r
50     struct AclIdContext\r
51     {\r
52         AclIdResponseCallBack callback;\r
53         AclIdContext(AclIdResponseCallBack cb) : callback(cb){}\r
54     };\r
55 \r
56     class OCCloudProvisioning\r
57     {\r
58 \r
59         private:\r
60             OCDevAddr  m_devAddr;\r
61         public:\r
62 \r
63             /**\r
64              * API to construct the CloudProvisioning\r
65              * @param ipAddr address of the cloud server\r
66              * @param port port of the cloud server\r
67              */\r
68             OCCloudProvisioning(std::string& ipAddr, uint16_t port);\r
69             ~OCCloudProvisioning();\r
70 \r
71             void setIpAddr(std::string& ipAddr)\r
72             {\r
73                 memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);\r
74             }\r
75 \r
76             void setPort(uint16_t port)\r
77             {\r
78                 m_devAddr.port = port;\r
79             }\r
80 \r
81             /**\r
82              * API to Request a certificate from the cloud\r
83              * @param callback function called by the stack on completion of request\r
84              * @return ::OC_STACK_OK on Success and other values otherwise\r
85              */\r
86             OCStackResult requestCertificate(ResponseCallBack callback);\r
87 \r
88             /**\r
89              * API to get ACL ID for the device\r
90              * @param deviceId device ID for which the Acl ID is requested\r
91              * @param callback function called by the stack on completion of request\r
92              * @return ::OC_STACK_OK on Success and other values otherwise\r
93              */\r
94             OCStackResult getAclIdByDevice(const std::string& deviceId, AclIdResponseCallBack callback);\r
95 \r
96             /**\r
97              * API to get ACL information about the given Acl ID\r
98              * @param aclId ACL ID for which the Acl information is requested\r
99              * @param callback function called by the stack on completion of request\r
100              * @return ::OC_STACK_OK on Success and other values otherwise\r
101              */\r
102             OCStackResult getIndividualAclInfo(const std::string& aclId, ResponseCallBack callback);\r
103 \r
104             /**\r
105              * API to get certificate revocation list\r
106              * @param callback function called by the stack on completion of request\r
107              * @return ::OC_STACK_OK on Success and other values otherwise\r
108              */\r
109             OCStackResult getCRL(ResponseCallBack callback);\r
110 \r
111             /**\r
112              * API to post the  certificate revocation list to cloud\r
113              * @param thisUpdate thisUpdate [mandatory param]\r
114              * @param nextUpdate nextUpdate [mandatory param]\r
115              * @param crl revocation list [optional]\r
116              * @param serialNumbers [optional]\r
117              * @param callback function called by the stack on completion of request\r
118              * @return ::OC_STACK_OK on Success and other values otherwise\r
119              */\r
120             OCStackResult postCRL(const std::string& thisUpdate,\r
121                     const std::string& nextUpdate,\r
122                     const OCByteString *crl,\r
123                     const stringArray_t *serialNumbers,\r
124                     ResponseCallBack callback);\r
125 \r
126             /**\r
127              * Common callback wrapper for all the callback functions.\r
128              * @param ctx user context passed to the request API\r
129              * @param result result of the request performed\r
130              * @param data response data\r
131              */\r
132             static void callbackWrapper(void* ctx, OCStackResult result, void* data);\r
133 \r
134             /**\r
135              * Callback wrapper for Acl ID get request\r
136              * @param ctx user context passed to the request API\r
137              * @param result result of the request performed\r
138              * @param data AclID for the device\r
139              */\r
140             static void aclIdResponseWrapper(void* ctx, OCStackResult result, void* data);\r
141     };\r
142 }\r
143 #endif //OC_CLOUD_PROVISIONING_CXX_H_\r