diff OrthancServer/Internals/MoveScp.cpp @ 2222:21713ce8717b

Fix handling of Move Originator AET and ID in C-MOVE SCP
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Dec 2016 14:34:33 +0100
parents bb199bccdc45
children a3a65de1840f
line wrap: on
line diff
--- a/OrthancServer/Internals/MoveScp.cpp	Tue Dec 13 12:13:12 2016 +0100
+++ b/OrthancServer/Internals/MoveScp.cpp	Tue Dec 13 14:34:33 2016 +0100
@@ -90,6 +90,8 @@
 #include "../../Core/Logging.h"
 #include "../../Core/OrthancException.h"
 
+#include <boost/lexical_cast.hpp>
+
 
 namespace Orthanc
 {
@@ -110,6 +112,42 @@
     };
 
 
+
+    static uint16_t GetMessageId(const DicomMap& message)
+    {
+      /**
+       * Retrieve the Message ID (0000,0110) for this C-MOVE request, if
+       * any. If present, this Message ID will be stored in the Move
+       * Originator Message ID (0000,1031) field of the C-MOVE response.
+       * http://dicom.nema.org/dicom/2013/output/chtml/part07/chapter_E.html
+       **/
+
+      const DicomValue* value = message.TestAndGetValue(DICOM_TAG_MESSAGE_ID);
+
+      if (value != NULL &&
+          !value->IsNull() &&
+          !value->IsBinary())
+      {
+        try
+        {
+          int tmp = boost::lexical_cast<int>(value->GetContent());
+          if (tmp >= 0 && tmp <= 0xffff)
+          {
+            return static_cast<uint16_t>(tmp);
+          }
+        }
+        catch (boost::bad_lexical_cast&)
+        {
+          LOG(WARNING) << "Cannot convert the Message ID (\"" << value->GetContent()
+                       << "\") of an incoming C-MOVE request to an integer, assuming zero";
+        }
+      }
+
+      return 0;
+    }
+
+
+
     void MoveScpCallback(
       /* in */ 
       void *callbackData,  
@@ -134,9 +172,8 @@
 
         try
         {
-          data.iterator_.reset(data.handler_->Handle(data.target_, input,
-                                                     *data.remoteIp_, *data.remoteAet_,
-                                                     *data.calledAet_, request->MessageID));
+          data.iterator_.reset(data.handler_->Handle(data.target_, input, *data.remoteIp_, *data.remoteAet_,
+                                                     *data.calledAet_, GetMessageId(input)));
 
           if (data.iterator_.get() == NULL)
           {