changeset 1579:b93c398f934d

check the size of the enumerations in the plugin engine
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 15:45:50 +0200
parents 09715095fc53
children bf502300c52e
files Core/Enumerations.cpp Core/Enumerations.h Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCDatabasePlugin.h Plugins/Include/orthanc/OrthancCPlugin.h Resources/ErrorCodes.json
diffstat 6 files changed, 72 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Tue Aug 25 15:33:36 2015 +0200
+++ b/Core/Enumerations.cpp	Tue Aug 25 15:45:50 2015 +0200
@@ -49,11 +49,14 @@
       case ErrorCode_Custom:
         return "Custom error, see the attached error message";
 
+      case ErrorCode_InternalError:
+        return "Internal error";
+
       case ErrorCode_Success:
         return "Success";
 
-      case ErrorCode_InternalError:
-        return "Internal error";
+      case ErrorCode_Plugin:
+        return "Error encountered within the plugin engine";
 
       case ErrorCode_NotImplemented:
         return "Not implemented yet";
@@ -127,9 +130,6 @@
       case ErrorCode_SharedLibrary:
         return "Error while using a shared library (plugin)";
 
-      case ErrorCode_Plugin:
-        return "Error encountered inside a plugin";
-
       default:
         return "Unknown error code";
     }
--- a/Core/Enumerations.h	Tue Aug 25 15:33:36 2015 +0200
+++ b/Core/Enumerations.h	Tue Aug 25 15:45:50 2015 +0200
@@ -45,9 +45,10 @@
   // "Resources/GenerateErrorCodes.py"
   enum ErrorCode
   {
-    ErrorCode_Custom = -1    /*!< Custom error, see the attached error message */,
+    ErrorCode_Custom = -2    /*!< Custom error, see the attached error message */,
+    ErrorCode_InternalError = -1    /*!< Internal error */,
     ErrorCode_Success = 0    /*!< Success */,
-    ErrorCode_InternalError = 1    /*!< Internal error */,
+    ErrorCode_Plugin = 1    /*!< Error encountered within the plugin engine */,
     ErrorCode_NotImplemented = 2    /*!< Not implemented yet */,
     ErrorCode_ParameterOutOfRange = 3    /*!< Parameter out of range */,
     ErrorCode_NotEnoughMemory = 4    /*!< Not enough memory */,
@@ -71,8 +72,7 @@
     ErrorCode_ReadOnly = 22    /*!< Cannot modify a read-only data structure */,
     ErrorCode_IncompatibleImageFormat = 23    /*!< Incompatible format of the images */,
     ErrorCode_IncompatibleImageSize = 24    /*!< Incompatible size of the images */,
-    ErrorCode_SharedLibrary = 25    /*!< Error while using a shared library (plugin) */,
-    ErrorCode_Plugin = 26    /*!< Error encountered inside a plugin */
+    ErrorCode_SharedLibrary = 25    /*!< Error while using a shared library (plugin) */
   };
 
   enum LogLevel
--- a/Plugins/Engine/OrthancPlugins.cpp	Tue Aug 25 15:33:36 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Tue Aug 25 15:45:50 2015 +0200
@@ -172,7 +172,16 @@
 
   OrthancPlugins::OrthancPlugins()
   {
-    if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode))
+    if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
+        sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
+        sizeof(int32_t) != sizeof(_OrthancPluginService) ||
+        sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
+        sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
+        sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
+        sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
+        sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
+        sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
+        sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType))
     {
       /* Sanity check of the compiler */
       throw OrthancException(ErrorCode_Plugin);
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h	Tue Aug 25 15:33:36 2015 +0200
+++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h	Tue Aug 25 15:45:50 2015 +0200
@@ -638,8 +638,13 @@
     void*                                payload)
   {
     OrthancPluginDatabaseContext* result = NULL;
+    _OrthancPluginRegisterDatabaseBackend params;
 
-    _OrthancPluginRegisterDatabaseBackend params;
+    if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType))
+    {
+      return NULL;
+    }
+
     memset(&params, 0, sizeof(params));
     params.backend = backend;
     params.result = &result;
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Aug 25 15:33:36 2015 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Aug 25 15:45:50 2015 +0200
@@ -160,6 +160,34 @@
    **/
   typedef enum
   {
+    OrthancPluginErrorCode_Custom = -2    /*!< Custom error, see the attached error message */,
+    OrthancPluginErrorCode_InternalError = -1    /*!< Internal error */,
+    OrthancPluginErrorCode_Success = 0    /*!< Success */,
+    OrthancPluginErrorCode_Plugin = 1    /*!< Error encountered within the plugin engine */,
+    OrthancPluginErrorCode_NotImplemented = 2    /*!< Not implemented yet */,
+    OrthancPluginErrorCode_ParameterOutOfRange = 3    /*!< Parameter out of range */,
+    OrthancPluginErrorCode_NotEnoughMemory = 4    /*!< Not enough memory */,
+    OrthancPluginErrorCode_BadParameterType = 5    /*!< Bad type for a parameter */,
+    OrthancPluginErrorCode_BadSequenceOfCalls = 6    /*!< Bad sequence of calls */,
+    OrthancPluginErrorCode_InexistentItem = 7    /*!< Accessing an inexistent item */,
+    OrthancPluginErrorCode_BadRequest = 8    /*!< Bad request */,
+    OrthancPluginErrorCode_NetworkProtocol = 9    /*!< Error in the network protocol */,
+    OrthancPluginErrorCode_SystemCommand = 10    /*!< Error while calling a system command */,
+    OrthancPluginErrorCode_Database = 11    /*!< Error with the database engine */,
+    OrthancPluginErrorCode_UriSyntax = 12    /*!< Badly formatted URI */,
+    OrthancPluginErrorCode_InexistentFile = 13    /*!< Inexistent file */,
+    OrthancPluginErrorCode_CannotWriteFile = 14    /*!< Cannot write to file */,
+    OrthancPluginErrorCode_BadFileFormat = 15    /*!< Bad file format */,
+    OrthancPluginErrorCode_Timeout = 16    /*!< Timeout */,
+    OrthancPluginErrorCode_UnknownResource = 17    /*!< Unknown resource */,
+    OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18    /*!< Incompatible version of the database */,
+    OrthancPluginErrorCode_FullStorage = 19    /*!< The file storage is full */,
+    OrthancPluginErrorCode_CorruptedFile = 20    /*!< Corrupted file (inconsistent MD5 hash) */,
+    OrthancPluginErrorCode_InexistentTag = 21    /*!< Inexistent tag */,
+    OrthancPluginErrorCode_ReadOnly = 22    /*!< Cannot modify a read-only data structure */,
+    OrthancPluginErrorCode_IncompatibleImageFormat = 23    /*!< Incompatible format of the images */,
+    OrthancPluginErrorCode_IncompatibleImageSize = 24    /*!< Incompatible size of the images */,
+    OrthancPluginErrorCode_SharedLibrary = 25    /*!< Error while using a shared library (plugin) */
   } OrthancPluginErrorCode;
 
 
@@ -608,7 +636,15 @@
   {
     int major, minor, revision;
 
-    if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode))
+    if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
+        sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
+        sizeof(int32_t) != sizeof(_OrthancPluginService) ||
+        sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
+        sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
+        sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
+        sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
+        sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
+        sizeof(int32_t) != sizeof(OrthancPluginCompressionType))
     {
       /* Mismatch in the size of the enumerations */
       return 0;
--- a/Resources/ErrorCodes.json	Tue Aug 25 15:33:36 2015 +0200
+++ b/Resources/ErrorCodes.json	Tue Aug 25 15:45:50 2015 +0200
@@ -1,8 +1,13 @@
 [
     {
+        "Code": -2, 
+        "Name": "Custom", 
+        "Description": "Custom error, see the attached error message"
+    }, 
+    {
         "Code": -1, 
-        "Name": "Custom", 
-        "Description": "Custom error, see the attached error message"
+        "Name": "InternalError", 
+        "Description": "Internal error"
     }, 
     {
         "Code": 0, 
@@ -12,9 +17,9 @@
     }, 
     {
         "Code": 1, 
-        "Name": "InternalError", 
-        "Description": "Internal error"
-    }, 
+        "Name": "Plugin", 
+        "Description": "Error encountered within the plugin engine"
+    },
     {
         "Code": 2, 
         "Name": "NotImplemented", 
@@ -143,10 +148,5 @@
         "Code": 25, 
         "Name": "SharedLibrary", 
         "Description": "Error while using a shared library (plugin)"
-    }, 
-    {
-        "Code": 26, 
-        "Name": "Plugin", 
-        "Description": "Error encountered inside a plugin"
     }
 ]