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 #ifndef IOTVT_SRM_UTILITY_H
22 #define IOTVT_SRM_UTILITY_H
25 #if defined (__TIZENRT__)
26 #include <apps/netutils/cJSON.h>
30 #include "securevirtualresourcetypes.h"
44 typedef struct OicParseQueryIter OicParseQueryIter_t;
47 * OicRestQueryIter data structure is used for book-keeping
48 * sub-REST query's attribute's and value's, starting location &
49 * length between calls to GetNextQuery(). This struct needs
50 * to be first initialized with ParseQueryIterInit().
53 struct OicParseQueryIter
55 unsigned char * attrPos; /**< stating location of attribute. */
56 size_t attrLen; /**< length of the attribute. */
57 unsigned char * valPos; /**< starting location of value. */
58 size_t valLen; /**< length of the value. */
59 coap_parse_iterator_t pi; /**< coap struct for tokenizing the query.*/
62 typedef enum OicSecOtmEvent{
70 * Callback function to recevie the OTM event on server side.
72 * @param addr PT's address (address can be NULL in case of init state)
73 * @param port PT's port (It is meaningless in case of init state & BLE)
74 * @param uuid PT's UUID (UUID can be NULL in case of init state & coap reqest)
75 * @param event OTM state (@ref OicSecOtmEvent_t)
77 typedef void (*OicSecOtmEventHandler_t)(const char* addr, uint16_t port,
78 const char* uuid, int event);
81 * Macro to verify success of operation.
82 * eg: VERIFY_SUCCESS(TAG, OC_STACK_OK == foo(), ERROR);
83 * @note Invoking function must define "exit:" label for goto functionality to work correctly.
85 #define VERIFY_SUCCESS(tag, op, logLevel) do{ if (!(op)) \
86 {OIC_LOG((logLevel), tag, #op " failed!!"); goto exit; } }while(0)
89 * Macro to verify argument is not equal to NULL.
90 * eg: VERIFY_NON_NULL(TAG, ptrData, ERROR);
91 * @note Invoking function must define "exit:" label for goto functionality to work correctly.
93 #define VERIFY_NON_NULL(tag, arg, logLevel) do{ if (NULL == (arg)) \
94 { OIC_LOG((logLevel), tag, #arg " is NULL"); goto exit; } }while(0)
97 * This method initializes the @ref OicParseQueryIter_t struct.
99 * @param query is the REST query, to be parsed.
100 * @param parseIter is the @ref OicParseQueryIter_t struct, to be initialized based on the query.
102 void ParseQueryIterInit(const unsigned char * query, OicParseQueryIter_t * parseIter);
105 * This method fills the @ref OicParseQueryIter_t struct with next REST query's
106 * attribute's and value's information.
108 * @param parseIter is the @ref OicParseQueryIter_t struct, has next query's attribute's
111 * @return reference to the @ref OicParseQueryIter_t if it has parsed query info, else
112 * NULL if it has no query to parse.
114 OicParseQueryIter_t * GetNextQuery(OicParseQueryIter_t * parseIter);
117 * This method acts as a helper function for JSON unmarshalling by various SVR's.
119 * @param jsonRoot point to the root JSON node containing the OicUuid array.
120 * @param arrayItem is the name of the JSON OicUuid array item.
121 * @param numUuids is the pointer to the number of OicUuid's available in JSON array.
122 * @param uuids is the pointer to the array of OicUuid's.
124 * @return ::OC_STACK_OK on success, some other value upon failure.
126 OCStackResult AddUuidArray(const cJSON* jsonRoot, const char* arrayItem,
127 size_t *numUuids, OicUuid_t** uuids);
130 * Function to getting string of ownership transfer method
132 * @prarm oxmType ownership transfer method
134 * @return string value of ownership transfer method
136 const char* GetOxmString(OicSecOxm_t oxmType);
139 * This method converts UUID to canonical format string.
141 * @param uuid Device UUID
142 * @param strUuid converted UUID in canonical format
143 * @return OC_STACK_OK for success.
145 * @note Caller needs to invoke OICFree after done using the return pointer
147 OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid);
151 * This method converts string UUID to OicUuid_t.
153 * @param strUuid Device UUID in string format
154 * @param uuid converted UUID in OicUuid_t format
155 * @return OC_STACK_OK for success.
158 OCStackResult ConvertStrToUuid(const char* strUuid, OicUuid_t* uuid);
161 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
163 * API to save the seed value to generate device UUID.
165 * @param seed buffer of seed value.
166 * @param seedSize byte length of seed
168 * @return ::OC_STACK_OK for Success, otherwise some error value.
170 OCStackResult SetDeviceIdSeed(const uint8_t* seed, size_t seedSize);
173 * API to register OTM event handler
175 * @param otmEventHandler implementation of OTM event handler (@ref OicSecOtmEventHandler_t)
177 void SetOtmEventHandler(OicSecOtmEventHandler_t otmEventHandler);
180 * Invoke OTM event handler to notify the OTM state.
182 * @param addr PT's address (address can be NULL in case of init state)
183 * @param port PT's port (It is meaningless in case of init state & BLE)
184 * @param uuid PT's UUID (UUID can be NULL in case of init state & coap reqest)
185 * @param event OTM state (@ref OicSecOtmEvent_t)
186 * @param result OTM result code
188 void InvokeOtmEventHandler(const char* addr, uint16_t port,
189 const OicUuid_t* uuid, OicSecOtmEvent_t event);
194 #endif // __cplusplus
196 #endif //IOTVT_SRM_UTILITY_H