changeset 2172:84d1d392a9ab

GenerateUuid() not available in sandboxed environments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Nov 2016 12:06:00 +0100
parents 35febe19e874
children 1c42860097fc
files Core/Cache/SharedArchive.cpp Core/FileStorage/StorageAccessor.cpp Core/HttpServer/HttpOutput.cpp Core/SystemToolbox.cpp Core/SystemToolbox.h Core/TemporaryFile.cpp Core/Toolbox.cpp Core/Toolbox.h OrthancServer/FromDcmtkBridge.cpp OrthancServer/Scheduler/ServerJob.cpp Plugins/Engine/OrthancPlugins.cpp UnitTestsSources/FileStorageTests.cpp UnitTestsSources/ServerIndexTests.cpp UnitTestsSources/StreamTests.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 15 files changed, 63 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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;
 
--- 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";
 
--- 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 <rpc.h>
+#else
+#  include <uuid/uuid.h>
+#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()
   {
--- 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();
 
--- 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)
     {
--- 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 <rpc.h>
-#else
-#  include <uuid/uuid.h>
-#endif
-}
-
-
 #if ORTHANC_ENABLE_PUGIXML == 1
 #  include "ChunkedBuffer.h"
 #  include <pugixml.hpp>
@@ -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)
--- 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);
--- 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);
--- 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")
   {
--- 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<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = 
-          CopyString(Toolbox::GenerateUuid());
+          CopyString(SystemToolbox::GenerateUuid());
         return true;
       }
 
--- 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<uint8_t> 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<std::string> 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);
   }
--- 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);
--- 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);
--- 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));
   }
 }