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
35 #include "securevirtualresourcetypes.h"
44 * Macro to verify the validity of cbor operation.
46 #define VERIFY_CBOR_SUCCESS(log_tag, err, log_message) \
47 if ((CborNoError != (err)) && (CborErrorOutOfMemory != (err))) \
49 if ((log_tag) && (log_message)) \
51 OIC_LOG_V(ERROR, (log_tag), "%s with cbor error: \'%s\'.", \
52 (log_message), (cbor_error_string(err))); \
57 #define VERIFY_PARAM_NON_NULL(log_tag, err, log_message) \
60 OIC_LOG_V(FATAL, (log_tag), "%s", (log_message)); \
65 typedef struct OCResource OCResource;
67 void OCPayloadDestroy(OCPayload* payload);
69 // Representation Payload
70 OCRepPayload* OCRepPayloadCreate();
72 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
74 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
76 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
78 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
80 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
81 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* iface);
82 bool OCRepPayloadAddModelVersion(OCRepPayload* payload, const char* dmv);
84 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
85 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* iface);
87 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
88 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
90 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
91 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
93 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
94 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
97 * This function allocates memory for the byte string and sets it in the payload.
99 * @param payload Pointer to the payload to which byte string needs to be added.
100 * @param name Name of the byte string.
101 * @param value Byte string and it's length.
103 * @return true on success, false upon failure.
105 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
108 * This function sets the byte string in the payload.
110 * @param payload Pointer to the payload to which byte string needs to be added.
111 * @param name Name of the byte string.
112 * @param value Byte string and it's length.
114 * @return true on success, false upon failure.
116 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
117 OCByteString* value);
120 * This function gets the byte string from the payload.
122 * @param payload Pointer to the payload from which byte string needs to be retrieved.
123 * @param name Name of the byte string.
124 * @param value Byte string and it's length.
126 * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
128 * @return true on success, false upon failure.
130 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
131 OCByteString* value);
133 bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value);
134 bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value);
135 bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value);
137 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
138 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
140 bool OCRepPayloadSetPropObject(OCRepPayload* payload, const char* name, const OCRepPayload* value);
141 bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name, OCRepPayload* value);
142 bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value);
145 bool OCRepPayloadSetPropPubDataType(OCRepPayload *payload, const char *name, const OicSecKey_t *value);
146 bool OCRepPayloadSetPropPubDataTypeAsOwner(OCRepPayload *payload, const char *name, const OicSecKey_t *value);
147 bool OCRepPayloadGetPropPubDataType(const OCRepPayload *payload, const char *name, OicSecKey_t *value);
151 * This function allocates memory for the byte string array and sets it in the payload.
153 * @param payload Pointer to the payload to which byte string array needs to be added.
154 * @param name Name of the byte string.
155 * @param array Byte string array.
156 * @param dimensions Number of byte strings in above array.
158 * @return true on success, false upon failure.
160 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
161 OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
164 * This function sets the byte string array in the payload.
166 * @param payload Pointer to the payload to which byte string array needs to be added.
167 * @param name Name of the byte string.
168 * @param array Byte string array.
169 * @param dimensions Number of byte strings in above array.
171 * @return true on success, false upon failure.
173 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
174 const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
177 * This function gets the byte string array from the payload.
179 * @param payload Pointer to the payload from which byte string array needs to be retrieved.
180 * @param name Name of the byte string array.
181 * @param value Byte string array.
182 * @param dimensions Number of byte strings in above array.
184 * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
185 * finished using the byte string array.
187 * @return true on success, false upon failure.
189 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
190 OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
192 bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name,
193 int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
194 bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name,
195 const int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
196 bool OCRepPayloadGetIntArray(const OCRepPayload* payload, const char* name,
197 int64_t** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
199 bool OCRepPayloadSetDoubleArrayAsOwner(OCRepPayload* payload, const char* name,
200 double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
201 bool OCRepPayloadSetDoubleArray(OCRepPayload* payload, const char* name,
202 const double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
203 bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name,
204 double** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
206 bool OCRepPayloadSetStringArrayAsOwner(OCRepPayload* payload, const char* name,
207 char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
208 bool OCRepPayloadSetStringArray(OCRepPayload* payload, const char* name,
209 const char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
210 bool OCRepPayloadGetStringArray(const OCRepPayload* payload, const char* name,
211 char*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
213 bool OCRepPayloadSetBoolArrayAsOwner(OCRepPayload* payload, const char* name,
214 bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
215 bool OCRepPayloadSetBoolArray(OCRepPayload* payload, const char* name,
216 const bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
217 bool OCRepPayloadGetBoolArray(const OCRepPayload* payload, const char* name,
218 bool** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
220 bool OCRepPayloadSetPropObjectArrayAsOwner(OCRepPayload* payload, const char* name,
221 OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
222 bool OCRepPayloadSetPropObjectArray(OCRepPayload* payload, const char* name,
223 const OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
224 bool OCRepPayloadGetPropObjectArray(const OCRepPayload* payload, const char* name,
225 OCRepPayload*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
227 void OCRepPayloadDestroy(OCRepPayload* payload);
230 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
232 OCSecurityPayload* OCSecurityPayloadCreate(const uint8_t* securityData, size_t size);
233 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
236 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
237 uint16_t securePort);
239 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
240 uint16_t securePort, uint16_t tcpPort);
242 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
243 bool OCResourcePayloadAddStringLL(OCStringLL **payload, const char* type);
245 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
246 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
248 void OCDiscoveryResourceDestroy(OCResourcePayload* payload);
249 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
252 OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
253 const OCStringLL *types, const char* specVer, const char* dmVer);
254 void OCDevicePayloadDestroy(OCDevicePayload* payload);
257 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
258 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
259 void OCPlatformInfoDestroy(OCPlatformInfo *info);
260 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
263 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
264 OCPresenceTrigger trigger, const char* resourceType);
265 void OCPresencePayloadDestroy(OCPresencePayload* payload);
268 OCStringLL* CloneOCStringLL (OCStringLL* ll);
269 void OCFreeOCStringLL(OCStringLL* ll);
272 * This function creates a list from a string (with separated contents if several)
273 * @param text single string or CSV text fields
274 * @return newly allocated linked list
275 * @note separator is ',' (according to rfc4180, ';' is not valid)
277 OCStringLL* OCCreateOCStringLL(const char* text);
280 * This function creates a string from a list (with separated contents if several)
281 * @param ll Pointer to list
282 * @return newly allocated string
283 * @note separator is ',' (according to rfc4180)
285 char* OCCreateString(const OCStringLL* ll);
288 * This function copies contents (and allocates if necessary)
289 * @param dest existing bytestring (or null to allocate here)
290 * @param source existing bytestring
291 * @return true of success false on any errors
293 bool OCByteStringCopy(OCByteString *dest, const OCByteString *source);