changeset 726:2811c0d5d0b1 sql-opti

Audit logs API: differentiate null and empty strings in LogData
author Alain Mazy <am@orthanc.team>
date Tue, 12 Aug 2025 10:46:03 +0200
parents b086e69efb8c
children 5d6ce8e26dec faa30d55b74d
files Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp
diffstat 3 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Mon Aug 11 18:44:34 2025 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Tue Aug 12 10:46:03 2025 +0200
@@ -1688,10 +1688,10 @@
         bool fillBase64;
         if (logDataInJson)
         {
-          if (it->GetLogData().empty())
+          if (!it->HasLogData())
           {
             serializedAuditLog["JsonLogData"] = Json::nullValue;
-            fillBase64 = false;  // TODO - Shouldn't this be the same behavior as (*) below?
+            fillBase64 = false;
           }
           else
           {
@@ -1703,7 +1703,7 @@
             }
             else
             {
-              // If the data is not JSON compatible, export it in base64 anyway (*)
+              // If the data is not JSON compatible, export it in base64 anyway
               fillBase64 = true;
             }
           }
@@ -1715,9 +1715,16 @@
 
         if (fillBase64)
         {
-          std::string b64;
-          Orthanc::Toolbox::EncodeBase64(b64, it->GetLogData());
-          serializedAuditLog["Base64LogData"] = b64;
+          if (it->HasLogData())
+          {
+            std::string b64;
+            Orthanc::Toolbox::EncodeBase64(b64, it->GetLogData());
+            serializedAuditLog["Base64LogData"] = b64;
+          }
+          else
+          {
+            serializedAuditLog["Base64LogData"] = Json::nullValue;
+          }
         }
 
         jsonLogs.append(serializedAuditLog);
--- a/Framework/Plugins/IDatabaseBackend.h	Mon Aug 11 18:44:34 2025 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Tue Aug 12 10:46:03 2025 +0200
@@ -47,6 +47,7 @@
       std::string resourceId_;
       std::string action_;
       std::string logData_;
+      bool hasLogData_;
 
     public:
       AuditLog(const std::string& timestamp,
@@ -55,14 +56,16 @@
                OrthancPluginResourceType resourceType,
                const std::string& resourceId,
                const std::string& action,
-               const std::string& logData) :
+               const std::string& logData,
+               bool hasLogData) :
         timestamp_(timestamp),
         sourcePlugin_(sourcePlugin),
         userId_(userId),
         resourceType_(resourceType),
         resourceId_(resourceId),
         action_(action),
-        logData_(logData)
+        logData_(logData),
+        hasLogData_(hasLogData)
       {
       }
 
@@ -100,6 +103,11 @@
       {
         return logData_;
       }
+
+      bool HasLogData() const
+      {
+        return hasLogData_;
+      }
     };
 
   public:
--- a/Framework/Plugins/IndexBackend.cpp	Mon Aug 11 18:44:34 2025 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Tue Aug 12 10:46:03 2025 +0200
@@ -4806,7 +4806,8 @@
                                   static_cast<OrthancPluginResourceType>(statement.ReadInteger64(3)),
                                   statement.ReadString(4),
                                   statement.ReadString(5),
-                                  statement.ReadStringOrNull(6)));
+                                  statement.ReadStringOrNull(6),
+                                  !statement.IsNull(6)));
 
           statement.Next();
         }