2016-03-23 01:53:39 +03:00
|
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <uuid/uuid.h>
|
2019-10-28 08:47:39 +03:00
|
|
|
|
|
|
|
#include "azure_macro_utils/macro_utils.h"
|
2016-04-06 06:50:09 +03:00
|
|
|
#include "azure_c_shared_utility/uniqueid.h"
|
2016-06-20 19:55:56 +03:00
|
|
|
#include "azure_c_shared_utility/xlogging.h"
|
2016-03-23 01:53:39 +03:00
|
|
|
|
2019-02-22 21:28:19 +03:00
|
|
|
MU_DEFINE_ENUM_STRINGS(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES);
|
2016-03-23 01:53:39 +03:00
|
|
|
|
|
|
|
UNIQUEID_RESULT UniqueId_Generate(char* uid, size_t len)
|
|
|
|
{
|
|
|
|
UNIQUEID_RESULT result;
|
|
|
|
|
|
|
|
/* Codes_SRS_UNIQUEID_07_002: [If uid is NULL then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */
|
|
|
|
/* Codes_SRS_UNIQUEID_07_003: [If len is less then 37 then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */
|
|
|
|
if (uid == NULL || len < 37)
|
|
|
|
{
|
|
|
|
result = UNIQUEID_INVALID_ARG;
|
2019-10-28 08:47:39 +03:00
|
|
|
LogError("Buffer Size is Null. (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UNIQUEID_RESULT, result));
|
2016-03-23 01:53:39 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uuid_t uuidVal;
|
|
|
|
uuid_generate(uuidVal);
|
|
|
|
|
|
|
|
/* Codes_SRS_UNIQUEID_07_001: [UniqueId_Generate shall create a unique Id 36 character long string.] */
|
|
|
|
memset(uid, 0, len);
|
|
|
|
uuid_unparse(uuidVal, uid);
|
2016-03-23 18:34:20 +03:00
|
|
|
result = UNIQUEID_OK;
|
2016-03-23 01:53:39 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|