Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 4453:4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 Jan 2021 10:02:46 +0100 |
parents | 6a6017027162 |
children | f20a7655fb1c |
rev | line source |
---|---|
0 | 1 /** |
59 | 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:
1213
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4382
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 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. |
136 | 11 * |
0 | 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. |
0 | 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/>. |
0 | 20 **/ |
21 | |
22 | |
23 // http://en.highscore.de/cpp/boost/stringhandling.html | |
24 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
25 #include "../PrecompiledHeaders.h" |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
26 #include "HttpServer.h" |
0 | 27 |
3357
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3356
diff
changeset
|
28 #include "../ChunkedBuffer.h" |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3356
diff
changeset
|
29 #include "../FileBuffer.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
30 #include "../Logging.h" |
2895 | 31 #include "../OrthancException.h" |
3357
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3356
diff
changeset
|
32 #include "../TemporaryFile.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
33 #include "HttpToolbox.h" |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
34 #include "IHttpHandler.h" |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
35 |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
36 #if ORTHANC_ENABLE_PUGIXML == 1 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
37 # include "IWebDavBucket.h" |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
38 #endif |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
39 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
40 #if ORTHANC_ENABLE_MONGOOSE == 1 |
3069 | 41 # include <mongoose.h> |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
42 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
43 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
3069 | 44 # include <civetweb.h> |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
45 # define MONGOOSE_USE_CALLBACKS 1 |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
46 # if !defined(CIVETWEB_HAS_DISABLE_KEEP_ALIVE) |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
47 # error Macro CIVETWEB_HAS_DISABLE_KEEP_ALIVE must be defined |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
48 # endif |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
49 # if !defined(CIVETWEB_HAS_WEBDAV_WRITING) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
50 # error Macro CIVETWEB_HAS_WEBDAV_WRITING must be defined |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
51 # endif |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
52 #else |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
53 # error "Either Mongoose or Civetweb must be enabled to compile this file" |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
54 #endif |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
55 |
0 | 56 #include <algorithm> |
57 #include <boost/algorithm/string.hpp> | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
58 #include <boost/algorithm/string/predicate.hpp> |
3672
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
59 #include <boost/filesystem.hpp> |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
60 #include <boost/lexical_cast.hpp> |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
61 #include <boost/thread.hpp> |
0 | 62 #include <iostream> |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
63 #include <stdio.h> |
0 | 64 #include <string.h> |
65 | |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
66 #if !defined(ORTHANC_ENABLE_SSL) |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
67 # error The macro ORTHANC_ENABLE_SSL must be defined |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
68 #endif |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
69 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
70 #if ORTHANC_ENABLE_SSL == 1 |
3801
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
71 # include <openssl/opensslv.h> |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
72 # include <openssl/err.h> |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
73 #endif |
0 | 74 |
59 | 75 #define ORTHANC_REALM "Orthanc Secure Area" |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
76 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
77 |
59 | 78 namespace Orthanc |
0 | 79 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
80 static const char MULTIPART_FORM[] = "multipart/form-data; boundary="; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
81 static unsigned int MULTIPART_FORM_LENGTH = sizeof(MULTIPART_FORM) / sizeof(char) - 1; |
0 | 82 |
83 | |
84 namespace | |
85 { | |
86 // Anonymous namespace to avoid clashes between compilation modules | |
911 | 87 class MongooseOutputStream : public IHttpOutputStream |
0 | 88 { |
89 private: | |
90 struct mg_connection* connection_; | |
91 | |
911 | 92 public: |
4201 | 93 explicit MongooseOutputStream(struct mg_connection* connection) : |
94 connection_(connection) | |
911 | 95 { |
96 } | |
97 | |
909 | 98 virtual void Send(bool isHeader, const void* buffer, size_t length) |
0 | 99 { |
217 | 100 if (length > 0) |
101 { | |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
102 int status = mg_write(connection_, buffer, length); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
103 if (status != static_cast<int>(length)) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
104 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
105 // status == 0 when the connection has been closed, -1 on error |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
106 throw OrthancException(ErrorCode_NetworkProtocol); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
107 } |
217 | 108 } |
0 | 109 } |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
110 |
911 | 111 virtual void OnHttpStatusReceived(HttpStatus status) |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
112 { |
911 | 113 // Ignore this |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
114 } |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
115 |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
116 virtual void DisableKeepAlive() |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
117 { |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
118 #if ORTHANC_ENABLE_MONGOOSE == 1 |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
119 throw OrthancException(ErrorCode_NotImplemented, |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
120 "Only available if using CivetWeb"); |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
121 |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
122 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
123 # if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1 |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
124 mg_disable_keep_alive(connection_); |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
125 # else |
4449
6a6017027162
"#warning" is not available on Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
126 # if defined(__GNUC__) || defined(__clang__) |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
127 # warning The function "mg_disable_keep_alive()" is not available, DICOMweb might run slowly |
4449
6a6017027162
"#warning" is not available on Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
128 # endif |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
129 throw OrthancException(ErrorCode_NotImplemented, |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
130 "Only available if using a patched version of CivetWeb"); |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
131 # endif |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
132 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
133 #else |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
134 # error Please support your embedded Web server here |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
135 #endif |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
136 } |
0 | 137 }; |
138 | |
139 | |
140 enum PostDataStatus | |
141 { | |
142 PostDataStatus_Success, | |
143 PostDataStatus_NoLength, | |
144 PostDataStatus_Pending, | |
145 PostDataStatus_Failure | |
146 }; | |
147 } | |
148 | |
149 | |
150 // TODO Move this to external file | |
151 | |
152 | |
153 class ChunkedFile : public ChunkedBuffer | |
154 { | |
155 private: | |
156 std::string filename_; | |
157 | |
158 public: | |
4201 | 159 explicit ChunkedFile(const std::string& filename) : |
0 | 160 filename_(filename) |
161 { | |
162 } | |
163 | |
164 const std::string& GetFilename() const | |
165 { | |
166 return filename_; | |
167 } | |
168 }; | |
169 | |
170 | |
171 | |
3836 | 172 class ChunkStore : public boost::noncopyable |
0 | 173 { |
174 private: | |
175 typedef std::list<ChunkedFile*> Content; | |
176 Content content_; | |
177 unsigned int numPlaces_; | |
178 | |
179 boost::mutex mutex_; | |
180 std::set<std::string> discardedFiles_; | |
181 | |
182 void Clear() | |
183 { | |
184 for (Content::iterator it = content_.begin(); | |
656 | 185 it != content_.end(); ++it) |
0 | 186 { |
187 delete *it; | |
188 } | |
189 } | |
190 | |
191 Content::iterator Find(const std::string& filename) | |
192 { | |
193 for (Content::iterator it = content_.begin(); | |
656 | 194 it != content_.end(); ++it) |
0 | 195 { |
196 if ((*it)->GetFilename() == filename) | |
197 { | |
198 return it; | |
199 } | |
200 } | |
201 | |
202 return content_.end(); | |
203 } | |
204 | |
205 void Remove(const std::string& filename) | |
206 { | |
207 Content::iterator it = Find(filename); | |
208 if (it != content_.end()) | |
209 { | |
210 delete *it; | |
211 content_.erase(it); | |
212 } | |
213 } | |
214 | |
215 public: | |
216 ChunkStore() | |
217 { | |
218 numPlaces_ = 10; | |
219 } | |
220 | |
221 ~ChunkStore() | |
222 { | |
223 Clear(); | |
224 } | |
225 | |
226 PostDataStatus Store(std::string& completed, | |
227 const char* chunkData, | |
228 size_t chunkSize, | |
229 const std::string& filename, | |
230 size_t filesize) | |
231 { | |
232 boost::mutex::scoped_lock lock(mutex_); | |
233 | |
234 std::set<std::string>::iterator wasDiscarded = discardedFiles_.find(filename); | |
235 if (wasDiscarded != discardedFiles_.end()) | |
236 { | |
237 discardedFiles_.erase(wasDiscarded); | |
238 return PostDataStatus_Failure; | |
239 } | |
240 | |
241 ChunkedFile* f; | |
242 Content::iterator it = Find(filename); | |
243 if (it == content_.end()) | |
244 { | |
245 f = new ChunkedFile(filename); | |
246 | |
247 // Make some room | |
248 if (content_.size() >= numPlaces_) | |
249 { | |
250 discardedFiles_.insert(content_.front()->GetFilename()); | |
251 delete content_.front(); | |
252 content_.pop_front(); | |
253 } | |
254 | |
255 content_.push_back(f); | |
256 } | |
257 else | |
258 { | |
259 f = *it; | |
260 } | |
261 | |
262 f->AddChunk(chunkData, chunkSize); | |
263 | |
264 if (f->GetNumBytes() > filesize) | |
265 { | |
266 Remove(filename); | |
267 } | |
268 else if (f->GetNumBytes() == filesize) | |
269 { | |
270 f->Flatten(completed); | |
271 Remove(filename); | |
272 return PostDataStatus_Success; | |
273 } | |
274 | |
275 return PostDataStatus_Pending; | |
276 } | |
277 | |
278 /*void Print() | |
279 { | |
280 boost::mutex::scoped_lock lock(mutex_); | |
281 | |
282 printf("ChunkStore status:\n"); | |
283 for (Content::const_iterator i = content_.begin(); | |
284 i != content_.end(); i++) | |
285 { | |
286 printf(" [%s]: %d\n", (*i)->GetFilename().c_str(), (*i)->GetNumBytes()); | |
287 } | |
288 printf("-----\n"); | |
289 }*/ | |
290 }; | |
291 | |
292 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
293 struct HttpServer::PImpl |
0 | 294 { |
295 struct mg_context *context_; | |
296 ChunkStore chunkStore_; | |
4201 | 297 |
298 PImpl() : | |
299 context_(NULL) | |
300 { | |
301 } | |
0 | 302 }; |
303 | |
304 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
305 ChunkStore& HttpServer::GetChunkStore() |
0 | 306 { |
307 return pimpl_->chunkStore_; | |
308 } | |
309 | |
310 | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
311 static PostDataStatus ReadBodyWithContentLength(std::string& body, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
312 struct mg_connection *connection, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
313 const std::string& contentLength) |
0 | 314 { |
4152
36257d6f348f
Support of multipart messages larger than 2GB in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
315 size_t length; |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
316 try |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
317 { |
4201 | 318 int64_t tmp = boost::lexical_cast<int64_t>(contentLength); |
319 if (tmp < 0) | |
320 { | |
321 return PostDataStatus_NoLength; | |
322 } | |
323 | |
324 length = static_cast<size_t>(tmp); | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
325 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
326 catch (boost::bad_lexical_cast&) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
327 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
328 return PostDataStatus_NoLength; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
329 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
330 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
331 body.resize(length); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
332 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
333 size_t pos = 0; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
334 while (length > 0) |
0 | 335 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
336 int r = mg_read(connection, &body[pos], length); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
337 if (r <= 0) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
338 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
339 return PostDataStatus_Failure; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
340 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
341 |
4152
36257d6f348f
Support of multipart messages larger than 2GB in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
342 assert(static_cast<size_t>(r) <= length); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
343 length -= r; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
344 pos += r; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
345 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
346 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
347 return PostDataStatus_Success; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
348 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
349 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
350 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
351 static PostDataStatus ReadBodyWithoutContentLength(std::string& body, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
352 struct mg_connection *connection) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
353 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
354 // Store the individual chunks in a temporary file, then read it |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
355 // back into the memory buffer "body" |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
356 FileBuffer buffer; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
357 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
358 std::string tmp(1024 * 1024, 0); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
359 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
360 for (;;) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
361 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
362 int r = mg_read(connection, &tmp[0], tmp.size()); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
363 if (r < 0) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
364 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
365 return PostDataStatus_Failure; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
366 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
367 else if (r == 0) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
368 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
369 break; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
370 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
371 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
372 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
373 buffer.Append(tmp.c_str(), r); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
374 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
375 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
376 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
377 buffer.Read(body); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
378 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
379 return PostDataStatus_Success; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
380 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
381 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
382 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
383 static PostDataStatus ReadBodyToString(std::string& body, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
384 struct mg_connection *connection, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
385 const HttpToolbox::Arguments& headers) |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
386 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
387 HttpToolbox::Arguments::const_iterator contentLength = headers.find("content-length"); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
388 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
389 if (contentLength != headers.end()) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
390 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
391 // "Content-Length" is available |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
392 return ReadBodyWithContentLength(body, connection, contentLength->second); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
393 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
394 else |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
395 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
396 // No Content-Length |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
397 return ReadBodyWithoutContentLength(body, connection); |
0 | 398 } |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
399 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
400 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
401 |
3414 | 402 static PostDataStatus ReadBodyToStream(IHttpHandler::IChunkedRequestReader& stream, |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
403 struct mg_connection *connection, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
404 const HttpToolbox::Arguments& headers) |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
405 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
406 HttpToolbox::Arguments::const_iterator contentLength = headers.find("content-length"); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
407 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
408 if (contentLength != headers.end()) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
409 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
410 // "Content-Length" is available |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
411 std::string body; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
412 PostDataStatus status = ReadBodyWithContentLength(body, connection, contentLength->second); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
413 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
414 if (status == PostDataStatus_Success && |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
415 !body.empty()) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
416 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
417 stream.AddBodyChunk(body.c_str(), body.size()); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
418 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
419 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
420 return status; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
421 } |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
422 else |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
423 { |
3404
e280ced38a4c
ErrorCode_UnsupportedMediaType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3395
diff
changeset
|
424 // No Content-Length: This is a chunked transfer. Stream the HTTP connection. |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
425 std::string tmp(1024 * 1024, 0); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
426 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
427 for (;;) |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
428 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
429 int r = mg_read(connection, &tmp[0], tmp.size()); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
430 if (r < 0) |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
431 { |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
432 return PostDataStatus_Failure; |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
433 } |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
434 else if (r == 0) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
435 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
436 break; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
437 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
438 else |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
439 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
440 stream.AddBodyChunk(tmp.c_str(), r); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
441 } |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
442 } |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
443 |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
444 return PostDataStatus_Success; |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
445 } |
0 | 446 } |
447 | |
448 | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
449 static PostDataStatus ParseMultipartForm(std::string &completedFile, |
0 | 450 struct mg_connection *connection, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
451 const HttpToolbox::Arguments& headers, |
0 | 452 const std::string& contentType, |
453 ChunkStore& chunkStore) | |
454 { | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
455 std::string boundary = "--" + contentType.substr(MULTIPART_FORM_LENGTH); |
0 | 456 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
457 std::string body; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
458 PostDataStatus status = ReadBodyToString(body, connection, headers); |
0 | 459 |
460 if (status != PostDataStatus_Success) | |
461 { | |
462 return status; | |
463 } | |
464 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
465 /*for (HttpToolbox::Arguments::const_iterator i = headers.begin(); i != headers.end(); i++) |
0 | 466 { |
467 std::cout << "Header [" << i->first << "] = " << i->second << "\n"; | |
468 } | |
469 printf("CHUNK\n");*/ | |
470 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
471 typedef HttpToolbox::Arguments::const_iterator ArgumentIterator; |
0 | 472 |
473 ArgumentIterator requestedWith = headers.find("x-requested-with"); | |
474 ArgumentIterator fileName = headers.find("x-file-name"); | |
475 ArgumentIterator fileSizeStr = headers.find("x-file-size"); | |
476 | |
338
3a3b3ba8c1e0
fix for uploads through internet explorer 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
333
diff
changeset
|
477 if (requestedWith != headers.end() && |
0 | 478 requestedWith->second != "XMLHttpRequest") |
479 { | |
480 return PostDataStatus_Failure; | |
481 } | |
482 | |
483 size_t fileSize = 0; | |
484 if (fileSizeStr != headers.end()) | |
485 { | |
486 try | |
487 { | |
488 fileSize = boost::lexical_cast<size_t>(fileSizeStr->second); | |
489 } | |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2790
diff
changeset
|
490 catch (boost::bad_lexical_cast&) |
0 | 491 { |
492 return PostDataStatus_Failure; | |
493 } | |
494 } | |
495 | |
496 typedef boost::find_iterator<std::string::iterator> FindIterator; | |
10 | 497 typedef boost::iterator_range<char*> Range; |
0 | 498 |
499 //chunkStore.Print(); | |
500 | |
3445 | 501 // TODO - Refactor using class "MultipartStreamReader" |
0 | 502 try |
503 { | |
504 FindIterator last; | |
505 for (FindIterator it = | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
506 make_find_iterator(body, boost::first_finder(boundary)); |
0 | 507 it!=FindIterator(); |
508 ++it) | |
509 { | |
510 if (last != FindIterator()) | |
511 { | |
10 | 512 Range part(&last->back(), &it->front()); |
0 | 513 Range content = boost::find_first(part, "\r\n\r\n"); |
345 | 514 if (/*content != Range()*/!content.empty()) |
0 | 515 { |
516 Range c(&content.back() + 1, &it->front() - 2); | |
517 size_t chunkSize = c.size(); | |
518 | |
519 if (chunkSize > 0) | |
520 { | |
521 const char* chunkData = &c.front(); | |
522 | |
523 if (fileName == headers.end()) | |
524 { | |
525 // This file is stored in a single chunk | |
526 completedFile.resize(chunkSize); | |
4201 | 527 memcpy(&completedFile[0], chunkData, chunkSize); |
0 | 528 return PostDataStatus_Success; |
529 } | |
530 else | |
531 { | |
532 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize); | |
533 } | |
534 } | |
10 | 535 } |
0 | 536 } |
537 | |
538 last = it; | |
539 } | |
540 } | |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2790
diff
changeset
|
541 catch (std::length_error&) |
0 | 542 { |
543 return PostDataStatus_Failure; | |
544 } | |
545 | |
546 return PostDataStatus_Pending; | |
547 } | |
548 | |
549 | |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
550 enum AccessMode |
23 | 551 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
552 AccessMode_Forbidden, |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
553 AccessMode_AuthorizationToken, |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
554 AccessMode_RegisteredUser |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
555 }; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
556 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
557 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
558 static AccessMode IsAccessGranted(const HttpServer& that, |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
559 const HttpToolbox::Arguments& headers) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
560 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
561 static const std::string BASIC = "Basic "; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
562 static const std::string BEARER = "Bearer "; |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
563 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
564 HttpToolbox::Arguments::const_iterator auth = headers.find("authorization"); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
565 if (auth != headers.end()) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
566 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
567 std::string s = auth->second; |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
568 if (boost::starts_with(s, BASIC)) |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
569 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
570 std::string b64 = s.substr(BASIC.length()); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
571 if (that.IsValidBasicHttpAuthentication(b64)) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
572 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
573 return AccessMode_RegisteredUser; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
574 } |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
575 } |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
576 else if (boost::starts_with(s, BEARER) && |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
577 that.GetIncomingHttpRequestFilter() != NULL) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
578 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
579 // New in Orthanc 1.8.1 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
580 std::string token = s.substr(BEARER.length()); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
581 if (that.GetIncomingHttpRequestFilter()->IsValidBearerToken(token)) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
582 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
583 return AccessMode_AuthorizationToken; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
584 } |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
585 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
586 } |
23 | 587 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
588 return AccessMode_Forbidden; |
23 | 589 } |
590 | |
591 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
592 static std::string GetAuthenticatedUsername(const HttpToolbox::Arguments& headers) |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
593 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
594 HttpToolbox::Arguments::const_iterator auth = headers.find("authorization"); |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
595 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
596 if (auth == headers.end()) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
597 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
598 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
599 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
600 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
601 std::string s = auth->second; |
1213 | 602 if (s.size() <= 6 || |
603 s.substr(0, 6) != "Basic ") | |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
604 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
605 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
606 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
607 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
608 std::string b64 = s.substr(6); |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
609 std::string decoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
610 Toolbox::DecodeBase64(decoded, b64); |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
611 size_t semicolons = decoded.find(':'); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
612 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
613 if (semicolons == std::string::npos) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
614 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
615 // Bad-formatted request |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
616 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
617 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
618 else |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
619 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
620 return decoded.substr(0, semicolons); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
621 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
622 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
623 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
624 |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
625 static bool ExtractMethod(HttpMethod& method, |
414 | 626 const struct mg_request_info *request, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
627 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
628 const HttpToolbox::GetArguments& argumentsGET) |
414 | 629 { |
630 std::string overriden; | |
631 | |
632 // Check whether some PUT/DELETE faking is done | |
633 | |
634 // 1. Faking with Google's approach | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
635 HttpToolbox::Arguments::const_iterator methodOverride = |
414 | 636 headers.find("x-http-method-override"); |
637 | |
638 if (methodOverride != headers.end()) | |
639 { | |
640 overriden = methodOverride->second; | |
641 } | |
642 else if (!strcmp(request->request_method, "GET")) | |
643 { | |
644 // 2. Faking with Ruby on Rail's approach | |
645 // GET /my/resource?_method=delete <=> DELETE /my/resource | |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
646 for (size_t i = 0; i < argumentsGET.size(); i++) |
414 | 647 { |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
648 if (argumentsGET[i].first == "_method") |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
649 { |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
650 overriden = argumentsGET[i].second; |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
651 break; |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
652 } |
414 | 653 } |
654 } | |
655 | |
656 if (overriden.size() > 0) | |
657 { | |
658 // A faking has been done within this request | |
659 Toolbox::ToUpperCase(overriden); | |
660 | |
4295 | 661 CLOG(INFO, HTTP) << "HTTP method faking has been detected for " << overriden; |
416 | 662 |
414 | 663 if (overriden == "PUT") |
664 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
665 method = HttpMethod_Put; |
416 | 666 return true; |
414 | 667 } |
668 else if (overriden == "DELETE") | |
669 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
670 method = HttpMethod_Delete; |
416 | 671 return true; |
414 | 672 } |
673 else | |
674 { | |
675 return false; | |
676 } | |
677 } | |
678 | |
679 // No PUT/DELETE faking was present | |
680 if (!strcmp(request->request_method, "GET")) | |
681 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
682 method = HttpMethod_Get; |
414 | 683 } |
684 else if (!strcmp(request->request_method, "POST")) | |
685 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
686 method = HttpMethod_Post; |
414 | 687 } |
688 else if (!strcmp(request->request_method, "DELETE")) | |
689 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
690 method = HttpMethod_Delete; |
414 | 691 } |
692 else if (!strcmp(request->request_method, "PUT")) | |
693 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
694 method = HttpMethod_Put; |
414 | 695 } |
696 else | |
697 { | |
698 return false; | |
699 } | |
700 | |
701 return true; | |
702 } | |
703 | |
704 | |
1517 | 705 static void ConfigureHttpCompression(HttpOutput& output, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
706 const HttpToolbox::Arguments& headers) |
1517 | 707 { |
708 // Look if the client wishes HTTP compression | |
709 // https://en.wikipedia.org/wiki/HTTP_compression | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
710 HttpToolbox::Arguments::const_iterator it = headers.find("accept-encoding"); |
1517 | 711 if (it != headers.end()) |
712 { | |
713 std::vector<std::string> encodings; | |
714 Toolbox::TokenizeString(encodings, it->second, ','); | |
715 | |
716 for (size_t i = 0; i < encodings.size(); i++) | |
717 { | |
718 std::string s = Toolbox::StripSpaces(encodings[i]); | |
719 | |
720 if (s == "deflate") | |
721 { | |
722 output.SetDeflateAllowed(true); | |
723 } | |
724 else if (s == "gzip") | |
725 { | |
726 output.SetGzipAllowed(true); | |
727 } | |
728 } | |
729 } | |
730 } | |
731 | |
732 | |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
733 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
734 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
735 # if CIVETWEB_HAS_WEBDAV_WRITING == 0 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
736 static void AnswerWebDavReadOnly(HttpOutput& output, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
737 const std::string& uri) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
738 { |
4295 | 739 CLOG(ERROR, HTTP) << "Orthanc was compiled without support for read-write access to WebDAV: " << uri; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
740 output.SendStatus(HttpStatus_403_Forbidden); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
741 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
742 # endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
743 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
744 static bool HandleWebDav(HttpOutput& output, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
745 const HttpServer::WebDavBuckets& buckets, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
746 const std::string& method, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
747 const HttpToolbox::Arguments& headers, |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
748 const std::string& uri, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
749 struct mg_connection *connection /* to read the PUT body if need be */) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
750 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
751 if (buckets.empty()) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
752 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
753 return false; // Speed up things if WebDAV is not used |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
754 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
755 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
756 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
757 * The "buckets" maps an URI relative to the root of the |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
758 * bucket, to the content of the bucket. The root URI does *not* |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
759 * contain a trailing slash. |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
760 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
761 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
762 if (method == "OPTIONS") |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
763 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
764 // Remove the trailing slash, if any (necessary for davfs2) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
765 std::string s = uri; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
766 if (!s.empty() && |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
767 s[s.size() - 1] == '/') |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
768 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
769 s.resize(s.size() - 1); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
770 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
771 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
772 HttpServer::WebDavBuckets::const_iterator bucket = buckets.find(s); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
773 if (bucket == buckets.end()) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
774 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
775 return false; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
776 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
777 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
778 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
779 output.AddHeader("DAV", "1,2"); // Necessary for Windows XP |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
780 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
781 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
782 output.AddHeader("Allow", "GET, PUT, DELETE, OPTIONS, PROPFIND, HEAD, LOCK, UNLOCK, PROPPATCH, MKCOL"); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
783 #else |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
784 output.AddHeader("Allow", "GET, PUT, DELETE, OPTIONS, PROPFIND, HEAD"); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
785 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
786 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
787 output.SendStatus(HttpStatus_200_Ok); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
788 return true; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
789 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
790 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
791 else if (method == "GET" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
792 method == "PROPFIND" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
793 method == "PROPPATCH" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
794 method == "PUT" || |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
795 method == "DELETE" || |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
796 method == "HEAD" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
797 method == "LOCK" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
798 method == "UNLOCK" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
799 method == "MKCOL") |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
800 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
801 // Locate the WebDAV bucket of interest, if any |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
802 for (HttpServer::WebDavBuckets::const_iterator bucket = buckets.begin(); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
803 bucket != buckets.end(); ++bucket) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
804 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
805 assert(!bucket->first.empty() && |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
806 bucket->first[bucket->first.size() - 1] != '/' && |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
807 bucket->second != NULL); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
808 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
809 if (uri == bucket->first || |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
810 boost::starts_with(uri, bucket->first + "/")) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
811 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
812 std::string s = uri.substr(bucket->first.size()); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
813 if (s.empty()) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
814 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
815 s = "/"; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
816 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
817 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
818 std::vector<std::string> path; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
819 Toolbox::SplitUriComponents(path, s); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
820 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
821 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
822 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
823 * WebDAV - PROPFIND |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
824 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
825 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
826 if (method == "PROPFIND") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
827 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
828 HttpToolbox::Arguments::const_iterator i = headers.find("depth"); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
829 if (i == headers.end()) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
830 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
831 throw OrthancException(ErrorCode_NetworkProtocol, "WebDAV PROPFIND without depth"); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
832 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
833 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
834 int depth = boost::lexical_cast<int>(i->second); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
835 if (depth != 0 && |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
836 depth != 1) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
837 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
838 throw OrthancException( |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
839 ErrorCode_NetworkProtocol, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
840 "WebDAV PROPFIND at unsupported depth (can only be 0 or 1): " + i->second); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
841 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
842 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
843 std::string answer; |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
844 |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
845 MimeType mime; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
846 std::string content; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
847 boost::posix_time::ptime modificationTime = boost::posix_time::second_clock::universal_time(); |
4246 | 848 |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
849 if (bucket->second->IsExistingFolder(path)) |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
850 { |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
851 if (depth == 0) |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
852 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
853 IWebDavBucket::Collection c; |
4246 | 854 c.Format(answer, uri); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
855 } |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
856 else if (depth == 1) |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
857 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
858 IWebDavBucket::Collection c; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
859 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
860 if (!bucket->second->ListCollection(c, path)) |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
861 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
862 output.SendStatus(HttpStatus_404_NotFound); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
863 return true; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
864 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
865 |
4246 | 866 c.Format(answer, uri); |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
867 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
868 else |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
869 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
870 throw OrthancException(ErrorCode_InternalError); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
871 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
872 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
873 else if (!path.empty() && |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
874 bucket->second->GetFileContent(mime, content, modificationTime, path)) |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
875 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
876 if (depth == 0 || |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
877 depth == 1) |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
878 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
879 std::unique_ptr<IWebDavBucket::File> f(new IWebDavBucket::File(path.back())); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
880 f->SetContentLength(content.size()); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
881 f->SetModificationTime(modificationTime); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
882 f->SetMimeType(mime); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
883 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
884 IWebDavBucket::Collection c; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
885 c.AddResource(f.release()); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
886 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
887 std::vector<std::string> p; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
888 Toolbox::SplitUriComponents(p, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
889 if (p.empty()) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
890 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
891 throw OrthancException(ErrorCode_InternalError); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
892 } |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
893 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
894 p.resize(p.size() - 1); |
4246 | 895 c.Format(answer, Toolbox::FlattenUri(p)); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
896 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
897 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
898 { |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
899 throw OrthancException(ErrorCode_InternalError); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
900 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
901 } |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
902 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
903 { |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
904 output.SendStatus(HttpStatus_404_NotFound); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
905 return true; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
906 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
907 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
908 output.AddHeader("Content-Type", "application/xml; charset=UTF-8"); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
909 output.SendStatus(HttpStatus_207_MultiStatus, answer); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
910 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
911 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
912 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
913 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
914 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
915 * WebDAV - GET and HEAD |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
916 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
917 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
918 else if (method == "GET" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
919 method == "HEAD") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
920 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
921 MimeType mime; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
922 std::string content; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
923 boost::posix_time::ptime modificationTime; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
924 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
925 if (bucket->second->GetFileContent(mime, content, modificationTime, path)) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
926 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
927 output.AddHeader("Content-Type", EnumerationToString(mime)); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
928 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
929 // "Last-Modified" is necessary on Windows XP. The "Z" |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
930 // suffix is mandatory on Windows >= 7. |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
931 output.AddHeader("Last-Modified", boost::posix_time::to_iso_extended_string(modificationTime) + "Z"); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
932 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
933 if (method == "GET") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
934 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
935 output.Answer(content); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
936 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
937 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
938 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
939 output.SendStatus(HttpStatus_200_Ok); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
940 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
941 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
942 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
943 { |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
944 output.SendStatus(HttpStatus_404_NotFound); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
945 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
946 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
947 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
948 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
949 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
950 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
951 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
952 * WebDAV - PUT |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
953 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
954 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
955 else if (method == "PUT") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
956 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
957 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
958 std::string body; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
959 if (ReadBodyToString(body, connection, headers) == PostDataStatus_Success) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
960 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
961 if (bucket->second->StoreFile(body, path)) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
962 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
963 //output.SendStatus(HttpStatus_200_Ok); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
964 output.SendStatus(HttpStatus_201_Created); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
965 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
966 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
967 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
968 output.SendStatus(HttpStatus_403_Forbidden); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
969 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
970 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
971 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
972 { |
4295 | 973 CLOG(ERROR, HTTP) << "Cannot read the content of a file to be stored in WebDAV"; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
974 output.SendStatus(HttpStatus_400_BadRequest); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
975 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
976 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
977 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
978 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
979 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
980 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
981 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
982 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
983 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
984 /** |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
985 * WebDAV - DELETE |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
986 **/ |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
987 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
988 else if (method == "DELETE") |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
989 { |
4252 | 990 if (bucket->second->DeleteItem(path)) |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
991 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
992 output.SendStatus(HttpStatus_204_NoContent); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
993 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
994 else |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
995 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
996 output.SendStatus(HttpStatus_403_Forbidden); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
997 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
998 return true; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
999 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1000 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1001 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1002 /** |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1003 * WebDAV - MKCOL |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1004 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1005 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1006 else if (method == "MKCOL") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1007 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1008 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1009 if (bucket->second->CreateFolder(path)) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1010 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1011 //output.SendStatus(HttpStatus_200_Ok); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1012 output.SendStatus(HttpStatus_201_Created); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1013 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1014 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1015 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1016 output.SendStatus(HttpStatus_403_Forbidden); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1017 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1018 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1019 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1020 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1021 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1022 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1023 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1024 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1025 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1026 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1027 * WebDAV - Faking PROPPATCH, LOCK and UNLOCK |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1028 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1029 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1030 else if (method == "PROPPATCH") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1031 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1032 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1033 IWebDavBucket::AnswerFakedProppatch(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1034 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1035 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1036 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1037 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1038 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1039 else if (method == "LOCK") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1040 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1041 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1042 IWebDavBucket::AnswerFakedLock(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1043 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1044 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1045 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1046 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1047 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1048 else if (method == "UNLOCK") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1049 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1050 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1051 IWebDavBucket::AnswerFakedUnlock(output); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1052 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1053 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1054 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1055 return true; |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1056 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1057 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1058 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1059 throw OrthancException(ErrorCode_InternalError); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1060 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1061 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1062 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1063 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1064 return false; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1065 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1066 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1067 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1068 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1069 * WebDAV - Unapplicable method (such as POST and DELETE) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1070 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1071 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1072 return false; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1073 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1074 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1075 #endif /* ORTHANC_ENABLE_PUGIXML == 1 */ |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1076 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1077 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1078 static void InternalCallback(HttpOutput& output /* out */, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1079 HttpMethod& method /* out */, |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1080 HttpServer& server, |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1081 struct mg_connection *connection, |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1082 const struct mg_request_info *request) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1083 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1084 bool localhost; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1085 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1086 #if ORTHANC_ENABLE_MONGOOSE == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1087 static const long LOCALHOST = (127ll << 24) + 1ll; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1088 localhost = (request->remote_ip == LOCALHOST); |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1089 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1090 // The "remote_ip" field of "struct mg_request_info" is tagged as |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1091 // deprecated in Civetweb, using "remote_addr" instead. |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1092 localhost = (std::string(request->remote_addr) == "127.0.0.1"); |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1093 #else |
3069 | 1094 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1095 #endif |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1096 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1097 // Check remote calls |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1098 if (!server.IsRemoteAccessAllowed() && |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1099 !localhost) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1100 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1101 output.SendUnauthorized(server.GetRealm()); // 401 error |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1102 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1103 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1104 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1105 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1106 // Extract the HTTP headers |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
1107 HttpToolbox::Arguments headers; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1108 for (int i = 0; i < request->num_headers; i++) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1109 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1110 std::string name = request->http_headers[i].name; |
1977
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
1111 std::string value = request->http_headers[i].value; |
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
1112 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1113 std::transform(name.begin(), name.end(), name.begin(), ::tolower); |
1977
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
1114 headers.insert(std::make_pair(name, value)); |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4273
diff
changeset
|
1115 CLOG(TRACE, HTTP) << "HTTP header: [" << name << "]: [" << value << "]"; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1116 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1117 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1118 if (server.IsHttpCompressionEnabled()) |
1517 | 1119 { |
1120 ConfigureHttpCompression(output, headers); | |
1121 } | |
1122 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1123 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1124 // Extract the GET arguments |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
1125 HttpToolbox::GetArguments argumentsGET; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1126 if (!strcmp(request->request_method, "GET")) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1127 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
1128 HttpToolbox::ParseGetArguments(argumentsGET, request->query_string); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1129 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1130 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1131 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1132 AccessMode accessMode = IsAccessGranted(server, headers); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1133 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1134 // Authenticate this connection |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1135 if (server.IsAuthenticationEnabled() && |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1136 accessMode == AccessMode_Forbidden) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1137 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1138 output.SendUnauthorized(server.GetRealm()); // 401 error |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1139 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1140 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1141 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1142 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1143 #if ORTHANC_ENABLE_MONGOOSE == 1 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1144 // Apply the filter, if it is installed |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1145 char remoteIp[24]; |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1146 sprintf(remoteIp, "%d.%d.%d.%d", |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1147 reinterpret_cast<const uint8_t*>(&request->remote_ip) [3], |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1148 reinterpret_cast<const uint8_t*>(&request->remote_ip) [2], |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1149 reinterpret_cast<const uint8_t*>(&request->remote_ip) [1], |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1150 reinterpret_cast<const uint8_t*>(&request->remote_ip) [0]); |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1151 |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1152 const char* requestUri = request->uri; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1153 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1154 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1155 const char* remoteIp = request->remote_addr; |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1156 const char* requestUri = request->local_uri; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1157 #else |
3069 | 1158 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1159 #endif |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1160 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1161 if (requestUri == NULL) |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1162 { |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1163 requestUri = ""; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1164 } |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1165 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1166 // Decompose the URI into its components |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1167 UriComponents uri; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1168 try |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1169 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1170 Toolbox::SplitUriComponents(uri, requestUri); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1171 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1172 catch (OrthancException&) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1173 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1174 output.SendStatus(HttpStatus_400_BadRequest); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1175 return; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1176 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1177 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1178 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1179 // Compute the HTTP method, taking method faking into consideration |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1180 method = HttpMethod_Get; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1181 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1182 #if ORTHANC_ENABLE_PUGIXML == 1 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1183 bool isWebDav = false; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1184 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1185 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1186 HttpMethod filterMethod; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1187 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1188 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1189 if (ExtractMethod(method, request, headers, argumentsGET)) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1190 { |
4295 | 1191 CLOG(INFO, HTTP) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1192 filterMethod = method; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1193 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1194 #if ORTHANC_ENABLE_PUGIXML == 1 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1195 else if (!strcmp(request->request_method, "OPTIONS") || |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1196 !strcmp(request->request_method, "PROPFIND") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1197 !strcmp(request->request_method, "HEAD")) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1198 { |
4295 | 1199 CLOG(INFO, HTTP) << "Incoming read-only WebDAV request: " |
1200 << request->request_method << " " << requestUri; | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1201 filterMethod = HttpMethod_Get; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1202 isWebDav = true; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1203 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1204 else if (!strcmp(request->request_method, "PROPPATCH") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1205 !strcmp(request->request_method, "LOCK") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1206 !strcmp(request->request_method, "UNLOCK") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1207 !strcmp(request->request_method, "MKCOL")) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1208 { |
4295 | 1209 CLOG(INFO, HTTP) << "Incoming read-write WebDAV request: " |
1210 << request->request_method << " " << requestUri; | |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1211 filterMethod = HttpMethod_Put; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1212 isWebDav = true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1213 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1214 #endif /* ORTHANC_ENABLE_PUGIXML == 1 */ |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1215 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1216 { |
4295 | 1217 CLOG(INFO, HTTP) << "Unknown HTTP method: " << request->request_method; |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1218 output.SendStatus(HttpStatus_400_BadRequest); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1219 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1220 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1221 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1222 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1223 const std::string username = GetAuthenticatedUsername(headers); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1224 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1225 if (accessMode != AccessMode_AuthorizationToken) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1226 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1227 // Check that this access is granted by the user's authorization |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1228 // filter. In the case of an authorization bearer token, grant |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1229 // full access to the API. |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1230 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1231 assert(accessMode == AccessMode_Forbidden || // Could be the case if "!server.IsAuthenticationEnabled()" |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1232 accessMode == AccessMode_RegisteredUser); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1233 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1234 IIncomingHttpRequestFilter *filter = server.GetIncomingHttpRequestFilter(); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1235 if (filter != NULL && |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1236 !filter->IsAllowed(filterMethod, requestUri, remoteIp, |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1237 username.c_str(), headers, argumentsGET)) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1238 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1239 output.SendStatus(HttpStatus_403_Forbidden); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1240 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1241 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1242 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1243 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1244 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1245 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1246 if (HandleWebDav(output, server.GetWebDavBuckets(), request->request_method, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1247 headers, requestUri, connection)) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1248 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1249 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1250 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1251 else if (isWebDav) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1252 { |
4295 | 1253 CLOG(INFO, HTTP) << "No WebDAV bucket is registered against URI: " |
1254 << request->request_method << " " << requestUri; | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1255 output.SendStatus(HttpStatus_404_NotFound); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1256 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1257 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1258 #endif |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1259 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1260 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1261 bool found = false; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1262 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1263 // Extract the body of the request for PUT and POST, or process |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1264 // the body as a stream |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
1265 |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
1266 // TODO Avoid unneccessary memcopy of the body |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
1267 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1268 std::string body; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1269 if (method == HttpMethod_Post || |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1270 method == HttpMethod_Put) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1271 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1272 PostDataStatus status; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1273 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1274 bool isMultipartForm = false; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1275 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
1276 HttpToolbox::Arguments::const_iterator ct = headers.find("content-type"); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1277 if (ct != headers.end() && |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1278 ct->second.size() >= MULTIPART_FORM_LENGTH && |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1279 !memcmp(ct->second.c_str(), MULTIPART_FORM, MULTIPART_FORM_LENGTH)) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1280 { |
3445 | 1281 /** |
1282 * The user uses the "upload" form of Orthanc Explorer, for | |
1283 * file uploads through a HTML form. | |
1284 **/ | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1285 status = ParseMultipartForm(body, connection, headers, ct->second, server.GetChunkStore()); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1286 isMultipartForm = true; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1287 } |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1288 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1289 if (!isMultipartForm) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1290 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3672
diff
changeset
|
1291 std::unique_ptr<IHttpHandler::IChunkedRequestReader> stream; |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1292 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1293 if (server.HasHandler()) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1294 { |
3414 | 1295 found = server.GetHandler().CreateChunkedRequestReader |
1296 (stream, RequestOrigin_RestApi, remoteIp, username.c_str(), method, uri, headers); | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1297 } |
3414 | 1298 |
1299 if (found) | |
1300 { | |
1301 if (stream.get() == NULL) | |
1302 { | |
1303 throw OrthancException(ErrorCode_InternalError); | |
1304 } | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1305 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1306 status = ReadBodyToStream(*stream, connection, headers); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1307 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1308 if (status == PostDataStatus_Success) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1309 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1310 stream->Execute(output); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1311 } |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1312 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1313 else |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1314 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1315 status = ReadBodyToString(body, connection, headers); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1316 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1317 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1318 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1319 switch (status) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1320 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1321 case PostDataStatus_NoLength: |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1112
diff
changeset
|
1322 output.SendStatus(HttpStatus_411_LengthRequired); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1323 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1324 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1325 case PostDataStatus_Failure: |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1112
diff
changeset
|
1326 output.SendStatus(HttpStatus_400_BadRequest); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1327 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1328 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1329 case PostDataStatus_Pending: |
1521 | 1330 output.AnswerEmpty(); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1331 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1332 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1333 case PostDataStatus_Success: |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1334 break; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1335 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1336 default: |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1337 throw OrthancException(ErrorCode_InternalError); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1338 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1339 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1340 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1341 if (!found && |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1342 server.HasHandler()) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1343 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1344 found = server.GetHandler().Handle(output, RequestOrigin_RestApi, remoteIp, username.c_str(), |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1345 method, uri, headers, argumentsGET, body.c_str(), body.size()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1346 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1347 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1348 if (!found) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1349 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1350 throw OrthancException(ErrorCode_UnknownResource); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1351 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1352 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1353 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1354 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1355 static void ProtectedCallback(struct mg_connection *connection, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1356 const struct mg_request_info *request) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1357 { |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1358 try |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1359 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1360 #if ORTHANC_ENABLE_MONGOOSE == 1 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1361 void *that = request->user_data; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1362 const char* requestUri = request->uri; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1363 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1364 // https://github.com/civetweb/civetweb/issues/409 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1365 void *that = mg_get_user_data(mg_get_context(connection)); |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1366 const char* requestUri = request->local_uri; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1367 #else |
3069 | 1368 # error |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1369 #endif |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1370 |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1371 if (requestUri == NULL) |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1372 { |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1373 requestUri = ""; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1374 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1375 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1376 HttpServer* server = reinterpret_cast<HttpServer*>(that); |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1377 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1378 if (server == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1379 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1380 MongooseOutputStream stream(connection); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1381 HttpOutput output(stream, false /* assume no keep-alive */); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1382 output.SendStatus(HttpStatus_500_InternalServerError); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1383 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1384 } |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1385 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1386 MongooseOutputStream stream(connection); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1387 HttpOutput output(stream, server->IsKeepAliveEnabled()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1388 HttpMethod method = HttpMethod_Get; |
1569 | 1389 |
1390 try | |
1570 | 1391 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1392 try |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1393 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1394 InternalCallback(output, method, *server, connection, request); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1395 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1396 catch (OrthancException&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1397 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1398 throw; // Pass the exception to the main handler below |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1399 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1400 // Now convert native exceptions as OrthancException |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1401 catch (boost::bad_lexical_cast&) |
1570 | 1402 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1403 throw OrthancException(ErrorCode_BadParameterType, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1404 "Syntax error in some user-supplied data"); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1405 } |
3672
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1406 catch (boost::filesystem::filesystem_error& e) |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1407 { |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1408 throw OrthancException(ErrorCode_InternalError, |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1409 "Error while accessing the filesystem: " + e.path1().string()); |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1410 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1411 catch (std::runtime_error&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1412 { |
3672
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1413 throw OrthancException(ErrorCode_BadRequest, |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1414 "Presumably an error while parsing the JSON body"); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1415 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1416 catch (std::bad_alloc&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1417 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1418 throw OrthancException(ErrorCode_NotEnoughMemory, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1419 "The server hosting Orthanc is running out of memory"); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1420 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1421 catch (...) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1422 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1423 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1424 "An unhandled exception was generated inside the HTTP server"); |
1570 | 1425 } |
1426 } | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1427 catch (OrthancException& e) |
1570 | 1428 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1429 assert(server != NULL); |
1569 | 1430 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1431 // Using this candidate handler results in an exception |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1432 try |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1433 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1434 if (server->GetExceptionFormatter() == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1435 { |
4295 | 1436 CLOG(ERROR, HTTP) << "Exception in the HTTP handler: " << e.What(); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1437 output.SendStatus(e.GetHttpStatus()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1438 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1439 else |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1440 { |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1441 server->GetExceptionFormatter()->Format(output, e, method, requestUri); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1442 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1443 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1444 catch (OrthancException&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1445 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1446 // An exception here reflects the fact that the status code |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1447 // was already set by the HTTP handler. |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1448 } |
1570 | 1449 } |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1450 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1451 catch (...) |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1452 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1453 // We should never arrive at this point, where it is even impossible to send an answer |
4295 | 1454 CLOG(ERROR, HTTP) << "Catastrophic error inside the HTTP server, giving up"; |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1455 } |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1456 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1457 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1458 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1459 #if MONGOOSE_USE_CALLBACKS == 0 |
0 | 1460 static void* Callback(enum mg_event event, |
1461 struct mg_connection *connection, | |
1462 const struct mg_request_info *request) | |
1463 { | |
1464 if (event == MG_NEW_REQUEST) | |
1465 { | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1466 ProtectedCallback(connection, request); |
0 | 1467 |
1468 // Mark as processed | |
1469 return (void*) ""; | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1470 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1471 else |
0 | 1472 { |
1473 return NULL; | |
1474 } | |
1475 } | |
1476 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1477 #elif MONGOOSE_USE_CALLBACKS == 1 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1478 static int Callback(struct mg_connection *connection) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1479 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1480 const struct mg_request_info *request = mg_get_request_info(connection); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1481 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1482 ProtectedCallback(connection, request); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1483 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1484 return 1; // Do not let Mongoose handle the request by itself |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1485 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1486 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1487 #else |
3069 | 1488 # error Please set MONGOOSE_USE_CALLBACKS |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1489 #endif |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1490 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1491 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1492 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1493 |
0 | 1494 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1495 bool HttpServer::IsRunning() const |
0 | 1496 { |
1497 return (pimpl_->context_ != NULL); | |
1498 } | |
1499 | |
1500 | |
4201 | 1501 HttpServer::HttpServer() : |
1502 pimpl_(new PImpl), | |
1503 handler_(NULL), | |
1504 remoteAllowed_(false), | |
1505 authentication_(false), | |
1506 sslVerifyPeers_(false), | |
1507 ssl_(false), | |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1508 sslMinimumVersion_(0), // Default to any of "SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2" |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1509 sslHasCiphers_(false), |
4201 | 1510 port_(8000), |
1511 filter_(NULL), | |
1512 keepAlive_(false), | |
1513 httpCompression_(true), | |
1514 exceptionFormatter_(NULL), | |
1515 realm_(ORTHANC_REALM), | |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1516 threadsCount_(50), // Default value in mongoose/civetweb |
4201 | 1517 tcpNoDelay_(true), |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1518 requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds) |
0 | 1519 { |
3145
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1520 #if ORTHANC_ENABLE_MONGOOSE == 1 |
4295 | 1521 CLOG(INFO, HTTP) << "This Orthanc server uses Mongoose as its embedded HTTP server"; |
3145
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1522 #endif |
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1523 |
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1524 #if ORTHANC_ENABLE_CIVETWEB == 1 |
4295 | 1525 CLOG(INFO, HTTP) << "This Orthanc server uses CivetWeb as its embedded HTTP server"; |
3145
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1526 #endif |
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1527 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
1528 #if ORTHANC_ENABLE_SSL == 1 |
749 | 1529 // Check for the Heartbleed exploit |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1530 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1531 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ && |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1532 OPENSSL_VERSION_NUMBER >= 0x1000100fL /* openssl-1.0.1 */) |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1533 { |
4295 | 1534 CLOG(WARNING, HTTP) << "This version of OpenSSL is vulnerable to the Heartbleed exploit"; |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1535 } |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1536 #endif |
0 | 1537 } |
1538 | |
1539 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1540 HttpServer::~HttpServer() |
0 | 1541 { |
1542 Stop(); | |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1543 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1544 #if ORTHANC_ENABLE_PUGIXML == 1 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1545 for (WebDavBuckets::iterator it = webDavBuckets_.begin(); it != webDavBuckets_.end(); ++it) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1546 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1547 assert(it->second != NULL); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1548 delete it->second; |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1549 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1550 #endif |
0 | 1551 } |
1552 | |
1553 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1554 void HttpServer::SetPortNumber(uint16_t port) |
0 | 1555 { |
1556 Stop(); | |
1557 port_ = port; | |
1558 } | |
1559 | |
4298 | 1560 uint16_t HttpServer::GetPortNumber() const |
1561 { | |
1562 return port_; | |
1563 } | |
1564 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1565 void HttpServer::Start() |
0 | 1566 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1567 #if ORTHANC_ENABLE_MONGOOSE == 1 |
4295 | 1568 CLOG(INFO, HTTP) << "Starting embedded Web server using Mongoose"; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1569 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
4295 | 1570 CLOG(INFO, HTTP) << "Starting embedded Web server using Civetweb"; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1571 #else |
3069 | 1572 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1573 #endif |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1574 |
0 | 1575 if (!IsRunning()) |
1576 { | |
1577 std::string port = boost::lexical_cast<std::string>(port_); | |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1578 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_); |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
1579 std::string requestTimeoutMilliseconds = boost::lexical_cast<std::string>(requestTimeout_ * 1000); |
4301
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1580 std::string keepAliveTimeoutMilliseconds = boost::lexical_cast<std::string>(CIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS * 1000); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1581 std::string sslMinimumVersion = boost::lexical_cast<std::string>(sslMinimumVersion_); |
0 | 1582 |
23 | 1583 if (ssl_) |
1584 { | |
1585 port += "s"; | |
1586 } | |
1587 | |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1588 std::vector<const char*> options; |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1589 |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1590 // Set the TCP port for the HTTP server |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1591 options.push_back("listening_ports"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1592 options.push_back(port.c_str()); |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
1593 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1594 // Optimization reported by Chris Hafey |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1595 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1596 options.push_back("enable_keep_alive"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1597 options.push_back(keepAlive_ ? "yes" : "no"); |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
1598 |
2579 | 1599 #if ORTHANC_ENABLE_CIVETWEB == 1 |
4301
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1600 /** |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1601 * The "keep_alive_timeout_ms" cannot use milliseconds, as the |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1602 * value of "timeout" in the HTTP header "Keep-Alive" must be |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1603 * expressed in seconds (at least for the Java client). |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1604 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1605 * https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1606 * https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#keep_alive_timeout_ms-500-or-0 |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1607 **/ |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1608 options.push_back("keep_alive_timeout_ms"); |
4301
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1609 options.push_back(keepAlive_ ? keepAliveTimeoutMilliseconds.c_str() : "0"); |
2577
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1610 #endif |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1611 |
3136
f948deef53d9
using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3069
diff
changeset
|
1612 #if ORTHANC_ENABLE_CIVETWEB == 1 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1613 // Disable TCP Nagle's algorithm to maximize speed (this |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1614 // option is not available in Mongoose). |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1615 // https://groups.google.com/d/topic/civetweb/35HBR9seFjU/discussion |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1616 // https://eklitzke.org/the-caveats-of-tcp-nodelay |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1617 options.push_back("tcp_nodelay"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1618 options.push_back(tcpNoDelay_ ? "1" : "0"); |
3136
f948deef53d9
using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3069
diff
changeset
|
1619 #endif |
f948deef53d9
using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3069
diff
changeset
|
1620 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1621 // Set the number of threads |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1622 options.push_back("num_threads"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1623 options.push_back(numThreads.c_str()); |
2577
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1624 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1625 // Set the timeout for the HTTP server |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1626 options.push_back("request_timeout_ms"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1627 options.push_back(requestTimeoutMilliseconds.c_str()); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1628 |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1629 // Set the client authentication |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1630 options.push_back("ssl_verify_peer"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1631 options.push_back(sslVerifyPeers_ ? "yes" : "no"); |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
1632 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1633 if (sslVerifyPeers_) |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1634 { |
4190
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1635 // Set the trusted client certificates (for X509 mutual authentication) |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1636 options.push_back("ssl_ca_file"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1637 options.push_back(trustedClientCertificates_.c_str()); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1638 } |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1639 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1640 if (ssl_) |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1641 { |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1642 // Restrict minimum SSL/TLS protocol version |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1643 options.push_back("ssl_protocol_version"); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1644 options.push_back(sslMinimumVersion.c_str()); |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1645 |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1646 // Set the accepted ciphers list |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1647 if (sslHasCiphers_) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1648 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1649 options.push_back("ssl_cipher_list"); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1650 options.push_back(sslCiphers_.c_str()); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1651 } |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1652 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1653 // Set the SSL certificate, if any |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1654 options.push_back("ssl_certificate"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1655 options.push_back(certificate_.c_str()); |
0 | 1656 }; |
1657 | |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1658 assert(options.size() % 2 == 0); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1659 options.push_back(NULL); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1660 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1661 #if MONGOOSE_USE_CALLBACKS == 0 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1662 pimpl_->context_ = mg_start(&Callback, this, &options[0]); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1663 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1664 #elif MONGOOSE_USE_CALLBACKS == 1 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1665 struct mg_callbacks callbacks; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1666 memset(&callbacks, 0, sizeof(callbacks)); |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1667 callbacks.begin_request = Callback; |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1668 pimpl_->context_ = mg_start(&callbacks, this, &options[0]); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1669 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1670 #else |
3069 | 1671 # error Please set MONGOOSE_USE_CALLBACKS |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1672 #endif |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1673 |
0 | 1674 if (!pimpl_->context_) |
1675 { | |
3801
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1676 bool isSslError = false; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1677 |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1678 #if ORTHANC_ENABLE_SSL == 1 |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1679 for (;;) |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1680 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1681 unsigned long code = ERR_get_error(); |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1682 if (code == 0) |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1683 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1684 break; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1685 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1686 else |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1687 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1688 isSslError = true; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1689 char message[1024]; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1690 ERR_error_string_n(code, message, sizeof(message) - 1); |
4295 | 1691 CLOG(ERROR, HTTP) << "OpenSSL error: " << message; |
3801
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1692 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1693 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1694 #endif |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1695 |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1696 if (isSslError) |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1697 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1698 throw OrthancException(ErrorCode_SslInitialization); |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1699 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1700 else |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1701 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1702 throw OrthancException(ErrorCode_HttpPortInUse, |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1703 " (port = " + boost::lexical_cast<std::string>(port_) + ")"); |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1704 } |
0 | 1705 } |
2633
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1706 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1707 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1708 for (WebDavBuckets::iterator it = webDavBuckets_.begin(); it != webDavBuckets_.end(); ++it) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1709 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1710 assert(it->second != NULL); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1711 it->second->Start(); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1712 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1713 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1714 |
4295 | 1715 CLOG(WARNING, HTTP) << "HTTP server listening on port: " << GetPortNumber() |
1716 << " (HTTPS encryption is " | |
1717 << (IsSslEnabled() ? "enabled" : "disabled") | |
1718 << ", remote access is " | |
1719 << (IsRemoteAccessAllowed() ? "" : "not ") | |
1720 << "allowed)"; | |
0 | 1721 } |
1722 } | |
1723 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1724 void HttpServer::Stop() |
0 | 1725 { |
1726 if (IsRunning()) | |
1727 { | |
1728 mg_stop(pimpl_->context_); | |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1729 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1730 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1731 for (WebDavBuckets::iterator it = webDavBuckets_.begin(); it != webDavBuckets_.end(); ++it) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1732 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1733 assert(it->second != NULL); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1734 it->second->Stop(); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1735 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1736 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1737 |
0 | 1738 pimpl_->context_ = NULL; |
1739 } | |
1740 } | |
1741 | |
1742 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1743 void HttpServer::ClearUsers() |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1744 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1745 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1746 registeredUsers_.clear(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1747 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1748 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1749 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1750 void HttpServer::RegisterUser(const char* username, |
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1751 const char* password) |
23 | 1752 { |
1753 Stop(); | |
24 | 1754 |
1755 std::string tag = std::string(username) + ":" + std::string(password); | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1756 std::string encoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1757 Toolbox::EncodeBase64(encoded, tag); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1758 registeredUsers_.insert(encoded); |
23 | 1759 } |
1760 | |
4298 | 1761 bool HttpServer::IsAuthenticationEnabled() const |
1762 { | |
1763 return authentication_; | |
1764 } | |
1765 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1766 void HttpServer::SetSslEnabled(bool enabled) |
23 | 1767 { |
1768 Stop(); | |
1769 | |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
1770 #if ORTHANC_ENABLE_SSL == 0 |
23 | 1771 if (enabled) |
1772 { | |
1674
4fc502d469f4
fix build if SSL is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1649
diff
changeset
|
1773 throw OrthancException(ErrorCode_SslDisabled); |
23 | 1774 } |
1775 else | |
1776 { | |
1777 ssl_ = false; | |
1778 } | |
1779 #else | |
1780 ssl_ = enabled; | |
1781 #endif | |
1782 } | |
1783 | |
4190
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1784 void HttpServer::SetSslVerifyPeers(bool enabled) |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1785 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1786 Stop(); |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1787 |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1788 #if ORTHANC_ENABLE_SSL == 0 |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1789 if (enabled) |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1790 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1791 throw OrthancException(ErrorCode_SslDisabled); |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1792 } |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1793 else |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1794 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1795 sslVerifyPeers_ = false; |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1796 } |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1797 #else |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1798 sslVerifyPeers_ = enabled; |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1799 #endif |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1800 } |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1801 |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1802 void HttpServer::SetSslMinimumVersion(unsigned int version) |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1803 { |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1804 Stop(); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1805 sslMinimumVersion_ = version; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1806 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1807 std::string info; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1808 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1809 switch (version) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1810 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1811 case 0: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1812 info = "SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1813 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1814 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1815 case 1: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1816 info = "SSL3+TLS1.0+TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1817 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1818 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1819 case 2: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1820 info = "TLS1.0+TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1821 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1822 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1823 case 3: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1824 info = "TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1825 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1826 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1827 case 4: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1828 info = "TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1829 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1830 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1831 default: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1832 info = "Unknown value (" + boost::lexical_cast<std::string>(version) + ")"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1833 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1834 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1835 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1836 CLOG(INFO, HTTP) << "Minimal accepted version of SSL/TLS protocol: " << info; |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1837 } |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1838 |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1839 void HttpServer::SetSslCiphers(const std::list<std::string>& ciphers) |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1840 { |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1841 Stop(); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1842 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1843 sslHasCiphers_ = true; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1844 sslCiphers_.clear(); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1845 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1846 for (std::list<std::string>::const_iterator |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1847 it = ciphers.begin(); it != ciphers.end(); ++it) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1848 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1849 if (it->empty()) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1850 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1851 throw OrthancException(ErrorCode_ParameterOutOfRange, "Empty name for a cipher"); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1852 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1853 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1854 if (!sslCiphers_.empty()) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1855 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1856 sslCiphers_ += ':'; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1857 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1858 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1859 sslCiphers_ += (*it); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1860 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1861 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1862 CLOG(INFO, HTTP) << "List of accepted SSL ciphers: " << sslCiphers_; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1863 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1864 if (sslCiphers_.empty()) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1865 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1866 CLOG(WARNING, HTTP) << "No cipher is accepted for SSL"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1867 } |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1868 } |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1869 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1870 void HttpServer::SetKeepAliveEnabled(bool enabled) |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1871 { |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1872 Stop(); |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1873 keepAlive_ = enabled; |
4295 | 1874 CLOG(INFO, HTTP) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled"); |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1875 |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1876 #if ORTHANC_ENABLE_MONGOOSE == 1 |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1877 if (enabled) |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1878 { |
4295 | 1879 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose"; |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1880 } |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1881 #endif |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1882 } |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1883 |
4298 | 1884 const std::string &HttpServer::GetSslCertificate() const |
1885 { | |
1886 return certificate_; | |
1887 } | |
1888 | |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1889 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1890 void HttpServer::SetAuthenticationEnabled(bool enabled) |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1891 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1892 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1893 authentication_ = enabled; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1894 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1895 |
4298 | 1896 bool HttpServer::IsSslEnabled() const |
1897 { | |
1898 return ssl_; | |
1899 } | |
1900 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1901 void HttpServer::SetSslCertificate(const char* path) |
23 | 1902 { |
1903 Stop(); | |
1904 certificate_ = path; | |
1905 } | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1906 |
4298 | 1907 bool HttpServer::IsRemoteAccessAllowed() const |
1908 { | |
1909 return remoteAllowed_; | |
1910 } | |
1911 | |
4190
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1912 void HttpServer::SetSslTrustedClientCertificates(const char* path) |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1913 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1914 Stop(); |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1915 trustedClientCertificates_ = path; |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1916 } |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1917 |
4298 | 1918 bool HttpServer::IsKeepAliveEnabled() const |
1919 { | |
1920 return keepAlive_; | |
1921 } | |
1922 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1923 void HttpServer::SetRemoteAccessAllowed(bool allowed) |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1924 { |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1925 Stop(); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1926 remoteAllowed_ = allowed; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1927 } |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1928 |
4298 | 1929 bool HttpServer::IsHttpCompressionEnabled() const |
1930 { | |
1931 return httpCompression_;; | |
1932 } | |
1933 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1934 void HttpServer::SetHttpCompressionEnabled(bool enabled) |
1517 | 1935 { |
1936 Stop(); | |
1937 httpCompression_ = enabled; | |
4295 | 1938 CLOG(WARNING, HTTP) << "HTTP compression is " << (enabled ? "enabled" : "disabled"); |
1517 | 1939 } |
4298 | 1940 |
1941 IIncomingHttpRequestFilter *HttpServer::GetIncomingHttpRequestFilter() const | |
1942 { | |
1943 return filter_; | |
1944 } | |
1592
d73124f6b439
configuration option HttpDescribeErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
1945 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1946 void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1947 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1948 Stop(); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1949 filter_ = &filter; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1950 } |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1951 |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1952 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1953 void HttpServer::SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter) |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1954 { |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1955 Stop(); |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1956 exceptionFormatter_ = &formatter; |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1957 } |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1958 |
4298 | 1959 IHttpExceptionFormatter *HttpServer::GetExceptionFormatter() |
1960 { | |
1961 return exceptionFormatter_; | |
1962 } | |
1963 | |
1964 const std::string &HttpServer::GetRealm() const | |
1965 { | |
1966 return realm_; | |
1967 } | |
1968 | |
1969 void HttpServer::SetRealm(const std::string &realm) | |
1970 { | |
1971 realm_ = realm; | |
1972 } | |
1973 | |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1974 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1975 bool HttpServer::IsValidBasicHttpAuthentication(const std::string& basic) const |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1976 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1977 return registeredUsers_.find(basic) != registeredUsers_.end(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1978 } |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1979 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1980 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1981 void HttpServer::Register(IHttpHandler& handler) |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1982 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1983 Stop(); |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1984 handler_ = &handler; |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1985 } |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1986 |
4298 | 1987 bool HttpServer::HasHandler() const |
1988 { | |
1989 return handler_ != NULL; | |
1990 } | |
1991 | |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1992 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1993 IHttpHandler& HttpServer::GetHandler() const |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1994 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1995 if (handler_ == NULL) |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1996 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1997 throw OrthancException(ErrorCode_InternalError); |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1998 } |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1999 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2000 return *handler_; |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2001 } |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2002 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2003 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2004 void HttpServer::SetThreadsCount(unsigned int threads) |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2005 { |
4201 | 2006 if (threads == 0) |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2007 { |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2008 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2009 } |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2010 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2011 Stop(); |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2012 threadsCount_ = threads; |
3180
07a2f637b76d
new option: "HttpThreadsCount" to set the number of threads in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
2013 |
4295 | 2014 CLOG(INFO, HTTP) << "The embedded HTTP server will use " << threads << " threads"; |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2015 } |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2016 |
4298 | 2017 unsigned int HttpServer::GetThreadsCount() const |
2018 { | |
2019 return threadsCount_; | |
2020 } | |
2021 | |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2022 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2023 void HttpServer::SetTcpNoDelay(bool tcpNoDelay) |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2024 { |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2025 Stop(); |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2026 tcpNoDelay_ = tcpNoDelay; |
4295 | 2027 CLOG(INFO, HTTP) << "TCP_NODELAY for the HTTP sockets is set to " |
2028 << (tcpNoDelay ? "true" : "false"); | |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2029 } |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2030 |
4298 | 2031 bool HttpServer::IsTcpNoDelay() const |
2032 { | |
2033 return tcpNoDelay_; | |
2034 } | |
2035 | |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2036 |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2037 void HttpServer::SetRequestTimeout(unsigned int seconds) |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2038 { |
4201 | 2039 if (seconds == 0) |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2040 { |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2041 throw OrthancException(ErrorCode_ParameterOutOfRange, |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2042 "Request timeout must be a stricly positive integer"); |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2043 } |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2044 |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2045 Stop(); |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2046 requestTimeout_ = seconds; |
4295 | 2047 CLOG(INFO, HTTP) << "Request timeout in the HTTP server is set to " << seconds << " seconds"; |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2048 } |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2049 |
4298 | 2050 unsigned int HttpServer::GetRequestTimeout() const |
2051 { | |
2052 return requestTimeout_; | |
2053 } | |
2054 | |
2055 | |
2056 #if ORTHANC_ENABLE_PUGIXML == 1 | |
2057 HttpServer::WebDavBuckets& HttpServer::GetWebDavBuckets() | |
2058 { | |
2059 return webDavBuckets_; | |
2060 } | |
2061 #endif | |
2062 | |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2063 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2064 #if ORTHANC_ENABLE_PUGIXML == 1 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2065 void HttpServer::Register(const std::vector<std::string>& root, |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2066 IWebDavBucket* bucket) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2067 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2068 std::unique_ptr<IWebDavBucket> protection(bucket); |
4229 | 2069 |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2070 if (bucket == NULL) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2071 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2072 throw OrthancException(ErrorCode_NullPointer); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2073 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2074 |
4229 | 2075 Stop(); |
2076 | |
2077 #if CIVETWEB_HAS_WEBDAV_WRITING == 0 | |
2078 if (webDavBuckets_.size() == 0) | |
2079 { | |
4295 | 2080 CLOG(WARNING, HTTP) << "Your version of the Orthanc framework was compiled " |
2081 << "without support for writing into WebDAV collections"; | |
4229 | 2082 } |
2083 #endif | |
2084 | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
2085 const std::string s = Toolbox::FlattenUri(root); |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2086 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2087 if (webDavBuckets_.find(s) != webDavBuckets_.end()) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2088 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2089 throw OrthancException(ErrorCode_ParameterOutOfRange, |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2090 "Cannot register two WebDAV buckets at the same root: " + s); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2091 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2092 else |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2093 { |
4295 | 2094 CLOG(INFO, HTTP) << "Branching WebDAV bucket at: " << s; |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2095 webDavBuckets_[s] = protection.release(); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2096 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2097 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2098 #endif |
0 | 2099 } |