replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / src / cloud / aclid.c
index e2424db..20da886 100644 (file)
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "pmutility.h"
-#include "srmutility.h"
 #include "cacommonutil.h"
 #include "aclresource.h"
 #include "ocpayloadcbor.h"
 #include "payload_logging.h"
 #include "utlist.h"
+#include "securevirtualresourcetypes.h"
 
 #define TAG "OIC_CLOUD_ACL_ID"
 
+/* Although this is already implemented in srmutility.h, we can't include the header file,
+ * because of "redefined VERIFY_NON_NULL"
+ */
+OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid);
+
 /**
  * ACL Id parse from received response
  *
@@ -546,3 +551,33 @@ OCStackResult OCCloudAclIndividualDeleteAce(void* ctx,
                         CT_ADAPTER_TCP, OC_LOW_QOS, &cbData, NULL, 0);
 }
 
+OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
+{
+    if (NULL == uuid || NULL == strUuid || NULL != *strUuid)
+    {
+        OIC_LOG(ERROR, TAG, "ConvertUuidToStr : Invalid param");
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    size_t uuidIdx = 0;
+    size_t urnIdx = 0;
+    const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
+    char *convertedUrn = (char*)OICCalloc(urnBufSize, sizeof(char));
+    VERIFY_NON_NULL(convertedUrn, TAG, "OICCalloc() is failed(convertedUrn)");
+
+    for (uuidIdx = 0, urnIdx = 0; uuidIdx < UUID_LENGTH && urnIdx < urnBufSize;
+            uuidIdx++, urnIdx += 2)
+    {
+        // canonical format for UUID has '8-4-4-4-12'
+        if (4 == uuidIdx || 6 == uuidIdx || 8 == uuidIdx || 10 == uuidIdx)
+        {
+            snprintf(convertedUrn + urnIdx, 2, "%c", '-');
+            urnIdx++;
+        }
+        snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
+    }
+    convertedUrn[urnBufSize - 1] = '\0';
+
+    *strUuid = convertedUrn;
+    return OC_STACK_OK;
+}