changeset 690:2e67366aab83

case-insensitive matching of Application Entity Titles
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Feb 2014 15:54:46 +0100
parents 2d0a347e8cfc
children a401e295f2db
files Core/Toolbox.cpp Core/Toolbox.h OrthancServer/DicomProtocol/DicomServer.cpp OrthancServer/DicomProtocol/DicomServer.h OrthancServer/Internals/CommandDispatcher.cpp OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancInitialization.cpp OrthancServer/OrthancInitialization.h OrthancServer/main.cpp Resources/Configuration.json
diffstat 10 files changed, 82 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Mon Feb 03 16:06:58 2014 +0100
+++ b/Core/Toolbox.cpp	Tue Feb 04 15:54:46 2014 +0100
@@ -219,6 +219,20 @@
   }
 
 
+  void Toolbox::ToUpperCase(std::string& result,
+                            const std::string& source)
+  {
+    result = source;
+    ToUpperCase(result);
+  }
+
+  void Toolbox::ToLowerCase(std::string& result,
+                            const std::string& source)
+  {
+    result = source;
+    ToLowerCase(result);
+  }
+
 
   void Toolbox::ReadFile(std::string& content,
                          const std::string& path) 
--- a/Core/Toolbox.h	Mon Feb 03 16:06:58 2014 +0100
+++ b/Core/Toolbox.h	Tue Feb 04 15:54:46 2014 +0100
@@ -50,9 +50,15 @@
   {
     void ServerBarrier();
 
-    void ToUpperCase(std::string& s);
+    void ToUpperCase(std::string& s);  // Inplace version
+
+    void ToLowerCase(std::string& s);  // Inplace version
 
-    void ToLowerCase(std::string& s);
+    void ToUpperCase(std::string& result,
+                     const std::string& source);
+
+    void ToLowerCase(std::string& result,
+                     const std::string& source);
 
     void ReadFile(std::string& content,
                   const std::string& path);
--- a/OrthancServer/DicomProtocol/DicomServer.cpp	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/DicomProtocol/DicomServer.cpp	Tue Feb 04 15:54:46 2014 +0100
@@ -36,6 +36,7 @@
 #include "../../Core/Toolbox.h"
 #include "../../Core/Uuid.h"
 #include "../Internals/CommandDispatcher.h"
+#include "../OrthancInitialization.h"
 #include "EmbeddedResources.h"
 
 #include <boost/thread.hpp>
@@ -404,4 +405,16 @@
 
     bagOfDispatchers_.StopAll();
   }
+
+  bool DicomServer::IsMyAETitle(const std::string& aet) const
+  {
+    if (!HasCalledApplicationEntityTitleCheck())
+    {
+      // OK, no check on the AET.
+      return true;
+    }
+
+    return Orthanc::IsSameAETitle(aet, GetApplicationEntityTitle());
+  }
+
 }
--- a/OrthancServer/DicomProtocol/DicomServer.h	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/DicomProtocol/DicomServer.h	Tue Feb 04 15:54:46 2014 +0100
@@ -106,6 +106,8 @@
     void Start();
   
     void Stop();
+
+    bool IsMyAETitle(const std::string& aet) const;
   };
 
 }
--- a/OrthancServer/Internals/CommandDispatcher.cpp	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/Internals/CommandDispatcher.cpp	Tue Feb 04 15:54:46 2014 +0100
@@ -385,12 +385,8 @@
         callingIP = std::string(/*OFSTRING_GUARD*/(callingIP_C));
         callingTitle = std::string(/*OFSTRING_GUARD*/(callingTitle_C));
         std::string calledTitle(/*OFSTRING_GUARD*/(calledTitle_C));
-        Toolbox::ToUpperCase(callingIP);
-        Toolbox::ToUpperCase(callingTitle);
-        Toolbox::ToUpperCase(calledTitle);
 
-        if (server.HasCalledApplicationEntityTitleCheck() &&
-            calledTitle != server.GetApplicationEntityTitle())
+        if (!server.IsMyAETitle(calledTitle))
         {
           T_ASC_RejectParameters rej =
             {
--- a/OrthancServer/OrthancFindRequestHandler.cpp	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/OrthancFindRequestHandler.cpp	Tue Feb 04 15:54:46 2014 +0100
@@ -48,20 +48,14 @@
             constraint.find('?') != std::string::npos);
   }
 
-  static std::string ToLowerCase(const std::string& s)
-  {
-    std::string result = s;
-    Toolbox::ToLowerCase(result);
-    return result;
-  }
-
   static bool ApplyRangeConstraint(const std::string& value,
                                    const std::string& constraint)
   {
     size_t separator = constraint.find('-');
-    std::string lower = ToLowerCase(constraint.substr(0, separator));
-    std::string upper = ToLowerCase(constraint.substr(separator + 1));
-    std::string v = ToLowerCase(value);
+    std::string lower, upper, v;
+    Toolbox::ToLowerCase(lower, constraint.substr(0, separator));
+    Toolbox::ToLowerCase(upper, constraint.substr(separator + 1));
+    Toolbox::ToLowerCase(v, value);
 
     if (lower.size() == 0 && upper.size() == 0)
     {
@@ -85,15 +79,17 @@
   static bool ApplyListConstraint(const std::string& value,
                                   const std::string& constraint)
   {
-    std::string v1 = ToLowerCase(value);
+    std::string v1;
+    Toolbox::ToLowerCase(v1, value);
 
     std::vector<std::string> items;
     Toolbox::TokenizeString(items, constraint, '\\');
 
     for (size_t i = 0; i < items.size(); i++)
     {
-      Toolbox::ToLowerCase(items[i]);
-      if (items[i] == v1)
+      std::string lower;
+      Toolbox::ToLowerCase(lower, items[i]);
+      if (lower == v1)
       {
         return true;
       }
@@ -129,7 +125,10 @@
     }
     else
     {
-      return ToLowerCase(value) == ToLowerCase(constraint);
+      std::string v, c;
+      Toolbox::ToLowerCase(v, value);
+      Toolbox::ToLowerCase(c, constraint);
+      return v == c;
     }
   }
 
--- a/OrthancServer/OrthancInitialization.cpp	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/OrthancInitialization.cpp	Tue Feb 04 15:54:46 2014 +0100
@@ -465,6 +465,25 @@
   }
 
 
+  bool IsSameAETitle(const std::string& aet1,
+                     const std::string& aet2)
+  {
+    if (GetGlobalBoolParameter("StrictAetComparison", false))
+    {
+      // Case-sensitive matching
+      return aet1 == aet2;
+    }
+    else
+    {
+      // Case-insensitive matching (default)
+      std::string tmp1, tmp2;
+      Toolbox::ToLowerCase(tmp1, aet1);
+      Toolbox::ToLowerCase(tmp2, aet2);
+      return tmp1 == tmp2;
+    }
+  }
+
+
   bool LookupDicomModalityUsingAETitle(const std::string& aet,
                                        std::string& symbolicName,
                                        std::string& address,
@@ -482,7 +501,7 @@
         std::string thisAet;
         GetDicomModalityUsingSymbolicName(*it, thisAet, address, port, manufacturer);
         
-        if (aet == thisAet)
+        if (IsSameAETitle(aet, thisAet))
         {
           return true;
         }
--- a/OrthancServer/OrthancInitialization.h	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/OrthancInitialization.h	Tue Feb 04 15:54:46 2014 +0100
@@ -93,4 +93,7 @@
                                      const std::string& aet);
 
   bool IsKnownAETitle(const std::string& aet);
+
+  bool IsSameAETitle(const std::string& aet1,
+                     const std::string& aet2);
 }
--- a/OrthancServer/main.cpp	Mon Feb 03 16:06:58 2014 +0100
+++ b/OrthancServer/main.cpp	Tue Feb 04 15:54:46 2014 +0100
@@ -453,5 +453,7 @@
 
   OrthancFinalize();
 
+  LOG(WARNING) << "Orthanc has stopped";
+
   return status;
 }
--- a/Resources/Configuration.json	Mon Feb 03 16:06:58 2014 +0100
+++ b/Resources/Configuration.json	Tue Feb 04 15:54:46 2014 +0100
@@ -142,5 +142,10 @@
   // Enable the DICOM server. If this parameter is set to "false",
   // Orthanc acts as a pure REST server. It will not be possible to
   // receive files or to do query/retrieve through the DICOM protocol.
-  "DicomServerEnabled" : true
+  "DicomServerEnabled" : true,
+
+  // By default, Orthanc compares AET (Application Entity Titles) in a
+  // case-insensitive way. Setting this option to "true" will enable
+  // case-sensitive matching.
+  "StrictAetComparison" : false
 }