Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomNetworking/Internals/GetScp.cpp @ 4912:45d6ce72a84e
fix linking of Sanitizer sample plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Feb 2022 17:46:28 +0100 |
parents | 43e613a7756b |
children | b23a4bb18065 |
rev | line source |
---|---|
3818 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
3818 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
3818 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
3818 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
3818 | 21 **/ |
22 | |
23 | |
24 | |
25 | |
26 /*========================================================================= | |
27 | |
28 This file is based on portions of the following project: | |
29 | |
30 Program: DCMTK 3.6.0 | |
31 Module: http://dicom.offis.de/dcmtk.php.en | |
32 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
33 Copyright (C) 1994-2011, OFFIS e.V. |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
34 All rights reserved. |
3818 | 35 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
36 This software and supporting documentation were developed by |
3818 | 37 |
38 OFFIS e.V. | |
39 R&D Division Health | |
40 Escherweg 2 | |
41 26121 Oldenburg, Germany | |
42 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
43 Redistribution and use in source and binary forms, with or without |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
44 modification, are permitted provided that the following conditions |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
45 are met: |
3818 | 46 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
47 - Redistributions of source code must retain the above copyright |
3818 | 48 notice, this list of conditions and the following disclaimer. |
49 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
50 - Redistributions in binary form must reproduce the above copyright |
3818 | 51 notice, this list of conditions and the following disclaimer in the |
52 documentation and/or other materials provided with the distribution. | |
53 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
54 - Neither the name of OFFIS nor the names of its contributors may be |
3818 | 55 used to endorse or promote products derived from this software |
56 without specific prior written permission. | |
57 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
58 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
59 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
60 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
61 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
62 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
63 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
64 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
65 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
66 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
67 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
68 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3818 | 69 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
70 =========================================================================*/ |
3818 | 71 |
72 | |
73 #include "../../PrecompiledHeaders.h" | |
74 #include <dcmtk/dcmnet/diutil.h> | |
75 #include <dcmtk/dcmdata/dcdeftag.h> | |
76 #include "GetScp.h" | |
77 | |
78 #include <memory> | |
79 | |
80 #include "../../DicomParsing/FromDcmtkBridge.h" | |
81 #include "../../DicomParsing/ToDcmtkBridge.h" | |
82 #include "../../Logging.h" | |
83 #include "../../OrthancException.h" | |
84 | |
85 #include <boost/lexical_cast.hpp> | |
86 | |
87 | |
88 namespace Orthanc | |
89 { | |
90 namespace | |
91 { | |
92 struct GetScpData | |
93 { | |
94 // Handle returns void. | |
95 IGetRequestHandler* handler_; | |
96 DcmDataset* lastRequest_; | |
97 T_ASC_Association * assoc_; | |
98 | |
99 std::string remoteIp_; | |
100 std::string remoteAet_; | |
101 std::string calledAet_; | |
3955
66879215cbf3
C-GET: add timeout, fix uninitalized priority, support multiple resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3954
diff
changeset
|
102 int timeout_; |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
103 bool canceled_; |
3818 | 104 |
4200 | 105 GetScpData() : |
106 handler_(NULL), | |
107 lastRequest_(NULL), | |
108 assoc_(NULL), | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
109 timeout_(0), |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
110 canceled_(false) |
3818 | 111 { |
112 }; | |
113 }; | |
114 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
115 static DcmDataset *BuildFailedInstanceList(const std::string& failedUIDs) |
3818 | 116 { |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
117 if (failedUIDs.empty()) |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
118 { |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
119 return NULL; |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
120 } |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
121 else |
3818 | 122 { |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
123 std::unique_ptr<DcmDataset> rspIds(new DcmDataset()); |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
124 |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
125 if (!DU_putStringDOElement(rspIds.get(), DCM_FailedSOPInstanceUIDList, failedUIDs.c_str())) |
3818 | 126 { |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
127 throw OrthancException(ErrorCode_InternalError, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
128 "getSCP: failed to build DCM_FailedSOPInstanceUIDList"); |
3818 | 129 } |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
130 |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
131 return rspIds.release(); |
3818 | 132 } |
133 } | |
134 | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
135 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
136 static void FillResponse(T_DIMSE_C_GetRSP& response, |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
137 DcmDataset** failedIdentifiers, |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
138 const IGetRequestHandler& handler) |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
139 { |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
140 response.DimseStatus = STATUS_Success; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
141 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
142 size_t processedCount = (handler.GetCompletedCount() + |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
143 handler.GetFailedCount() + |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
144 handler.GetWarningCount()); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
145 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
146 if (processedCount > handler.GetSubOperationCount()) |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
147 { |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
148 throw OrthancException(ErrorCode_InternalError); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
149 } |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
150 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
151 response.NumberOfRemainingSubOperations = (handler.GetSubOperationCount() - processedCount); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
152 response.NumberOfCompletedSubOperations = handler.GetCompletedCount(); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
153 response.NumberOfFailedSubOperations = handler.GetFailedCount(); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
154 response.NumberOfWarningSubOperations = handler.GetWarningCount(); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
155 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
156 // http://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_C.4.3.3.html |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
157 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
158 if (handler.GetFailedCount() > 0 || |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
159 handler.GetWarningCount() > 0) |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
160 { |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
161 /** |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
162 * "Warning if one or more sub-operations were successfully |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
163 * completed and one or more sub-operations were unsuccessful |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
164 * or had a status of warning. Warning if all sub-operations |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
165 * had a status of Warning" |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
166 **/ |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
167 response.DimseStatus = STATUS_GET_Warning_SubOperationsCompleteOneOrMoreFailures; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
168 } |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
169 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
170 if (handler.GetFailedCount() > 0 && |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
171 handler.GetFailedCount() == handler.GetSubOperationCount()) |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
172 { |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
173 /** |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
174 * "Failure or Refused if all sub-operations were |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
175 * unsuccessful." => We choose to generate a "Refused - Out |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
176 * of Resources - Unable to perform suboperations" status. |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
177 */ |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
178 response.DimseStatus = STATUS_GET_Refused_OutOfResourcesSubOperations; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
179 } |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
180 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
181 *failedIdentifiers = BuildFailedInstanceList(handler.GetFailedUids()); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
182 } |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
183 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
184 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
185 static void GetScpCallback( |
3818 | 186 /* in */ |
187 void *callbackData, | |
188 OFBool cancelled, | |
189 T_DIMSE_C_GetRQ *request, | |
190 DcmDataset *requestIdentifiers, | |
191 int responseCount, | |
192 /* out */ | |
193 T_DIMSE_C_GetRSP *response, | |
194 DcmDataset **responseIdentifiers, | |
195 DcmDataset **statusDetail) | |
196 { | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
197 assert(response != NULL); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
198 assert(responseIdentifiers != NULL); |
4286
526bd8bad850
debug logs for C-MOVE and C-GET SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4284
diff
changeset
|
199 assert(requestIdentifiers != NULL); |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
200 |
3818 | 201 bzero(response, sizeof(T_DIMSE_C_GetRSP)); |
202 *statusDetail = NULL; | |
203 *responseIdentifiers = NULL; | |
204 | |
205 GetScpData& data = *reinterpret_cast<GetScpData*>(callbackData); | |
206 if (data.lastRequest_ == NULL) | |
207 { | |
4286
526bd8bad850
debug logs for C-MOVE and C-GET SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4284
diff
changeset
|
208 { |
4288 | 209 std::stringstream s; // DcmObject::PrintHelper cannot be used with VS2008 |
210 requestIdentifiers->print(s); | |
211 CLOG(TRACE, DICOM) << "Received C-GET Request:" << std::endl << s.str(); | |
4286
526bd8bad850
debug logs for C-MOVE and C-GET SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4284
diff
changeset
|
212 } |
526bd8bad850
debug logs for C-MOVE and C-GET SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4284
diff
changeset
|
213 |
3818 | 214 DicomMap input; |
4137
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
215 std::set<DicomTag> ignoreTagLength; |
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
216 FromDcmtkBridge::ExtractDicomSummary(input, *requestIdentifiers, 0 /* don't truncate tags */, ignoreTagLength); |
3818 | 217 |
218 try | |
219 { | |
3959
76a24be12912
c-get: support of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3955
diff
changeset
|
220 if (!data.handler_->Handle( |
76a24be12912
c-get: support of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3955
diff
changeset
|
221 input, data.remoteIp_, data.remoteAet_, data.calledAet_, |
76a24be12912
c-get: support of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3955
diff
changeset
|
222 data.timeout_ < 0 ? 0 : static_cast<uint32_t>(data.timeout_))) |
3818 | 223 { |
224 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; | |
225 return; | |
226 } | |
227 } | |
228 catch (OrthancException& e) | |
229 { | |
230 // Internal error! | |
4284
756126cd2219
moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4258
diff
changeset
|
231 CLOG(ERROR, DICOM) << "IGetRequestHandler Failed: " << e.What(); |
3818 | 232 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; |
233 return; | |
234 } | |
235 | |
236 data.lastRequest_ = requestIdentifiers; | |
237 } | |
238 else if (data.lastRequest_ != requestIdentifiers) | |
239 { | |
240 // Internal error! | |
4284
756126cd2219
moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4258
diff
changeset
|
241 CLOG(ERROR, DICOM) << "IGetRequestHandler Failed: Internal error lastRequestIdentifier"; |
3818 | 242 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; |
243 return; | |
244 } | |
245 | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
246 if (data.canceled_) |
3818 | 247 { |
4284
756126cd2219
moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4258
diff
changeset
|
248 CLOG(ERROR, DICOM) << "IGetRequestHandler Failed: Cannot pursue a request that was canceled by the SCU"; |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
249 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
250 return; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
251 } |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
252 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
253 if (data.handler_->GetSubOperationCount() == |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
254 data.handler_->GetCompletedCount() + |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
255 data.handler_->GetFailedCount() + |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
256 data.handler_->GetWarningCount()) |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
257 { |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
258 // We're all done |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
259 FillResponse(*response, responseIdentifiers, *data.handler_); |
3818 | 260 } |
261 else | |
262 { | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
263 bool isContinue; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
264 |
3818 | 265 try |
266 { | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
267 isContinue = data.handler_->DoNext(data.assoc_); |
3818 | 268 } |
269 catch (OrthancException& e) | |
270 { | |
271 // Internal error! | |
4284
756126cd2219
moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4258
diff
changeset
|
272 CLOG(ERROR, DICOM) << "IGetRequestHandler Failed: " << e.What(); |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
273 FillResponse(*response, responseIdentifiers, *data.handler_); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
274 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
275 // Fix the status code that is computed by "FillResponse()" |
3818 | 276 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; |
277 return; | |
278 } | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
279 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
280 FillResponse(*response, responseIdentifiers, *data.handler_); |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
281 |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
282 if (isContinue) |
3818 | 283 { |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
284 response->DimseStatus = STATUS_Pending; |
3818 | 285 } |
286 else | |
287 { | |
4258
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
288 response->DimseStatus = STATUS_GET_Cancel_SubOperationsTerminatedDueToCancelIndication; |
6f5d4bfb2c90
C-GET SCP: Fix responses and handling of cancel
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4200
diff
changeset
|
289 data.canceled_ = true; |
3818 | 290 } |
291 } | |
292 } | |
293 } | |
294 | |
295 OFCondition Internals::getScp(T_ASC_Association * assoc, | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
296 T_DIMSE_Message * msg, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
297 T_ASC_PresentationContextID presID, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
298 IGetRequestHandler& handler, |
4200 | 299 const std::string& remoteIp, |
300 const std::string& remoteAet, | |
301 const std::string& calledAet, | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
302 int timeout) |
3818 | 303 { |
304 GetScpData data; | |
305 data.lastRequest_ = NULL; | |
306 data.handler_ = &handler; | |
307 data.assoc_ = assoc; | |
308 data.remoteIp_ = remoteIp; | |
309 data.remoteAet_ = remoteAet; | |
310 data.calledAet_ = calledAet; | |
3955
66879215cbf3
C-GET: add timeout, fix uninitalized priority, support multiple resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3954
diff
changeset
|
311 data.timeout_ = timeout; |
3818 | 312 |
313 OFCondition cond = DIMSE_getProvider(assoc, presID, &msg->msg.CGetRQ, | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
314 GetScpCallback, &data, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
315 /*opt_blockMode*/ (timeout ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
316 /*opt_dimse_timeout*/ timeout); |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
317 |
3818 | 318 // if some error occured, dump corresponding information and remove the outfile if necessary |
319 if (cond.bad()) | |
320 { | |
321 OFString temp_str; | |
4284
756126cd2219
moving all logs from DicomNetworking folder into the "dicom" category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4258
diff
changeset
|
322 CLOG(ERROR, DICOM) << "Get SCP Failed: " << cond.text(); |
3818 | 323 } |
324 | |
325 return cond; | |
326 } | |
327 } |