changeset 1573:3309878b3e16

more information about the origin of requests submitted to the DICOM handlers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 13:05:22 +0200
parents 904096e7367e
children 0c29ebe80ac9
files OrthancServer/DicomInstanceToStore.cpp OrthancServer/DicomInstanceToStore.h OrthancServer/DicomProtocol/IFindRequestHandler.h OrthancServer/DicomProtocol/IMoveRequestHandler.h OrthancServer/DicomProtocol/IStoreRequestHandler.h OrthancServer/Internals/CommandDispatcher.cpp OrthancServer/Internals/CommandDispatcher.h OrthancServer/Internals/FindScp.cpp OrthancServer/Internals/FindScp.h OrthancServer/Internals/MoveScp.cpp OrthancServer/Internals/MoveScp.h OrthancServer/Internals/StoreScp.cpp OrthancServer/Internals/StoreScp.h OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancFindRequestHandler.h OrthancServer/OrthancMoveRequestHandler.cpp OrthancServer/OrthancMoveRequestHandler.h OrthancServer/main.cpp
diffstat 18 files changed, 88 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomInstanceToStore.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/DicomInstanceToStore.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -190,6 +190,7 @@
 
       case RequestOrigin_DicomProtocol:
       {
+        result["RemoteIp"] = remoteIp_;
         result["RemoteAet"] = dicomRemoteAet_;
         result["CalledAet"] = dicomCalledAet_;
         break;
@@ -197,7 +198,7 @@
 
       case RequestOrigin_Http:
       {
-        result["RemoteIp"] = httpRemoteIp_;
+        result["RemoteIp"] = remoteIp_;
         result["Username"] = httpUsername_;
         break;
       }
@@ -215,10 +216,12 @@
   }
 
 
-  void DicomInstanceToStore::SetDicomProtocolOrigin(const char* remoteAet,
+  void DicomInstanceToStore::SetDicomProtocolOrigin(const char* remoteIp,
+                                                    const char* remoteAet,
                                                     const char* calledAet)
   {
     origin_ = RequestOrigin_DicomProtocol;
+    remoteIp_ = remoteIp;
     dicomRemoteAet_ = remoteAet;
     dicomCalledAet_ = calledAet;
   }
@@ -229,7 +232,7 @@
 
     if (origin_ == RequestOrigin_Http)
     {
-      httpRemoteIp_ = call.GetRemoteIp();
+      remoteIp_ = call.GetRemoteIp();
       httpUsername_ = call.GetUsername();
     }
   }
@@ -238,7 +241,7 @@
                                            const char* username)
   {
     origin_ = RequestOrigin_Http;
-    httpRemoteIp_ = remoteIp;
+    remoteIp_ = remoteIp;
     httpUsername_ = username;
   }
 
--- a/OrthancServer/DicomInstanceToStore.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/DicomInstanceToStore.h	Tue Aug 25 13:05:22 2015 +0200
@@ -145,9 +145,9 @@
     SmartContainer<Json::Value>  json_;
 
     RequestOrigin origin_;
+    std::string remoteIp_;
     std::string dicomRemoteAet_;
     std::string dicomCalledAet_;
-    std::string httpRemoteIp_;
     std::string httpUsername_;
     ServerIndex::MetadataMap metadata_;
 
@@ -158,7 +158,8 @@
     {
     }
 
-    void SetDicomProtocolOrigin(const char* remoteAet,
+    void SetDicomProtocolOrigin(const char* remoteIp,
+                                const char* remoteAet,
                                 const char* calledAet);
 
     void SetRestOrigin(const RestApiCall& call);
--- a/OrthancServer/DicomProtocol/IFindRequestHandler.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/DicomProtocol/IFindRequestHandler.h	Tue Aug 25 13:05:22 2015 +0200
@@ -55,6 +55,7 @@
      **/
     virtual bool Handle(DicomFindAnswers& answers,
                         const DicomMap& input,
-                        const std::string& callingAETitle) = 0;
+                        const std::string& remoteIp,
+                        const std::string& remoteAet) = 0;
   };
 }
--- a/OrthancServer/DicomProtocol/IMoveRequestHandler.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/DicomProtocol/IMoveRequestHandler.h	Tue Aug 25 13:05:22 2015 +0200
@@ -68,7 +68,9 @@
     }
 
     virtual IMoveRequestIterator* Handle(const std::string& target,
-                                         const DicomMap& input) = 0;
+                                         const DicomMap& input,
+                                         const std::string& remoteIp,
+                                         const std::string& remoteAet) = 0;
   };
 
 }
--- a/OrthancServer/DicomProtocol/IStoreRequestHandler.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/DicomProtocol/IStoreRequestHandler.h	Tue Aug 25 13:05:22 2015 +0200
@@ -50,6 +50,7 @@
     virtual void Handle(const std::string& dicomFile,
                         const DicomMap& dicomSummary,
                         const Json::Value& dicomJson,
+                        const std::string& remoteIp,
                         const std::string& remoteAet,
                         const std::string& calledAet) = 0;
   };
--- a/OrthancServer/Internals/CommandDispatcher.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/CommandDispatcher.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -771,11 +771,11 @@
         if (supported && 
             request != DicomRequestType_Echo &&  // Always allow incoming ECHO requests
             filter_ != NULL &&
-            !filter_->IsAllowedRequest(callingIP_, callingAETitle_, request))
+            !filter_->IsAllowedRequest(remoteIp_, remoteAet_, request))
         {
           LOG(ERROR) << EnumerationToString(request) 
                      << " requests are disallowed for the AET \"" 
-                     << callingAETitle_ << "\"";
+                     << remoteAet_ << "\"";
           cond = DIMSE_ILLEGALASSOCIATION;
           supported = false;
           finished = true;
@@ -798,7 +798,7 @@
               {
                 std::auto_ptr<IStoreRequestHandler> handler
                   (server_.GetStoreRequestHandlerFactory().ConstructStoreRequestHandler());
-                cond = Internals::storeScp(assoc_, &msg, presID, *handler);
+                cond = Internals::storeScp(assoc_, &msg, presID, *handler, remoteIp_);
               }
               break;
 
@@ -807,7 +807,7 @@
               {
                 std::auto_ptr<IMoveRequestHandler> handler
                   (server_.GetMoveRequestHandlerFactory().ConstructMoveRequestHandler());
-                cond = Internals::moveScp(assoc_, &msg, presID, *handler);
+                cond = Internals::moveScp(assoc_, &msg, presID, *handler, remoteIp_, remoteAet_);
               }
               break;
 
@@ -816,7 +816,7 @@
               {
                 std::auto_ptr<IFindRequestHandler> handler
                   (server_.GetFindRequestHandlerFactory().ConstructFindRequestHandler());
-                cond = Internals::findScp(assoc_, &msg, presID, *handler, callingAETitle_);
+                cond = Internals::findScp(assoc_, &msg, presID, *handler, remoteIp_, remoteAet_);
               }
               break;
 
--- a/OrthancServer/Internals/CommandDispatcher.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/CommandDispatcher.h	Tue Aug 25 13:05:22 2015 +0200
@@ -50,20 +50,20 @@
       uint32_t elapsedTimeSinceLastCommand_;
       const DicomServer& server_;
       T_ASC_Association* assoc_;
-      std::string callingIP_;
-      std::string callingAETitle_;
+      std::string remoteIp_;
+      std::string remoteAet_;
       IApplicationEntityFilter* filter_;
 
     public:
       CommandDispatcher(const DicomServer& server,
                         T_ASC_Association* assoc,
-                        const std::string& callingIP,
-                        const std::string& callingAETitle,
+                        const std::string& remoteIp,
+                        const std::string& remoteAet,
                         IApplicationEntityFilter* filter) :
         server_(server),
         assoc_(assoc),
-        callingIP_(callingIP),
-        callingAETitle_(callingAETitle),
+        remoteIp_(remoteIp),
+        remoteAet_(remoteAet),
         filter_(filter)
       {
         clientTimeout_ = server.GetClientTimeout();
--- a/OrthancServer/Internals/FindScp.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/FindScp.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -99,7 +99,8 @@
       DicomMap input_;
       DicomFindAnswers answers_;
       DcmDataset* lastRequest_;
-      const std::string* callingAETitle_;
+      const std::string* remoteIp_;
+      const std::string* remoteAet_;
       bool noCroppingOfResults_;
     };
 
@@ -126,7 +127,8 @@
 
         try
         {
-          data.noCroppingOfResults_ = data.handler_->Handle(data.answers_, data.input_, *data.callingAETitle_);
+          data.noCroppingOfResults_ = data.handler_->Handle(data.answers_, data.input_, 
+                                                            *data.remoteIp_, *data.remoteAet_);
         }
         catch (OrthancException& e)
         {
@@ -174,12 +176,14 @@
                                  T_DIMSE_Message * msg, 
                                  T_ASC_PresentationContextID presID,
                                  IFindRequestHandler& handler,
-                                 const std::string& callingAETitle)
+                                 const std::string& remoteIp,
+                                 const std::string& remoteAet)
   {
     FindScpData data;
     data.lastRequest_ = NULL;
     data.handler_ = &handler;
-    data.callingAETitle_ = &callingAETitle;
+    data.remoteIp_ = &remoteIp;
+    data.remoteAet_ = &remoteAet;
     data.noCroppingOfResults_ = true;
 
     OFCondition cond = DIMSE_findProvider(assoc, presID, &msg->msg.CFindRQ, 
--- a/OrthancServer/Internals/FindScp.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/FindScp.h	Tue Aug 25 13:05:22 2015 +0200
@@ -44,6 +44,7 @@
                         T_DIMSE_Message * msg, 
                         T_ASC_PresentationContextID presID,
                         IFindRequestHandler& handler,
-                        const std::string& callingAETitle);
+                        const std::string& remoteIp,
+                        const std::string& remoteAet);
   }
 }
--- a/OrthancServer/Internals/MoveScp.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/MoveScp.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -104,6 +104,8 @@
       unsigned int failureCount_;
       unsigned int warningCount_;
       std::auto_ptr<IMoveRequestIterator> iterator_;
+      const std::string* remoteIp_;
+      const std::string* remoteAet_;
     };
 
 
@@ -130,7 +132,8 @@
 
         try
         {
-          data.iterator_.reset(data.handler_->Handle(data.target_, data.input_));
+          data.iterator_.reset(data.handler_->Handle(data.target_, data.input_, 
+                                                     *data.remoteIp_, *data.remoteAet_));
 
           if (data.iterator_.get() == NULL)
           {
@@ -210,12 +213,16 @@
   OFCondition Internals::moveScp(T_ASC_Association * assoc, 
                                  T_DIMSE_Message * msg, 
                                  T_ASC_PresentationContextID presID,
-                                 IMoveRequestHandler& handler)
+                                 IMoveRequestHandler& handler,
+                                 const std::string& remoteIp,
+                                 const std::string& remoteAet)
   {
     MoveScpData data;
     data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination);
     data.lastRequest_ = NULL;
     data.handler_ = &handler;
+    data.remoteIp_ = &remoteIp;
+    data.remoteAet_ = &remoteAet;
 
     OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, 
                                           MoveScpCallback, &data,
--- a/OrthancServer/Internals/MoveScp.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/MoveScp.h	Tue Aug 25 13:05:22 2015 +0200
@@ -43,6 +43,8 @@
     OFCondition moveScp(T_ASC_Association * assoc, 
                         T_DIMSE_Message * msg, 
                         T_ASC_PresentationContextID presID,
-                        IMoveRequestHandler& handler);
+                        IMoveRequestHandler& handler,
+                        const std::string& remoteIp,
+                        const std::string& remoteAet);
   }
 }
--- a/OrthancServer/Internals/StoreScp.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/StoreScp.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -102,6 +102,7 @@
     struct StoreCallbackData
     {
       IStoreRequestHandler* handler;
+      const std::string* remoteIp;
       const char* remoteAET;
       const char* calledAET;
       const char* modality;
@@ -202,7 +203,7 @@
             {
               try
               {
-                cbdata->handler->Handle(buffer, summary, dicomJson, cbdata->remoteAET, cbdata->calledAET);
+                cbdata->handler->Handle(buffer, summary, dicomJson, *cbdata->remoteIp, cbdata->remoteAET, cbdata->calledAET);
               }
               catch (OrthancException& e)
               {
@@ -237,7 +238,8 @@
   OFCondition Internals::storeScp(T_ASC_Association * assoc, 
                                   T_DIMSE_Message * msg, 
                                   T_ASC_PresentationContextID presID,
-                                  IStoreRequestHandler& handler)
+                                  IStoreRequestHandler& handler,
+                                  const std::string& remoteIp)
   {
     OFCondition cond = EC_Normal;
     T_DIMSE_C_StoreRQ *req;
@@ -246,23 +248,24 @@
     req = &msg->msg.CStoreRQ;
 
     // intialize some variables
-    StoreCallbackData callbackData;
-    callbackData.handler = &handler;
-    callbackData.modality = dcmSOPClassUIDToModality(req->AffectedSOPClassUID/*, "UNKNOWN"*/);
-    if (callbackData.modality == NULL)
-      callbackData.modality = "UNKNOWN";
+    StoreCallbackData data;
+    data.handler = &handler;
+    data.remoteIp = &remoteIp;
+    data.modality = dcmSOPClassUIDToModality(req->AffectedSOPClassUID/*, "UNKNOWN"*/);
+    if (data.modality == NULL)
+      data.modality = "UNKNOWN";
 
-    callbackData.affectedSOPInstanceUID = req->AffectedSOPInstanceUID;
-    callbackData.messageID = req->MessageID;
+    data.affectedSOPInstanceUID = req->AffectedSOPInstanceUID;
+    data.messageID = req->MessageID;
     if (assoc && assoc->params)
     {
-      callbackData.remoteAET = assoc->params->DULparams.callingAPTitle;
-      callbackData.calledAET = assoc->params->DULparams.calledAPTitle;
+      data.remoteAET = assoc->params->DULparams.callingAPTitle;
+      data.calledAET = assoc->params->DULparams.calledAPTitle;
     }
     else
     {
-      callbackData.remoteAET = "";
-      callbackData.calledAET = "";
+      data.remoteAET = "";
+      data.calledAET = "";
     }
 
     DcmFileFormat dcmff;
@@ -278,7 +281,7 @@
     DcmDataset *dset = dcmff.getDataset();
 
     cond = DIMSE_storeProvider(assoc, presID, req, NULL, /*opt_useMetaheader*/OFFalse, &dset,
-                               storeScpCallback, &callbackData, 
+                               storeScpCallback, &data, 
                                /*opt_blockMode*/ DIMSE_BLOCKING, 
                                /*opt_dimse_timeout*/ 0);
 
--- a/OrthancServer/Internals/StoreScp.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/Internals/StoreScp.h	Tue Aug 25 13:05:22 2015 +0200
@@ -43,6 +43,7 @@
     OFCondition storeScp(T_ASC_Association * assoc, 
                          T_DIMSE_Message * msg, 
                          T_ASC_PresentationContextID presID,
-                         IStoreRequestHandler& handler);
+                         IStoreRequestHandler& handler,
+                         const std::string& remoteIp);
   }
 }
--- a/OrthancServer/OrthancFindRequestHandler.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/OrthancFindRequestHandler.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -216,7 +216,8 @@
 
   bool OrthancFindRequestHandler::Handle(DicomFindAnswers& answers,
                                          const DicomMap& input,
-                                         const std::string& callingAETitle)
+                                         const std::string& remoteIp,
+                                         const std::string& remoteAet)
   {
     /**
      * Ensure that the calling modality is known to Orthanc.
@@ -224,7 +225,7 @@
 
     RemoteModalityParameters modality;
 
-    if (!Configuration::LookupDicomModalityUsingAETitle(modality, callingAETitle))
+    if (!Configuration::LookupDicomModalityUsingAETitle(modality, remoteAet))
     {
       throw OrthancException("Unknown modality");
     }
--- a/OrthancServer/OrthancFindRequestHandler.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/OrthancFindRequestHandler.h	Tue Aug 25 13:05:22 2015 +0200
@@ -57,7 +57,8 @@
 
     virtual bool Handle(DicomFindAnswers& answers,
                         const DicomMap& input,
-                        const std::string& callingAETitle);
+                        const std::string& remoteIp,
+                        const std::string& remoteAet);
 
     unsigned int GetMaxResults() const
     {
--- a/OrthancServer/OrthancMoveRequestHandler.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/OrthancMoveRequestHandler.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -130,10 +130,12 @@
   }
 
 
-  IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& aet,
-                                                          const DicomMap& input)
+  IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& targetAet,
+                                                          const DicomMap& input,
+                                                          const std::string& remoteIp,
+                                                          const std::string& remoteAet)
   {
-    LOG(WARNING) << "Move-SCU request received for AET \"" << aet << "\"";
+    LOG(WARNING) << "Move-SCU request received for AET \"" << targetAet << "\"";
 
     {
       DicomArray query(input);
@@ -176,7 +178,7 @@
           LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input) ||
           LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input))
       {
-        return new OrthancMoveRequestIterator(context_, aet, publicId);
+        return new OrthancMoveRequestIterator(context_, targetAet, publicId);
       }
       else
       {
@@ -221,6 +223,6 @@
       throw OrthancException(ErrorCode_BadRequest);
     }
 
-    return new OrthancMoveRequestIterator(context_, aet, publicId);
+    return new OrthancMoveRequestIterator(context_, targetAet, publicId);
   }
 }
--- a/OrthancServer/OrthancMoveRequestHandler.h	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/OrthancMoveRequestHandler.h	Tue Aug 25 13:05:22 2015 +0200
@@ -51,7 +51,9 @@
     {
     }
 
-    virtual IMoveRequestIterator* Handle(const std::string& target,
-                                         const DicomMap& input);
+    virtual IMoveRequestIterator* Handle(const std::string& targetAet,
+                                         const DicomMap& input,
+                                         const std::string& remoteIp,
+                                         const std::string& remoteAet);
   };
 }
--- a/OrthancServer/main.cpp	Tue Aug 25 12:10:12 2015 +0200
+++ b/OrthancServer/main.cpp	Tue Aug 25 13:05:22 2015 +0200
@@ -66,16 +66,18 @@
   {
   }
 
+
   virtual void Handle(const std::string& dicomFile,
                       const DicomMap& dicomSummary,
                       const Json::Value& dicomJson,
+                      const std::string& remoteIp,
                       const std::string& remoteAet,
-                      const std::string& calledAet)
+                      const std::string& calledAet) 
   {
     if (dicomFile.size() > 0)
     {
       DicomInstanceToStore toStore;
-      toStore.SetDicomProtocolOrigin(remoteAet.c_str(), calledAet.c_str());
+      toStore.SetDicomProtocolOrigin(remoteIp.c_str(), remoteAet.c_str(), calledAet.c_str());
       toStore.SetBuffer(dicomFile);
       toStore.SetSummary(dicomSummary);
       toStore.SetJson(dicomJson);