changeset 2170:baf8dd89b4e0

improved support for sandboxed environments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Nov 2016 11:45:02 +0100
parents d15de5685ad8
children 35febe19e874
files Core/Images/IImageWriter.cpp Core/Images/IImageWriter.h Core/Images/JpegReader.cpp Core/Images/JpegReader.h Core/Images/JpegWriter.cpp Core/Images/JpegWriter.h Core/Images/PngReader.cpp Core/Images/PngReader.h Core/Images/PngWriter.cpp Core/Images/PngWriter.h
diffstat 10 files changed, 37 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Images/IImageWriter.cpp	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/IImageWriter.cpp	Wed Nov 23 11:45:02 2016 +0100
@@ -32,18 +32,13 @@
 
 #include "IImageWriter.h"
 
-#include "../OrthancException.h"
-
-#if !defined(ORTHANC_SANDBOXED)
-#  error The macro ORTHANC_SANDBOXED must be defined
-#endif
-
 #if ORTHANC_SANDBOXED == 0
 #  include "../SystemToolbox.h"
 #endif
 
 namespace Orthanc
 {
+#if ORTHANC_SANDBOXED == 0
   void IImageWriter::WriteToFileInternal(const std::string& path,
                                          unsigned int width,
                                          unsigned int height,
@@ -51,12 +46,9 @@
                                          PixelFormat format,
                                          const void* buffer)
   {
-#if ORTHANC_SANDBOXED == 0
     std::string compressed;
     WriteToMemoryInternal(compressed, width, height, pitch, format, buffer);
     SystemToolbox::WriteFile(compressed, path);
-#else
-    throw OrthancException(ErrorCode_CannotWriteFile);  // Unavailable in sandboxed environments
+  }
 #endif
-  }
 }
--- a/Core/Images/IImageWriter.h	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/IImageWriter.h	Wed Nov 23 11:45:02 2016 +0100
@@ -36,6 +36,10 @@
 
 #include <boost/noncopyable.hpp>
 
+#if !defined(ORTHANC_SANDBOXED)
+#  error The macro ORTHANC_SANDBOXED must be defined
+#endif
+
 namespace Orthanc
 {
   class IImageWriter : public boost::noncopyable
@@ -48,12 +52,14 @@
                                        PixelFormat format,
                                        const void* buffer) = 0;
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToFileInternal(const std::string& path,
                                      unsigned int width,
                                      unsigned int height,
                                      unsigned int pitch,
                                      PixelFormat format,
                                      const void* buffer);
+#endif
 
   public:
     virtual ~IImageWriter()
@@ -67,11 +73,13 @@
                             accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
     }
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToFile(const std::string& path,
                              const ImageAccessor& accessor)
     {
       WriteToFileInternal(path, accessor.GetWidth(), accessor.GetHeight(),
                           accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
     }
+#endif
   };
 }
--- a/Core/Images/JpegReader.cpp	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/JpegReader.cpp	Wed Nov 23 11:45:02 2016 +0100
@@ -94,6 +94,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   void JpegReader::ReadFromFile(const std::string& filename)
   {
     FILE* fp = SystemToolbox::OpenFile(filename, FileMode_ReadBinary);
@@ -135,6 +136,7 @@
     jpeg_destroy_decompress(&cinfo);
     fclose(fp);
   }
+#endif
 
 
   void JpegReader::ReadFromMemory(const void* buffer,
--- a/Core/Images/JpegReader.h	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/JpegReader.h	Wed Nov 23 11:45:02 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/Core/Images/JpegWriter.cpp	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/JpegWriter.cpp	Wed Nov 23 11:45:02 2016 +0100
@@ -112,6 +112,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   void JpegWriter::WriteToFileInternal(const std::string& filename,
                                        unsigned int width,
                                        unsigned int height,
@@ -155,6 +156,7 @@
 
     fclose(fp);
   }
+#endif
 
 
   void JpegWriter::WriteToMemoryInternal(std::string& jpeg,
--- a/Core/Images/JpegWriter.h	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/JpegWriter.h	Wed Nov 23 11:45:02 2016 +0100
@@ -46,12 +46,14 @@
                                      PixelFormat format,
                                      const void* buffer);
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToMemoryInternal(std::string& jpeg,
                                        unsigned int width,
                                        unsigned int height,
                                        unsigned int pitch,
                                        PixelFormat format,
                                        const void* buffer);
+#endif
 
   private:
     uint8_t  quality_;
--- a/Core/Images/PngReader.cpp	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/PngReader.cpp	Wed Nov 23 11:45:02 2016 +0100
@@ -42,6 +42,7 @@
 
 namespace Orthanc
 {
+#if ORTHANC_SANDBOXED == 0
   namespace 
   {
     struct FileRabi
@@ -66,6 +67,7 @@
       }
     };
   }
+#endif
 
 
   struct PngReader::PngRabi
@@ -207,6 +209,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 +235,7 @@
 
     Read(rabi);
   }
+#endif
 
 
   namespace
--- a/Core/Images/PngReader.h	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/PngReader.h	Wed Nov 23 11:45:02 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/Core/Images/PngWriter.cpp	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/PngWriter.cpp	Wed Nov 23 11:45:02 2016 +0100
@@ -203,6 +203,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   void PngWriter::WriteToFileInternal(const std::string& filename,
                                       unsigned int width,
                                       unsigned int height,
@@ -230,7 +231,7 @@
 
     fclose(fp);
   }
-
+#endif
 
 
   static void MemoryCallback(png_structp png_ptr, 
--- a/Core/Images/PngWriter.h	Tue Nov 22 15:03:14 2016 +0100
+++ b/Core/Images/PngWriter.h	Wed Nov 23 11:45:02 2016 +0100
@@ -48,12 +48,14 @@
                                      PixelFormat format,
                                      const void* buffer);
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToMemoryInternal(std::string& png,
                                        unsigned int width,
                                        unsigned int height,
                                        unsigned int pitch,
                                        PixelFormat format,
                                        const void* buffer);
+#endif
 
   private:
     struct PImpl;