changeset 7004:a890a3f0d2ac

configuration single source of truth: strings
author Alain Mazy <am@orthanc.team>
date Mon, 06 Jul 2026 17:09:54 +0200
parents f931f34383db
children 8e440add1d47
files NEWS OrthancServer/Resources/Configuration.json OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/OrthancConfiguration.h OrthancServer/Sources/OrthancInitialization.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h OrthancServer/Sources/ServerTranscoder.cpp OrthancServer/Sources/main.cpp
diffstat 10 files changed, 70 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Jul 06 16:33:25 2026 +0200
+++ b/NEWS	Mon Jul 06 17:09:54 2026 +0200
@@ -27,7 +27,8 @@
   - When Orthanc was requested to return a private tag in a C-Find query, Orthanc was actually not returning 
     the resources that did not contain the private tag although it was not used as a filter in the query.
 * Fix mismatches between the configuration default values and the documentation:
-  - "HttpTimeout": 0 (no timeout).  It was previously documented as 60.
+  - "HttpTimeout" was documented as 60 while its default value is 0 (no timeout).
+  - "Name" was documented as "MyOrthanc" while its default value is "ORTHANC".
 
 
 REST API
--- a/OrthancServer/Resources/Configuration.json	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Resources/Configuration.json	Mon Jul 06 17:09:54 2026 +0200
@@ -10,7 +10,7 @@
 
   // The logical name of this instance of Orthanc. This one is
   // displayed in Orthanc Explorer and at the URI "/system".
-  "Name" : "MyOrthanc",
+  "Name" : "ORTHANC",
 
   // Path to the directory that holds the heavyweight files (i.e. the
   // raw DICOM instances). Backslashes must be either escaped by
--- a/OrthancServer/Sources/OrthancConfiguration.cpp	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.cpp	Mon Jul 06 17:09:54 2026 +0200
@@ -509,17 +509,20 @@
   }
 
 
-  std::string OrthancConfiguration::GetStringParameter(const std::string& parameter,
-                                                       const std::string& defaultValue) const
+  std::string OrthancConfiguration::GetStringParameter(const std::string& parameter) const
   {
     std::string value;
     if (LookupStringParameter(value, parameter))
     {
       return value;
     }
+    else if (defaultConfiguration.isMember(parameter) && defaultConfiguration[parameter].type() == Json::stringValue)
+    {
+      return defaultConfiguration[parameter].asString();
+    }
     else
     {
-      return defaultValue;
+      throw OrthancException(ErrorCode_InternalError, std::string("No or invalid default parameter found in the default configuration for '") + parameter + "'");
     }
   }
 
@@ -1068,9 +1071,11 @@
   
   TemporaryFile* OrthancConfiguration::CreateTemporaryFile() const
   {
-    if (json_.isMember(TEMPORARY_DIRECTORY))
+    std::string temporaryDirectory = ".";
+
+    if (LookupStringParameter(temporaryDirectory, TEMPORARY_DIRECTORY))
     {
-      return new TemporaryFile(InterpretStringParameterAsPath(GetStringParameter(TEMPORARY_DIRECTORY, ".")), "");
+      return new TemporaryFile(InterpretStringParameterAsPath(temporaryDirectory), "");
     }
     else
     {
@@ -1082,7 +1087,7 @@
   std::string OrthancConfiguration::GetDefaultPrivateCreator() const
   {
     // New configuration option in Orthanc 1.6.0
-    return GetStringParameter("DefaultPrivateCreator", "");
+    return GetStringParameter("DefaultPrivateCreator");
   }
 
 
--- a/OrthancServer/Sources/OrthancConfiguration.h	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.h	Mon Jul 06 17:09:54 2026 +0200
@@ -54,6 +54,7 @@
 #define ORTHANC_CONFIG_DICOM_DEFAULT_RETRIEVE_METHOD "DicomDefaultRetrieveMethod"
 #define ORTHANC_CONFIG_PATIENT_LEVEL_ENABLED "PatientLevelEnabled"
 #define ORTHANC_CONFIG_READ_ONLY "ReadOnly"
+#define ORTHANC_CONFIG_STORAGE_DIRECTORY "StorageDirectory"
 
 
 namespace Orthanc
@@ -198,8 +199,7 @@
     bool LookupStringParameter(std::string& target,
                                const std::string& parameter) const;
 
-    std::string GetStringParameter(const std::string& parameter,
-                                   const std::string& defaultValue) const;
+    std::string GetStringParameter(const std::string& parameter) const;
     
     bool LookupIntegerParameter(int& target,
                                 const std::string& parameter) const;
@@ -292,27 +292,22 @@
 
     std::string GetOrthancAET() const
     {
-      return GetStringParameter(ORTHANC_CONFIG_DICOM_AET, "ORTHANC");
+      return GetStringParameter(ORTHANC_CONFIG_DICOM_AET);
     }
 
     std::string GetOrthancName() const
     {
-      return GetStringParameter(ORTHANC_CONFIG_NAME, "ORTHANC");
-    }
-
-    std::string GetIngestTranscoding() const
-    {
-      return GetStringParameter(ORTHANC_CONFIG_INGEST_TRANSCODING, "");
+      return GetStringParameter(ORTHANC_CONFIG_NAME);
     }
 
     std::string GetMaximumStorageMode() const
     {
-      return GetStringParameter(ORTHANC_CONFIG_MAXIMUM_STORAGE_MODE, "Recycle");
+      return GetStringParameter(ORTHANC_CONFIG_MAXIMUM_STORAGE_MODE);
     }
 
     std::string GetDicomDefaultRetrieveMethod() const
     {
-      return GetStringParameter(ORTHANC_CONFIG_DICOM_DEFAULT_RETRIEVE_METHOD, "C-MOVE");
+      return GetStringParameter(ORTHANC_CONFIG_DICOM_DEFAULT_RETRIEVE_METHOD);
     }
     unsigned int GetMaximumStorageCacheSize() const
     {
--- a/OrthancServer/Sources/OrthancInitialization.cpp	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/OrthancInitialization.cpp	Mon Jul 06 17:09:54 2026 +0200
@@ -72,10 +72,6 @@
 
 
 
-static const char* const STORAGE_DIRECTORY = "StorageDirectory";
-static const char* const ORTHANC_STORAGE = "OrthancStorage";
-
-
 namespace Orthanc
 {
   static void RegisterUserMetadata(const Json::Value& config)
@@ -356,27 +352,16 @@
 
     {
       std::string locale;
-      
-      if (lock.GetJson().isMember(LOCALE))
-      {
-        locale = lock.GetConfiguration().GetStringParameter(LOCALE, "");
-      }
-      
+      lock.GetConfiguration().LookupStringParameter(locale, LOCALE);
+
       bool loadPrivate = lock.GetConfiguration().GetBooleanParameter(LOAD_PRIVATE_DICTIONARY);
       Orthanc::InitializeFramework(locale, loadPrivate);
     }
 
     // The Orthanc framework is now initialized
 
-    if (lock.GetJson().isMember(DEFAULT_ENCODING))
-    {
-      std::string encoding = lock.GetConfiguration().GetStringParameter(DEFAULT_ENCODING, "");
-      SetDefaultDicomEncoding(StringToEncoding(encoding.c_str()));
-    }
-    else
-    {
-      SetDefaultDicomEncoding(ORTHANC_DEFAULT_DICOM_ENCODING);
-    }
+    std::string encoding = lock.GetConfiguration().GetStringParameter(DEFAULT_ENCODING);
+    SetDefaultDicomEncoding(StringToEncoding(encoding.c_str()));
 
     if (lock.GetJson().isMember(PKCS11))
     {
@@ -437,11 +422,17 @@
     OrthancConfiguration::ReaderLock lock;
 
     std::string storageDirectoryStr = 
-      lock.GetConfiguration().GetStringParameter(STORAGE_DIRECTORY, ORTHANC_STORAGE);
+      lock.GetConfiguration().GetStringParameter(ORTHANC_CONFIG_STORAGE_DIRECTORY);
+
+    std::string indexDirectoryStr;
+    if (!lock.GetConfiguration().LookupStringParameter(indexDirectoryStr, "IndexDirectory"))
+    {
+      indexDirectoryStr = storageDirectoryStr;
+    }
 
     // Open the database
     boost::filesystem::path indexDirectory = lock.GetConfiguration().InterpretStringParameterAsPath(
-      lock.GetConfiguration().GetStringParameter("IndexDirectory", storageDirectoryStr));
+      indexDirectoryStr);
 
     LOG(WARNING) << "SQLite index directory: " << SystemToolbox::PathToUtf8(indexDirectory);
 
@@ -525,7 +516,7 @@
     OrthancConfiguration::ReaderLock lock;
 
     std::string storageDirectoryStr = 
-      lock.GetConfiguration().GetStringParameter(STORAGE_DIRECTORY, ORTHANC_STORAGE);
+      lock.GetConfiguration().GetStringParameter(ORTHANC_CONFIG_STORAGE_DIRECTORY);
 
     boost::filesystem::path storageDirectory = 
       lock.GetConfiguration().InterpretStringParameterAsPath(storageDirectoryStr);
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Mon Jul 06 17:09:54 2026 +0200
@@ -172,7 +172,7 @@
       result[ORTHANC_CONFIG_MAXIMUM_STORAGE_CACHE_SIZE] = lock.GetConfiguration().GetMaximumStorageCacheSize(); // New in Orthanc 1.12.12
       result[ORTHANC_CONFIG_STORE_MD5_FOR_ATTACHMENTS] = lock.GetConfiguration().HasStoreMD5ForAttachments(); // New in Orthanc 1.12.12
       result[ORTHANC_CONFIG_STORAGE_COMPRESSION] = lock.GetConfiguration().HasStorageCompression(); // New in Orthanc 1.11.0
-      result[ORTHANC_CONFIG_INGEST_TRANSCODING] = lock.GetConfiguration().GetIngestTranscoding(); // New in Orthanc 1.11.0
+      result[ORTHANC_CONFIG_INGEST_TRANSCODING] = context.GetIngestTranscoding(); // New in Orthanc 1.11.0
       result[ORTHANC_CONFIG_DATABASE_SERVER_IDENTIFIER] = lock.GetConfiguration().GetDatabaseServerIdentifier();
       result[ORTHANC_CONFIG_MAXIMUM_STORAGE_SIZE] = lock.GetConfiguration().GetMaximumStorageSize(); // New in Orthanc 1.11.3
       result[ORTHANC_CONFIG_MAXIMUM_PATIENT_COUNT] = lock.GetConfiguration().GetMaximumPatientCount(); // New in Orthanc 1.12.4
--- a/OrthancServer/Sources/ServerContext.cpp	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Mon Jul 06 17:09:54 2026 +0200
@@ -431,7 +431,7 @@
         metricsRegistry_->SetEnabled(lock.GetConfiguration().GetBooleanParameter("MetricsEnabled"));
 
         // New configuration options in Orthanc 1.5.1
-        findStorageAccessMode_ = StringToFindStorageAccessMode(lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always"));
+        findStorageAccessMode_ = StringToFindStorageAccessMode(lock.GetConfiguration().GetStringParameter("StorageAccessOnFind"));
         limitFindInstances_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances");
         limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults");
 
@@ -481,7 +481,7 @@
           CLOG(INFO, DICOM) << "Deidentification of log contents (notably for DIMSE queries) is enabled";
 
           DicomVersion version = StringToDicomVersion(
-              lock.GetConfiguration().GetStringParameter("DeidentifyLogsDicomVersion", "2023b"));
+              lock.GetConfiguration().GetStringParameter("DeidentifyLogsDicomVersion"));
           CLOG(INFO, DICOM) << "Version of DICOM standard used for deidentification is "
                             << EnumerationToString(version);
 
--- a/OrthancServer/Sources/ServerContext.h	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Mon Jul 06 17:09:54 2026 +0200
@@ -336,6 +336,11 @@
       return patientLevelEnabled_;
     }
 
+    std::string GetIngestTranscoding() const
+    {
+      return GetTransferSyntaxUid(ingestTransferSyntax_);
+    }
+
     void SetCompressionEnabled(bool enabled);
 
     bool IsCompressionEnabled() const
--- a/OrthancServer/Sources/ServerTranscoder.cpp	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/ServerTranscoder.cpp	Mon Jul 06 17:09:54 2026 +0200
@@ -46,7 +46,7 @@
     OrthancConfiguration::ReaderLock lock;
 
     // New option in Orthanc 1.7.0
-    builtinDecoderTranscoderOrder_ = StringToBuiltinDecoderTranscoderOrder(lock.GetConfiguration().GetStringParameter("BuiltinDecoderTranscoderOrder", "After"));
+    builtinDecoderTranscoderOrder_ = StringToBuiltinDecoderTranscoderOrder(lock.GetConfiguration().GetStringParameter("BuiltinDecoderTranscoderOrder"));
 
     // New option in Orthanc 1.12.6
     dynamic_cast<DcmtkTranscoder&>(*dcmtkTranscoder_).SetDefaultLossyQuality(lock.GetConfiguration().GetDicomLossyTranscodingQuality());
--- a/OrthancServer/Sources/main.cpp	Mon Jul 06 16:33:25 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Mon Jul 06 17:09:54 2026 +0200
@@ -1227,7 +1227,7 @@
       if (lock.GetConfiguration().GetBooleanParameter("SslEnabled"))
       {
         boost::filesystem::path certificate = lock.GetConfiguration().InterpretStringParameterAsPath(
-          lock.GetConfiguration().GetStringParameter("SslCertificate", "certificate.pem"));
+          lock.GetConfiguration().GetStringParameter("SslCertificate"));
         httpServer.SetSslEnabled(true);
         httpServer.SetSslCertificate(certificate.c_str());
         
@@ -1275,7 +1275,7 @@
       if (lock.GetConfiguration().GetBooleanParameter("SslVerifyPeers"))
       {
         boost::filesystem::path trustedClientCertificates = lock.GetConfiguration().InterpretStringParameterAsPath(
-          lock.GetConfiguration().GetStringParameter("SslTrustedClientCertificates", "trustedCertificates.pem"));
+          lock.GetConfiguration().GetStringParameter("SslTrustedClientCertificates"));
         httpServer.SetSslVerifyPeers(true);
         httpServer.SetSslTrustedClientCertificates(trustedClientCertificates);
       }
@@ -1402,11 +1402,18 @@
       dicomServer.SetDicomTlsEnabled(lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_ENABLED));
       if (dicomServer.IsDicomTlsEnabled())
       {
-        dicomServer.SetOwnCertificatePath(
-          lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""),
-          lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, ""));
-        dicomServer.SetTrustedCertificatesPath(
-          lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_TRUSTED_CERTIFICATES, ""));
+        std::string tlsPrivateKey, tlsCertificate;
+        if (lock.GetConfiguration().LookupStringParameter(tlsPrivateKey, KEY_DICOM_TLS_PRIVATE_KEY)
+            && lock.GetConfiguration().LookupStringParameter(tlsCertificate, KEY_DICOM_TLS_CERTIFICATE))
+        {
+          dicomServer.SetOwnCertificatePath(tlsPrivateKey, tlsCertificate);
+        }
+
+        std::string tlsTrustedCertificates;
+        if (lock.GetConfiguration().LookupStringParameter(tlsTrustedCertificates, KEY_DICOM_TLS_TRUSTED_CERTIFICATES))
+        {
+          dicomServer.SetTrustedCertificatesPath(tlsTrustedCertificates);
+        }
         dicomServer.SetMinimumTlsVersion(
           lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_DICOM_TLS_MINIMUM_PROTOCOL_VERSION));
         
@@ -1660,7 +1667,7 @@
     // ServerContext, otherwise the possible Lua scripts will not be
     // able to properly issue HTTP/HTTPS queries
 
-    std::string httpsCaCertificatesStr = lock.GetConfiguration().GetStringParameter("HttpsCACertificates", "");
+    std::string httpsCaCertificatesStr = lock.GetConfiguration().GetStringParameter("HttpsCACertificates");
     boost::filesystem::path httpsCaCertificates;
     if (!httpsCaCertificatesStr.empty())
     {
@@ -1675,7 +1682,7 @@
     // value (DEFAULT_HTTP_TIMEOUT = 60 seconds in Orthanc 1.5.7)
     HttpClient::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpTimeout"));
     
-    HttpClient::SetDefaultProxy(lock.GetConfiguration().GetStringParameter("HttpProxy", ""));
+    HttpClient::SetDefaultProxy(lock.GetConfiguration().GetStringParameter("HttpProxy"));
     
     DicomAssociationParameters::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScuTimeout"));
 
@@ -1697,13 +1704,18 @@
     }
 
     // Configuration of DICOM TLS for Orthanc SCU (since Orthanc 1.9.0)
-    DicomAssociationParameters::SetDefaultOwnCertificatePath(
-      lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""),
-      lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, ""));
-    DicomAssociationParameters::SetDefaultTrustedCertificatesPath(
-      lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_TRUSTED_CERTIFICATES, ""));
-    DicomAssociationParameters::SetDefaultMaximumPduLength(
-      lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH));
+    std::string tlsPrivateKey, tlsCertificate;
+    if (lock.GetConfiguration().LookupStringParameter(tlsPrivateKey, KEY_DICOM_TLS_PRIVATE_KEY)
+        && lock.GetConfiguration().LookupStringParameter(tlsCertificate, KEY_DICOM_TLS_CERTIFICATE))
+    {
+      DicomAssociationParameters::SetDefaultOwnCertificatePath(tlsPrivateKey, tlsCertificate);
+    }
+
+    std::string tlsTrustedCertificates;
+    if (lock.GetConfiguration().LookupStringParameter(tlsTrustedCertificates, KEY_DICOM_TLS_TRUSTED_CERTIFICATES))
+    {
+      DicomAssociationParameters::SetDefaultTrustedCertificatesPath(tlsTrustedCertificates);
+    }
 
     // New option in Orthanc 1.9.3
     DicomAssociationParameters::SetDefaultRemoteCertificateRequired(