# HG changeset patch # User Sebastien Jodogne # Date 1522310943 -7200 # Node ID 795d71f66f3180d37ad614bcadcc33597ffe6a15 # Parent 886230938339fb58cb4b672698b9f0775de85546 sync diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/Cache/SharedArchive.cpp --- a/Resources/Orthanc/Core/Cache/SharedArchive.cpp Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/Cache/SharedArchive.cpp Thu Mar 29 10:09:03 2018 +0200 @@ -34,7 +34,7 @@ #include "../PrecompiledHeaders.h" #include "SharedArchive.h" -#include "../SystemToolbox.h" +#include "../Toolbox.h" namespace Orthanc @@ -100,7 +100,7 @@ RemoveInternal(oldest); } - std::string id = SystemToolbox::GenerateUuid(); + std::string id = Toolbox::GenerateUuid(); RemoveInternal(id); // Should never be useful because of UUID archive_[id] = obj; lru_.Add(id); diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/FileStorage/StorageAccessor.cpp --- a/Resources/Orthanc/Core/FileStorage/StorageAccessor.cpp Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/FileStorage/StorageAccessor.cpp Thu Mar 29 10:09:03 2018 +0200 @@ -37,7 +37,7 @@ #include "../Compression/ZlibCompressor.h" #include "../OrthancException.h" #include "../Toolbox.h" -#include "../SystemToolbox.h" +#include "../Toolbox.h" #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 # include "../HttpServer/HttpStreamTranscoder.h" @@ -51,7 +51,7 @@ CompressionType compression, bool storeMd5) { - std::string uuid = SystemToolbox::GenerateUuid(); + std::string uuid = Toolbox::GenerateUuid(); std::string md5; diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/SystemToolbox.cpp --- a/Resources/Orthanc/Core/SystemToolbox.cpp Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/SystemToolbox.cpp Thu Mar 29 10:09:03 2018 +0200 @@ -62,19 +62,6 @@ #endif -// Inclusions for UUID -// http://stackoverflow.com/a/1626302 - -extern "C" -{ -#if defined(_WIN32) -# include -#else -# include -#endif -} - - #include "Logging.h" #include "OrthancException.h" #include "Toolbox.h" @@ -539,28 +526,6 @@ } - 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; - } - - static boost::posix_time::ptime GetNow(bool utc) { if (utc) diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/SystemToolbox.h --- a/Resources/Orthanc/Core/SystemToolbox.h Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/SystemToolbox.h Thu Mar 29 10:09:03 2018 +0200 @@ -93,8 +93,6 @@ FILE* OpenFile(const std::string& path, FileMode mode); - std::string GenerateUuid(); - std::string GetNowIsoString(bool utc); void GetNowDicom(std::string& date, diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/TemporaryFile.cpp --- a/Resources/Orthanc/Core/TemporaryFile.cpp Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/TemporaryFile.cpp Thu Mar 29 10:09:03 2018 +0200 @@ -52,7 +52,7 @@ #endif // We use UUID to create unique path to temporary files - std::string filename = "Orthanc-" + Orthanc::SystemToolbox::GenerateUuid(); + std::string filename = "Orthanc-" + Orthanc::Toolbox::GenerateUuid(); if (extension != NULL) { diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/Toolbox.cpp --- a/Resources/Orthanc/Core/Toolbox.cpp Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/Toolbox.cpp Thu Mar 29 10:09:03 2018 +0200 @@ -87,8 +87,94 @@ #endif +// Inclusions for UUID +// http://stackoverflow.com/a/1626302 + +extern "C" +{ +#if defined(_WIN32) +# include +#else +# include +#endif +} + + + namespace Orthanc { + void Toolbox::LinesIterator::FindEndOfLine() + { + lineEnd_ = lineStart_; + + while (lineEnd_ < content_.size() && + content_[lineEnd_] != '\n' && + content_[lineEnd_] != '\r') + { + lineEnd_ += 1; + } + } + + + Toolbox::LinesIterator::LinesIterator(const std::string& content) : + content_(content), + lineStart_(0) + { + FindEndOfLine(); + } + + + bool Toolbox::LinesIterator::GetLine(std::string& target) const + { + assert(lineStart_ <= content_.size() && + lineEnd_ <= content_.size() && + lineStart_ <= lineEnd_); + + if (lineStart_ == content_.size()) + { + return false; + } + else + { + target = content_.substr(lineStart_, lineEnd_ - lineStart_); + return true; + } + } + + + void Toolbox::LinesIterator::Next() + { + lineStart_ = lineEnd_; + + if (lineStart_ != content_.size()) + { + assert(content_[lineStart_] == '\r' || + content_[lineStart_] == '\n'); + + char second; + + if (content_[lineStart_] == '\r') + { + second = '\n'; + } + else + { + second = '\r'; + } + + lineStart_ += 1; + + if (lineStart_ < content_.size() && + content_[lineStart_] == second) + { + lineStart_ += 1; + } + + FindEndOfLine(); + } + } + + void Toolbox::ToUpperCase(std::string& s) { std::transform(s.begin(), s.end(), s.begin(), toupper); @@ -1376,4 +1462,65 @@ return boost::locale::conv::utf_to_utf(w); } #endif + + + 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; + } } + + + +OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) +{ + return reinterpret_cast(new Orthanc::Toolbox::LinesIterator(content)); +} + + +bool OrthancLinesIterator_GetLine(std::string& target, + const OrthancLinesIterator* iterator) +{ + if (iterator != NULL) + { + return reinterpret_cast(iterator)->GetLine(target); + } + else + { + return false; + } +} + + +void OrthancLinesIterator_Next(OrthancLinesIterator* iterator) +{ + if (iterator != NULL) + { + reinterpret_cast(iterator)->Next(); + } +} + + +void OrthancLinesIterator_Free(OrthancLinesIterator* iterator) +{ + if (iterator != NULL) + { + delete reinterpret_cast(iterator); + } +} diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Core/Toolbox.h --- a/Resources/Orthanc/Core/Toolbox.h Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Core/Toolbox.h Thu Mar 29 10:09:03 2018 +0200 @@ -79,6 +79,24 @@ namespace Toolbox { + class LinesIterator + { + private: + const std::string& content_; + size_t lineStart_; + size_t lineEnd_; + + void FindEndOfLine(); + + public: + LinesIterator(const std::string& content); + + bool GetLine(std::string& target) const; + + void Next(); + }; + + void ToUpperCase(std::string& s); // Inplace version void ToLowerCase(std::string& s); // Inplace version @@ -214,5 +232,28 @@ std::string ToUpperCaseWithAccents(const std::string& source); #endif + + std::string GenerateUuid(); } } + + + + +/** + * The plain C, opaque data structure "OrthancLinesIterator" is a thin + * wrapper around Orthanc::Toolbox::LinesIterator, and is only used by + * "../Resources/WebAssembly/dcdict.cc", in order to avoid code + * duplication + **/ + +struct OrthancLinesIterator; + +OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content); + +bool OrthancLinesIterator_GetLine(std::string& target, + const OrthancLinesIterator* iterator); + +void OrthancLinesIterator_Next(OrthancLinesIterator* iterator); + +void OrthancLinesIterator_Free(OrthancLinesIterator* iterator); diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/NEWS --- a/Resources/Orthanc/NEWS Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/NEWS Thu Mar 29 10:09:03 2018 +0200 @@ -29,13 +29,15 @@ * Orthanc now uses UTC (universal time) instead of local time in its database * Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005) -* Upgrade to curl 7.57.0 for static and Windows builds * Support of Linux Standard Base * Static linking against libuuid (from e2fsprogs) * Fix static build on CentOS 6 -* Upgrade to JsonCpp 1.8.4 for static builds * Possibility of using JsonCpp 0.10.6 if the compiler does not support C++11 with the "-DUSE_LEGACY_JSONCPP=ON" CMake option +* Upgraded dependencies for static and Windows builds: + - curl 7.57.0 + - jsoncpp 1.8.4 + - zlib 1.2.11 Version 1.3.1 (2017-11-29) diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake --- a/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake Thu Mar 29 10:09:03 2018 +0200 @@ -145,6 +145,7 @@ ) elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + # No support for threads in WebAssembly else() message(FATAL_ERROR "Support your platform here") @@ -254,7 +255,8 @@ CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl64") + CMAKE_SYSTEM_NAME STREQUAL "NaCl64" OR + CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # For WebAssembly or asm.js list(APPEND BOOST_SOURCES ${BOOST_SOURCES_DIR}/libs/locale/src/posix/codecvt.cpp ${BOOST_SOURCES_DIR}/libs/locale/src/posix/collate.cpp diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Resources/CMake/Compiler.cmake --- a/Resources/Orthanc/Resources/CMake/Compiler.cmake Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Resources/CMake/Compiler.cmake Thu Mar 29 10:09:03 2018 +0200 @@ -174,6 +174,12 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") message("Building using Emscripten (for WebAssembly or asm.js targets)") + # The BINARYEN_TRAP_MODE specifies what to do when divisions per + # zero (and similar conditions like integer overflows) are + # encountered: The "clamp" mode avoids throwing errors, as they + # cannot be properly catched by "try {} catch (...)" constructions. + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -s BINARYEN_TRAP_MODE='\"clamp\"'") + else() message(FATAL_ERROR "Support your platform here") endif() diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Resources/CMake/OrthancFrameworkConfiguration.cmake --- a/Resources/Orthanc/Resources/CMake/OrthancFrameworkConfiguration.cmake Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Resources/CMake/OrthancFrameworkConfiguration.cmake Thu Mar 29 10:09:03 2018 +0200 @@ -282,10 +282,6 @@ ${ORTHANC_ROOT}/Core/Compression/GzipCompressor.cpp ${ORTHANC_ROOT}/Core/Compression/ZipWriter.cpp ${ORTHANC_ROOT}/Core/Compression/ZlibCompressor.cpp - - # This is the minizip distribution to create ZIP files using zlib - ${ORTHANC_ROOT}/Resources/ThirdParty/minizip/ioapi.c - ${ORTHANC_ROOT}/Resources/ThirdParty/minizip/zip.c ) endif() @@ -339,7 +335,14 @@ ## if (ENABLE_LOCALE) - include(${CMAKE_CURRENT_LIST_DIR}/LibIconvConfiguration.cmake) + if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + # In WebAssembly or asm.js, we rely on the version of iconv that + # is shipped with the stdlib + unset(USE_BOOST_ICONV CACHE) + else() + include(${CMAKE_CURRENT_LIST_DIR}/LibIconvConfiguration.cmake) + endif() + add_definitions(-DORTHANC_ENABLE_LOCALE=1) endif() @@ -359,10 +362,7 @@ ##################################################################### include(${CMAKE_CURRENT_LIST_DIR}/JsonCppConfiguration.cmake) - -if (NOT ORTHANC_SANDBOXED) - include(${CMAKE_CURRENT_LIST_DIR}/UuidConfiguration.cmake) -endif() +include(${CMAKE_CURRENT_LIST_DIR}/UuidConfiguration.cmake) # We put Boost as the last dependency, as it is the heaviest to # configure, which allows to quickly spot problems when configuring @@ -396,7 +396,6 @@ endif() set(ORTHANC_DICOM_SOURCES_INTERNAL - ${ORTHANC_ROOT}/Core/DicomParsing/DicomDirWriter.cpp ${ORTHANC_ROOT}/Core/DicomParsing/DicomModification.cpp ${ORTHANC_ROOT}/Core/DicomParsing/FromDcmtkBridge.cpp ${ORTHANC_ROOT}/Core/DicomParsing/ParsedDicomFile.cpp @@ -477,6 +476,7 @@ list(APPEND ORTHANC_CORE_SOURCES_INTERNAL ${ORTHANC_ROOT}/Core/Cache/SharedArchive.cpp + ${ORTHANC_ROOT}/Core/DicomParsing/DicomDirWriter.cpp ${ORTHANC_ROOT}/Core/FileStorage/FilesystemStorage.cpp ${ORTHANC_ROOT}/Core/FileStorage/StorageAccessor.cpp ${ORTHANC_ROOT}/Core/MultiThreading/BagOfTasksProcessor.cpp @@ -536,6 +536,16 @@ ${ORTHANC_ROOT}/Resources/ThirdParty/base64/base64.cpp ) + +if (ENABLE_ZLIB) + list(APPEND ORTHANC_CORE_SOURCES_DEPENDENCIES + # This is the minizip distribution to create ZIP files using zlib + ${ORTHANC_ROOT}/Resources/ThirdParty/minizip/ioapi.c + ${ORTHANC_ROOT}/Resources/ThirdParty/minizip/zip.c + ) +endif() + + set(ORTHANC_CORE_SOURCES ${ORTHANC_CORE_SOURCES_INTERNAL} ${ORTHANC_CORE_SOURCES_DEPENDENCIES} diff -r 886230938339 -r 795d71f66f31 Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake --- a/Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake Wed Mar 28 11:29:13 2018 +0200 +++ b/Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake Thu Mar 29 10:09:03 2018 +0200 @@ -1,7 +1,7 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_ZLIB) - SET(ZLIB_SOURCES_DIR ${CMAKE_BINARY_DIR}/zlib-1.2.7) - SET(ZLIB_URL "http://www.orthanc-server.com/downloads/third-party/zlib-1.2.7.tar.gz") - SET(ZLIB_MD5 "60df6a37c56e7c1366cca812414f7b85") + SET(ZLIB_SOURCES_DIR ${CMAKE_BINARY_DIR}/zlib-1.2.11) + SET(ZLIB_URL "http://www.orthanc-server.com/downloads/third-party/zlib-1.2.11.tar.gz") + SET(ZLIB_MD5 "1c9f62f0778697a09d36121ead88e08e") DownloadPackage(${ZLIB_MD5} ${ZLIB_URL} "${ZLIB_SOURCES_DIR}")