# HG changeset patch # User Sebastien Jodogne # Date 1479899160 -3600 # Node ID 84d1d392a9abe0ca4f128efdb21b06810bc6d5a7 # Parent 35febe19e87406c46e0e68c000436d30b85fb07a GenerateUuid() not available in sandboxed environments diff -r 35febe19e874 -r 84d1d392a9ab Core/Cache/SharedArchive.cpp --- a/Core/Cache/SharedArchive.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/Cache/SharedArchive.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -33,6 +33,8 @@ #include "../PrecompiledHeaders.h" #include "SharedArchive.h" +#include "../SystemToolbox.h" + namespace Orthanc { @@ -97,7 +99,7 @@ RemoveInternal(oldest); } - std::string id = Toolbox::GenerateUuid(); + std::string id = SystemToolbox::GenerateUuid(); RemoveInternal(id); // Should never be useful because of UUID archive_[id] = obj; lru_.Add(id); diff -r 35febe19e874 -r 84d1d392a9ab Core/FileStorage/StorageAccessor.cpp --- a/Core/FileStorage/StorageAccessor.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/FileStorage/StorageAccessor.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -37,6 +37,7 @@ #include "../OrthancException.h" #include "../HttpServer/HttpStreamTranscoder.h" #include "../Toolbox.h" +#include "../SystemToolbox.h" namespace Orthanc { @@ -46,7 +47,7 @@ CompressionType compression, bool storeMd5) { - std::string uuid = Toolbox::GenerateUuid(); + std::string uuid = SystemToolbox::GenerateUuid(); std::string md5; diff -r 35febe19e874 -r 84d1d392a9ab Core/HttpServer/HttpOutput.cpp --- a/Core/HttpServer/HttpOutput.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/HttpServer/HttpOutput.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -35,6 +35,7 @@ #include "../Logging.h" #include "../OrthancException.h" +#include "../SystemToolbox.h" #include "../Toolbox.h" #include "../Compression/GzipCompressor.h" #include "../Compression/ZlibCompressor.h" @@ -438,7 +439,7 @@ header += *it; } - multipartBoundary_ = Toolbox::GenerateUuid(); + multipartBoundary_ = SystemToolbox::GenerateUuid(); multipartContentType_ = contentType; header += "Content-Type: multipart/" + subType + "; type=" + contentType + "; boundary=" + multipartBoundary_ + "\r\n\r\n"; diff -r 35febe19e874 -r 84d1d392a9ab Core/SystemToolbox.cpp --- a/Core/SystemToolbox.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/SystemToolbox.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -59,6 +59,19 @@ #endif +// Inclusions for UUID +// http://stackoverflow.com/a/1626302 + +extern "C" +{ +#ifdef WIN32 +# include +#else +# include +#endif +} + + #include "Logging.h" #include "OrthancException.h" #include "Toolbox.h" @@ -477,6 +490,28 @@ } + std::string SystemToolbox::GenerateUuid() + { +#ifdef WIN32 + UUID uuid; + UuidCreate ( &uuid ); + + unsigned char * str; + UuidToStringA ( &uuid, &str ); + + std::string s( ( char* ) str ); + + RpcStringFreeA ( &str ); +#else + uuid_t uuid; + uuid_generate_random ( uuid ); + char s[37]; + uuid_unparse ( uuid, s ); +#endif + return s; + } + + #if BOOST_HAS_DATE_TIME == 1 std::string SystemToolbox::GetNowIsoString() { diff -r 35febe19e874 -r 84d1d392a9ab Core/SystemToolbox.h --- a/Core/SystemToolbox.h Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/SystemToolbox.h Wed Nov 23 12:06:00 2016 +0100 @@ -90,6 +90,8 @@ FILE* OpenFile(const std::string& path, FileMode mode); + std::string GenerateUuid(); + #if BOOST_HAS_DATE_TIME == 1 std::string GetNowIsoString(); diff -r 35febe19e874 -r 84d1d392a9ab Core/TemporaryFile.cpp --- a/Core/TemporaryFile.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/TemporaryFile.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -51,7 +51,7 @@ #endif // We use UUID to create unique path to temporary files - std::string filename = "Orthanc-" + Orthanc::Toolbox::GenerateUuid(); + std::string filename = "Orthanc-" + Orthanc::SystemToolbox::GenerateUuid(); if (extension != NULL) { diff -r 35febe19e874 -r 84d1d392a9ab Core/Toolbox.cpp --- a/Core/Toolbox.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/Toolbox.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -78,19 +78,6 @@ -// Inclusions for UUID -// http://stackoverflow.com/a/1626302 - -extern "C" -{ -#ifdef WIN32 -# include -#else -# include -#endif -} - - #if ORTHANC_ENABLE_PUGIXML == 1 # include "ChunkedBuffer.h" # include @@ -1226,28 +1213,6 @@ } - std::string Toolbox::GenerateUuid() - { -#ifdef WIN32 - UUID uuid; - UuidCreate ( &uuid ); - - unsigned char * str; - UuidToStringA ( &uuid, &str ); - - std::string s( ( char* ) str ); - - RpcStringFreeA ( &str ); -#else - uuid_t uuid; - uuid_generate_random ( uuid ); - char s[37]; - uuid_unparse ( uuid, s ); -#endif - return s; - } - - bool Toolbox::IsUuid(const std::string& str) { if (str.size() != 36) diff -r 35febe19e874 -r 84d1d392a9ab Core/Toolbox.h --- a/Core/Toolbox.h Wed Nov 23 11:46:42 2016 +0100 +++ b/Core/Toolbox.h Wed Nov 23 12:06:00 2016 +0100 @@ -204,8 +204,6 @@ const std::string& key, unsigned int defaultValue); - std::string GenerateUuid(); - bool IsUuid(const std::string& str); bool StartsWithUuid(const std::string& str); diff -r 35febe19e874 -r 84d1d392a9ab OrthancServer/FromDcmtkBridge.cpp --- a/OrthancServer/FromDcmtkBridge.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/OrthancServer/FromDcmtkBridge.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -39,6 +39,7 @@ #include "FromDcmtkBridge.h" #include "ToDcmtkBridge.h" #include "../Core/Logging.h" +#include "../Core/SystemToolbox.h" #include "../Core/Toolbox.h" #include "../Core/TemporaryFile.h" #include "../Core/OrthancException.h" @@ -1119,7 +1120,7 @@ // The "PatientID" field is of type LO (Long String), 64 // Bytes Maximum. An UUID is of length 36, thus it can be used // as a random PatientID. - return Toolbox::GenerateUuid(); + return SystemToolbox::GenerateUuid(); case ResourceType_Instance: return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); diff -r 35febe19e874 -r 84d1d392a9ab OrthancServer/Scheduler/ServerJob.cpp --- a/OrthancServer/Scheduler/ServerJob.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/OrthancServer/Scheduler/ServerJob.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -34,6 +34,7 @@ #include "ServerJob.h" #include "../../Core/OrthancException.h" +#include "../../Core/SystemToolbox.h" #include "../../Core/Toolbox.h" namespace Orthanc @@ -95,7 +96,7 @@ ServerJob::ServerJob() : - jobId_(Toolbox::GenerateUuid()), + jobId_(SystemToolbox::GenerateUuid()), submitted_(false), description_("no description") { diff -r 35febe19e874 -r 84d1d392a9ab Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -2588,7 +2588,7 @@ case _OrthancPluginService_GenerateUuid: { *reinterpret_cast(parameters)->result = - CopyString(Toolbox::GenerateUuid()); + CopyString(SystemToolbox::GenerateUuid()); return true; } diff -r 35febe19e874 -r 84d1d392a9ab UnitTestsSources/FileStorageTests.cpp --- a/UnitTestsSources/FileStorageTests.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/UnitTestsSources/FileStorageTests.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -60,8 +60,8 @@ { FilesystemStorage s("UnitTestsStorage"); - std::string data = Toolbox::GenerateUuid(); - std::string uid = Toolbox::GenerateUuid(); + std::string data = SystemToolbox::GenerateUuid(); + std::string uid = SystemToolbox::GenerateUuid(); s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown); std::string d; s.Read(d, uid, FileContentType_Unknown); @@ -75,8 +75,8 @@ FilesystemStorage s("UnitTestsStorage"); std::vector data; - StringToVector(data, Toolbox::GenerateUuid()); - std::string uid = Toolbox::GenerateUuid(); + StringToVector(data, SystemToolbox::GenerateUuid()); + std::string uid = SystemToolbox::GenerateUuid(); s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown); std::string d; s.Read(d, uid, FileContentType_Unknown); @@ -93,8 +93,8 @@ std::list u; for (unsigned int i = 0; i < 10; i++) { - std::string t = Toolbox::GenerateUuid(); - std::string uid = Toolbox::GenerateUuid(); + std::string t = SystemToolbox::GenerateUuid(); + std::string uid = SystemToolbox::GenerateUuid(); s.Create(uid.c_str(), &t[0], t.size(), FileContentType_Unknown); u.push_back(uid); } diff -r 35febe19e874 -r 84d1d392a9ab UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -815,7 +815,7 @@ for (size_t i = 0; i < ids.size(); i++) { - FileInfo info(Toolbox::GenerateUuid(), FileContentType_Dicom, 1, "md5"); + FileInfo info(SystemToolbox::GenerateUuid(), FileContentType_Dicom, 1, "md5"); index.AddAttachment(info, ids[i]); index.ComputeStatistics(tmp); diff -r 35febe19e874 -r 84d1d392a9ab UnitTestsSources/StreamTests.cpp --- a/UnitTestsSources/StreamTests.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/UnitTestsSources/StreamTests.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -34,6 +34,7 @@ #include "gtest/gtest.h" #include "../Core/SystemToolbox.h" +#include "../Core/SystemToolbox.h" #include "../Core/Toolbox.h" #include "../Core/OrthancException.h" #include "../Core/HttpServer/BufferHttpSender.h" @@ -113,7 +114,7 @@ TEST(Zlib, Basic) { - std::string s = Toolbox::GenerateUuid(); + std::string s = SystemToolbox::GenerateUuid(); s = s + s + s + s; std::string compressed, compressed2; @@ -130,7 +131,7 @@ TEST(Zlib, Level) { - std::string s = Toolbox::GenerateUuid(); + std::string s = SystemToolbox::GenerateUuid(); s = s + s + s + s; std::string compressed, compressed2; @@ -147,7 +148,7 @@ TEST(Zlib, DISABLED_Corrupted) // Disabled because it may result in a crash { - std::string s = Toolbox::GenerateUuid(); + std::string s = SystemToolbox::GenerateUuid(); s = s + s + s + s; std::string compressed; @@ -252,7 +253,7 @@ { ZlibCompressor compressor; - const std::string s = "Hello world " + Toolbox::GenerateUuid(); + const std::string s = "Hello world " + SystemToolbox::GenerateUuid(); std::string t; IBufferCompressor::Compress(t, compressor, s); diff -r 35febe19e874 -r 84d1d392a9ab UnitTestsSources/UnitTestsMain.cpp --- a/UnitTestsSources/UnitTestsMain.cpp Wed Nov 23 11:46:42 2016 +0100 +++ b/UnitTestsSources/UnitTestsMain.cpp Wed Nov 23 12:06:00 2016 +0100 @@ -53,7 +53,7 @@ { for (int i = 0; i < 10; i++) { - std::string s = Toolbox::GenerateUuid(); + std::string s = SystemToolbox::GenerateUuid(); ASSERT_TRUE(Toolbox::IsUuid(s)); } }