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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 #ifndef __STDC_FORMAT_MACROS
25 #define __STDC_FORMAT_MACROS
27 #ifndef __STDC_LIMIT_MACROS
28 #define __STDC_LIMIT_MACROS
36 #if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
37 #include "securevirtualresourcetypes.h"
46 * Macro to verify the validity of cbor operation.
48 #define VERIFY_CBOR_SUCCESS(log_tag, err, log_message) \
49 if ((CborNoError != (err)) && (CborErrorOutOfMemory != (err))) \
51 if ((log_tag) && (log_message)) \
53 OIC_LOG_V(ERROR, (log_tag), "%s with cbor error: \'%s\'.", \
54 (log_message), (cbor_error_string(err))); \
59 #define VERIFY_PARAM_NON_NULL(log_tag, err, log_message) \
62 OIC_LOG_V(FATAL, (log_tag), "%s", (log_message)); \
67 typedef struct OCResource OCResource;
69 void OCPayloadDestroy(OCPayload* payload);
71 // Representation Payload
72 OCRepPayload* OCRepPayloadCreate();
74 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
76 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
78 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
80 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
82 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
83 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* iface);
84 bool OCRepPayloadAddModelVersion(OCRepPayload* payload, const char* dmv);
86 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
87 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* iface);
89 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
90 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
92 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
93 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
95 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
96 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
99 * This function allocates memory for the byte string and sets it in the payload.
101 * @param payload Pointer to the payload to which byte string needs to be added.
102 * @param name Name of the byte string.
103 * @param value Byte string and it's length.
105 * @return true on success, false upon failure.
107 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
110 * This function sets the byte string in the payload.
112 * @param payload Pointer to the payload to which byte string needs to be added.
113 * @param name Name of the byte string.
114 * @param value Byte string and it's length.
116 * @return true on success, false upon failure.
118 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
119 OCByteString* value);
122 * This function gets the byte string from the payload.
124 * @param payload Pointer to the payload from which byte string needs to be retrieved.
125 * @param name Name of the byte string.
126 * @param value Byte string and it's length.
128 * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
130 * @return true on success, false upon failure.
132 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
133 OCByteString* value);
135 bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value);
136 bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value);
137 bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value);
139 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
140 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
142 bool OCRepPayloadSetPropObject(OCRepPayload* payload, const char* name, const OCRepPayload* value);
143 bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name, OCRepPayload* value);
144 bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value);
147 bool OCRepPayloadSetPropPubDataType(OCRepPayload *payload, const char *name, const OicSecKey_t *value);
148 bool OCRepPayloadSetPropPubDataTypeAsOwner(OCRepPayload *payload, const char *name, const OicSecKey_t *value);
149 bool OCRepPayloadGetPropPubDataType(const OCRepPayload *payload, const char *name, OicSecKey_t *value);
153 * This function allocates memory for the byte string array and sets it in the payload.
155 * @param payload Pointer to the payload to which byte string array needs to be added.
156 * @param name Name of the byte string.
157 * @param array Byte string array.
158 * @param dimensions Number of byte strings in above array.
160 * @return true on success, false upon failure.
162 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
163 OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
166 * This function sets the byte string array in the payload.
168 * @param payload Pointer to the payload to which byte string array needs to be added.
169 * @param name Name of the byte string.
170 * @param array Byte string array.
171 * @param dimensions Number of byte strings in above array.
173 * @return true on success, false upon failure.
175 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
176 const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
179 * This function gets the byte string array from the payload.
181 * @param payload Pointer to the payload from which byte string array needs to be retrieved.
182 * @param name Name of the byte string array.
183 * @param value Byte string array.
184 * @param dimensions Number of byte strings in above array.
186 * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
187 * finished using the byte string array.
189 * @return true on success, false upon failure.
191 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
192 OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
194 bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name,
195 int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
196 bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name,
197 const int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
198 bool OCRepPayloadGetIntArray(const OCRepPayload* payload, const char* name,
199 int64_t** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
201 bool OCRepPayloadSetDoubleArrayAsOwner(OCRepPayload* payload, const char* name,
202 double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
203 bool OCRepPayloadSetDoubleArray(OCRepPayload* payload, const char* name,
204 const double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
205 bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name,
206 double** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
208 bool OCRepPayloadSetStringArrayAsOwner(OCRepPayload* payload, const char* name,
209 char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
210 bool OCRepPayloadSetStringArray(OCRepPayload* payload, const char* name,
211 const char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
212 bool OCRepPayloadGetStringArray(const OCRepPayload* payload, const char* name,
213 char*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
215 bool OCRepPayloadSetBoolArrayAsOwner(OCRepPayload* payload, const char* name,
216 bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
217 bool OCRepPayloadSetBoolArray(OCRepPayload* payload, const char* name,
218 const bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
219 bool OCRepPayloadGetBoolArray(const OCRepPayload* payload, const char* name,
220 bool** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
222 bool OCRepPayloadSetPropObjectArrayAsOwner(OCRepPayload* payload, const char* name,
223 OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
224 bool OCRepPayloadSetPropObjectArray(OCRepPayload* payload, const char* name,
225 const OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
226 bool OCRepPayloadGetPropObjectArray(const OCRepPayload* payload, const char* name,
227 OCRepPayload*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
229 void OCRepPayloadDestroy(OCRepPayload* payload);
232 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
234 OCSecurityPayload* OCSecurityPayloadCreate(const uint8_t* securityData, size_t size);
235 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
238 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
239 uint16_t securePort);
241 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
242 uint16_t securePort, uint16_t tcpPort);
244 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
245 bool OCResourcePayloadAddStringLL(OCStringLL **payload, const char* type);
247 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
248 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
250 void OCDiscoveryResourceDestroy(OCResourcePayload* payload);
251 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
254 OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
255 const OCStringLL *types, const char* specVer, const char* dmVer);
256 void OCDevicePayloadDestroy(OCDevicePayload* payload);
259 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
260 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
261 void OCPlatformInfoDestroy(OCPlatformInfo *info);
262 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
265 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
266 OCPresenceTrigger trigger, const char* resourceType);
267 void OCPresencePayloadDestroy(OCPresencePayload* payload);
270 OCStringLL* CloneOCStringLL (OCStringLL* ll);
271 void OCFreeOCStringLL(OCStringLL* ll);
274 * This function creates a list from a string (with separated contents if several)
275 * @param text single string or CSV text fields
276 * @return newly allocated linked list
277 * @note separator is ',' (according to rfc4180, ';' is not valid)
279 OCStringLL* OCCreateOCStringLL(const char* text);
282 * This function creates a string from a list (with separated contents if several)
283 * @param ll Pointer to list
284 * @return newly allocated string
285 * @note separator is ',' (according to rfc4180)
287 char* OCCreateString(const OCStringLL* ll);
290 * This function copies contents (and allocates if necessary)
291 * @param dest existing bytestring (or null to allocate here)
292 * @param source existing bytestring
293 * @return true of success false on any errors
295 bool OCByteStringCopy(OCByteString *dest, const OCByteString *source);