changeset 4997:1f93dc290628

fix compatibility with dcmtk 3.6.7
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 May 2022 17:29:58 +0200
parents 0f0ada196993
children f67b8bb90ab6
files OrthancFramework/Sources/DicomNetworking/Internals/DicomTls.cpp
diffstat 1 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/Internals/DicomTls.cpp	Wed May 04 10:50:34 2022 +0200
+++ b/OrthancFramework/Sources/DicomNetworking/Internals/DicomTls.cpp	Wed May 04 17:29:58 2022 +0200
@@ -45,6 +45,19 @@
 {
   namespace Internals
   {
+#if DCMTK_VERSION_NUMBER >= 367
+    static bool IsFailure(OFCondition cond)
+    {
+      return !cond.good();
+    }
+#else
+    static bool IsFailure(DcmTransportLayerStatus status)
+    {
+      return (status != TCS_ok);
+    }
+#endif
+
+
     DcmTLSTransportLayer* InitializeDicomTls(T_ASC_Network *network,
                                              T_ASC_NetworkRole role,
                                              const std::string& ownPrivateKeyPath,
@@ -107,19 +120,19 @@
         new DcmTLSTransportLayer(tmpRole /*opt_networkRole*/, NULL /*opt_readSeedFile*/,
                                  OFFalse /*initializeOpenSSL, done by Orthanc::Toolbox::InitializeOpenSsl()*/));
 
-      if (tls->addTrustedCertificateFile(trustedCertificatesPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/) != TCS_ok)
+      if (IsFailure(tls->addTrustedCertificateFile(trustedCertificatesPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/)))
       {
         throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with trusted certificates for DICOM TLS: " +
                                trustedCertificatesPath);
       }
 
-      if (tls->setPrivateKeyFile(ownPrivateKeyPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/) != TCS_ok)
+      if (IsFailure(tls->setPrivateKeyFile(ownPrivateKeyPath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/)))
       {
         throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with private key for DICOM TLS: " +
                                ownPrivateKeyPath);
       }
 
-      if (tls->setCertificateFile(ownCertificatePath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/) != TCS_ok)
+      if (IsFailure(tls->setCertificateFile(ownCertificatePath.c_str(), DCF_Filetype_PEM /*opt_keyFileFormat*/)))
       {
         throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse PEM file with own certificate for DICOM TLS: " +
                                ownCertificatePath);
@@ -132,18 +145,18 @@
       }
 
 #if DCMTK_VERSION_NUMBER >= 364
-      if (tls->setTLSProfile(TSP_Profile_BCP195 /*opt_tlsProfile*/) != TCS_ok)
+      if (IsFailure(tls->setTLSProfile(TSP_Profile_BCP195 /*opt_tlsProfile*/)))
       {
         throw OrthancException(ErrorCode_InternalError, "Cannot set the DICOM TLS profile");
       }
     
-      if (tls->activateCipherSuites())
+      if (IsFailure(tls->activateCipherSuites()))
       {
         throw OrthancException(ErrorCode_InternalError, "Cannot activate the cipher suites for DICOM TLS");
       }
 #else
       CLOG(INFO, DICOM) << "Using the following cipher suites for DICOM TLS: " << opt_ciphersuites;
-      if (tls->setCipherSuites(opt_ciphersuites.c_str()) != TCS_ok)
+      if (IsFailure(tls->setCipherSuites(opt_ciphersuites.c_str())))
       {
         throw OrthancException(ErrorCode_InternalError, "Unable to set cipher suites to: " + opt_ciphersuites);
       }