changeset 7002:28683da53c6b

Configuration: read the default values from Configuration.json to have a single source of truth (done for uint only)
author Alain Mazy <am@orthanc.team>
date Mon, 06 Jul 2026 16:14:09 +0200
parents 0d2fa25aa933
children f931f34383db
files NEWS OrthancServer/Resources/Configuration.json OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/OrthancConfiguration.h OrthancServer/Sources/OrthancInitialization.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerJobs/LuaJobManager.cpp OrthancServer/Sources/main.cpp
diffstat 9 files changed, 68 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Jul 06 14:03:39 2026 +0200
+++ b/NEWS	Mon Jul 06 16:14:09 2026 +0200
@@ -26,6 +26,9 @@
     Orthanc now returns the full sequence content when the matched resource contains the requested sequence.
   - 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.
+
 
 REST API
 --------
--- a/OrthancServer/Resources/Configuration.json	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Resources/Configuration.json	Mon Jul 06 16:14:09 2026 +0200
@@ -626,7 +626,8 @@
   "HttpVerbose" : false,
 
   // Set the timeout for HTTP requests issued by Orthanc (in seconds).
-  "HttpTimeout" : 60,
+  // 0 means no timeout.
+  "HttpTimeout" : 0,
 
   // Enable the verification of the peers certificates during HTTPS
   // requests. Setting this option to "false" is equivalent to the
--- a/OrthancServer/Sources/OrthancConfiguration.cpp	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.cpp	Mon Jul 06 16:14:09 2026 +0200
@@ -50,6 +50,8 @@
 static const char* const CONFIG_LOADER_THREADS = "LoaderThreads";
 static const char* const CONFIG_ZIP_LOADER_THREADS = "ZipLoaderThreads"; // for backward compatibility only
 
+static Json::Value defaultConfiguration;
+
 namespace Orthanc
 {
   static void AddFileToConfiguration(Json::Value& target,
@@ -133,6 +135,22 @@
   static void ReadConfiguration(Json::Value& target, 
                                 const boost::filesystem::path &configurationFile)
   {
+    // lazy loading of the default configuration
+    if (defaultConfiguration.empty())
+    {
+      std::string defaultConfigurationContent;
+      GetFileResource(defaultConfigurationContent, ServerResources::CONFIGURATION_SAMPLE);
+
+      Json::Value tmp;
+      if (!Toolbox::ReadJson(tmp, defaultConfigurationContent) ||
+          tmp.type() != Json::objectValue)
+      {
+        throw OrthancException(ErrorCode_InternalError, "The default configuration file does not follow the JSON syntax !!");
+      }
+
+      Toolbox::CopyJsonWithoutComments(defaultConfiguration, tmp);
+    }
+
     target = Json::objectValue;
 
     if (!configurationFile.empty())
@@ -568,17 +586,20 @@
   }
 
 
-  unsigned int OrthancConfiguration::GetUnsignedIntegerParameter(const std::string& parameter,
-                                                                 unsigned int defaultValue) const
+  unsigned int OrthancConfiguration::GetUnsignedIntegerParameter(const std::string& parameter) const
   {
     unsigned int v;
     if (LookupUnsignedIntegerParameter(v, parameter))
     {
       return v;
     }
+    else if (defaultConfiguration.isMember(parameter) && defaultConfiguration[parameter].type() == Json::intValue)
+    {
+      return static_cast<unsigned int>(defaultConfiguration[parameter].asInt());
+    }
     else
     {
-      return defaultValue;
+      throw OrthancException(ErrorCode_InternalError, std::string("No or invalid default parameter found in the default configuration for '") + parameter + "'");
     }
   }
 
@@ -742,7 +763,7 @@
 
   unsigned int OrthancConfiguration::GetDicomLossyTranscodingQuality() const
   {
-    return GetUnsignedIntegerParameter(DICOM_LOSSY_TRANSCODING_QUALITY, 90);
+    return GetUnsignedIntegerParameter(DICOM_LOSSY_TRANSCODING_QUALITY);
   }
 
 
@@ -1353,7 +1374,12 @@
   unsigned int OrthancConfiguration::GetLoaderThreads() const
   {
     // from 1.10.0 to 1.12.10, only CONFIG_ZIP_LOADER_THREADS was available -> read from it if CONFIG_LOADER_THREADS is not specified.
-    unsigned int loaderThreads = GetUnsignedIntegerParameter(CONFIG_LOADER_THREADS, GetUnsignedIntegerParameter(CONFIG_ZIP_LOADER_THREADS, 1));
+    unsigned int loaderThreads = 1; // old ZipLoaderThreads default value
+
+    if (!LookupUnsignedIntegerParameter(loaderThreads, CONFIG_LOADER_THREADS))
+    {
+      LookupUnsignedIntegerParameter(loaderThreads, CONFIG_ZIP_LOADER_THREADS); // we cannot use GetUnsignedIntegerParameter() because there is no default value for this old configuration
+    }
 
     if (loaderThreads <= 1)
     {
--- a/OrthancServer/Sources/OrthancConfiguration.h	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.h	Mon Jul 06 16:14:09 2026 +0200
@@ -210,8 +210,7 @@
     bool LookupUnsignedIntegerParameter(unsigned int& target,
                                         const std::string& parameter) const;
 
-    unsigned int GetUnsignedIntegerParameter(const std::string& parameter,
-                                             unsigned int defaultValue) const;
+    unsigned int GetUnsignedIntegerParameter(const std::string& parameter) const;
 
     bool LookupBooleanParameter(bool& target,
                                 const std::string& parameter) const;
@@ -318,27 +317,27 @@
     }
     unsigned int GetMaximumStorageCacheSize() const
     {
-      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_MAXIMUM_STORAGE_CACHE_SIZE, 128);
+      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_MAXIMUM_STORAGE_CACHE_SIZE);
     }
 
     unsigned int GetMaximumStorageSize() const
     {
-      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_MAXIMUM_STORAGE_SIZE, 0);
+      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_MAXIMUM_STORAGE_SIZE);
     }
 
     unsigned int GetMaximumPatientCount() const
     {
-      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_MAXIMUM_PATIENT_COUNT, 0);
+      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_MAXIMUM_PATIENT_COUNT);
     }
     
     unsigned int GetDicomPort() const
     {
-      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_DICOM_PORT, 4242);
+      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_DICOM_PORT);
     }
 
     unsigned int GetHttpPort() const
     {
-      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_HTTP_PORT, 8042);
+      return GetUnsignedIntegerParameter(ORTHANC_CONFIG_HTTP_PORT);
     }
 
     bool HasCheckRevisions() const
--- a/OrthancServer/Sources/OrthancInitialization.cpp	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/OrthancInitialization.cpp	Mon Jul 06 16:14:09 2026 +0200
@@ -399,7 +399,7 @@
 #if HAVE_MALLOPT == 1
     // New in Orthanc 1.8.2
     // https://orthanc.uclouvain.be/book/faq/scalability.html#controlling-memory-usage
-    unsigned int maxArena = lock.GetConfiguration().GetUnsignedIntegerParameter(MALLOC_ARENA_MAX, 5);
+    unsigned int maxArena = lock.GetConfiguration().GetUnsignedIntegerParameter(MALLOC_ARENA_MAX);
     if (maxArena != 0)
     {
       // https://man7.org/linux/man-pages/man3/mallopt.3.html
--- a/OrthancServer/Sources/ServerContext.cpp	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Mon Jul 06 16:14:09 2026 +0200
@@ -415,11 +415,11 @@
         OrthancConfiguration::ReaderLock lock;
 
         queryRetrieveArchive_.reset(
-          new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("QueryRetrieveSize", 100)));
+          new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("QueryRetrieveSize")));
         mediaArchive_.reset(
-          new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1)));
+          new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize")));
         defaultLocalAet_ = lock.GetConfiguration().GetOrthancAET();
-        jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2));
+        jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs"));
 
         saveJobs_ = lock.GetConfiguration().GetBooleanParameter("SaveJobs", true);
         if (readOnly_ && saveJobs_)
@@ -432,11 +432,11 @@
 
         // New configuration options in Orthanc 1.5.1
         findStorageAccessMode_ = StringToFindStorageAccessMode(lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always"));
-        limitFindInstances_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0);
-        limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0);
+        limitFindInstances_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances");
+        limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults");
 
         // New configuration option in Orthanc 1.6.0
-        storageCommitmentReports_.reset(new StorageCommitmentReports(lock.GetConfiguration().GetUnsignedIntegerParameter("StorageCommitmentReportsSize", 100)));
+        storageCommitmentReports_.reset(new StorageCommitmentReports(lock.GetConfiguration().GetUnsignedIntegerParameter("StorageCommitmentReportsSize")));
 
         // New options in Orthanc 1.7.0
         transcodeDicomProtocol_ = lock.GetConfiguration().GetBooleanParameter("TranscodeDicomProtocol", true);
--- a/OrthancServer/Sources/ServerIndex.cpp	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/ServerIndex.cpp	Mon Jul 06 16:14:09 2026 +0200
@@ -464,7 +464,7 @@
     
     {
       OrthancConfiguration::ReaderLock lock;
-      stableAge = lock.GetConfiguration().GetUnsignedIntegerParameter("StableAge", 60);
+      stableAge = lock.GetConfiguration().GetUnsignedIntegerParameter("StableAge");
     }
 
     if (stableAge < 1)
--- a/OrthancServer/Sources/ServerJobs/LuaJobManager.cpp	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/LuaJobManager.cpp	Mon Jul 06 16:14:09 2026 +0200
@@ -62,7 +62,7 @@
     
     {
       OrthancConfiguration::ReaderLock lock;
-      dicomTimeout = lock.GetConfiguration().GetUnsignedIntegerParameter("DicomAssociationCloseDelay", 5);
+      dicomTimeout = lock.GetConfiguration().GetUnsignedIntegerParameter("DicomAssociationCloseDelay");
     }
 
     connectionManager_.SetInactivityTimeout(dicomTimeout * 1000);  // Milliseconds expected
--- a/OrthancServer/Sources/main.cpp	Mon Jul 06 14:03:39 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Mon Jul 06 16:14:09 2026 +0200
@@ -234,8 +234,8 @@
 
     {
       OrthancConfiguration::ReaderLock lock;
-      result->SetMaxResults(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0));
-      result->SetMaxInstances(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0));
+      result->SetMaxResults(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults"));
+      result->SetMaxInstances(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances"));
     }
 
     if (result->GetMaxResults() == 0)
@@ -1116,20 +1116,20 @@
       httpDescribeErrors = lock.GetConfiguration().GetBooleanParameter("HttpDescribeErrors", true);
   
       // HTTP server
-      httpServer.SetThreadsCount(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpThreadsCount", 50));
+      httpServer.SetThreadsCount(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpThreadsCount"));
       httpServer.SetPortNumber(lock.GetConfiguration().GetHttpPort());
       std::set<std::string> httpBindAddresses;
       lock.GetConfiguration().GetSetOfStringsParameter(httpBindAddresses, "HttpBindAddresses");
       httpServer.SetBindAddresses(httpBindAddresses);
       httpServer.SetRemoteAccessAllowed(lock.GetConfiguration().GetBooleanParameter("RemoteAccessAllowed", false));
       httpServer.SetKeepAliveEnabled(lock.GetConfiguration().GetBooleanParameter("KeepAlive", defaultKeepAlive));
-      httpServer.SetKeepAliveTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("KeepAliveTimeout", 1));
+      httpServer.SetKeepAliveTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("KeepAliveTimeout"));
       httpServer.SetHttpCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("HttpCompressionEnabled", false));
       httpServer.SetTcpNoDelay(lock.GetConfiguration().GetBooleanParameter("TcpNoDelay", true));
-      httpServer.SetRequestTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpRequestTimeout", 30));
+      httpServer.SetRequestTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpRequestTimeout"));
 
       // New in Orthanc 1.12.11
-      const unsigned int maxBodySize = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumRequestBodySizeMB", 8192);
+      const unsigned int maxBodySize = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumRequestBodySizeMB");
       if (maxBodySize != 0)
       {
         const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(maxBodySize * MEGABYTE);
@@ -1141,7 +1141,7 @@
         LOG(WARNING) << "No limit on the maximum body size in HTTP requests";
       }
 
-      const unsigned int maxSizeInArchive = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumFileSizeInArchiveMB", 4096);
+      const unsigned int maxSizeInArchive = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumFileSizeInArchiveMB");
       if (maxSizeInArchive != 0)
       {
         const uint64_t size = Toolbox::BoundMemorySizeToCurrentArchitecture(maxSizeInArchive * MEGABYTE);
@@ -1231,8 +1231,7 @@
         
         // Default to TLS 1.2+1.3 as SSL minimum
         // See https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md "ssl_protocol_version" for mapping
-        static const unsigned int TLS_1_2_AND_1_3 = 4;
-        unsigned int minimumVersion = lock.GetConfiguration().GetUnsignedIntegerParameter("SslMinimumProtocolVersion", TLS_1_2_AND_1_3);
+        unsigned int minimumVersion = lock.GetConfiguration().GetUnsignedIntegerParameter("SslMinimumProtocolVersion");
         httpServer.SetSslMinimumVersion(minimumVersion);
 
         static const char* SSL_CIPHERS_ACCEPTED = "SslCiphersAccepted";
@@ -1392,9 +1391,9 @@
     {
       OrthancConfiguration::ReaderLock lock;
       dicomServer.SetCalledApplicationEntityTitleCheck(lock.GetConfiguration().GetBooleanParameter("DicomCheckCalledAet", false));
-      dicomServer.SetAssociationTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScpTimeout", 30));
+      dicomServer.SetAssociationTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScpTimeout"));
       dicomServer.SetPortNumber(lock.GetConfiguration().GetDicomPort());
-      dicomServer.SetThreadsCount(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomThreadsCount", 4));
+      dicomServer.SetThreadsCount(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomThreadsCount"));
       dicomServer.SetApplicationEntityTitle(lock.GetConfiguration().GetOrthancAET());
 
       // Configuration of DICOM TLS for Orthanc SCP (since Orthanc 1.9.0)
@@ -1407,14 +1406,14 @@
         dicomServer.SetTrustedCertificatesPath(
           lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_TRUSTED_CERTIFICATES, ""));
         dicomServer.SetMinimumTlsVersion(
-          lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_DICOM_TLS_MINIMUM_PROTOCOL_VERSION, 0));
+          lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_DICOM_TLS_MINIMUM_PROTOCOL_VERSION));
         
         std::set<std::string> acceptedCiphers;
         lock.GetConfiguration().GetSetOfStringsParameter(acceptedCiphers, KEY_DICOM_TLS_ACCEPTED_CIPHERS);
         dicomServer.SetAcceptedCiphers(acceptedCiphers);
       }
 
-      dicomServer.SetMaximumPduLength(lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH, 16384));
+      dicomServer.SetMaximumPduLength(lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH));
 
       // New option in Orthanc 1.9.3
       dicomServer.SetRemoteCertificateRequired(
@@ -1673,13 +1672,13 @@
 
     // The value "0" below makes the class HttpClient use its default
     // value (DEFAULT_HTTP_TIMEOUT = 60 seconds in Orthanc 1.5.7)
-    HttpClient::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpTimeout", 0));
+    HttpClient::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("HttpTimeout"));
     
     HttpClient::SetDefaultProxy(lock.GetConfiguration().GetStringParameter("HttpProxy", ""));
     
-    DicomAssociationParameters::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScuTimeout", 10));
+    DicomAssociationParameters::SetDefaultTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScuTimeout"));
 
-    maxCompletedJobs = lock.GetConfiguration().GetUnsignedIntegerParameter("JobsHistorySize", 10);
+    maxCompletedJobs = lock.GetConfiguration().GetUnsignedIntegerParameter("JobsHistorySize");
 
     if (maxCompletedJobs == 0)
     {
@@ -1690,7 +1689,7 @@
     readOnly = lock.GetConfiguration().GetBooleanParameter(ORTHANC_CONFIG_READ_ONLY, false);
     
     // New option in Orthanc 1.12.6
-    maxDcmtkConcurrentTranscoders = lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_CONCURRENT_DCMTK_TRANSCODERS, 0);
+    maxDcmtkConcurrentTranscoders = lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_CONCURRENT_DCMTK_TRANSCODERS);
     if (maxDcmtkConcurrentTranscoders == 0)
     {
       maxDcmtkConcurrentTranscoders = static_cast<unsigned int>(boost::thread::hardware_concurrency());
@@ -1703,7 +1702,7 @@
     DicomAssociationParameters::SetDefaultTrustedCertificatesPath(
       lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_TRUSTED_CERTIFICATES, ""));
     DicomAssociationParameters::SetDefaultMaximumPduLength(
-      lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH, 16384));
+      lock.GetConfiguration().GetUnsignedIntegerParameter(KEY_MAXIMUM_PDU_LENGTH));
 
     // New option in Orthanc 1.9.3
     DicomAssociationParameters::SetDefaultRemoteCertificateRequired(