diff Core/DicomNetworking/RemoteModalityParameters.cpp @ 2872:9d08edde614b

Possibility to restrict the allowed DICOM commands for each modality
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Oct 2018 14:19:48 +0200
parents 6eebc2eb3168
children d924f9bb61cc
line wrap: on
line diff
--- a/Core/DicomNetworking/RemoteModalityParameters.cpp	Tue Oct 09 12:51:20 2018 +0200
+++ b/Core/DicomNetworking/RemoteModalityParameters.cpp	Tue Oct 09 14:19:48 2018 +0200
@@ -43,26 +43,38 @@
 
 
 static const char* KEY_AET = "AET";
+static const char* KEY_ALLOW_ECHO = "AllowEcho";
+static const char* KEY_ALLOW_FIND = "AllowFind";
+static const char* KEY_ALLOW_GET = "AllowGet";
+static const char* KEY_ALLOW_MOVE = "AllowMove";
+static const char* KEY_ALLOW_STORE = "AllowStore";
+static const char* KEY_HOST = "Host";
 static const char* KEY_MANUFACTURER = "Manufacturer";
 static const char* KEY_PORT = "Port";
-static const char* KEY_HOST = "Host";
 
 
 namespace Orthanc
 {
-  RemoteModalityParameters::RemoteModalityParameters() :
-    aet_("ORTHANC"),
-    host_("127.0.0.1"),
-    port_(104),
-    manufacturer_(ModalityManufacturer_Generic)
+  void RemoteModalityParameters::Clear()
   {
+    aet_ = "ORTHANC";
+    host_ = "127.0.0.1";
+    port_ = 104;
+    manufacturer_ = ModalityManufacturer_Generic;
+    allowEcho_ = true;
+    allowStore_ = true;
+    allowFind_ = true;
+    allowMove_ = true;
+    allowGet_ = true;
   }
 
+
   RemoteModalityParameters::RemoteModalityParameters(const std::string& aet,
                                                      const std::string& host,
                                                      uint16_t port,
                                                      ModalityManufacturer manufacturer)
   {
+    Clear();
     SetApplicationEntityTitle(aet);
     SetHost(host);
     SetPortNumber(port);
@@ -70,6 +82,17 @@
   }
 
 
+  static void CheckPortNumber(int value)
+  {
+    if (value <= 0 || 
+        value >= 65535)
+    {
+      LOG(ERROR) << "A TCP port number must be in range [1..65534], but found: " << value;
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
   static uint16_t ReadPortNumber(const Json::Value& value)
   {
     int tmp;
@@ -96,15 +119,15 @@
         throw OrthancException(ErrorCode_BadFileFormat);
     }
 
-    if (tmp <= 0 || tmp >= 65535)
-    {
-      LOG(ERROR) << "A TCP port number must be in range [1..65534], but found: " << tmp;
-      throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }
-    else
-    {
-      return static_cast<uint16_t>(tmp);
-    }
+    CheckPortNumber(tmp);
+    return static_cast<uint16_t>(tmp);
+  }
+
+
+  void RemoteModalityParameters::SetPortNumber(uint16_t port)
+  {
+    CheckPortNumber(port);
+    port_ = port;
   }
 
 
@@ -162,12 +185,97 @@
     {
       manufacturer_ = ModalityManufacturer_Generic;
     }
+
+    if (serialized.isMember(KEY_ALLOW_ECHO))
+    {
+      allowEcho_ = SerializationToolbox::ReadBoolean(serialized, KEY_ALLOW_ECHO);
+    }
+
+    if (serialized.isMember(KEY_ALLOW_FIND))
+    {
+      allowFind_ = SerializationToolbox::ReadBoolean(serialized, KEY_ALLOW_FIND);
+    }
+
+    if (serialized.isMember(KEY_ALLOW_STORE))
+    {
+      allowStore_ = SerializationToolbox::ReadBoolean(serialized, KEY_ALLOW_STORE);
+    }
+
+    if (serialized.isMember(KEY_ALLOW_GET))
+    {
+      allowGet_ = SerializationToolbox::ReadBoolean(serialized, KEY_ALLOW_GET);
+    }
+
+    if (serialized.isMember(KEY_ALLOW_MOVE))
+    {
+      allowMove_ = SerializationToolbox::ReadBoolean(serialized, KEY_ALLOW_MOVE);
+    }
+  }
+
+
+  bool RemoteModalityParameters::IsRequestAllowed(DicomRequestType type) const
+  {
+    switch (type)
+    {
+      case DicomRequestType_Echo:
+        return allowEcho_;
+
+      case DicomRequestType_Find:
+        return allowFind_;
+
+      case DicomRequestType_Get:
+        return allowGet_;
+
+      case DicomRequestType_Move:
+        return allowMove_;
+
+      case DicomRequestType_Store:
+        return allowStore_;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
+  void RemoteModalityParameters::SetRequestAllowed(DicomRequestType type,
+                                                   bool allowed)
+  {
+    switch (type)
+    {
+      case DicomRequestType_Echo:
+        allowEcho_ = allowed;
+        break;
+
+      case DicomRequestType_Find:
+        allowFind_ = allowed;
+        break;
+
+      case DicomRequestType_Get:
+        allowGet_ = allowed;
+        break;
+
+      case DicomRequestType_Move:
+        allowMove_ = allowed;
+        break;
+
+      case DicomRequestType_Store:
+        allowStore_ = allowed;
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
   }
 
 
   bool RemoteModalityParameters::IsAdvancedFormatNeeded() const
   {
-    return false; // TODO
+    return (!allowEcho_ ||
+            !allowStore_ ||
+            !allowFind_ ||
+            !allowGet_ ||
+            !allowMove_);
   }
 
   
@@ -182,6 +290,11 @@
       target[KEY_HOST] = host_;
       target[KEY_PORT] = port_;
       target[KEY_MANUFACTURER] = EnumerationToString(manufacturer_);
+      target[KEY_ALLOW_ECHO] = allowEcho_;
+      target[KEY_ALLOW_STORE] = allowStore_;
+      target[KEY_ALLOW_FIND] = allowFind_;
+      target[KEY_ALLOW_GET] = allowGet_;
+      target[KEY_ALLOW_MOVE] = allowMove_;
     }
     else
     {
@@ -196,6 +309,8 @@
   
   void RemoteModalityParameters::Unserialize(const Json::Value& serialized)
   {
+    Clear();
+
     switch (serialized.type())
     {
       case Json::objectValue: