changeset 2137:595cf22b3e7e

safety checks of macros
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Nov 2016 15:07:50 +0100
parents dd609a99d39a
children 41b70d5b44c9
files CMakeLists.txt Core/HttpClient.h Core/HttpServer/MongooseServer.cpp Core/Logging.h Core/Pkcs11.h Core/Toolbox.cpp Core/Toolbox.h OrthancServer/Internals/DicomImageDecoder.h OrthancServer/OrthancInitialization.h Plugins/Engine/OrthancPlugins.h Plugins/Samples/DatabasePlugin/CMakeLists.txt
diffstat 11 files changed, 101 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Wed Nov 09 14:08:05 2016 +0100
+++ b/CMakeLists.txt	Wed Nov 09 15:07:50 2016 +0100
@@ -407,6 +407,8 @@
   -DORTHANC_VERSION="${ORTHANC_VERSION}"
   -DORTHANC_DATABASE_VERSION=${ORTHANC_DATABASE_VERSION}
   -DORTHANC_ENABLE_LOGGING=1
+  -DORTHANC_ENABLE_BASE64=1
+  -DORTHANC_ENABLE_MD5=1
   -DORTHANC_MAXIMUM_TAG_LENGTH=256
   -DORTHANC_BUILD_UNIT_TESTS=1
 
--- a/Core/HttpClient.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/Core/HttpClient.h	Wed Nov 09 15:07:50 2016 +0100
@@ -39,6 +39,15 @@
 #include <boost/shared_ptr.hpp>
 #include <json/json.h>
 
+#if !defined(ORTHANC_ENABLE_SSL)
+#  error The macro ORTHANC_ENABLE_SSL must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_PKCS11)
+#  error The macro ORTHANC_ENABLE_PKCS11 must be defined
+#endif
+
+
 namespace Orthanc
 {
   class HttpClient
--- a/Core/HttpServer/MongooseServer.cpp	Wed Nov 09 14:08:05 2016 +0100
+++ b/Core/HttpServer/MongooseServer.cpp	Wed Nov 09 15:07:50 2016 +0100
@@ -49,6 +49,10 @@
 #include <stdio.h>
 #include <boost/thread.hpp>
 
+#if !defined(ORTHANC_ENABLE_SSL)
+#  error The macro ORTHANC_ENABLE_SSL must be defined
+#endif
+
 #if ORTHANC_ENABLE_SSL == 1
 #include <openssl/opensslv.h>
 #endif
--- a/Core/Logging.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/Core/Logging.h	Wed Nov 09 15:07:50 2016 +0100
@@ -34,6 +34,10 @@
 
 #include <iostream>
 
+#if !defined(ORTHANC_ENABLE_LOGGING)
+#  error The macro ORTHANC_ENABLE_LOGGING must be defined
+#endif
+
 namespace Orthanc
 {
   namespace Logging
--- a/Core/Pkcs11.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/Core/Pkcs11.h	Wed Nov 09 15:07:50 2016 +0100
@@ -32,6 +32,14 @@
 
 #pragma once
 
+#if !defined(ORTHANC_ENABLE_PKCS11)
+#  error The macro ORTHANC_ENABLE_PKCS11 must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_SSL)
+#  error The macro ORTHANC_ENABLE_SSL must be defined
+#endif
+
 #if ORTHANC_ENABLE_PKCS11 != 1 || ORTHANC_ENABLE_SSL != 1
 #  error This file cannot be used if OpenSSL or PKCS#11 support is disabled
 #endif
--- a/Core/Toolbox.cpp	Wed Nov 09 14:08:05 2016 +0100
+++ b/Core/Toolbox.cpp	Wed Nov 09 15:07:50 2016 +0100
@@ -80,13 +80,13 @@
 #include <boost/locale.hpp>
 
 
-#if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1
-#include "../Resources/ThirdParty/md5/md5.h"
+#if ORTHANC_ENABLE_MD5 == 1
+#  include "../Resources/ThirdParty/md5/md5.h"
 #endif
 
 
-#if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1
-#include "../Resources/ThirdParty/base64/base64.h"
+#if ORTHANC_ENABLE_BASE64 == 1
+#  include "../Resources/ThirdParty/base64/base64.h"
 #endif
 
 
@@ -123,7 +123,7 @@
   }
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   static bool finish_;
   static ServerBarrierEvent barrierEvent_;
 
@@ -230,7 +230,7 @@
   }
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   void Toolbox::ReadFile(std::string& content,
                          const std::string& path) 
   {
@@ -259,7 +259,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   bool Toolbox::ReadHeader(std::string& header,
                            const std::string& path,
                            size_t headerSize)
@@ -306,7 +306,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   void Toolbox::WriteFile(const void* content,
                           size_t size,
                           const std::string& path)
@@ -334,7 +334,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   void Toolbox::WriteFile(const std::string& content,
                           const std::string& path)
   {
@@ -344,7 +344,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   void Toolbox::RemoveFile(const std::string& path)
   {
     if (boost::filesystem::exists(path))
@@ -530,7 +530,7 @@
 
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   uint64_t Toolbox::GetFileSize(const std::string& path)
   {
     try
@@ -545,7 +545,7 @@
 #endif
 
 
-#if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1
+#if ORTHANC_ENABLE_MD5 == 1
   static char GetHexadecimalCharacter(uint8_t value)
   {
     assert(value < 16);
@@ -602,7 +602,7 @@
 #endif
 
 
-#if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1
+#if ORTHANC_ENABLE_BASE64 == 1
   void Toolbox::EncodeBase64(std::string& result, 
                              const std::string& data)
   {
@@ -696,7 +696,7 @@
     return std::string(pathbuf);
   }
 
-#elif defined(ORTHANC_SANDBOXED) && ORTHANC_SANDBOXED == 1
+#elif ORTHANC_SANDBOXED == 1
   // Sandboxed Orthanc, no access to the executable
 
 #else
@@ -704,7 +704,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   std::string Toolbox::GetPathToExecutable()
   {
     boost::filesystem::path p(GetPathToExecutableInternal());
@@ -1178,7 +1178,7 @@
   }
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   void Toolbox::MakeDirectory(const std::string& path)
   {
     if (boost::filesystem::exists(path))
@@ -1199,7 +1199,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   bool Toolbox::IsExistingFile(const std::string& path)
   {
     return boost::filesystem::exists(path);
@@ -1329,7 +1329,7 @@
 #endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   void Toolbox::ExecuteSystemCommand(const std::string& command,
                                      const std::vector<std::string>& arguments)
   {
@@ -1498,6 +1498,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   int Toolbox::GetProcessId()
   {
 #if defined(_WIN32)
@@ -1506,9 +1507,10 @@
     return static_cast<int>(getpid());
 #endif
   }
+#endif
 
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
   bool Toolbox::IsRegularFile(const std::string& path)
   {
     namespace fs = boost::filesystem;
--- a/Core/Toolbox.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/Core/Toolbox.h	Wed Nov 09 15:07:50 2016 +0100
@@ -39,6 +39,27 @@
 #include <string>
 #include <json/json.h>
 
+
+#if !defined(ORTHANC_ENABLE_BASE64)
+#  error The macro ORTHANC_ENABLE_BASE64 must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_MD5)
+#  error The macro ORTHANC_ENABLE_MD5 must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_PUGIXML)
+#  error The macro ORTHANC_ENABLE_PUGIXML must be defined
+#endif
+
+#if !defined(BOOST_HAS_REGEX)
+#  error The macro BOOST_HAS_REGEX must be defined
+#endif
+
+#if !defined(ORTHANC_SANDBOXED)
+#  define ORTHANC_SANDBOXED  0
+#endif
+
 namespace Orthanc
 {
   typedef std::vector<std::string> UriComponents;
@@ -51,7 +72,7 @@
   {
     void USleep(uint64_t microSeconds);
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
     ServerBarrierEvent ServerBarrier(const bool& stopFlag);
 
     ServerBarrierEvent ServerBarrier();
@@ -67,29 +88,21 @@
     void ToLowerCase(std::string& result,
                      const std::string& source);
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
     void ReadFile(std::string& content,
                   const std::string& path);
-#endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
     bool ReadHeader(std::string& header,
                     const std::string& path,
                     size_t headerSize);
-#endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
     void WriteFile(const std::string& content,
                    const std::string& path);
-#endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
     void WriteFile(const void* content,
                    size_t size,
                    const std::string& path);
-#endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
     void RemoveFile(const std::string& path);
 #endif
 
@@ -108,11 +121,11 @@
     std::string FlattenUri(const UriComponents& components,
                            size_t fromLevel = 0);
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
     uint64_t GetFileSize(const std::string& path);
 #endif
 
-#if !defined(ORTHANC_ENABLE_MD5) || ORTHANC_ENABLE_MD5 == 1
+#if ORTHANC_ENABLE_MD5 == 1
     void ComputeMD5(std::string& result,
                     const std::string& data);
 
@@ -133,7 +146,7 @@
 
     bool IsSHA1(const std::string& s);
 
-#if !defined(ORTHANC_ENABLE_BASE64) || ORTHANC_ENABLE_BASE64 == 1
+#if ORTHANC_ENABLE_BASE64 == 1
     void DecodeBase64(std::string& result, 
                       const std::string& data);
 
@@ -151,7 +164,7 @@
                              const std::string& content);
 #endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
     std::string GetPathToExecutable();
 
     std::string GetDirectoryOfExecutable();
@@ -190,11 +203,9 @@
                         const std::string& source,
                         char separator);
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
     void MakeDirectory(const std::string& path);
-#endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
     bool IsExistingFile(const std::string& path);
 #endif
 
@@ -205,7 +216,7 @@
                    const std::string& arrayElement = "item");
 #endif
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
+#if ORTHANC_SANDBOXED == 0
     void ExecuteSystemCommand(const std::string& command,
                               const std::vector<std::string>& arguments);
 #endif
@@ -218,9 +229,9 @@
     bool StartsWith(const std::string& str,
                     const std::string& prefix);
 
+#if ORTHANC_SANDBOXED == 0
     int GetProcessId();
 
-#if !defined(ORTHANC_SANDBOXED) || ORTHANC_SANDBOXED != 1
     bool IsRegularFile(const std::string& path);
 #endif
 
--- a/OrthancServer/Internals/DicomImageDecoder.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/OrthancServer/Internals/DicomImageDecoder.h	Wed Nov 09 15:07:50 2016 +0100
@@ -36,6 +36,15 @@
 
 #include <memory>
 
+#if !defined(ORTHANC_ENABLE_JPEG)
+#  error The macro ORTHANC_ENABLE_JPEG must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_JPEG_LOSSLESS)
+#  error The macro ORTHANC_ENABLE_JPEG_LOSSLESS must be defined
+#endif
+
+
 class DcmDataset;
 class DcmCodec;
 class DcmCodecParameter;
--- a/OrthancServer/OrthancInitialization.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/OrthancServer/OrthancInitialization.h	Wed Nov 09 15:07:50 2016 +0100
@@ -46,6 +46,15 @@
 #include "IDatabaseWrapper.h"
 #include "ServerEnumerations.h"
 
+#if !defined(ORTHANC_ENABLE_JPEG)
+#  error The macro ORTHANC_ENABLE_JPEG must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_JPEG_LOSSLESS)
+#  error The macro ORTHANC_ENABLE_JPEG_LOSSLESS must be defined
+#endif
+
+
 class DcmDataset;
 class DcmItem;
 
--- a/Plugins/Engine/OrthancPlugins.h	Wed Nov 09 14:08:05 2016 +0100
+++ b/Plugins/Engine/OrthancPlugins.h	Wed Nov 09 15:07:50 2016 +0100
@@ -34,6 +34,11 @@
 
 #include "PluginsErrorDictionary.h"
 
+#if !defined(ORTHANC_ENABLE_PLUGINS)
+#  error The macro ORTHANC_ENABLE_PLUGINS must be defined
+#endif
+
+
 #if ORTHANC_ENABLE_PLUGINS != 1
 
 #include <boost/noncopyable.hpp>
--- a/Plugins/Samples/DatabasePlugin/CMakeLists.txt	Wed Nov 09 14:08:05 2016 +0100
+++ b/Plugins/Samples/DatabasePlugin/CMakeLists.txt	Wed Nov 09 15:07:50 2016 +0100
@@ -32,7 +32,6 @@
   -DORTHANC_ENABLE_LOGGING=0
   -DORTHANC_ENABLE_BASE64=0
   -DORTHANC_ENABLE_MD5=0
-  -DORTHANC_ENABLE_DCMTK=0
   -DORTHANC_ENABLE_PLUGINS=1
   -DSAMPLE_DATABASE_VERSION="${SAMPLE_DATABASE_VERSION}"
   )