diff OrthancServer/DicomInstanceToStore.cpp @ 1572:904096e7367e

More information about the origin request in OnStoredInstance() callbacks
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 12:10:12 +0200
parents f967bdf8534e
children 3309878b3e16
line wrap: on
line diff
--- a/OrthancServer/DicomInstanceToStore.cpp	Tue Aug 25 11:04:19 2015 +0200
+++ b/OrthancServer/DicomInstanceToStore.cpp	Tue Aug 25 12:10:12 2015 +0200
@@ -171,4 +171,96 @@
 
     return json_.GetConstContent();
   }
+
+
+
+  void DicomInstanceToStore::GetOriginInformation(Json::Value& result) const
+  {
+    result = Json::objectValue;
+    result["RequestOrigin"] = EnumerationToString(origin_);
+
+    switch (origin_)
+    {
+      case RequestOrigin_Unknown:
+      {
+        // None of the methods "SetDicomProtocolOrigin()", "SetHttpOrigin()",
+        // "SetLuaOrigin()" or "SetPluginsOrigin()" was called!
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      }
+
+      case RequestOrigin_DicomProtocol:
+      {
+        result["RemoteAet"] = dicomRemoteAet_;
+        result["CalledAet"] = dicomCalledAet_;
+        break;
+      }
+
+      case RequestOrigin_Http:
+      {
+        result["RemoteIp"] = httpRemoteIp_;
+        result["Username"] = httpUsername_;
+        break;
+      }
+
+      case RequestOrigin_Lua:
+      case RequestOrigin_Plugins:
+      {
+        // No additional information available for these kinds of requests
+        break;
+      }
+
+      default:
+        throw OrthancException(ErrorCode_InternalError);
+    }
+  }
+
+
+  void DicomInstanceToStore::SetDicomProtocolOrigin(const char* remoteAet,
+                                                    const char* calledAet)
+  {
+    origin_ = RequestOrigin_DicomProtocol;
+    dicomRemoteAet_ = remoteAet;
+    dicomCalledAet_ = calledAet;
+  }
+
+  void DicomInstanceToStore::SetRestOrigin(const RestApiCall& call)
+  {
+    origin_ = call.GetRequestOrigin();
+
+    if (origin_ == RequestOrigin_Http)
+    {
+      httpRemoteIp_ = call.GetRemoteIp();
+      httpUsername_ = call.GetUsername();
+    }
+  }
+
+  void DicomInstanceToStore::SetHttpOrigin(const char* remoteIp,
+                                           const char* username)
+  {
+    origin_ = RequestOrigin_Http;
+    httpRemoteIp_ = remoteIp;
+    httpUsername_ = username;
+  }
+
+  void DicomInstanceToStore::SetLuaOrigin()
+  {
+    origin_ = RequestOrigin_Lua;
+  }
+
+  void DicomInstanceToStore::SetPluginsOrigin()
+  {
+    origin_ = RequestOrigin_Plugins;
+  }
+
+  const char* DicomInstanceToStore::GetRemoteAet() const
+  {
+    if (origin_ == RequestOrigin_DicomProtocol)
+    {
+      return dicomRemoteAet_.c_str();
+    }
+    else
+    {
+      return "";
+    }
+  }
 }