Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Oracle/ParseDicomSuccessMessage.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Oracle/ParseDicomSuccessMessage.cpp@30deba7bc8e2 |
children | 85e117739eca |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
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 | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "ParseDicomSuccessMessage.h" | |
23 | |
24 #include <DicomParsing/ParsedDicomFile.h> | |
25 #include <HttpServer/MultipartStreamReader.h> | |
26 #include <OrthancException.h> | |
27 | |
28 namespace OrthancStone | |
29 { | |
30 class MultipartHandler : public Orthanc::MultipartStreamReader::IHandler | |
31 { | |
32 private: | |
33 std::unique_ptr<Orthanc::ParsedDicomFile> dicom_; | |
34 size_t size_; | |
35 | |
36 public: | |
37 MultipartHandler() : | |
38 size_(0) | |
39 { | |
40 } | |
41 | |
42 virtual void HandlePart(const std::map<std::string, std::string>& headers, | |
43 const void* part, | |
44 size_t size) | |
45 { | |
46 if (dicom_.get()) | |
47 { | |
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, | |
49 "Multiple DICOM instances were contained in a WADO-RS request"); | |
50 } | |
51 else | |
52 { | |
53 dicom_.reset(new Orthanc::ParsedDicomFile(part, size)); | |
54 size_ = size; | |
55 } | |
56 } | |
57 | |
58 Orthanc::ParsedDicomFile* ReleaseDicom() | |
59 { | |
60 if (dicom_.get()) | |
61 { | |
62 return dicom_.release(); | |
63 } | |
64 else | |
65 { | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, | |
67 "WADO-RS request didn't contain any DICOM instance"); | |
68 } | |
69 } | |
70 | |
71 size_t GetSize() const | |
72 { | |
73 return size_; | |
74 } | |
75 }; | |
76 | |
77 | |
78 Orthanc::ParsedDicomFile* ParseDicomSuccessMessage::ParseWadoAnswer( | |
79 size_t& fileSize /* OUT */, | |
80 const std::string& answer, | |
81 const std::map<std::string, std::string>& headers) | |
82 { | |
83 std::string contentType, subType, boundary, header; | |
84 if (Orthanc::MultipartStreamReader::GetMainContentType(header, headers) && | |
85 Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, header) && | |
86 contentType == "multipart/related" && | |
87 subType == "application/dicom") | |
88 { | |
89 MultipartHandler handler; | |
90 | |
91 { | |
92 Orthanc::MultipartStreamReader reader(boundary); | |
93 reader.SetHandler(handler); | |
94 reader.AddChunk(answer); | |
95 reader.CloseStream(); | |
96 } | |
97 | |
98 fileSize = handler.GetSize(); | |
99 return handler.ReleaseDicom(); | |
100 } | |
101 else | |
102 { | |
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, | |
104 "Multipart/related answer of application/dicom was expected from DICOMweb server"); | |
105 } | |
106 } | |
107 } |