Mercurial > hg > orthanc-stone
changeset 22:b01d46e5a2b3
support for sandboxed environments
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Nov 2016 12:08:15 +0100 |
parents | 20f623762e8e |
children | a4a1e4033403 |
files | CMakeLists.txt Framework/Messaging/MessagingToolbox.cpp Resources/CMake/OrthancStone.cmake Resources/Orthanc/Core/Images/JpegReader.cpp Resources/Orthanc/Core/Images/JpegReader.h Resources/Orthanc/Core/Images/PngReader.cpp Resources/Orthanc/Core/Images/PngReader.h Resources/Orthanc/Core/SystemToolbox.cpp Resources/Orthanc/Core/SystemToolbox.h Resources/Orthanc/Core/Toolbox.cpp Resources/Orthanc/Core/Toolbox.h Resources/Orthanc/Resources/CMake/GoogleTestConfiguration.cmake Resources/SyncOrthancFolder.py |
diffstat | 13 files changed, 132 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Tue Nov 22 15:54:06 2016 +0100 +++ b/CMakeLists.txt Wed Nov 23 12:08:15 2016 +0100 @@ -6,12 +6,8 @@ ## Build a static library containing the Orthanc Stone framework ##################################################################### +SET(STONE_SANDBOXED OFF) include(Resources/CMake/OrthancStone.cmake) - -add_definitions( - -DORTHANC_SANDBOXED=0 - ) - add_library(OrthancStone STATIC ${ORTHANC_STONE_SOURCES})
--- a/Framework/Messaging/MessagingToolbox.cpp Tue Nov 22 15:54:06 2016 +0100 +++ b/Framework/Messaging/MessagingToolbox.cpp Wed Nov 23 12:08:15 2016 +0100 @@ -46,6 +46,7 @@ #if defined(__native_client__) # include <boost/math/special_functions/round.hpp> #else +# include <boost/date_time/posix_time/posix_time.hpp> # include <boost/date_time/microsec_time_clock.hpp> #endif
--- a/Resources/CMake/OrthancStone.cmake Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/CMake/OrthancStone.cmake Wed Nov 23 12:08:15 2016 +0100 @@ -8,6 +8,7 @@ # Generic parameters SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") +SET(STONE_SANDBOXED OFF CACHE BOOL "Whether Stone runs inside a sandboxed environment (such as Google NaCl)") # Optional components SET(ENABLE_CURL ON CACHE BOOL "Include support for libcurl") @@ -59,35 +60,54 @@ ## Configure optional third-party components ##################################################################### -if (ENABLE_LOGGING) - add_definitions(-DORTHANC_ENABLE_LOGGING=1) +if (STONE_SANDBOXED) + add_definitions( + -DORTHANC_ENABLE_CURL=0 + -DORTHANC_ENABLE_LOGGING=0 + -DORTHANC_ENABLE_SDL=0 + -DORTHANC_ENABLE_SSL=0 + -DORTHANC_SANDBOXED=1 + ) else() - add_definitions(-DORTHANC_ENABLE_LOGGING=0) -endif() + list(APPEND ORTHANC_STONE_SOURCES + ${ORTHANC_ROOT}/Core/HttpClient.cpp + ${ORTHANC_ROOT}/Core/SystemToolbox.cpp + ) -if (ENABLE_SDL) - include(${CMAKE_CURRENT_LIST_DIR}/SdlConfiguration.cmake) - add_definitions(-DORTHANC_ENABLE_SDL=1) -else() - add_definitions(-DORTHANC_ENABLE_SDL=0) -endif() + add_definitions( + -DORTHANC_SANDBOXED=0 + ) + + if (ENABLE_LOGGING) + add_definitions(-DORTHANC_ENABLE_LOGGING=1) + else() + add_definitions(-DORTHANC_ENABLE_LOGGING=0) + endif() -if (ENABLE_CURL) - add_definitions(-DORTHANC_ENABLE_CURL=1) - include(${ORTHANC_ROOT}/Resources/CMake/LibCurlConfiguration.cmake) + if (ENABLE_SDL) + include(${CMAKE_CURRENT_LIST_DIR}/SdlConfiguration.cmake) + add_definitions(-DORTHANC_ENABLE_SDL=1) + else() + add_definitions(-DORTHANC_ENABLE_SDL=0) + endif() + + if (ENABLE_CURL) + add_definitions(-DORTHANC_ENABLE_CURL=1) + include(${ORTHANC_ROOT}/Resources/CMake/LibCurlConfiguration.cmake) - if (ENABLE_SSL) - set(ENABLE_PKCS11 OFF) - add_definitions(-DORTHANC_ENABLE_SSL=1) - include(${ORTHANC_ROOT}/Resources/CMake/OpenSslConfiguration.cmake) + if (ENABLE_SSL) + set(ENABLE_PKCS11 OFF) + add_definitions(-DORTHANC_ENABLE_SSL=1) + include(${ORTHANC_ROOT}/Resources/CMake/OpenSslConfiguration.cmake) + else() + add_definitions(-DORTHANC_ENABLE_SSL=0) + endif() else() - add_definitions(-DORTHANC_ENABLE_SSL=0) + add_definitions( + -DORTHANC_ENABLE_SSL=0 + -DORTHANC_ENABLE_CURL=0 + ) endif() -else() - add_definitions( - -DORTHANC_ENABLE_SSL=0 - -DORTHANC_ENABLE_CURL=0 - ) endif() add_definitions( @@ -180,7 +200,6 @@ ${ORTHANC_ROOT}/Core/Compression/DeflateBaseCompressor.cpp ${ORTHANC_ROOT}/Core/Compression/GzipCompressor.cpp ${ORTHANC_ROOT}/Core/Enumerations.cpp - ${ORTHANC_ROOT}/Core/HttpClient.cpp ${ORTHANC_ROOT}/Core/Images/Image.cpp ${ORTHANC_ROOT}/Core/Images/ImageAccessor.cpp ${ORTHANC_ROOT}/Core/Images/ImageBuffer.cpp @@ -189,7 +208,6 @@ ${ORTHANC_ROOT}/Core/Images/JpegReader.cpp ${ORTHANC_ROOT}/Core/Images/PngReader.cpp ${ORTHANC_ROOT}/Core/Logging.cpp - ${ORTHANC_ROOT}/Core/SystemToolbox.cpp ${ORTHANC_ROOT}/Core/Toolbox.cpp ${ORTHANC_ROOT}/Core/WebServiceParameters.cpp ${ORTHANC_ROOT}/Resources/ThirdParty/base64/base64.cpp
--- a/Resources/Orthanc/Core/Images/JpegReader.cpp Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/Images/JpegReader.cpp Wed Nov 23 12:08:15 2016 +0100 @@ -36,7 +36,11 @@ #include "JpegErrorManager.h" #include "../OrthancException.h" #include "../Logging.h" -#include "../SystemToolbox.h" + +#if ORTHANC_SANDBOXED == 0 +# include "../SystemToolbox.h" +#endif + namespace Orthanc { @@ -94,6 +98,7 @@ } +#if ORTHANC_SANDBOXED == 0 void JpegReader::ReadFromFile(const std::string& filename) { FILE* fp = SystemToolbox::OpenFile(filename, FileMode_ReadBinary); @@ -135,6 +140,7 @@ jpeg_destroy_decompress(&cinfo); fclose(fp); } +#endif void JpegReader::ReadFromMemory(const void* buffer,
--- a/Resources/Orthanc/Core/Images/JpegReader.h Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/Images/JpegReader.h Wed Nov 23 12:08:15 2016 +0100 @@ -37,6 +37,10 @@ #include <string> #include <boost/noncopyable.hpp> +#if !defined(ORTHANC_SANDBOXED) +# error The macro ORTHANC_SANDBOXED must be defined +#endif + namespace Orthanc { class JpegReader : @@ -47,7 +51,9 @@ std::string content_; public: +#if ORTHANC_SANDBOXED == 0 void ReadFromFile(const std::string& filename); +#endif void ReadFromMemory(const void* buffer, size_t size);
--- a/Resources/Orthanc/Core/Images/PngReader.cpp Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/Images/PngReader.cpp Wed Nov 23 12:08:15 2016 +0100 @@ -34,14 +34,18 @@ #include "PngReader.h" #include "../OrthancException.h" -#include "../SystemToolbox.h" #include "../Toolbox.h" +#if ORTHANC_SANDBOXED == 0 +# include "../SystemToolbox.h" +#endif + #include <png.h> #include <string.h> // For memcpy() namespace Orthanc { +#if ORTHANC_SANDBOXED == 0 namespace { struct FileRabi @@ -66,6 +70,7 @@ } }; } +#endif struct PngReader::PngRabi @@ -207,6 +212,8 @@ AssignWritable(format, width, height, pitch, &data_[0]); } + +#if ORTHANC_SANDBOXED == 0 void PngReader::ReadFromFile(const std::string& filename) { FileRabi f(filename.c_str()); @@ -231,6 +238,7 @@ Read(rabi); } +#endif namespace
--- a/Resources/Orthanc/Core/Images/PngReader.h Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/Images/PngReader.h Wed Nov 23 12:08:15 2016 +0100 @@ -41,6 +41,10 @@ #include <boost/shared_ptr.hpp> #include <boost/noncopyable.hpp> +#if !defined(ORTHANC_SANDBOXED) +# error The macro ORTHANC_SANDBOXED must be defined +#endif + namespace Orthanc { class PngReader : @@ -59,7 +63,9 @@ public: PngReader(); +#if ORTHANC_SANDBOXED == 0 void ReadFromFile(const std::string& filename); +#endif void ReadFromMemory(const void* buffer, size_t size);
--- a/Resources/Orthanc/Core/SystemToolbox.cpp Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/SystemToolbox.cpp Wed Nov 23 12:08:15 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/Resources/Orthanc/Core/SystemToolbox.h Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/SystemToolbox.h Wed Nov 23 12:08:15 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/Resources/Orthanc/Core/Toolbox.cpp Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/Toolbox.cpp Wed Nov 23 12:08:15 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/Resources/Orthanc/Core/Toolbox.h Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Core/Toolbox.h Wed Nov 23 12:08:15 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/Resources/Orthanc/Resources/CMake/GoogleTestConfiguration.cmake Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/Orthanc/Resources/CMake/GoogleTestConfiguration.cmake Wed Nov 23 12:08:15 2016 +0100 @@ -1,9 +1,26 @@ if (USE_GTEST_DEBIAN_SOURCE_PACKAGE) - set(GTEST_SOURCES /usr/src/gtest/src/gtest-all.cc) - include_directories(/usr/src/gtest) + find_path(GTEST_DEBIAN_SOURCES_DIR + NAMES src/gtest-all.cc + PATHS + /usr/src/gtest + /usr/src/googletest/googletest + PATH_SUFFIXES src + ) - if (NOT EXISTS /usr/include/gtest/gtest.h OR - NOT EXISTS ${GTEST_SOURCES}) + find_path(GTEST_DEBIAN_INCLUDE_DIR + NAMES gtest.h + PATHS + /usr/include/gtest + ) + + message("Path to the Debian Google Test sources: ${GTEST_DEBIAN_SOURCES_DIR}") + message("Path to the Debian Google Test includes: ${GTEST_DEBIAN_INCLUDE_DIR}") + + set(GTEST_SOURCES ${GTEST_DEBIAN_SOURCES_DIR}/src/gtest-all.cc) + include_directories(${GTEST_DEBIAN_SOURCES_DIR}) + + if (NOT EXISTS ${GTEST_SOURCES} OR + NOT EXISTS ${GTEST_DEBIAN_INCLUDE_DIR}/gtest.h) message(FATAL_ERROR "Please install the libgtest-dev package") endif()
--- a/Resources/SyncOrthancFolder.py Tue Nov 22 15:54:06 2016 +0100 +++ b/Resources/SyncOrthancFolder.py Wed Nov 23 12:08:15 2016 +0100 @@ -92,7 +92,7 @@ except: pass - url = '%s/%s/%s' % (REPOSITORY, branch, source) + url = '%s/%s/%s?aaiai' % (REPOSITORY, branch, source) with open(target, 'w') as f: f.write(urllib2.urlopen(url).read())