# HG changeset patch # User Sebastien Jodogne # Date 1391525686 -3600 # Node ID 2e67366aab830bc7b324182327c5bdf6aa0bd422 # Parent 2d0a347e8cfcece11eb80c2926ef5f689ab21c6c case-insensitive matching of Application Entity Titles diff -r 2d0a347e8cfc -r 2e67366aab83 Core/Toolbox.cpp --- 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) diff -r 2d0a347e8cfc -r 2e67366aab83 Core/Toolbox.h --- 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); diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/DicomProtocol/DicomServer.cpp --- 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 @@ -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()); + } + } diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/DicomProtocol/DicomServer.h --- 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; }; } diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/Internals/CommandDispatcher.cpp --- 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 = { diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/OrthancFindRequestHandler.cpp --- 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 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; } } diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/OrthancInitialization.cpp --- 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; } diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/OrthancInitialization.h --- 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); } diff -r 2d0a347e8cfc -r 2e67366aab83 OrthancServer/main.cpp --- 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; } diff -r 2d0a347e8cfc -r 2e67366aab83 Resources/Configuration.json --- 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 }