Mercurial > hg > orthanc
annotate Core/FileStorage/CompressedFileStorageAccessor.cpp @ 1373:21a2929e541d query-retrieve
Move SCU conformance
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 28 May 2015 12:19:26 +0200 |
parents | 6e7e5ed91c2d |
children | f967bdf8534e |
rev | line source |
---|---|
221 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1137
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1137
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
221 | 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 | |
32 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
33 #include "../PrecompiledHeaders.h" |
221 | 34 #include "CompressedFileStorageAccessor.h" |
35 | |
36 #include "../OrthancException.h" | |
37 #include "FileStorageAccessor.h" | |
38 #include "../HttpServer/BufferHttpSender.h" | |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
39 #include "../Uuid.h" |
221 | 40 |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
41 #include <memory> |
1137
d9c27f9f1a51
OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1135
diff
changeset
|
42 #include <glog/logging.h> |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
43 |
221 | 44 namespace Orthanc |
45 { | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
46 FileInfo CompressedFileStorageAccessor::WriteInternal(const void* data, |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
47 size_t size, |
233 | 48 FileContentType type) |
221 | 49 { |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
50 std::string uuid = Toolbox::GenerateUuid(); |
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
51 |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
52 std::string md5; |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
53 |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
54 if (storeMD5_) |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
55 { |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
56 Toolbox::ComputeMD5(md5, data, size); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
57 } |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
58 |
221 | 59 switch (compressionType_) |
60 { | |
61 case CompressionType_None: | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
62 { |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
63 GetStorageArea().Create(uuid.c_str(), data, size, type); |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
64 return FileInfo(uuid, type, size, md5); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
65 } |
221 | 66 |
67 case CompressionType_Zlib: | |
68 { | |
69 std::string compressed; | |
70 zlib_.Compress(compressed, data, size); | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
71 |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
72 std::string compressedMD5; |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
73 |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
74 if (storeMD5_) |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
75 { |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
76 Toolbox::ComputeMD5(compressedMD5, compressed); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
77 } |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
78 |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
79 if (compressed.size() > 0) |
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
80 { |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
81 GetStorageArea().Create(uuid.c_str(), &compressed[0], compressed.size(), type); |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
82 } |
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
83 else |
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
84 { |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
85 GetStorageArea().Create(uuid.c_str(), NULL, 0, type); |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
86 } |
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
87 |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
88 return FileInfo(uuid, type, size, md5, |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
89 CompressionType_Zlib, compressed.size(), compressedMD5); |
221 | 90 } |
91 | |
92 default: | |
93 throw OrthancException(ErrorCode_NotImplemented); | |
94 } | |
95 } | |
96 | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
97 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
98 CompressedFileStorageAccessor::CompressedFileStorageAccessor() : |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
99 storage_(NULL), |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
100 compressionType_(CompressionType_None) |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
101 { |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
102 } |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
103 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
104 |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
105 CompressedFileStorageAccessor::CompressedFileStorageAccessor(IStorageArea& storage) : |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
106 storage_(&storage), |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
107 compressionType_(CompressionType_None) |
221 | 108 { |
109 } | |
110 | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
111 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
112 IStorageArea& CompressedFileStorageAccessor::GetStorageArea() |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
113 { |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
114 if (storage_ == NULL) |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
115 { |
1137
d9c27f9f1a51
OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1135
diff
changeset
|
116 LOG(ERROR) << "No storage area is currently available"; |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
117 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
118 } |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
119 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
120 return *storage_; |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
121 } |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
122 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
123 |
221 | 124 void CompressedFileStorageAccessor::Read(std::string& content, |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
125 const std::string& uuid, |
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
126 FileContentType type) |
221 | 127 { |
128 switch (compressionType_) | |
129 { | |
130 case CompressionType_None: | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
131 GetStorageArea().Read(content, uuid, type); |
221 | 132 break; |
133 | |
134 case CompressionType_Zlib: | |
135 { | |
136 std::string compressed; | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
137 GetStorageArea().Read(compressed, uuid, type); |
221 | 138 zlib_.Uncompress(content, compressed); |
139 break; | |
140 } | |
141 | |
142 default: | |
143 throw OrthancException(ErrorCode_NotImplemented); | |
144 } | |
145 } | |
146 | |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
147 HttpFileSender* CompressedFileStorageAccessor::ConstructHttpFileSender(const std::string& uuid, |
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
148 FileContentType type) |
221 | 149 { |
150 switch (compressionType_) | |
151 { | |
152 case CompressionType_None: | |
153 { | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
154 FileStorageAccessor uncompressedAccessor(GetStorageArea()); |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
155 return uncompressedAccessor.ConstructHttpFileSender(uuid, type); |
221 | 156 } |
157 | |
158 case CompressionType_Zlib: | |
159 { | |
160 std::string compressed; | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
161 GetStorageArea().Read(compressed, uuid, type); |
221 | 162 |
163 std::auto_ptr<BufferHttpSender> sender(new BufferHttpSender); | |
164 zlib_.Uncompress(sender->GetBuffer(), compressed); | |
165 | |
166 return sender.release(); | |
167 } | |
168 | |
169 default: | |
170 throw OrthancException(ErrorCode_NotImplemented); | |
171 } | |
172 } | |
1134
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
173 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
174 |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
175 void CompressedFileStorageAccessor::Remove(const std::string& uuid, |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
176 FileContentType type) |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
177 { |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
178 GetStorageArea().Remove(uuid, type); |
ba9fd42284d0
preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
179 } |
221 | 180 } |