Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomNetworking/Internals/GetScp.cpp @ 4137:6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Aug 2020 17:38:55 +0200 |
parents | 2724977419fb |
children | 7112a8af0b63 |
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 | |
3970
4d1dcdf5c57e
fix date in some files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3959
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
3818 | 6 * |
7 * 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
|
8 * 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
|
9 * 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
|
10 * the License, or (at your option) any later version. |
3818 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * 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
|
15 * Lesser General Public License for more details. |
3818 | 16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
3818 | 20 **/ |
21 | |
22 | |
23 | |
24 | |
25 /*========================================================================= | |
26 | |
27 This file is based on portions of the following project: | |
28 | |
29 Program: DCMTK 3.6.0 | |
30 Module: http://dicom.offis.de/dcmtk.php.en | |
31 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
32 Copyright (C) 1994-2011, OFFIS e.V. |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
33 All rights reserved. |
3818 | 34 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
35 This software and supporting documentation were developed by |
3818 | 36 |
37 OFFIS e.V. | |
38 R&D Division Health | |
39 Escherweg 2 | |
40 26121 Oldenburg, Germany | |
41 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
42 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
|
43 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
|
44 are met: |
3818 | 45 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
46 - Redistributions of source code must retain the above copyright |
3818 | 47 notice, this list of conditions and the following disclaimer. |
48 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
49 - Redistributions in binary form must reproduce the above copyright |
3818 | 50 notice, this list of conditions and the following disclaimer in the |
51 documentation and/or other materials provided with the distribution. | |
52 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
53 - Neither the name of OFFIS nor the names of its contributors may be |
3818 | 54 used to endorse or promote products derived from this software |
55 without specific prior written permission. | |
56 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
57 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
|
58 "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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 (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
|
67 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3818 | 68 |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
69 =========================================================================*/ |
3818 | 70 |
71 | |
72 #include "../../PrecompiledHeaders.h" | |
73 #include <dcmtk/dcmnet/diutil.h> | |
74 #include <dcmtk/dcmdata/dcdeftag.h> | |
75 #include "GetScp.h" | |
76 | |
77 #include <memory> | |
78 | |
79 #include "../../DicomParsing/FromDcmtkBridge.h" | |
80 #include "../../DicomParsing/ToDcmtkBridge.h" | |
81 #include "../../Logging.h" | |
82 #include "../../OrthancException.h" | |
83 | |
84 #include <boost/lexical_cast.hpp> | |
85 | |
86 | |
87 namespace Orthanc | |
88 { | |
89 namespace | |
90 { | |
91 struct GetScpData | |
92 { | |
93 // Handle returns void. | |
94 IGetRequestHandler* handler_; | |
95 DcmDataset* lastRequest_; | |
96 T_ASC_Association * assoc_; | |
97 | |
98 std::string remoteIp_; | |
99 std::string remoteAet_; | |
100 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
|
101 int timeout_; |
3818 | 102 |
103 GetScpData() | |
104 { | |
105 handler_ = NULL; | |
106 lastRequest_ = NULL; | |
107 assoc_ = NULL; | |
108 }; | |
109 }; | |
110 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
111 static DcmDataset *BuildFailedInstanceList(const std::string& failedUIDs) |
3818 | 112 { |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
113 if (failedUIDs.empty()) |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
114 { |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
115 return NULL; |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
116 } |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
117 else |
3818 | 118 { |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
119 std::unique_ptr<DcmDataset> rspIds(new DcmDataset()); |
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 if (!DU_putStringDOElement(rspIds.get(), DCM_FailedSOPInstanceUIDList, failedUIDs.c_str())) |
3818 | 122 { |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
123 throw OrthancException(ErrorCode_InternalError, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
124 "getSCP: failed to build DCM_FailedSOPInstanceUIDList"); |
3818 | 125 } |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
126 |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
127 return rspIds.release(); |
3818 | 128 } |
129 } | |
130 | |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
131 static void GetScpCallback( |
3818 | 132 /* in */ |
133 void *callbackData, | |
134 OFBool cancelled, | |
135 T_DIMSE_C_GetRQ *request, | |
136 DcmDataset *requestIdentifiers, | |
137 int responseCount, | |
138 /* out */ | |
139 T_DIMSE_C_GetRSP *response, | |
140 DcmDataset **responseIdentifiers, | |
141 DcmDataset **statusDetail) | |
142 { | |
143 bzero(response, sizeof(T_DIMSE_C_GetRSP)); | |
144 *statusDetail = NULL; | |
145 *responseIdentifiers = NULL; | |
146 | |
147 GetScpData& data = *reinterpret_cast<GetScpData*>(callbackData); | |
148 if (data.lastRequest_ == NULL) | |
149 { | |
150 DicomMap input; | |
4137
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
151 std::set<DicomTag> ignoreTagLength; |
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
152 FromDcmtkBridge::ExtractDicomSummary(input, *requestIdentifiers, 0 /* don't truncate tags */, ignoreTagLength); |
3818 | 153 |
154 try | |
155 { | |
3959
76a24be12912
c-get: support of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3955
diff
changeset
|
156 if (!data.handler_->Handle( |
76a24be12912
c-get: support of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3955
diff
changeset
|
157 input, data.remoteIp_, data.remoteAet_, data.calledAet_, |
76a24be12912
c-get: support of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3955
diff
changeset
|
158 data.timeout_ < 0 ? 0 : static_cast<uint32_t>(data.timeout_))) |
3818 | 159 { |
160 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; | |
161 return; | |
162 } | |
163 } | |
164 catch (OrthancException& e) | |
165 { | |
166 // Internal error! | |
167 LOG(ERROR) << "IGetRequestHandler Failed: " << e.What(); | |
168 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; | |
169 return; | |
170 } | |
171 | |
172 data.lastRequest_ = requestIdentifiers; | |
173 } | |
174 else if (data.lastRequest_ != requestIdentifiers) | |
175 { | |
176 // Internal error! | |
177 LOG(ERROR) << "IGetRequestHandler Failed: Internal error lastRequestIdentifier"; | |
178 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; | |
179 return; | |
180 } | |
181 | |
3954 | 182 if (data.handler_->GetRemainingCount() == 0) |
3818 | 183 { |
184 response->DimseStatus = STATUS_Success; | |
185 } | |
186 else | |
187 { | |
188 IGetRequestHandler::Status status; | |
189 | |
190 try | |
191 { | |
192 status = data.handler_->DoNext(data.assoc_); | |
193 } | |
194 catch (OrthancException& e) | |
195 { | |
196 // Internal error! | |
197 LOG(ERROR) << "IGetRequestHandler Failed: " << e.What(); | |
198 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; | |
199 return; | |
200 } | |
201 | |
202 if (status == STATUS_Success) | |
203 { | |
3954 | 204 if (responseCount < static_cast<int>(data.handler_->GetRemainingCount())) |
3818 | 205 { |
206 response->DimseStatus = STATUS_Pending; | |
207 } | |
208 else | |
209 { | |
210 response->DimseStatus = STATUS_Success; | |
211 } | |
212 } | |
213 else | |
214 { | |
215 response->DimseStatus = STATUS_GET_Failed_UnableToProcess; | |
216 | |
3954 | 217 if (data.handler_->GetFailedCount() > 0 || |
218 data.handler_->GetWarningCount() > 0) | |
3818 | 219 { |
220 response->DimseStatus = STATUS_GET_Warning_SubOperationsCompleteOneOrMoreFailures; | |
221 } | |
3954 | 222 |
3818 | 223 /* |
3953
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
224 * if all the sub-operations failed then we need to generate |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
225 * a failed or refused status. cf. DICOM part 4, C.4.3.3.1 |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
226 * we choose to generate a "Refused - Out of Resources - |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
227 * Unable to perform suboperations" status. |
3818 | 228 */ |
3954 | 229 if ((data.handler_->GetFailedCount() > 0) && |
230 ((data.handler_->GetCompletedCount() + | |
231 data.handler_->GetWarningCount()) == 0)) | |
3818 | 232 { |
233 response->DimseStatus = STATUS_GET_Refused_OutOfResourcesSubOperations; | |
234 } | |
235 | |
3954 | 236 *responseIdentifiers = BuildFailedInstanceList(data.handler_->GetFailedUids()); |
3818 | 237 } |
238 } | |
239 | |
3954 | 240 response->NumberOfRemainingSubOperations = data.handler_->GetRemainingCount(); |
241 response->NumberOfCompletedSubOperations = data.handler_->GetCompletedCount(); | |
242 response->NumberOfFailedSubOperations = data.handler_->GetFailedCount(); | |
243 response->NumberOfWarningSubOperations = data.handler_->GetWarningCount(); | |
3818 | 244 } |
245 } | |
246 | |
247 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
|
248 T_DIMSE_Message * msg, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
249 T_ASC_PresentationContextID presID, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
250 IGetRequestHandler& handler, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
251 std::string remoteIp, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
252 std::string remoteAet, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
253 std::string calledAet, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
254 int timeout) |
3818 | 255 { |
256 GetScpData data; | |
257 data.lastRequest_ = NULL; | |
258 data.handler_ = &handler; | |
259 data.assoc_ = assoc; | |
260 data.remoteIp_ = remoteIp; | |
261 data.remoteAet_ = remoteAet; | |
262 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
|
263 data.timeout_ = timeout; |
3818 | 264 |
265 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
|
266 GetScpCallback, &data, |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
267 /*opt_blockMode*/ (timeout ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
268 /*opt_dimse_timeout*/ timeout); |
620e87e9e816
c-get: fixing memory with failedUIDs_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3818
diff
changeset
|
269 |
3818 | 270 // if some error occured, dump corresponding information and remove the outfile if necessary |
271 if (cond.bad()) | |
272 { | |
273 OFString temp_str; | |
274 LOG(ERROR) << "Get SCP Failed: " << cond.text(); | |
275 } | |
276 | |
277 return cond; | |
278 } | |
279 } |