summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-06 09:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-06 13:47:18 +0000
commit3ef61c73a97b31000a21e323e04ad5397e517c4c (patch)
tree516534f41936adbf4eb2f1ba447508847ef98dac
parent555b31faa192c7a85c84979bea28d4914e93c784 (diff)
downloadpdfium-3ef61c73a97b31000a21e323e04ad5397e517c4c.tar.xz
GUID cleanup
This CL removes fx_guid and inlines into CXFA_FM2JSContext as needed. Change-Id: I08a1f03fd4be46730eee24ab73b8b5c0daf9cd7d Reviewed-on: https://pdfium-review.googlesource.com/13094 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--BUILD.gn2
-rw-r--r--core/fxcrt/fx_guid.cpp30
-rw-r--r--core/fxcrt/fx_guid.h22
-rw-r--r--core/fxcrt/fx_random.cpp52
-rw-r--r--core/fxcrt/fx_random.h2
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp25
6 files changed, 46 insertions, 87 deletions
diff --git a/BUILD.gn b/BUILD.gn
index ec37644f0f..6b4ff62bfd 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -942,8 +942,6 @@ static_library("fxcrt") {
"core/fxcrt/css/cfx_cssvaluelistparser.h",
"core/fxcrt/fx_arabic.cpp",
"core/fxcrt/fx_arabic.h",
- "core/fxcrt/fx_guid.cpp",
- "core/fxcrt/fx_guid.h",
"core/fxcrt/ifx_chariter.h",
"core/fxcrt/ifx_locale.h",
"core/fxcrt/xml/cfx_saxcontext.cpp",
diff --git a/core/fxcrt/fx_guid.cpp b/core/fxcrt/fx_guid.cpp
deleted file mode 100644
index 4d3a4e9a5f..0000000000
--- a/core/fxcrt/fx_guid.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcrt/fx_guid.h"
-
-#include "core/fxcrt/fx_extension.h"
-#include "core/fxcrt/fx_random.h"
-
-void FX_GUID_CreateV4(FX_GUID* pGUID) {
- FX_Random_GenerateMT((uint32_t*)pGUID, 4);
- uint8_t& b = ((uint8_t*)pGUID)[6];
- b = (b & 0x0F) | 0x40;
-}
-
-CFX_ByteString FX_GUID_ToString(const FX_GUID* pGUID, bool bSeparator) {
- CFX_ByteString bsStr;
- char* pBuf = bsStr.GetBuffer(40);
- for (int32_t i = 0; i < 16; i++) {
- uint8_t b = reinterpret_cast<const uint8_t*>(pGUID)[i];
- FXSYS_IntToTwoHexChars(b, pBuf);
- pBuf += 2;
- if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9))
- *pBuf++ = L'-';
- }
- bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
- return bsStr;
-}
diff --git a/core/fxcrt/fx_guid.h b/core/fxcrt/fx_guid.h
deleted file mode 100644
index e80efc4ca1..0000000000
--- a/core/fxcrt/fx_guid.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCRT_FX_GUID_H_
-#define CORE_FXCRT_FX_GUID_H_
-
-#include "core/fxcrt/fx_string.h"
-
-struct FX_GUID {
- uint32_t data1;
- uint16_t data2;
- uint16_t data3;
- uint8_t data4[8];
-};
-
-void FX_GUID_CreateV4(FX_GUID* pGUID);
-CFX_ByteString FX_GUID_ToString(const FX_GUID* pGUID, bool bSeparator = true);
-
-#endif // CORE_FXCRT_FX_GUID_H_
diff --git a/core/fxcrt/fx_random.cpp b/core/fxcrt/fx_random.cpp
index 4d8fc0efcf..866a7a97ef 100644
--- a/core/fxcrt/fx_random.cpp
+++ b/core/fxcrt/fx_random.cpp
@@ -49,6 +49,30 @@ bool GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount) {
}
#endif
+void Random_GenerateBase(uint32_t* pBuffer, int32_t iCount) {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+ SYSTEMTIME st1, st2;
+ ::GetSystemTime(&st1);
+ do {
+ ::GetSystemTime(&st2);
+ } while (memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0);
+ uint32_t dwHash1 =
+ FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true);
+ uint32_t dwHash2 =
+ FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true);
+ ::srand((dwHash1 << 16) | (uint32_t)dwHash2);
+#else
+ time_t tmLast = time(nullptr);
+ time_t tmCur;
+ while ((tmCur = time(nullptr)) == tmLast)
+ continue;
+
+ ::srand((tmCur << 16) | (tmLast & 0xFFFF));
+#endif
+ while (iCount-- > 0)
+ *pBuffer++ = static_cast<uint32_t>((::rand() << 16) | (::rand() & 0xFFFF));
+}
+
} // namespace
void* FX_Random_MT_Start(uint32_t dwSeed) {
@@ -105,9 +129,9 @@ void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount) {
uint32_t dwSeed;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
if (!GenerateCryptoRandom(&dwSeed, 1))
- FX_Random_GenerateBase(&dwSeed, 1);
+ Random_GenerateBase(&dwSeed, 1);
#else
- FX_Random_GenerateBase(&dwSeed, 1);
+ Random_GenerateBase(&dwSeed, 1);
#endif
void* pContext = FX_Random_MT_Start(dwSeed);
while (iCount-- > 0)
@@ -115,27 +139,3 @@ void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount) {
FX_Random_MT_Close(pContext);
}
-
-void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount) {
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
- SYSTEMTIME st1, st2;
- ::GetSystemTime(&st1);
- do {
- ::GetSystemTime(&st2);
- } while (memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0);
- uint32_t dwHash1 =
- FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true);
- uint32_t dwHash2 =
- FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true);
- ::srand((dwHash1 << 16) | (uint32_t)dwHash2);
-#else
- time_t tmLast = time(nullptr);
- time_t tmCur;
- while ((tmCur = time(nullptr)) == tmLast)
- continue;
-
- ::srand((tmCur << 16) | (tmLast & 0xFFFF));
-#endif
- while (iCount-- > 0)
- *pBuffer++ = static_cast<uint32_t>((::rand() << 16) | (::rand() & 0xFFFF));
-}
diff --git a/core/fxcrt/fx_random.h b/core/fxcrt/fx_random.h
index c07ef797cf..52d514ba53 100644
--- a/core/fxcrt/fx_random.h
+++ b/core/fxcrt/fx_random.h
@@ -12,7 +12,7 @@
void* FX_Random_MT_Start(uint32_t dwSeed);
void FX_Random_MT_Close(void* pContext);
uint32_t FX_Random_MT_Generate(void* pContext);
-void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount);
+
void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount);
#endif // CORE_FXCRT_FX_RANDOM_H_
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 6c70a3db1a..f49d98ab61 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -14,7 +14,7 @@
#include "core/fxcrt/cfx_decimal.h"
#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_extension.h"
-#include "core/fxcrt/fx_guid.h"
+#include "core/fxcrt/fx_random.h"
#include "fxjs/cfxjse_arguments.h"
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
@@ -514,6 +514,23 @@ bool IsPartOfNumberW(wchar_t ch) {
return std::iswdigit(ch) || ch == L'-' || ch == L'.';
}
+CFX_ByteString GUIDString(bool bSeparator) {
+ uint8_t data[16];
+ FX_Random_GenerateMT(reinterpret_cast<uint32_t*>(data), 4);
+ data[6] = (data[6] & 0x0F) | 0x40;
+
+ CFX_ByteString bsStr;
+ char* pBuf = bsStr.GetBuffer(40);
+ for (int32_t i = 0; i < 16; ++i, pBuf += 2) {
+ if (bSeparator && (i == 4 || i == 6 || i == 8 || i == 10))
+ *pBuf++ = L'-';
+
+ FXSYS_IntToTwoHexChars(data[i], pBuf);
+ }
+ bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
+ return bsStr;
+}
+
} // namespace
// static
@@ -4324,11 +4341,7 @@ void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis,
std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
iNum = static_cast<int32_t>(ValueToFloat(pThis, argOne.get()));
}
- FX_GUID guid;
- FX_GUID_CreateV4(&guid);
-
- CFX_ByteString bsUId = FX_GUID_ToString(&guid, !!iNum);
- args.GetReturnValue()->SetString(bsUId.AsStringC());
+ args.GetReturnValue()->SetString(GUIDString(!!iNum).AsStringC());
}
// static