Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/FilesystemHttpSender.cpp @ 4709:a9a75281cae9 openssl-3.x
fix build on MSVC 2008 32bit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Jun 2021 10:26:27 +0200 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
rev | line source |
---|---|
208 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
208 | 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. |
208 | 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. |
208 | 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/>. |
208 | 20 **/ |
21 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
22 #include "../PrecompiledHeaders.h" |
208 | 23 #include "FilesystemHttpSender.h" |
24 | |
1522 | 25 #include "../OrthancException.h" |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
26 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
27 static const size_t CHUNK_SIZE = 64 * 1024; // Use 64KB chunks |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
28 |
208 | 29 namespace Orthanc |
30 { | |
1522 | 31 void FilesystemHttpSender::Initialize(const boost::filesystem::path& path) |
208 | 32 { |
1522 | 33 SetContentFilename(path.filename().string()); |
34 file_.open(path.string().c_str(), std::ifstream::binary); | |
35 | |
36 if (!file_.is_open()) | |
37 { | |
38 throw OrthancException(ErrorCode_InexistentFile); | |
39 } | |
208 | 40 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
41 file_.seekg(0, file_.end); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
42 size_ = file_.tellg(); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
43 file_.seekg(0, file_.beg); |
217 | 44 } |
45 | |
4298 | 46 FilesystemHttpSender::FilesystemHttpSender(const std::string& path) |
47 { | |
48 Initialize(path); | |
49 } | |
50 | |
51 FilesystemHttpSender::FilesystemHttpSender(const boost::filesystem::path& path) | |
52 { | |
53 Initialize(path); | |
54 } | |
55 | |
56 FilesystemHttpSender::FilesystemHttpSender(const std::string& path, | |
57 MimeType contentType) | |
58 { | |
59 SetContentType(contentType); | |
60 Initialize(path); | |
61 } | |
62 | |
63 FilesystemHttpSender::FilesystemHttpSender(const FilesystemStorage& storage, | |
64 const std::string& uuid) | |
65 { | |
66 Initialize(storage.GetPath(uuid)); | |
67 } | |
68 | |
69 uint64_t FilesystemHttpSender::GetContentLength() | |
70 { | |
71 return size_; | |
72 } | |
73 | |
1522 | 74 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
75 bool FilesystemHttpSender::ReadNextChunk() |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
76 { |
1525 | 77 if (chunk_.size() == 0) |
1522 | 78 { |
1525 | 79 chunk_.resize(CHUNK_SIZE); |
1522 | 80 } |
81 | |
1525 | 82 file_.read(&chunk_[0], chunk_.size()); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
83 |
1525 | 84 if ((file_.flags() & std::istream::failbit) || |
85 file_.gcount() < 0) | |
1522 | 86 { |
1525 | 87 throw OrthancException(ErrorCode_CorruptedFile); |
1522 | 88 } |
89 | |
2332 | 90 chunkSize_ = static_cast<size_t>(file_.gcount()); |
1525 | 91 |
92 return chunkSize_ > 0; | |
208 | 93 } |
4298 | 94 |
95 const char *FilesystemHttpSender::GetChunkContent() | |
96 { | |
97 return chunk_.c_str(); | |
98 } | |
99 | |
100 size_t FilesystemHttpSender::GetChunkSize() | |
101 { | |
102 return chunkSize_; | |
103 } | |
208 | 104 } |