# HG changeset patch # User Sebastien Jodogne # Date 1478704367 -3600 # Node ID aa4b8895cd231c0debeff667277180288d42eaa8 # Parent 764c9157301b98bb3ddafa4c4cd04ad18cda1d4d reorganization diff -r 764c9157301b -r aa4b8895cd23 Core/FileStorage/FilesystemStorage.cpp --- a/Core/FileStorage/FilesystemStorage.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/FileStorage/FilesystemStorage.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -83,7 +83,7 @@ //root_ = boost::filesystem::absolute(root).string(); root_ = root; - Toolbox::MakeDirectory(root); + SystemToolbox::MakeDirectory(root); } @@ -143,7 +143,7 @@ } } - Toolbox::WriteFile(content, size, path.string()); + SystemToolbox::WriteFile(content, size, path.string()); } @@ -155,7 +155,7 @@ << "\" content type"; content.clear(); - Toolbox::ReadFile(content, GetPath(uuid).string()); + SystemToolbox::ReadFile(content, GetPath(uuid).string()); } @@ -177,7 +177,7 @@ { for (fs::recursive_directory_iterator current(root_), end; current != end ; ++current) { - if (Toolbox::IsRegularFile(current->path().string())) + if (SystemToolbox::IsRegularFile(current->path().string())) { try { diff -r 764c9157301b -r aa4b8895cd23 Core/HttpClient.cpp --- a/Core/HttpClient.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/HttpClient.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -773,14 +773,14 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } - if (!Toolbox::IsRegularFile(certificateFile)) + if (!SystemToolbox::IsRegularFile(certificateFile)) { LOG(ERROR) << "Cannot open certificate file: " << certificateFile; throw OrthancException(ErrorCode_InexistentFile); } if (!certificateKeyFile.empty() && - !Toolbox::IsRegularFile(certificateKeyFile)) + !SystemToolbox::IsRegularFile(certificateKeyFile)) { LOG(ERROR) << "Cannot open key file: " << certificateKeyFile; throw OrthancException(ErrorCode_InexistentFile); diff -r 764c9157301b -r aa4b8895cd23 Core/HttpServer/FilesystemHttpHandler.cpp --- a/Core/HttpServer/FilesystemHttpHandler.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/HttpServer/FilesystemHttpHandler.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -95,7 +95,7 @@ #endif std::string h = Toolbox::FlattenUri(uri) + "/" + f; - if (Toolbox::IsRegularFile(it->path().string())) + if (SystemToolbox::IsRegularFile(it->path().string())) { s += "
  • " + f + "
  • "; } @@ -158,7 +158,7 @@ p /= uri[i]; } - if (Toolbox::IsRegularFile(p.string())) + if (SystemToolbox::IsRegularFile(p.string())) { FilesystemHttpSender sender(p); output.Answer(sender); // TODO COMPRESSION diff -r 764c9157301b -r aa4b8895cd23 Core/Images/Font.cpp --- a/Core/Images/Font.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Images/Font.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -135,7 +135,7 @@ void Font::LoadFromFile(const std::string& path) { std::string font; - Toolbox::ReadFile(font, path); + SystemToolbox::ReadFile(font, path); LoadFromMemory(font); } diff -r 764c9157301b -r aa4b8895cd23 Core/Images/IImageWriter.cpp --- a/Core/Images/IImageWriter.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Images/IImageWriter.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -47,7 +47,7 @@ #if ORTHANC_SANDBOXED == 0 std::string compressed; WriteToMemoryInternal(compressed, width, height, pitch, format, buffer); - Toolbox::WriteFile(compressed, path); + SystemToolbox::WriteFile(compressed, path); #else throw OrthancException(ErrorCode_CannotWriteFile); // Unavailable in sandboxed environments #endif diff -r 764c9157301b -r aa4b8895cd23 Core/Images/JpegReader.cpp --- a/Core/Images/JpegReader.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Images/JpegReader.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -96,7 +96,7 @@ void JpegReader::ReadFromFile(const std::string& filename) { - FILE* fp = Toolbox::OpenFile(filename, FileMode_ReadBinary); + FILE* fp = SystemToolbox::OpenFile(filename, FileMode_ReadBinary); if (!fp) { throw OrthancException(ErrorCode_InexistentFile); diff -r 764c9157301b -r aa4b8895cd23 Core/Images/JpegWriter.cpp --- a/Core/Images/JpegWriter.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Images/JpegWriter.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -119,7 +119,7 @@ PixelFormat format, const void* buffer) { - FILE* fp = Toolbox::OpenFile(filename, FileMode_WriteBinary); + FILE* fp = SystemToolbox::OpenFile(filename, FileMode_WriteBinary); if (fp == NULL) { throw OrthancException(ErrorCode_CannotWriteFile); diff -r 764c9157301b -r aa4b8895cd23 Core/Images/PngReader.cpp --- a/Core/Images/PngReader.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Images/PngReader.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -49,7 +49,7 @@ FileRabi(const char* filename) { - fp_ = Toolbox::OpenFile(filename, FileMode_ReadBinary); + fp_ = SystemToolbox::OpenFile(filename, FileMode_ReadBinary); if (!fp_) { throw OrthancException(ErrorCode_InexistentFile); diff -r 764c9157301b -r aa4b8895cd23 Core/Images/PngWriter.cpp --- a/Core/Images/PngWriter.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Images/PngWriter.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -211,7 +211,7 @@ { Prepare(width, height, pitch, format, buffer); - FILE* fp = Toolbox::OpenFile(filename, FileMode_WriteBinary); + FILE* fp = SystemToolbox::OpenFile(filename, FileMode_WriteBinary); if (!fp) { throw OrthancException(ErrorCode_CannotWriteFile); diff -r 764c9157301b -r aa4b8895cd23 Core/Logging.cpp --- a/Core/Logging.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Logging.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -150,7 +150,7 @@ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); boost::filesystem::path root(directory); - boost::filesystem::path exe(Toolbox::GetPathToExecutable()); + boost::filesystem::path exe(SystemToolbox::GetPathToExecutable()); if (!boost::filesystem::exists(root) || !boost::filesystem::is_directory(root)) @@ -166,7 +166,7 @@ now.time_of_day().hours(), now.time_of_day().minutes(), now.time_of_day().seconds(), - Toolbox::GetProcessId()); + SystemToolbox::GetProcessId()); std::string programName = exe.filename().replace_extension("").string(); diff -r 764c9157301b -r aa4b8895cd23 Core/Toolbox.cpp --- a/Core/Toolbox.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Toolbox.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -123,75 +123,6 @@ } -#if ORTHANC_SANDBOXED == 0 - static bool finish_; - static ServerBarrierEvent barrierEvent_; - -#if defined(_WIN32) - static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) - { - // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx - finish_ = true; - return true; - } -#else - static void SignalHandler(int signal) - { - if (signal == SIGHUP) - { - barrierEvent_ = ServerBarrierEvent_Reload; - } - - finish_ = true; - } -#endif - - - static ServerBarrierEvent ServerBarrierInternal(const bool* stopFlag) - { -#if defined(_WIN32) - SetConsoleCtrlHandler(ConsoleControlHandler, true); -#else - signal(SIGINT, SignalHandler); - signal(SIGQUIT, SignalHandler); - signal(SIGTERM, SignalHandler); - signal(SIGHUP, SignalHandler); -#endif - - // Active loop that awakens every 100ms - finish_ = false; - barrierEvent_ = ServerBarrierEvent_Stop; - while (!(*stopFlag || finish_)) - { - Toolbox::USleep(100 * 1000); - } - -#if defined(_WIN32) - SetConsoleCtrlHandler(ConsoleControlHandler, false); -#else - signal(SIGINT, NULL); - signal(SIGQUIT, NULL); - signal(SIGTERM, NULL); - signal(SIGHUP, NULL); -#endif - - return barrierEvent_; - } - - - ServerBarrierEvent Toolbox::ServerBarrier(const bool& stopFlag) - { - return ServerBarrierInternal(&stopFlag); - } - - ServerBarrierEvent Toolbox::ServerBarrier() - { - const bool stopFlag = false; - return ServerBarrierInternal(&stopFlag); - } -#endif /* ORTHANC_SANDBOXED */ - - void Toolbox::ToUpperCase(std::string& s) { std::transform(s.begin(), s.end(), s.begin(), toupper); @@ -219,149 +150,6 @@ } - static std::streamsize GetStreamSize(std::istream& f) - { - // http://www.cplusplus.com/reference/iostream/istream/tellg/ - f.seekg(0, std::ios::end); - std::streamsize size = f.tellg(); - f.seekg(0, std::ios::beg); - - return size; - } - - -#if ORTHANC_SANDBOXED == 0 - void Toolbox::ReadFile(std::string& content, - const std::string& path) - { - if (!IsRegularFile(path)) - { - LOG(ERROR) << std::string("The path does not point to a regular file: ") << path; - throw OrthancException(ErrorCode_RegularFileExpected); - } - - boost::filesystem::ifstream f; - f.open(path, std::ifstream::in | std::ifstream::binary); - if (!f.good()) - { - throw OrthancException(ErrorCode_InexistentFile); - } - - std::streamsize size = GetStreamSize(f); - content.resize(size); - if (size != 0) - { - f.read(reinterpret_cast(&content[0]), size); - } - - f.close(); - } -#endif - - -#if ORTHANC_SANDBOXED == 0 - bool Toolbox::ReadHeader(std::string& header, - const std::string& path, - size_t headerSize) - { - if (!IsRegularFile(path)) - { - LOG(ERROR) << std::string("The path does not point to a regular file: ") << path; - throw OrthancException(ErrorCode_RegularFileExpected); - } - - boost::filesystem::ifstream f; - f.open(path, std::ifstream::in | std::ifstream::binary); - if (!f.good()) - { - throw OrthancException(ErrorCode_InexistentFile); - } - - bool full = true; - - { - std::streamsize size = GetStreamSize(f); - if (size <= 0) - { - headerSize = 0; - full = false; - } - else if (static_cast(size) < headerSize) - { - headerSize = size; // Truncate to the size of the file - full = false; - } - } - - header.resize(headerSize); - if (headerSize != 0) - { - f.read(reinterpret_cast(&header[0]), headerSize); - } - - f.close(); - - return full; - } -#endif - - -#if ORTHANC_SANDBOXED == 0 - void Toolbox::WriteFile(const void* content, - size_t size, - const std::string& path) - { - boost::filesystem::ofstream f; - f.open(path, std::ofstream::out | std::ofstream::binary); - if (!f.good()) - { - throw OrthancException(ErrorCode_CannotWriteFile); - } - - if (size != 0) - { - f.write(reinterpret_cast(content), size); - - if (!f.good()) - { - f.close(); - throw OrthancException(ErrorCode_FileStorageCannotWrite); - } - } - - f.close(); - } -#endif - - -#if ORTHANC_SANDBOXED == 0 - void Toolbox::WriteFile(const std::string& content, - const std::string& path) - { - WriteFile(content.size() > 0 ? content.c_str() : NULL, - content.size(), path); - } -#endif - - -#if ORTHANC_SANDBOXED == 0 - void Toolbox::RemoveFile(const std::string& path) - { - if (boost::filesystem::exists(path)) - { - if (IsRegularFile(path)) - { - boost::filesystem::remove(path); - } - else - { - throw OrthancException(ErrorCode_RegularFileExpected); - } - } - } -#endif - - void Toolbox::SplitUriComponents(UriComponents& components, const std::string& uri) { @@ -529,22 +317,6 @@ } - -#if ORTHANC_SANDBOXED == 0 - uint64_t Toolbox::GetFileSize(const std::string& path) - { - try - { - return static_cast(boost::filesystem::file_size(path)); - } - catch (boost::filesystem::filesystem_error&) - { - throw OrthancException(ErrorCode_InexistentFile); - } - } -#endif - - #if ORTHANC_ENABLE_MD5 == 1 static char GetHexadecimalCharacter(uint8_t value) { @@ -661,65 +433,6 @@ #endif - -#if defined(_WIN32) - static std::string GetPathToExecutableInternal() - { - // Yes, this is ugly, but there is no simple way to get the - // required buffer size, so we use a big constant - std::vector buffer(32768); - /*int bytes =*/ GetModuleFileNameA(NULL, &buffer[0], static_cast(buffer.size() - 1)); - return std::string(&buffer[0]); - } - -#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) - static std::string GetPathToExecutableInternal() - { - std::vector buffer(PATH_MAX + 1); - ssize_t bytes = readlink("/proc/self/exe", &buffer[0], buffer.size() - 1); - if (bytes == 0) - { - throw OrthancException(ErrorCode_PathToExecutable); - } - - return std::string(&buffer[0]); - } - -#elif defined(__APPLE__) && defined(__MACH__) - static std::string GetPathToExecutableInternal() - { - char pathbuf[PATH_MAX + 1]; - unsigned int bufsize = static_cast(sizeof(pathbuf)); - - _NSGetExecutablePath( pathbuf, &bufsize); - - return std::string(pathbuf); - } - -#elif ORTHANC_SANDBOXED == 1 - // Sandboxed Orthanc, no access to the executable - -#else -#error Support your platform here -#endif - - -#if ORTHANC_SANDBOXED == 0 - std::string Toolbox::GetPathToExecutable() - { - boost::filesystem::path p(GetPathToExecutableInternal()); - return boost::filesystem::absolute(p).string(); - } - - - std::string Toolbox::GetDirectoryOfExecutable() - { - boost::filesystem::path p(GetPathToExecutableInternal()); - return boost::filesystem::absolute(p.parent_path()).string(); - } -#endif - - static const char* GetBoostLocaleEncoding(const Encoding sourceEncoding) { switch (sourceEncoding) @@ -997,30 +710,6 @@ } -#if BOOST_HAS_DATE_TIME == 1 - std::string Toolbox::GetNowIsoString() - { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - return boost::posix_time::to_iso_string(now); - } - - void Toolbox::GetNowDicom(std::string& date, - std::string& time) - { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - tm tm = boost::posix_time::to_tm(now); - - char s[32]; - sprintf(s, "%04d%02d%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); - date.assign(s); - - // TODO milliseconds - sprintf(s, "%02d%02d%02d.%06d", tm.tm_hour, tm.tm_min, tm.tm_sec, 0); - time.assign(s); - } -#endif - - std::string Toolbox::StripSpaces(const std::string& source) { size_t first = 0; @@ -1178,35 +867,6 @@ } -#if ORTHANC_SANDBOXED == 0 - void Toolbox::MakeDirectory(const std::string& path) - { - if (boost::filesystem::exists(path)) - { - if (!boost::filesystem::is_directory(path)) - { - throw OrthancException(ErrorCode_DirectoryOverFile); - } - } - else - { - if (!boost::filesystem::create_directories(path)) - { - throw OrthancException(ErrorCode_MakeDirectory); - } - } - } -#endif - - -#if ORTHANC_SANDBOXED == 0 - bool Toolbox::IsExistingFile(const std::string& path) - { - return boost::filesystem::exists(path); - } -#endif - - #if ORTHANC_ENABLE_PUGIXML == 1 class ChunkedBufferWriter : public pugi::xml_writer { @@ -1329,66 +989,6 @@ #endif -#if ORTHANC_SANDBOXED == 0 - void Toolbox::ExecuteSystemCommand(const std::string& command, - const std::vector& arguments) - { - // Convert the arguments as a C array - std::vector args(arguments.size() + 2); - - args.front() = const_cast(command.c_str()); - - for (size_t i = 0; i < arguments.size(); i++) - { - args[i + 1] = const_cast(arguments[i].c_str()); - } - - args.back() = NULL; - - int status; - -#if defined(_WIN32) - // http://msdn.microsoft.com/en-us/library/275khfab.aspx - status = static_cast(_spawnvp(_P_OVERLAY, command.c_str(), &args[0])); - -#else - int pid = fork(); - - if (pid == -1) - { - // Error in fork() -#if ORTHANC_ENABLE_LOGGING == 1 - LOG(ERROR) << "Cannot fork a child process"; -#endif - - throw OrthancException(ErrorCode_SystemCommand); - } - else if (pid == 0) - { - // Execute the system command in the child process - execvp(command.c_str(), &args[0]); - - // We should never get here - _exit(1); - } - else - { - // Wait for the system command to exit - waitpid(pid, &status, 0); - } -#endif - - if (status != 0) - { -#if ORTHANC_ENABLE_LOGGING == 1 - LOG(ERROR) << "System command failed with status code " << status; -#endif - - throw OrthancException(ErrorCode_SystemCommand); - } - } -#endif - bool Toolbox::IsInteger(const std::string& str) { @@ -1496,68 +1096,6 @@ return str.compare(0, prefix.size(), prefix) == 0; } } - - -#if ORTHANC_SANDBOXED == 0 - int Toolbox::GetProcessId() - { -#if defined(_WIN32) - return static_cast(_getpid()); -#else - return static_cast(getpid()); -#endif - } -#endif - - -#if ORTHANC_SANDBOXED == 0 - bool Toolbox::IsRegularFile(const std::string& path) - { - namespace fs = boost::filesystem; - - try - { - if (fs::exists(path)) - { - fs::file_status status = fs::status(path); - return (status.type() == boost::filesystem::regular_file || - status.type() == boost::filesystem::reparse_file); // Fix BitBucket issue #11 - } - } - catch (fs::filesystem_error&) - { - } - - return false; - } -#endif - - - FILE* Toolbox::OpenFile(const std::string& path, - FileMode mode) - { -#if defined(_WIN32) - // TODO Deal with special characters by converting to the current locale -#endif - - const char* m; - switch (mode) - { - case FileMode_ReadBinary: - m = "rb"; - break; - - case FileMode_WriteBinary: - m = "wb"; - break; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - - return fopen(path.c_str(), m); - } - static bool IsUnreservedCharacter(char c) @@ -1698,4 +1236,441 @@ return static_cast(v); } } + + +#if ORTHANC_SANDBOXED == 0 + + static bool finish_; + static ServerBarrierEvent barrierEvent_; + +#if defined(_WIN32) + static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) + { + // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx + finish_ = true; + return true; + } +#else + static void SignalHandler(int signal) + { + if (signal == SIGHUP) + { + barrierEvent_ = ServerBarrierEvent_Reload; + } + + finish_ = true; + } +#endif + + + static ServerBarrierEvent ServerBarrierInternal(const bool* stopFlag) + { +#if defined(_WIN32) + SetConsoleCtrlHandler(ConsoleControlHandler, true); +#else + signal(SIGINT, SignalHandler); + signal(SIGQUIT, SignalHandler); + signal(SIGTERM, SignalHandler); + signal(SIGHUP, SignalHandler); +#endif + + // Active loop that awakens every 100ms + finish_ = false; + barrierEvent_ = ServerBarrierEvent_Stop; + while (!(*stopFlag || finish_)) + { + Toolbox::USleep(100 * 1000); + } + +#if defined(_WIN32) + SetConsoleCtrlHandler(ConsoleControlHandler, false); +#else + signal(SIGINT, NULL); + signal(SIGQUIT, NULL); + signal(SIGTERM, NULL); + signal(SIGHUP, NULL); +#endif + + return barrierEvent_; + } + + + ServerBarrierEvent SystemToolbox::ServerBarrier(const bool& stopFlag) + { + return ServerBarrierInternal(&stopFlag); + } + + + ServerBarrierEvent SystemToolbox::ServerBarrier() + { + const bool stopFlag = false; + return ServerBarrierInternal(&stopFlag); + } + + + static std::streamsize GetStreamSize(std::istream& f) + { + // http://www.cplusplus.com/reference/iostream/istream/tellg/ + f.seekg(0, std::ios::end); + std::streamsize size = f.tellg(); + f.seekg(0, std::ios::beg); + + return size; + } + + + void SystemToolbox::ReadFile(std::string& content, + const std::string& path) + { + if (!IsRegularFile(path)) + { + LOG(ERROR) << std::string("The path does not point to a regular file: ") << path; + throw OrthancException(ErrorCode_RegularFileExpected); + } + + boost::filesystem::ifstream f; + f.open(path, std::ifstream::in | std::ifstream::binary); + if (!f.good()) + { + throw OrthancException(ErrorCode_InexistentFile); + } + + std::streamsize size = GetStreamSize(f); + content.resize(size); + if (size != 0) + { + f.read(reinterpret_cast(&content[0]), size); + } + + f.close(); + } + + + bool SystemToolbox::ReadHeader(std::string& header, + const std::string& path, + size_t headerSize) + { + if (!IsRegularFile(path)) + { + LOG(ERROR) << std::string("The path does not point to a regular file: ") << path; + throw OrthancException(ErrorCode_RegularFileExpected); + } + + boost::filesystem::ifstream f; + f.open(path, std::ifstream::in | std::ifstream::binary); + if (!f.good()) + { + throw OrthancException(ErrorCode_InexistentFile); + } + + bool full = true; + + { + std::streamsize size = GetStreamSize(f); + if (size <= 0) + { + headerSize = 0; + full = false; + } + else if (static_cast(size) < headerSize) + { + headerSize = size; // Truncate to the size of the file + full = false; + } + } + + header.resize(headerSize); + if (headerSize != 0) + { + f.read(reinterpret_cast(&header[0]), headerSize); + } + + f.close(); + + return full; + } + + + void SystemToolbox::WriteFile(const void* content, + size_t size, + const std::string& path) + { + boost::filesystem::ofstream f; + f.open(path, std::ofstream::out | std::ofstream::binary); + if (!f.good()) + { + throw OrthancException(ErrorCode_CannotWriteFile); + } + + if (size != 0) + { + f.write(reinterpret_cast(content), size); + + if (!f.good()) + { + f.close(); + throw OrthancException(ErrorCode_FileStorageCannotWrite); + } + } + + f.close(); + } + + + void SystemToolbox::WriteFile(const std::string& content, + const std::string& path) + { + WriteFile(content.size() > 0 ? content.c_str() : NULL, + content.size(), path); + } + + + void SystemToolbox::RemoveFile(const std::string& path) + { + if (boost::filesystem::exists(path)) + { + if (IsRegularFile(path)) + { + boost::filesystem::remove(path); + } + else + { + throw OrthancException(ErrorCode_RegularFileExpected); + } + } + } + + + uint64_t SystemToolbox::GetFileSize(const std::string& path) + { + try + { + return static_cast(boost::filesystem::file_size(path)); + } + catch (boost::filesystem::filesystem_error&) + { + throw OrthancException(ErrorCode_InexistentFile); + } + } + + + void SystemToolbox::MakeDirectory(const std::string& path) + { + if (boost::filesystem::exists(path)) + { + if (!boost::filesystem::is_directory(path)) + { + throw OrthancException(ErrorCode_DirectoryOverFile); + } + } + else + { + if (!boost::filesystem::create_directories(path)) + { + throw OrthancException(ErrorCode_MakeDirectory); + } + } + } + + + bool SystemToolbox::IsExistingFile(const std::string& path) + { + return boost::filesystem::exists(path); + } + + +#if defined(_WIN32) + static std::string GetPathToExecutableInternal() + { + // Yes, this is ugly, but there is no simple way to get the + // required buffer size, so we use a big constant + std::vector buffer(32768); + /*int bytes =*/ GetModuleFileNameA(NULL, &buffer[0], static_cast(buffer.size() - 1)); + return std::string(&buffer[0]); + } + +#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) + static std::string GetPathToExecutableInternal() + { + std::vector buffer(PATH_MAX + 1); + ssize_t bytes = readlink("/proc/self/exe", &buffer[0], buffer.size() - 1); + if (bytes == 0) + { + throw OrthancException(ErrorCode_PathToExecutable); + } + + return std::string(&buffer[0]); + } + +#elif defined(__APPLE__) && defined(__MACH__) + static std::string GetPathToExecutableInternal() + { + char pathbuf[PATH_MAX + 1]; + unsigned int bufsize = static_cast(sizeof(pathbuf)); + + _NSGetExecutablePath( pathbuf, &bufsize); + + return std::string(pathbuf); + } + +#else +#error Support your platform here +#endif + + + std::string SystemToolbox::GetPathToExecutable() + { + boost::filesystem::path p(GetPathToExecutableInternal()); + return boost::filesystem::absolute(p).string(); + } + + + std::string SystemToolbox::GetDirectoryOfExecutable() + { + boost::filesystem::path p(GetPathToExecutableInternal()); + return boost::filesystem::absolute(p.parent_path()).string(); + } + + + void SystemToolbox::ExecuteSystemCommand(const std::string& command, + const std::vector& arguments) + { + // Convert the arguments as a C array + std::vector args(arguments.size() + 2); + + args.front() = const_cast(command.c_str()); + + for (size_t i = 0; i < arguments.size(); i++) + { + args[i + 1] = const_cast(arguments[i].c_str()); + } + + args.back() = NULL; + + int status; + +#if defined(_WIN32) + // http://msdn.microsoft.com/en-us/library/275khfab.aspx + status = static_cast(_spawnvp(_P_OVERLAY, command.c_str(), &args[0])); + +#else + int pid = fork(); + + if (pid == -1) + { + // Error in fork() +#if ORTHANC_ENABLE_LOGGING == 1 + LOG(ERROR) << "Cannot fork a child process"; +#endif + + throw OrthancException(ErrorCode_SystemCommand); + } + else if (pid == 0) + { + // Execute the system command in the child process + execvp(command.c_str(), &args[0]); + + // We should never get here + _exit(1); + } + else + { + // Wait for the system command to exit + waitpid(pid, &status, 0); + } +#endif + + if (status != 0) + { +#if ORTHANC_ENABLE_LOGGING == 1 + LOG(ERROR) << "System command failed with status code " << status; +#endif + + throw OrthancException(ErrorCode_SystemCommand); + } + } + + + int SystemToolbox::GetProcessId() + { +#if defined(_WIN32) + return static_cast(_getpid()); +#else + return static_cast(getpid()); +#endif + } + + + bool SystemToolbox::IsRegularFile(const std::string& path) + { + namespace fs = boost::filesystem; + + try + { + if (fs::exists(path)) + { + fs::file_status status = fs::status(path); + return (status.type() == boost::filesystem::regular_file || + status.type() == boost::filesystem::reparse_file); // Fix BitBucket issue #11 + } + } + catch (fs::filesystem_error&) + { + } + + return false; + } + + + FILE* SystemToolbox::OpenFile(const std::string& path, + FileMode mode) + { +#if defined(_WIN32) + // TODO Deal with special characters by converting to the current locale +#endif + + const char* m; + switch (mode) + { + case FileMode_ReadBinary: + m = "rb"; + break; + + case FileMode_WriteBinary: + m = "wb"; + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + return fopen(path.c_str(), m); + } + + +#if BOOST_HAS_DATE_TIME == 1 + std::string SystemToolbox::GetNowIsoString() + { + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + return boost::posix_time::to_iso_string(now); + } + + void SystemToolbox::GetNowDicom(std::string& date, + std::string& time) + { + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + tm tm = boost::posix_time::to_tm(now); + + char s[32]; + sprintf(s, "%04d%02d%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + date.assign(s); + + // TODO milliseconds + sprintf(s, "%02d%02d%02d.%06d", tm.tm_hour, tm.tm_min, tm.tm_sec, 0); + time.assign(s); + } +#endif + + +#endif /* ORTHANC_SANDBOXED */ } diff -r 764c9157301b -r aa4b8895cd23 Core/Toolbox.h --- a/Core/Toolbox.h Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Toolbox.h Wed Nov 09 16:12:47 2016 +0100 @@ -72,12 +72,6 @@ { void USleep(uint64_t microSeconds); -#if ORTHANC_SANDBOXED == 0 - ServerBarrierEvent ServerBarrier(const bool& stopFlag); - - ServerBarrierEvent ServerBarrier(); -#endif - void ToUpperCase(std::string& s); // Inplace version void ToLowerCase(std::string& s); // Inplace version @@ -88,24 +82,6 @@ void ToLowerCase(std::string& result, const std::string& source); -#if ORTHANC_SANDBOXED == 0 - void ReadFile(std::string& content, - const std::string& path); - - bool ReadHeader(std::string& header, - const std::string& path, - size_t headerSize); - - void WriteFile(const std::string& content, - const std::string& path); - - void WriteFile(const void* content, - size_t size, - const std::string& path); - - void RemoveFile(const std::string& path); -#endif - void SplitUriComponents(UriComponents& components, const std::string& uri); @@ -121,10 +97,6 @@ std::string FlattenUri(const UriComponents& components, size_t fromLevel = 0); -#if ORTHANC_SANDBOXED == 0 - uint64_t GetFileSize(const std::string& path); -#endif - #if ORTHANC_ENABLE_MD5 == 1 void ComputeMD5(std::string& result, const std::string& data); @@ -164,12 +136,6 @@ const std::string& content); #endif -#if ORTHANC_SANDBOXED == 0 - std::string GetPathToExecutable(); - - std::string GetDirectoryOfExecutable(); -#endif - std::string ConvertToUtf8(const std::string& source, Encoding sourceEncoding); @@ -183,13 +149,6 @@ std::string StripSpaces(const std::string& source); -#if BOOST_HAS_DATE_TIME == 1 - std::string GetNowIsoString(); - - void GetNowDicom(std::string& date, - std::string& time); -#endif - // In-place percent-decoding for URL void UrlDecode(std::string& s); @@ -203,12 +162,6 @@ const std::string& source, char separator); -#if ORTHANC_SANDBOXED == 0 - void MakeDirectory(const std::string& path); - - bool IsExistingFile(const std::string& path); -#endif - #if ORTHANC_ENABLE_PUGIXML == 1 void JsonToXml(std::string& target, const Json::Value& source, @@ -216,11 +169,6 @@ const std::string& arrayElement = "item"); #endif -#if ORTHANC_SANDBOXED == 0 - void ExecuteSystemCommand(const std::string& command, - const std::vector& arguments); -#endif - bool IsInteger(const std::string& str); void CopyJsonWithoutComments(Json::Value& target, @@ -229,15 +177,6 @@ bool StartsWith(const std::string& str, const std::string& prefix); -#if ORTHANC_SANDBOXED == 0 - int GetProcessId(); - - bool IsRegularFile(const std::string& path); -#endif - - FILE* OpenFile(const std::string& path, - FileMode mode); - void UriEncode(std::string& target, const std::string& source); @@ -257,4 +196,57 @@ const std::string& key, unsigned int defaultValue); } + + +#if ORTHANC_SANDBOXED == 0 + namespace SystemToolbox + { + ServerBarrierEvent ServerBarrier(const bool& stopFlag); + + ServerBarrierEvent ServerBarrier(); + + void ReadFile(std::string& content, + const std::string& path); + + bool ReadHeader(std::string& header, + const std::string& path, + size_t headerSize); + + void WriteFile(const void* content, + size_t size, + const std::string& path); + + void WriteFile(const std::string& content, + const std::string& path); + + void RemoveFile(const std::string& path); + + uint64_t GetFileSize(const std::string& path); + + void MakeDirectory(const std::string& path); + + bool IsExistingFile(const std::string& path); + + std::string GetPathToExecutable(); + + std::string GetDirectoryOfExecutable(); + + void ExecuteSystemCommand(const std::string& command, + const std::vector& arguments); + + int GetProcessId(); + + bool IsRegularFile(const std::string& path); + + FILE* OpenFile(const std::string& path, + FileMode mode); + +#if BOOST_HAS_DATE_TIME == 1 + std::string GetNowIsoString(); + + void GetNowDicom(std::string& date, + std::string& time); +#endif + } +#endif /* ORTHANC_SANDBOXED */ } diff -r 764c9157301b -r aa4b8895cd23 Core/Uuid.cpp --- a/Core/Uuid.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Uuid.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -117,46 +117,48 @@ return IsUuid(str.substr(0, 36)); } + } - static std::string CreateTemporaryPath(const char* extension) - { + static std::string CreateTemporaryPath(const char* extension) + { #if BOOST_HAS_FILESYSTEM_V3 == 1 - boost::filesystem::path tmpDir = boost::filesystem::temp_directory_path(); + boost::filesystem::path tmpDir = boost::filesystem::temp_directory_path(); #elif defined(__linux__) - boost::filesystem::path tmpDir("/tmp"); + boost::filesystem::path tmpDir("/tmp"); #else #error Support your platform here #endif - // We use UUID to create unique path to temporary files - std::string filename = "Orthanc-" + Orthanc::Toolbox::GenerateUuid(); + // We use UUID to create unique path to temporary files + std::string filename = "Orthanc-" + Orthanc::Toolbox::GenerateUuid(); - if (extension != NULL) - { - filename.append(extension); - } + if (extension != NULL) + { + filename.append(extension); + } - tmpDir /= filename; - return tmpDir.string(); - } + tmpDir /= filename; + return tmpDir.string(); + } - TemporaryFile::TemporaryFile() : - path_(CreateTemporaryPath(NULL)) - { - } +#if ORTHANC_SANDBOXED == 0 + TemporaryFile::TemporaryFile() : + path_(CreateTemporaryPath(NULL)) + { + } - TemporaryFile::TemporaryFile(const char* extension) : - path_(CreateTemporaryPath(extension)) - { - } + TemporaryFile::TemporaryFile(const char* extension) : + path_(CreateTemporaryPath(extension)) + { + } - TemporaryFile::~TemporaryFile() - { - boost::filesystem::remove(path_); - } - } + TemporaryFile::~TemporaryFile() + { + boost::filesystem::remove(path_); + } +#endif } diff -r 764c9157301b -r aa4b8895cd23 Core/Uuid.h --- a/Core/Uuid.h Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/Uuid.h Wed Nov 09 16:12:47 2016 +0100 @@ -43,6 +43,10 @@ * http://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid **/ +#if !defined(ORTHANC_SANDBOXED) +# define ORTHANC_SANDBOXED 0 +#endif + #include "Toolbox.h" namespace Orthanc @@ -54,33 +58,35 @@ bool IsUuid(const std::string& str); bool StartsWithUuid(const std::string& str); - - class TemporaryFile - { - private: - std::string path_; + } - public: - TemporaryFile(); +#if ORTHANC_SANDBOXED == 0 + class TemporaryFile + { + private: + std::string path_; - TemporaryFile(const char* extension); + public: + TemporaryFile(); - ~TemporaryFile(); + TemporaryFile(const char* extension); + + ~TemporaryFile(); - const std::string& GetPath() const - { - return path_; - } + const std::string& GetPath() const + { + return path_; + } - void Write(const std::string& content) - { - Toolbox::WriteFile(content, path_); - } + void Write(const std::string& content) + { + SystemToolbox::WriteFile(content, path_); + } - void Read(std::string& content) const - { - Toolbox::ReadFile(content, path_); - } - }; - } + void Read(std::string& content) const + { + SystemToolbox::ReadFile(content, path_); + } + }; +#endif } diff -r 764c9157301b -r aa4b8895cd23 Core/WebServiceParameters.cpp --- a/Core/WebServiceParameters.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Core/WebServiceParameters.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -66,14 +66,14 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } - if (!Toolbox::IsRegularFile(certificateFile)) + if (!SystemToolbox::IsRegularFile(certificateFile)) { LOG(ERROR) << "Cannot open certificate file: " << certificateFile; throw OrthancException(ErrorCode_InexistentFile); } if (!certificateKeyFile.empty() && - !Toolbox::IsRegularFile(certificateKeyFile)) + !SystemToolbox::IsRegularFile(certificateKeyFile)) { LOG(ERROR) << "Cannot open key file: " << certificateKeyFile; throw OrthancException(ErrorCode_InexistentFile); diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/DicomDirWriter.cpp --- a/OrthancServer/DicomDirWriter.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/DicomDirWriter.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -126,7 +126,7 @@ { private: std::string fileSetId_; - Toolbox::TemporaryFile file_; + TemporaryFile file_; std::auto_ptr dir_; typedef std::pair IndexKey; @@ -260,7 +260,7 @@ // cf. "DicomDirInterface::buildStudyRecord()" std::string nowDate, nowTime; - Toolbox::GetNowDicom(nowDate, nowTime); + SystemToolbox::GetNowDicom(nowDate, nowTime); std::string studyDate; if (!GetUtf8TagValue(studyDate, dicom, encoding, DCM_StudyDate) && diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/OrthancInitialization.cpp --- a/OrthancServer/OrthancInitialization.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/OrthancInitialization.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -128,7 +128,7 @@ { std::string content; - Toolbox::ReadFile(content, path.string()); + SystemToolbox::ReadFile(content, path.string()); Json::Value tmp; Json::Reader reader; diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -758,7 +758,7 @@ // Inject time-related information std::string date, time; - Toolbox::GetNowDicom(date, time); + SystemToolbox::GetNowDicom(date, time); dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_DATE, date); dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_TIME, time); dicom.ReplacePlainString(DICOM_TAG_CONTENT_DATE, date); diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/OrthancRestApi/OrthancRestArchive.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -547,7 +547,7 @@ const bool isZip64 = IsZip64Required(stats.GetUncompressedSize(), stats.GetInstancesCount()); // Create a RAII for the temporary file to manage the ZIP file - Toolbox::TemporaryFile tmp; + TemporaryFile tmp; { // Create a ZIP writer @@ -634,7 +634,7 @@ const bool isZip64 = IsZip64Required(stats.GetUncompressedSize(), stats.GetInstancesCount()); // Create a RAII for the temporary file to manage the ZIP file - Toolbox::TemporaryFile tmp; + TemporaryFile tmp; { // Create a ZIP writer diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -192,7 +192,7 @@ std::string target; call.BodyToString(target); - Toolbox::WriteFile(dicom, target); + SystemToolbox::WriteFile(dicom, target); call.GetOutput().AnswerBuffer("{}", "application/json"); } diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -131,7 +131,7 @@ static void GetNowIsoString(RestApiGetCall& call) { - call.GetOutput().AnswerBuffer(Toolbox::GetNowIsoString(), "text/plain"); + call.GetOutput().AnswerBuffer(SystemToolbox::GetNowIsoString(), "text/plain"); } diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/ParsedDicomFile.cpp --- a/OrthancServer/ParsedDicomFile.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/ParsedDicomFile.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -855,7 +855,7 @@ // TODO Avoid using a temporary memory buffer, write directly on disk std::string content; SaveToMemoryBuffer(content); - Toolbox::WriteFile(content, path); + SystemToolbox::WriteFile(content, path); } diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/Scheduler/CallSystemCommand.cpp --- a/OrthancServer/Scheduler/CallSystemCommand.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/Scheduler/CallSystemCommand.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -61,13 +61,13 @@ std::string dicom; context_.ReadDicom(dicom, *it); - Toolbox::TemporaryFile tmp; + TemporaryFile tmp; tmp.Write(dicom); std::vector args = arguments_; args.push_back(tmp.GetPath()); - Toolbox::ExecuteSystemCommand(command_, args); + SystemToolbox::ExecuteSystemCommand(command_, args); // Only chain with other commands if this command succeeds outputs.push_back(*it); diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/ServerIndex.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -757,7 +757,7 @@ } // Attach the auto-computed metadata for the patient/study/series levels - std::string now = Toolbox::GetNowIsoString(); + std::string now = SystemToolbox::GetNowIsoString(); db_.SetMetadata(series, MetadataType_LastUpdate, now); db_.SetMetadata(study, MetadataType_LastUpdate, now); db_.SetMetadata(patient, MetadataType_LastUpdate, now); @@ -1261,7 +1261,7 @@ type, publicId, remoteModality, - Toolbox::GetNowIsoString(), + SystemToolbox::GetNowIsoString(), patientId, studyInstanceUid, seriesInstanceUid, diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/ServerIndexChange.h --- a/OrthancServer/ServerIndexChange.h Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/ServerIndexChange.h Wed Nov 09 16:12:47 2016 +0100 @@ -58,7 +58,7 @@ changeType_(changeType), resourceType_(resourceType), publicId_(publicId), - date_(Toolbox::GetNowIsoString()) + date_(SystemToolbox::GetNowIsoString()) { } diff -r 764c9157301b -r aa4b8895cd23 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/OrthancServer/main.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -612,7 +612,7 @@ std::string path = Configuration::InterpretStringParameterAsPath(*it); LOG(WARNING) << "Installing the Lua scripts from: " << path; std::string script; - Toolbox::ReadFile(script, path); + SystemToolbox::ReadFile(script, path); LuaScripting::Locker locker(context.GetLua()); locker.GetLua().Execute(script); @@ -657,7 +657,7 @@ for (;;) { - ServerBarrierEvent event = Toolbox::ServerBarrier(restApi.LeaveBarrierFlag()); + ServerBarrierEvent event = SystemToolbox::ServerBarrier(restApi.LeaveBarrierFlag()); restart = restApi.IsResetRequestReceived(); if (!restart && @@ -1202,7 +1202,7 @@ #endif std::string target = argument.substr(9); - Toolbox::WriteFile(configurationSample, target); + SystemToolbox::WriteFile(configurationSample, target); return 0; } else @@ -1223,7 +1223,7 @@ { try { - boost::filesystem::path exe(Toolbox::GetPathToExecutable()); + boost::filesystem::path exe(SystemToolbox::GetPathToExecutable()); std::time_t creation = boost::filesystem::last_write_time(exe); boost::posix_time::ptime converted(boost::posix_time::from_time_t(creation)); version += " (" + boost::posix_time::to_iso_string(converted) + ")"; diff -r 764c9157301b -r aa4b8895cd23 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -2172,14 +2172,14 @@ { case _OrthancPluginService_GetOrthancPath: { - std::string s = Toolbox::GetPathToExecutable(); + std::string s = SystemToolbox::GetPathToExecutable(); *reinterpret_cast(parameters)->result = CopyString(s); return true; } case _OrthancPluginService_GetOrthancDirectory: { - std::string s = Toolbox::GetDirectoryOfExecutable(); + std::string s = SystemToolbox::GetDirectoryOfExecutable(); *reinterpret_cast(parameters)->result = CopyString(s); return true; } @@ -2366,7 +2366,7 @@ *reinterpret_cast(parameters); std::string content; - Toolbox::ReadFile(content, p.path); + SystemToolbox::ReadFile(content, p.path); CopyToMemoryBuffer(*p.target, content.size() > 0 ? content.c_str() : NULL, content.size()); return true; @@ -2376,7 +2376,7 @@ { const _OrthancPluginWriteFile& p = *reinterpret_cast(parameters); - Toolbox::WriteFile(p.data, p.size, p.path); + SystemToolbox::WriteFile(p.data, p.size, p.path); return true; } diff -r 764c9157301b -r aa4b8895cd23 Resources/Samples/Tools/RecoverCompressedFile.cpp --- a/Resources/Samples/Tools/RecoverCompressedFile.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/Resources/Samples/Tools/RecoverCompressedFile.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -40,7 +40,7 @@ fflush(stderr); std::string content; - Orthanc::Toolbox::ReadFile(content, argv[1]); + Orthanc::SystemToolbox::ReadFile(content, argv[1]); fprintf(stderr, "Decompressing the content of the file...\n"); fflush(stderr); @@ -56,7 +56,7 @@ if (argc == 3) { - Orthanc::Toolbox::WriteFile(uncompressed, argv[2]); + Orthanc::SystemToolbox::WriteFile(uncompressed, argv[2]); } else { diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/FromDcmtkTests.cpp --- a/UnitTestsSources/FromDcmtkTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/FromDcmtkTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -857,7 +857,7 @@ { std::string s; - Orthanc::Toolbox::ReadFile(s, PATH); + Orthanc::SystemToolbox::ReadFile(s, PATH); Orthanc::ParsedDicomFile f(s); std::auto_ptr decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); @@ -919,7 +919,7 @@ { std::string s; - Orthanc::Toolbox::ReadFile(s, PATH); + Orthanc::SystemToolbox::ReadFile(s, PATH); Orthanc::ParsedDicomFile f(s); std::auto_ptr decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); @@ -973,7 +973,7 @@ { std::string s; - Orthanc::Toolbox::ReadFile(s, PATH); + Orthanc::SystemToolbox::ReadFile(s, PATH); Orthanc::ParsedDicomFile f(s); std::auto_ptr decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); @@ -1027,7 +1027,7 @@ { std::string s; - Orthanc::Toolbox::ReadFile(s, PATH); + Orthanc::SystemToolbox::ReadFile(s, PATH); Orthanc::ParsedDicomFile f(s); std::auto_ptr decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/ImageTests.cpp --- a/UnitTestsSources/ImageTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/ImageTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -72,7 +72,7 @@ w.WriteToFile("UnitTestsResults/ColorPattern.png", accessor); std::string f, md5; - Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png"); + Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png"); Orthanc::Toolbox::ComputeMD5(md5, f); ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5); } @@ -100,7 +100,7 @@ w.WriteToFile("UnitTestsResults/Gray8Pattern.png", accessor); std::string f, md5; - Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png"); + Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png"); Orthanc::Toolbox::ComputeMD5(md5, f); ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5); } @@ -129,7 +129,7 @@ w.WriteToFile("UnitTestsResults/Gray16Pattern.png", accessor); std::string f, md5; - Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png"); + Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png"); Orthanc::Toolbox::ComputeMD5(md5, f); ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5); } @@ -180,8 +180,8 @@ } { - Orthanc::Toolbox::TemporaryFile tmp; - Orthanc::Toolbox::WriteFile(s, tmp.GetPath()); + Orthanc::TemporaryFile tmp; + Orthanc::SystemToolbox::WriteFile(s, tmp.GetPath()); Orthanc::PngReader r2; r2.ReadFromFile(tmp.GetPath()); @@ -225,10 +225,10 @@ w.WriteToFile("UnitTestsResults/hello.jpg", img); w.WriteToMemory(s, img); - Orthanc::Toolbox::WriteFile(s, "UnitTestsResults/hello2.jpg"); + Orthanc::SystemToolbox::WriteFile(s, "UnitTestsResults/hello2.jpg"); std::string t; - Orthanc::Toolbox::ReadFile(t, "UnitTestsResults/hello.jpg"); + Orthanc::SystemToolbox::ReadFile(t, "UnitTestsResults/hello.jpg"); ASSERT_EQ(s.size(), t.size()); ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); } diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/MultiThreadingTests.cpp --- a/UnitTestsSources/MultiThreadingTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/MultiThreadingTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -151,7 +151,7 @@ lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676277", 0); } - Toolbox::ServerBarrier(); + SystemToolbox::ServerBarrier(); printf("DONE\n"); fflush(stdout); } @@ -246,7 +246,7 @@ printf("** %s\n", i->c_str()); } - //Toolbox::ServerBarrier(); + //SystemToolbox::ServerBarrier(); //Toolbox::USleep(3000000); scheduler.Stop(); diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/RestApiTests.cpp --- a/UnitTestsSources/RestApiTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/RestApiTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -100,12 +100,12 @@ TEST(HttpClient, Ssl) { - Toolbox::WriteFile(BITBUCKET_CERTIFICATES, "UnitTestsResults/bitbucket.cert"); + SystemToolbox::WriteFile(BITBUCKET_CERTIFICATES, "UnitTestsResults/bitbucket.cert"); /*{ std::string s; - Toolbox::ReadFile(s, "/usr/share/ca-certificates/mozilla/WoSign.crt"); - Toolbox::WriteFile(s, "UnitTestsResults/bitbucket.cert"); + SystemToolbox::ReadFile(s, "/usr/share/ca-certificates/mozilla/WoSign.crt"); + SystemToolbox::WriteFile(s, "UnitTestsResults/bitbucket.cert"); }*/ HttpClient c; diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/SQLiteTests.cpp --- a/UnitTestsSources/SQLiteTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/SQLiteTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -58,7 +58,7 @@ TEST(SQLite, Connection) { - Toolbox::RemoveFile("UnitTestsResults/coucou"); + SystemToolbox::RemoveFile("UnitTestsResults/coucou"); SQLite::Connection c; c.Open("UnitTestsResults/coucou"); c.Execute("CREATE TABLE c(k INTEGER PRIMARY KEY AUTOINCREMENT, v INTEGER)"); diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -671,7 +671,7 @@ { const std::string path = "UnitTestsStorage"; - Toolbox::RemoveFile(path + "/index"); + SystemToolbox::RemoveFile(path + "/index"); FilesystemStorage storage(path); DatabaseWrapper db; // The SQLite DB is in memory db.Open(); @@ -769,7 +769,7 @@ { const std::string path = "UnitTestsStorage"; - Toolbox::RemoveFile(path + "/index"); + SystemToolbox::RemoveFile(path + "/index"); FilesystemStorage storage(path); DatabaseWrapper db; // The SQLite DB is in memory db.Open(); @@ -824,7 +824,7 @@ } // Because the DB is in memory, the SQLite index must not have been created - ASSERT_FALSE(Toolbox::IsRegularFile(path + "/index")); + ASSERT_FALSE(SystemToolbox::IsRegularFile(path + "/index")); context.Stop(); db.Close(); diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/StreamTests.cpp --- a/UnitTestsSources/StreamTests.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/StreamTests.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -233,14 +233,14 @@ std::string t; { - Toolbox::WriteFile(s, path); + SystemToolbox::WriteFile(s, path); FilesystemHttpSender sender(path); ASSERT_TRUE(ReadAllStream(t, sender)); ASSERT_EQ(s, t); } { - Toolbox::WriteFile("", path); + SystemToolbox::WriteFile("", path); FilesystemHttpSender sender(path); ASSERT_TRUE(ReadAllStream(t, sender)); ASSERT_EQ(0u, t.size()); diff -r 764c9157301b -r aa4b8895cd23 UnitTestsSources/UnitTestsMain.cpp --- a/UnitTestsSources/UnitTestsMain.cpp Wed Nov 09 15:25:09 2016 +0100 +++ b/UnitTestsSources/UnitTestsMain.cpp Wed Nov 09 16:12:47 2016 +0100 @@ -374,8 +374,8 @@ TEST(Toolbox, PathToExecutable) { - printf("[%s]\n", Toolbox::GetPathToExecutable().c_str()); - printf("[%s]\n", Toolbox::GetDirectoryOfExecutable().c_str()); + printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str()); + printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str()); } TEST(Toolbox, StripSpaces) @@ -543,7 +543,7 @@ std::string path; { - Toolbox::TemporaryFile tmp; + TemporaryFile tmp; path = tmp.GetPath(); std::string s; @@ -552,28 +552,28 @@ s.append("World"); ASSERT_EQ(11u, s.size()); - Toolbox::WriteFile(s, path.c_str()); + SystemToolbox::WriteFile(s, path.c_str()); std::string t; - Toolbox::ReadFile(t, path.c_str()); + SystemToolbox::ReadFile(t, path.c_str()); ASSERT_EQ(11u, t.size()); ASSERT_EQ(0, t[5]); ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); std::string h; - ASSERT_EQ(true, Toolbox::ReadHeader(h, path.c_str(), 1)); + ASSERT_EQ(true, SystemToolbox::ReadHeader(h, path.c_str(), 1)); ASSERT_EQ(1u, h.size()); ASSERT_EQ('H', h[0]); - ASSERT_TRUE(Toolbox::ReadHeader(h, path.c_str(), 0)); + ASSERT_TRUE(SystemToolbox::ReadHeader(h, path.c_str(), 0)); ASSERT_EQ(0u, h.size()); - ASSERT_FALSE(Toolbox::ReadHeader(h, path.c_str(), 32)); + ASSERT_FALSE(SystemToolbox::ReadHeader(h, path.c_str(), 32)); ASSERT_EQ(11u, h.size()); ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size())); } std::string u; - ASSERT_THROW(Toolbox::ReadFile(u, path.c_str()), OrthancException); + ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException); } @@ -896,7 +896,7 @@ args[0] = "Hello"; args[1] = "World"; - Toolbox::ExecuteSystemCommand("echo", args); + SystemToolbox::ExecuteSystemCommand("echo", args); } #endif @@ -987,7 +987,7 @@ Logging::Initialize(); Logging::EnableInfoLevel(true); Toolbox::DetectEndianness(); - Toolbox::MakeDirectory("UnitTestsResults"); + SystemToolbox::MakeDirectory("UnitTestsResults"); OrthancInitialize(); ::testing::InitGoogleTest(&argc, argv);