Merge branch 'security-basecamp' into master
[platform/upstream/iotivity.git] / resource / csdk / security / include / srmutility.h
index 34f3237..9230ef6 100644 (file)
 #define IOTVT_SRM_UTILITY_H
 
 #include "ocstack.h"
-#include "uthash.h"
+#include "cJSON.h"
+#include "securevirtualresourcetypes.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+#include "uri.h"
+#ifdef __cplusplus
+}
+#endif
+
 
 #ifdef __cplusplus
 extern "C" {
 #endif // __cplusplus
 
+
+typedef struct OicParseQueryIter OicParseQueryIter_t;
+
+/**
+ * @brief   OicRestQueryIter data structure is used for book-keeping
+ *          sub-REST query's attribute's and value's, starting location &
+ *          length between calls to GetNextQuery(). This struct needs
+ *          to be first initialized with ParseQueryIterInit().
+ *
+ */
+struct OicParseQueryIter
+{
+    unsigned char * attrPos;    /**<stating location of attribute */
+    size_t attrLen;             /**<length of the attribute */
+    unsigned char * valPos;     /**<starting location of value*/
+    size_t valLen;              /**<length of the value*/
+    coap_parse_iterator_t pi;   /**<coap struct for tokenizing the query*/
+};
+
 /**
  * @def VERIFY_SUCCESS
  * @brief Macro to verify success of operation.
@@ -35,8 +64,8 @@ extern "C" {
  * @note Invoking function must define "exit:" label for goto functionality to work correctly.
  *
  */
-#define VERIFY_SUCCESS(tag, op, logLevel) { if (!(op)) \
-            {OC_LOG((logLevel), tag, PCF(#op " failed!!")); goto exit;} }
+#define VERIFY_SUCCESS(tag, op, logLevel) do{ if (!(op)) \
+            {OC_LOG((logLevel), tag, PCF(#op " failed!!")); goto exit; } }while(0)
 
 /**
  * @def VERIFY_NON_NULL
@@ -45,9 +74,45 @@ extern "C" {
  * @note Invoking function must define "exit:" label for goto functionality to work correctly.
  *
  */
-#define VERIFY_NON_NULL(tag, arg, logLevel) { if (NULL == (arg)) \
-            { OC_LOG((logLevel), tag, PCF(#arg " is NULL")); goto exit; } }
+#define VERIFY_NON_NULL(tag, arg, logLevel) do{ if (NULL == (arg)) \
+            { OC_LOG((logLevel), tag, PCF(#arg " is NULL")); goto exit; } }while(0)
 
+/**
+ * This method initializes the OicParseQueryIter_t struct
+ *
+ *@param query     - REST query, to be parsed
+ *@param parseIter - OicParseQueryIter_t struct, to be initialized
+ *
+ */
+void ParseQueryIterInit(unsigned char * query, OicParseQueryIter_t * parseIter);
+
+
+/**
+ * This method fills the OicParseQueryIter_t struct with next REST query's
+ * attribute's and value's information
+ *
+ *@param parseIter - OicParseQueryIter_t struct, has next query's attribute's & value's info
+ *
+ * @retval
+ *     OicParseQueryIter_t *  - has parsed query info
+ *     NULL                   - has no query to parse
+ */
+OicParseQueryIter_t * GetNextQuery(OicParseQueryIter_t * parseIter);
+
+
+
+/**
+ * This method acts as a helper funtion for JSON unmarshalling by various SVR's.
+ *
+ * @param jsonRoot  - root JSON node containing the OicUuid array
+ * @param arrayItem - name of the JSON OicUuid array item
+ * @param numUuids  - pointer to the number of OicUuid's available in JSON array
+ * @param uuids     - pointer to the array of OicUuid's
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult AddUuidArray(cJSON* jsonRoot, const char* arrayItem,
+                           size_t *numUuids, OicUuid_t** uuids );
 
 #ifdef __cplusplus
 }