Mercurial > hg > orthanc
annotate OrthancServer/OrthancMoveRequestHandler.cpp @ 1202:476a17cfdf42
Fix crash when bad HTTP credentials are provided
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 27 Oct 2014 13:45:36 +0100 |
parents | 84513f2ee1f3 |
children | 1ea4094d077c |
rev | line source |
---|---|
619 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
619 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
619 | 34 #include "OrthancMoveRequestHandler.h" |
35 | |
36 #include <glog/logging.h> | |
37 | |
38 #include "OrthancInitialization.h" | |
39 | |
40 namespace Orthanc | |
41 { | |
42 namespace | |
43 { | |
44 // Anonymous namespace to avoid clashes between compilation modules | |
45 | |
46 class OrthancMoveRequestIterator : public IMoveRequestIterator | |
47 { | |
48 private: | |
49 ServerContext& context_; | |
50 std::vector<std::string> instances_; | |
51 size_t position_; | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
52 RemoteModalityParameters remote_; |
771 | 53 |
619 | 54 public: |
55 OrthancMoveRequestIterator(ServerContext& context, | |
771 | 56 const std::string& aet, |
619 | 57 const std::string& publicId) : |
58 context_(context), | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
59 position_(0) |
619 | 60 { |
771 | 61 LOG(INFO) << "Sending resource " << publicId << " to modality \"" << aet << "\""; |
619 | 62 |
63 std::list<std::string> tmp; | |
64 context_.GetIndex().GetChildInstances(tmp, publicId); | |
65 | |
66 instances_.reserve(tmp.size()); | |
656 | 67 for (std::list<std::string>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
619 | 68 { |
69 instances_.push_back(*it); | |
70 } | |
771 | 71 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
72 remote_ = Configuration::GetModalityUsingAet(aet); |
619 | 73 } |
74 | |
75 virtual unsigned int GetSubOperationCount() const | |
76 { | |
77 return instances_.size(); | |
78 } | |
79 | |
80 virtual Status DoNext() | |
81 { | |
82 if (position_ >= instances_.size()) | |
83 { | |
84 return Status_Failure; | |
85 } | |
86 | |
87 const std::string& id = instances_[position_++]; | |
88 | |
89 std::string dicom; | |
90 context_.ReadFile(dicom, id, FileContentType_Dicom); | |
771 | 91 |
92 { | |
776 | 93 ReusableDicomUserConnection::Locker locker |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
94 (context_.GetReusableDicomUserConnection(), remote_); |
776 | 95 locker.GetConnection().Store(dicom); |
771 | 96 } |
619 | 97 |
98 return Status_Success; | |
99 } | |
100 }; | |
101 } | |
102 | |
103 | |
104 bool OrthancMoveRequestHandler::LookupResource(std::string& publicId, | |
105 DicomTag tag, | |
106 const DicomMap& input) | |
107 { | |
108 if (!input.HasTag(tag)) | |
109 { | |
110 return false; | |
111 } | |
112 | |
113 std::string value = input.GetValue(tag).AsString(); | |
114 | |
115 std::list<std::string> ids; | |
116 context_.GetIndex().LookupTagValue(ids, tag, value); | |
117 | |
118 if (ids.size() != 1) | |
119 { | |
120 return false; | |
121 } | |
122 else | |
123 { | |
124 publicId = ids.front(); | |
125 return true; | |
126 } | |
127 } | |
128 | |
129 | |
771 | 130 IMoveRequestIterator* OrthancMoveRequestHandler::Handle(const std::string& aet, |
619 | 131 const DicomMap& input) |
132 { | |
771 | 133 LOG(WARNING) << "Move-SCU request received for AET \"" << aet << "\""; |
619 | 134 |
135 | |
136 /** | |
137 * Retrieve the query level. | |
138 **/ | |
139 | |
140 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL); | |
141 if (levelTmp == NULL) | |
142 { | |
143 throw OrthancException(ErrorCode_BadRequest); | |
144 } | |
145 | |
146 ResourceType level = StringToResourceType(levelTmp->AsString().c_str()); | |
147 | |
148 /** | |
149 * Lookup for the resource to be sent. | |
150 **/ | |
151 | |
152 bool ok; | |
153 std::string publicId; | |
154 | |
155 switch (level) | |
156 { | |
157 case ResourceType_Patient: | |
158 ok = LookupResource(publicId, DICOM_TAG_PATIENT_ID, input); | |
159 break; | |
160 | |
161 case ResourceType_Study: | |
162 ok = LookupResource(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input); | |
163 break; | |
164 | |
165 case ResourceType_Series: | |
166 ok = LookupResource(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input); | |
167 break; | |
168 | |
169 case ResourceType_Instance: | |
170 ok = LookupResource(publicId, DICOM_TAG_SOP_INSTANCE_UID, input); | |
171 break; | |
172 | |
173 default: | |
174 ok = false; | |
175 } | |
176 | |
177 if (!ok) | |
178 { | |
179 throw OrthancException(ErrorCode_BadRequest); | |
180 } | |
181 | |
771 | 182 return new OrthancMoveRequestIterator(context_, aet, publicId); |
619 | 183 } |
184 } |