Mercurial > hg > orthanc
annotate Core/HttpServer/MongooseServer.cpp @ 3109:6aa8d90aeee5
minor layout modification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jan 2019 10:46:16 +0100 |
parents | 3db9697a0a58 |
children | f948deef53d9 |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
136 | 11 * |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
0 | 23 * |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 // http://en.highscore.de/cpp/boost/stringhandling.html | |
35 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
36 #include "../PrecompiledHeaders.h" |
0 | 37 #include "MongooseServer.h" |
38 | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
39 #include "../Logging.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
40 #include "../ChunkedBuffer.h" |
2895 | 41 #include "../OrthancException.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
42 #include "HttpToolbox.h" |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
43 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
44 #if ORTHANC_ENABLE_MONGOOSE == 1 |
3069 | 45 # 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
|
46 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
47 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
3069 | 48 # 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
|
49 # define MONGOOSE_USE_CALLBACKS 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
50 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
51 #else |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
52 # 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
|
53 #endif |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
54 |
0 | 55 #include <algorithm> |
56 #include <string.h> | |
57 #include <boost/lexical_cast.hpp> | |
58 #include <boost/algorithm/string.hpp> | |
59 #include <iostream> | |
60 #include <string.h> | |
61 #include <stdio.h> | |
62 #include <boost/thread.hpp> | |
63 | |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
64 #if !defined(ORTHANC_ENABLE_SSL) |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
65 # error The macro ORTHANC_ENABLE_SSL must be defined |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
66 #endif |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
67 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
68 #if ORTHANC_ENABLE_SSL == 1 |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
69 #include <openssl/opensslv.h> |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
70 #endif |
0 | 71 |
59 | 72 #define ORTHANC_REALM "Orthanc Secure Area" |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
73 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
74 |
59 | 75 namespace Orthanc |
0 | 76 { |
77 static const char multipart[] = "multipart/form-data; boundary="; | |
78 static unsigned int multipartLength = sizeof(multipart) / sizeof(char) - 1; | |
79 | |
80 | |
81 namespace | |
82 { | |
83 // Anonymous namespace to avoid clashes between compilation modules | |
911 | 84 class MongooseOutputStream : public IHttpOutputStream |
0 | 85 { |
86 private: | |
87 struct mg_connection* connection_; | |
88 | |
911 | 89 public: |
90 MongooseOutputStream(struct mg_connection* connection) : connection_(connection) | |
91 { | |
92 } | |
93 | |
909 | 94 virtual void Send(bool isHeader, const void* buffer, size_t length) |
0 | 95 { |
217 | 96 if (length > 0) |
97 { | |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
98 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
|
99 if (status != static_cast<int>(length)) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
100 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
101 // 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
|
102 throw OrthancException(ErrorCode_NetworkProtocol); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
103 } |
217 | 104 } |
0 | 105 } |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
106 |
911 | 107 virtual void OnHttpStatusReceived(HttpStatus status) |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
108 { |
911 | 109 // Ignore this |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
110 } |
0 | 111 }; |
112 | |
113 | |
114 enum PostDataStatus | |
115 { | |
116 PostDataStatus_Success, | |
117 PostDataStatus_NoLength, | |
118 PostDataStatus_Pending, | |
119 PostDataStatus_Failure | |
120 }; | |
121 } | |
122 | |
123 | |
124 // TODO Move this to external file | |
125 | |
126 | |
127 class ChunkedFile : public ChunkedBuffer | |
128 { | |
129 private: | |
130 std::string filename_; | |
131 | |
132 public: | |
133 ChunkedFile(const std::string& filename) : | |
134 filename_(filename) | |
135 { | |
136 } | |
137 | |
138 const std::string& GetFilename() const | |
139 { | |
140 return filename_; | |
141 } | |
142 }; | |
143 | |
144 | |
145 | |
146 class ChunkStore | |
147 { | |
148 private: | |
149 typedef std::list<ChunkedFile*> Content; | |
150 Content content_; | |
151 unsigned int numPlaces_; | |
152 | |
153 boost::mutex mutex_; | |
154 std::set<std::string> discardedFiles_; | |
155 | |
156 void Clear() | |
157 { | |
158 for (Content::iterator it = content_.begin(); | |
656 | 159 it != content_.end(); ++it) |
0 | 160 { |
161 delete *it; | |
162 } | |
163 } | |
164 | |
165 Content::iterator Find(const std::string& filename) | |
166 { | |
167 for (Content::iterator it = content_.begin(); | |
656 | 168 it != content_.end(); ++it) |
0 | 169 { |
170 if ((*it)->GetFilename() == filename) | |
171 { | |
172 return it; | |
173 } | |
174 } | |
175 | |
176 return content_.end(); | |
177 } | |
178 | |
179 void Remove(const std::string& filename) | |
180 { | |
181 Content::iterator it = Find(filename); | |
182 if (it != content_.end()) | |
183 { | |
184 delete *it; | |
185 content_.erase(it); | |
186 } | |
187 } | |
188 | |
189 public: | |
190 ChunkStore() | |
191 { | |
192 numPlaces_ = 10; | |
193 } | |
194 | |
195 ~ChunkStore() | |
196 { | |
197 Clear(); | |
198 } | |
199 | |
200 PostDataStatus Store(std::string& completed, | |
201 const char* chunkData, | |
202 size_t chunkSize, | |
203 const std::string& filename, | |
204 size_t filesize) | |
205 { | |
206 boost::mutex::scoped_lock lock(mutex_); | |
207 | |
208 std::set<std::string>::iterator wasDiscarded = discardedFiles_.find(filename); | |
209 if (wasDiscarded != discardedFiles_.end()) | |
210 { | |
211 discardedFiles_.erase(wasDiscarded); | |
212 return PostDataStatus_Failure; | |
213 } | |
214 | |
215 ChunkedFile* f; | |
216 Content::iterator it = Find(filename); | |
217 if (it == content_.end()) | |
218 { | |
219 f = new ChunkedFile(filename); | |
220 | |
221 // Make some room | |
222 if (content_.size() >= numPlaces_) | |
223 { | |
224 discardedFiles_.insert(content_.front()->GetFilename()); | |
225 delete content_.front(); | |
226 content_.pop_front(); | |
227 } | |
228 | |
229 content_.push_back(f); | |
230 } | |
231 else | |
232 { | |
233 f = *it; | |
234 } | |
235 | |
236 f->AddChunk(chunkData, chunkSize); | |
237 | |
238 if (f->GetNumBytes() > filesize) | |
239 { | |
240 Remove(filename); | |
241 } | |
242 else if (f->GetNumBytes() == filesize) | |
243 { | |
244 f->Flatten(completed); | |
245 Remove(filename); | |
246 return PostDataStatus_Success; | |
247 } | |
248 | |
249 return PostDataStatus_Pending; | |
250 } | |
251 | |
252 /*void Print() | |
253 { | |
254 boost::mutex::scoped_lock lock(mutex_); | |
255 | |
256 printf("ChunkStore status:\n"); | |
257 for (Content::const_iterator i = content_.begin(); | |
258 i != content_.end(); i++) | |
259 { | |
260 printf(" [%s]: %d\n", (*i)->GetFilename().c_str(), (*i)->GetNumBytes()); | |
261 } | |
262 printf("-----\n"); | |
263 }*/ | |
264 }; | |
265 | |
266 | |
267 struct MongooseServer::PImpl | |
268 { | |
269 struct mg_context *context_; | |
270 ChunkStore chunkStore_; | |
271 }; | |
272 | |
273 | |
274 ChunkStore& MongooseServer::GetChunkStore() | |
275 { | |
276 return pimpl_->chunkStore_; | |
277 } | |
278 | |
279 | |
280 | |
416 | 281 static PostDataStatus ReadBody(std::string& postData, |
282 struct mg_connection *connection, | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
283 const IHttpHandler::Arguments& headers) |
0 | 284 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
285 IHttpHandler::Arguments::const_iterator cs = headers.find("content-length"); |
0 | 286 if (cs == headers.end()) |
287 { | |
288 return PostDataStatus_NoLength; | |
289 } | |
290 | |
291 int length; | |
292 try | |
293 { | |
294 length = boost::lexical_cast<int>(cs->second); | |
295 } | |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2790
diff
changeset
|
296 catch (boost::bad_lexical_cast&) |
0 | 297 { |
298 return PostDataStatus_NoLength; | |
299 } | |
300 | |
301 if (length < 0) | |
302 { | |
303 length = 0; | |
304 } | |
305 | |
306 postData.resize(length); | |
307 | |
308 size_t pos = 0; | |
309 while (length > 0) | |
310 { | |
311 int r = mg_read(connection, &postData[pos], length); | |
312 if (r <= 0) | |
313 { | |
314 return PostDataStatus_Failure; | |
315 } | |
418
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
417
diff
changeset
|
316 |
8 | 317 assert(r <= length); |
0 | 318 length -= r; |
319 pos += r; | |
320 } | |
321 | |
322 return PostDataStatus_Success; | |
323 } | |
324 | |
325 | |
326 | |
327 static PostDataStatus ParseMultipartPost(std::string &completedFile, | |
328 struct mg_connection *connection, | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
329 const IHttpHandler::Arguments& headers, |
0 | 330 const std::string& contentType, |
331 ChunkStore& chunkStore) | |
332 { | |
333 std::string boundary = "--" + contentType.substr(multipartLength); | |
334 | |
335 std::string postData; | |
416 | 336 PostDataStatus status = ReadBody(postData, connection, headers); |
0 | 337 |
338 if (status != PostDataStatus_Success) | |
339 { | |
340 return status; | |
341 } | |
342 | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
343 /*for (IHttpHandler::Arguments::const_iterator i = headers.begin(); i != headers.end(); i++) |
0 | 344 { |
345 std::cout << "Header [" << i->first << "] = " << i->second << "\n"; | |
346 } | |
347 printf("CHUNK\n");*/ | |
348 | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
349 typedef IHttpHandler::Arguments::const_iterator ArgumentIterator; |
0 | 350 |
351 ArgumentIterator requestedWith = headers.find("x-requested-with"); | |
352 ArgumentIterator fileName = headers.find("x-file-name"); | |
353 ArgumentIterator fileSizeStr = headers.find("x-file-size"); | |
354 | |
338
3a3b3ba8c1e0
fix for uploads through internet explorer 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
333
diff
changeset
|
355 if (requestedWith != headers.end() && |
0 | 356 requestedWith->second != "XMLHttpRequest") |
357 { | |
358 return PostDataStatus_Failure; | |
359 } | |
360 | |
361 size_t fileSize = 0; | |
362 if (fileSizeStr != headers.end()) | |
363 { | |
364 try | |
365 { | |
366 fileSize = boost::lexical_cast<size_t>(fileSizeStr->second); | |
367 } | |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2790
diff
changeset
|
368 catch (boost::bad_lexical_cast&) |
0 | 369 { |
370 return PostDataStatus_Failure; | |
371 } | |
372 } | |
373 | |
374 typedef boost::find_iterator<std::string::iterator> FindIterator; | |
10 | 375 typedef boost::iterator_range<char*> Range; |
0 | 376 |
377 //chunkStore.Print(); | |
378 | |
379 try | |
380 { | |
381 FindIterator last; | |
382 for (FindIterator it = | |
383 make_find_iterator(postData, boost::first_finder(boundary)); | |
384 it!=FindIterator(); | |
385 ++it) | |
386 { | |
387 if (last != FindIterator()) | |
388 { | |
10 | 389 Range part(&last->back(), &it->front()); |
0 | 390 Range content = boost::find_first(part, "\r\n\r\n"); |
345 | 391 if (/*content != Range()*/!content.empty()) |
0 | 392 { |
393 Range c(&content.back() + 1, &it->front() - 2); | |
394 size_t chunkSize = c.size(); | |
395 | |
396 if (chunkSize > 0) | |
397 { | |
398 const char* chunkData = &c.front(); | |
399 | |
400 if (fileName == headers.end()) | |
401 { | |
402 // This file is stored in a single chunk | |
403 completedFile.resize(chunkSize); | |
404 if (chunkSize > 0) | |
405 { | |
406 memcpy(&completedFile[0], chunkData, chunkSize); | |
407 } | |
408 return PostDataStatus_Success; | |
409 } | |
410 else | |
411 { | |
412 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize); | |
413 } | |
414 } | |
10 | 415 } |
0 | 416 } |
417 | |
418 last = it; | |
419 } | |
420 } | |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2790
diff
changeset
|
421 catch (std::length_error&) |
0 | 422 { |
423 return PostDataStatus_Failure; | |
424 } | |
425 | |
426 return PostDataStatus_Pending; | |
427 } | |
428 | |
429 | |
1202
476a17cfdf42
Fix crash when bad HTTP credentials are provided
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1122
diff
changeset
|
430 static bool IsAccessGranted(const MongooseServer& that, |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
431 const IHttpHandler::Arguments& headers) |
23 | 432 { |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
433 bool granted = false; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
434 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
435 IHttpHandler::Arguments::const_iterator auth = headers.find("authorization"); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
436 if (auth != headers.end()) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
437 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
438 std::string s = auth->second; |
1213 | 439 if (s.size() > 6 && |
440 s.substr(0, 6) == "Basic ") | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
441 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
442 std::string b64 = s.substr(6); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
443 granted = that.IsValidBasicHttpAuthentication(b64); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
444 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
445 } |
23 | 446 |
1202
476a17cfdf42
Fix crash when bad HTTP credentials are provided
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1122
diff
changeset
|
447 return granted; |
23 | 448 } |
449 | |
450 | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
451 static std::string GetAuthenticatedUsername(const IHttpHandler::Arguments& headers) |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
452 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
453 IHttpHandler::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
|
454 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
455 if (auth == headers.end()) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
456 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
457 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
458 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
459 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
460 std::string s = auth->second; |
1213 | 461 if (s.size() <= 6 || |
462 s.substr(0, 6) != "Basic ") | |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
463 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
464 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
465 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
466 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
467 std::string b64 = s.substr(6); |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
468 std::string decoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
469 Toolbox::DecodeBase64(decoded, b64); |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
470 size_t semicolons = decoded.find(':'); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
471 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
472 if (semicolons == std::string::npos) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
473 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
474 // Bad-formatted request |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
475 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
476 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
477 else |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
478 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
479 return decoded.substr(0, semicolons); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
480 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
481 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
482 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
483 |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
484 static bool ExtractMethod(HttpMethod& method, |
414 | 485 const struct mg_request_info *request, |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
486 const IHttpHandler::Arguments& headers, |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
487 const IHttpHandler::GetArguments& argumentsGET) |
414 | 488 { |
489 std::string overriden; | |
490 | |
491 // Check whether some PUT/DELETE faking is done | |
492 | |
493 // 1. Faking with Google's approach | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
494 IHttpHandler::Arguments::const_iterator methodOverride = |
414 | 495 headers.find("x-http-method-override"); |
496 | |
497 if (methodOverride != headers.end()) | |
498 { | |
499 overriden = methodOverride->second; | |
500 } | |
501 else if (!strcmp(request->request_method, "GET")) | |
502 { | |
503 // 2. Faking with Ruby on Rail's approach | |
504 // 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
|
505 for (size_t i = 0; i < argumentsGET.size(); i++) |
414 | 506 { |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
507 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
|
508 { |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
509 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
|
510 break; |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
511 } |
414 | 512 } |
513 } | |
514 | |
515 if (overriden.size() > 0) | |
516 { | |
517 // A faking has been done within this request | |
518 Toolbox::ToUpperCase(overriden); | |
519 | |
416 | 520 LOG(INFO) << "HTTP method faking has been detected for " << overriden; |
521 | |
414 | 522 if (overriden == "PUT") |
523 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
524 method = HttpMethod_Put; |
416 | 525 return true; |
414 | 526 } |
527 else if (overriden == "DELETE") | |
528 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
529 method = HttpMethod_Delete; |
416 | 530 return true; |
414 | 531 } |
532 else | |
533 { | |
534 return false; | |
535 } | |
536 } | |
537 | |
538 // No PUT/DELETE faking was present | |
539 if (!strcmp(request->request_method, "GET")) | |
540 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
541 method = HttpMethod_Get; |
414 | 542 } |
543 else if (!strcmp(request->request_method, "POST")) | |
544 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
545 method = HttpMethod_Post; |
414 | 546 } |
547 else if (!strcmp(request->request_method, "DELETE")) | |
548 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
549 method = HttpMethod_Delete; |
414 | 550 } |
551 else if (!strcmp(request->request_method, "PUT")) | |
552 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
553 method = HttpMethod_Put; |
414 | 554 } |
555 else | |
556 { | |
557 return false; | |
558 } | |
559 | |
560 return true; | |
561 } | |
562 | |
563 | |
1517 | 564 static void ConfigureHttpCompression(HttpOutput& output, |
565 const IHttpHandler::Arguments& headers) | |
566 { | |
567 // Look if the client wishes HTTP compression | |
568 // https://en.wikipedia.org/wiki/HTTP_compression | |
569 IHttpHandler::Arguments::const_iterator it = headers.find("accept-encoding"); | |
570 if (it != headers.end()) | |
571 { | |
572 std::vector<std::string> encodings; | |
573 Toolbox::TokenizeString(encodings, it->second, ','); | |
574 | |
575 for (size_t i = 0; i < encodings.size(); i++) | |
576 { | |
577 std::string s = Toolbox::StripSpaces(encodings[i]); | |
578 | |
579 if (s == "deflate") | |
580 { | |
581 output.SetDeflateAllowed(true); | |
582 } | |
583 else if (s == "gzip") | |
584 { | |
585 output.SetGzipAllowed(true); | |
586 } | |
587 } | |
588 } | |
589 } | |
590 | |
591 | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
592 static void InternalCallback(HttpOutput& output /* out */, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
593 HttpMethod& method /* out */, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
594 MongooseServer& server, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
595 struct mg_connection *connection, |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
596 const struct mg_request_info *request) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
597 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
598 bool localhost; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
599 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
600 #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
|
601 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
|
602 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
|
603 #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
|
604 // 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
|
605 // 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
|
606 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
|
607 #else |
3069 | 608 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
609 #endif |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
610 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
611 // Check remote calls |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
612 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
|
613 !localhost) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
614 { |
2790
c7313e1f7644
MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2635
diff
changeset
|
615 output.SendUnauthorized(server.GetRealm()); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
616 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
617 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
618 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
619 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
620 // Extract the HTTP headers |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
621 IHttpHandler::Arguments headers; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
622 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
|
623 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
624 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
|
625 std::string value = request->http_headers[i].value; |
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
626 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
627 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
|
628 headers.insert(std::make_pair(name, value)); |
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
629 VLOG(1) << "HTTP header: [" << name << "]: [" << value << "]"; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
630 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
631 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
632 if (server.IsHttpCompressionEnabled()) |
1517 | 633 { |
634 ConfigureHttpCompression(output, headers); | |
635 } | |
636 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
637 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
638 // Extract the GET arguments |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
639 IHttpHandler::GetArguments argumentsGET; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
640 if (!strcmp(request->request_method, "GET")) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
641 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
642 HttpToolbox::ParseGetArguments(argumentsGET, request->query_string); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
643 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
644 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
645 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
646 // Compute the HTTP method, taking method faking into consideration |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
647 method = HttpMethod_Get; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
648 if (!ExtractMethod(method, request, headers, argumentsGET)) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
649 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1112
diff
changeset
|
650 output.SendStatus(HttpStatus_400_BadRequest); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
651 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
652 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
653 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
654 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
655 // Authenticate this connection |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
656 if (server.IsAuthenticationEnabled() && |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
657 !IsAccessGranted(server, headers)) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
658 { |
2790
c7313e1f7644
MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2635
diff
changeset
|
659 output.SendUnauthorized(server.GetRealm()); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
660 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
661 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
662 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
663 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
664 #if ORTHANC_ENABLE_MONGOOSE == 1 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
665 // 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
|
666 char remoteIp[24]; |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
673 const char* requestUri = request->uri; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
674 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
675 #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
|
676 const char* remoteIp = request->remote_addr; |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
677 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
|
678 #else |
3069 | 679 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
680 #endif |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
681 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
682 if (requestUri == NULL) |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
683 { |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
684 requestUri = ""; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
685 } |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
686 |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
687 std::string username = GetAuthenticatedUsername(headers); |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
688 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
689 IIncomingHttpRequestFilter *filter = server.GetIncomingHttpRequestFilter(); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
690 if (filter != NULL) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
691 { |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
692 if (!filter->IsAllowed(method, requestUri, remoteIp, |
2268
ce5c13b95dac
New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
693 username.c_str(), headers, argumentsGET)) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
694 { |
2790
c7313e1f7644
MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2635
diff
changeset
|
695 //output.SendUnauthorized(server.GetRealm()); |
1963
af0c90ae0915
Use 403 Forbidden status if the incoming HTTP request is disallowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
696 output.SendStatus(HttpStatus_403_Forbidden); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
697 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
698 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
699 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
700 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
701 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
702 // Extract the body of the request for PUT and POST |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
703 |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
704 // 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
|
705 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
706 std::string body; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
707 if (method == HttpMethod_Post || |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
708 method == HttpMethod_Put) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
709 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
710 PostDataStatus status; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
711 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
712 IHttpHandler::Arguments::const_iterator ct = headers.find("content-type"); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
713 if (ct == headers.end()) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
714 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
715 // No content-type specified. Assume no multi-part content occurs at this point. |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
716 status = ReadBody(body, connection, headers); |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
717 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
718 else |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
719 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
720 std::string contentType = ct->second; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
721 if (contentType.size() >= multipartLength && |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
722 !memcmp(contentType.c_str(), multipart, multipartLength)) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
723 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
724 status = ParseMultipartPost(body, connection, headers, contentType, server.GetChunkStore()); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
725 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
726 else |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
727 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
728 status = ReadBody(body, connection, headers); |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
729 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
730 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
731 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
732 switch (status) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
733 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
734 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
|
735 output.SendStatus(HttpStatus_411_LengthRequired); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
736 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
737 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
738 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
|
739 output.SendStatus(HttpStatus_400_BadRequest); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
740 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
741 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
742 case PostDataStatus_Pending: |
1521 | 743 output.AnswerEmpty(); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
744 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
745 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
746 default: |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
747 break; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
748 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
749 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
750 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
751 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
752 // Decompose the URI into its components |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
753 UriComponents uri; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
754 try |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
755 { |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
756 Toolbox::SplitUriComponents(uri, requestUri); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
757 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
758 catch (OrthancException&) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
759 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1112
diff
changeset
|
760 output.SendStatus(HttpStatus_400_BadRequest); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
761 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
762 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
763 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
764 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
765 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
766 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
767 bool found = false; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
768 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
769 if (server.HasHandler()) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
770 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
771 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
|
772 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
|
773 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
774 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
775 if (!found) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
776 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
777 throw OrthancException(ErrorCode_UnknownResource); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
778 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
779 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
780 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
781 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
782 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
|
783 const struct mg_request_info *request) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
784 { |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
785 try |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
786 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
787 #if ORTHANC_ENABLE_MONGOOSE == 1 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
788 void *that = request->user_data; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
789 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
|
790 #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
|
791 // 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
|
792 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
|
793 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
|
794 #else |
3069 | 795 # error |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
796 #endif |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
797 |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
798 if (requestUri == NULL) |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
799 { |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
800 requestUri = ""; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
801 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
802 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
803 MongooseServer* server = reinterpret_cast<MongooseServer*>(that); |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
804 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
805 if (server == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
806 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
807 MongooseOutputStream stream(connection); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
808 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
|
809 output.SendStatus(HttpStatus_500_InternalServerError); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
810 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
811 } |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
812 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
813 MongooseOutputStream stream(connection); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
814 HttpOutput output(stream, server->IsKeepAliveEnabled()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
815 HttpMethod method = HttpMethod_Get; |
1569 | 816 |
817 try | |
1570 | 818 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
819 try |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
820 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
821 InternalCallback(output, method, *server, connection, request); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
822 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
823 catch (OrthancException&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
824 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
825 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
|
826 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
827 // Now convert native exceptions as OrthancException |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
828 catch (boost::bad_lexical_cast&) |
1570 | 829 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
830 throw OrthancException(ErrorCode_BadParameterType, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
831 "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
|
832 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
833 catch (std::runtime_error&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
834 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
835 // Presumably an error while parsing the JSON body |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
836 throw OrthancException(ErrorCode_BadRequest); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
837 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
838 catch (std::bad_alloc&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
839 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
840 throw OrthancException(ErrorCode_NotEnoughMemory, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
841 "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
|
842 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
843 catch (...) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
844 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
845 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
846 "An unhandled exception was generated inside the HTTP server"); |
1570 | 847 } |
848 } | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
849 catch (OrthancException& e) |
1570 | 850 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
851 assert(server != NULL); |
1569 | 852 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
853 // 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
|
854 try |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
855 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
856 if (server->GetExceptionFormatter() == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
857 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
858 LOG(ERROR) << "Exception in the HTTP handler: " << e.What(); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
859 output.SendStatus(e.GetHttpStatus()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
860 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
861 else |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
862 { |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
863 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
|
864 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
865 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
866 catch (OrthancException&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
867 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
868 // 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
|
869 // 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
|
870 } |
1570 | 871 } |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
872 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
873 catch (...) |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
874 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
875 // We should never arrive at this point, where it is even impossible to send an answer |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
876 LOG(ERROR) << "Catastrophic error inside the HTTP server, giving up"; |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
877 } |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
878 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
879 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
880 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
881 #if MONGOOSE_USE_CALLBACKS == 0 |
0 | 882 static void* Callback(enum mg_event event, |
883 struct mg_connection *connection, | |
884 const struct mg_request_info *request) | |
885 { | |
886 if (event == MG_NEW_REQUEST) | |
887 { | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
888 ProtectedCallback(connection, request); |
0 | 889 |
890 // Mark as processed | |
891 return (void*) ""; | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
892 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
893 else |
0 | 894 { |
895 return NULL; | |
896 } | |
897 } | |
898 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
899 #elif MONGOOSE_USE_CALLBACKS == 1 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
900 static int Callback(struct mg_connection *connection) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
901 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
902 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
|
903 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
904 ProtectedCallback(connection, request); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
905 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
906 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
|
907 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
908 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
909 #else |
3069 | 910 # error Please set MONGOOSE_USE_CALLBACKS |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
911 #endif |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
912 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
913 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
914 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
915 |
0 | 916 |
917 bool MongooseServer::IsRunning() const | |
918 { | |
919 return (pimpl_->context_ != NULL); | |
920 } | |
921 | |
922 | |
923 MongooseServer::MongooseServer() : pimpl_(new PImpl) | |
924 { | |
925 pimpl_->context_ = NULL; | |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
926 handler_ = NULL; |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
927 remoteAllowed_ = false; |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
928 authentication_ = false; |
23 | 929 ssl_ = false; |
0 | 930 port_ = 8000; |
417 | 931 filter_ = NULL; |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
932 keepAlive_ = false; |
1517 | 933 httpCompression_ = true; |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
934 exceptionFormatter_ = NULL; |
2790
c7313e1f7644
MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2635
diff
changeset
|
935 realm_ = ORTHANC_REALM; |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
936 threadsCount_ = 50; // Default value in mongoose |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
937 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
938 #if ORTHANC_ENABLE_SSL == 1 |
749 | 939 // 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
|
940 // 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
|
941 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
|
942 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
|
943 { |
749 | 944 LOG(WARNING) << "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
|
945 } |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
946 #endif |
0 | 947 } |
948 | |
949 | |
950 MongooseServer::~MongooseServer() | |
951 { | |
952 Stop(); | |
953 } | |
954 | |
955 | |
128 | 956 void MongooseServer::SetPortNumber(uint16_t port) |
0 | 957 { |
958 Stop(); | |
959 port_ = port; | |
960 } | |
961 | |
962 void MongooseServer::Start() | |
963 { | |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
964 #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
|
965 LOG(INFO) << "Starting embedded Web server using Mongoose"; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
966 #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
|
967 LOG(INFO) << "Starting embedded Web server using Civetweb"; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
968 #else |
3069 | 969 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
970 #endif |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
971 |
0 | 972 if (!IsRunning()) |
973 { | |
974 std::string port = boost::lexical_cast<std::string>(port_); | |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
975 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_); |
0 | 976 |
23 | 977 if (ssl_) |
978 { | |
979 port += "s"; | |
980 } | |
981 | |
0 | 982 const char *options[] = { |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
983 // Set the TCP port for the HTTP server |
0 | 984 "listening_ports", port.c_str(), |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
985 |
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
986 // Optimization reported by Chris Hafey |
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
987 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
988 "enable_keep_alive", (keepAlive_ ? "yes" : "no"), |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
989 |
2579 | 990 #if ORTHANC_ENABLE_CIVETWEB == 1 |
2577
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
991 // https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no |
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
992 "keep_alive_timeout_ms", (keepAlive_ ? "500" : "0"), |
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
993 #endif |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
994 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
995 // Set the number of threads |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
996 "num_threads", numThreads.c_str(), |
2577
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
997 |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
998 // Set the SSL certificate, if any. This must be the last option. |
23 | 999 ssl_ ? "ssl_certificate" : NULL, |
1000 certificate_.c_str(), | |
0 | 1001 NULL |
1002 }; | |
1003 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1004 #if MONGOOSE_USE_CALLBACKS == 0 |
0 | 1005 pimpl_->context_ = mg_start(&Callback, this, options); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1006 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1007 #elif MONGOOSE_USE_CALLBACKS == 1 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1008 struct mg_callbacks callbacks; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1009 memset(&callbacks, 0, sizeof(callbacks)); |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1010 callbacks.begin_request = Callback; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1011 pimpl_->context_ = mg_start(&callbacks, this, options); |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1012 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1013 #else |
3069 | 1014 # error Please set MONGOOSE_USE_CALLBACKS |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1015 #endif |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1016 |
0 | 1017 if (!pimpl_->context_) |
1018 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
1019 throw OrthancException(ErrorCode_HttpPortInUse); |
0 | 1020 } |
2633
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1021 |
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1022 LOG(WARNING) << "HTTP server listening on port: " << GetPortNumber() |
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1023 << " (HTTPS encryption is " |
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1024 << (IsSslEnabled() ? "enabled" : "disabled") |
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1025 << ", remote access is " |
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1026 << (IsRemoteAccessAllowed() ? "" : "not ") |
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1027 << "allowed)"; |
0 | 1028 } |
1029 } | |
1030 | |
1031 void MongooseServer::Stop() | |
1032 { | |
1033 if (IsRunning()) | |
1034 { | |
1035 mg_stop(pimpl_->context_); | |
1036 pimpl_->context_ = NULL; | |
1037 } | |
1038 } | |
1039 | |
1040 | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1041 void MongooseServer::ClearUsers() |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1042 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1043 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1044 registeredUsers_.clear(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1045 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1046 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1047 |
23 | 1048 void MongooseServer::RegisterUser(const char* username, |
1049 const char* password) | |
1050 { | |
1051 Stop(); | |
24 | 1052 |
1053 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
|
1054 std::string encoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1055 Toolbox::EncodeBase64(encoded, tag); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1056 registeredUsers_.insert(encoded); |
23 | 1057 } |
1058 | |
1059 void MongooseServer::SetSslEnabled(bool enabled) | |
1060 { | |
1061 Stop(); | |
1062 | |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
1063 #if ORTHANC_ENABLE_SSL == 0 |
23 | 1064 if (enabled) |
1065 { | |
1674
4fc502d469f4
fix build if SSL is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1649
diff
changeset
|
1066 throw OrthancException(ErrorCode_SslDisabled); |
23 | 1067 } |
1068 else | |
1069 { | |
1070 ssl_ = false; | |
1071 } | |
1072 #else | |
1073 ssl_ = enabled; | |
1074 #endif | |
1075 } | |
1076 | |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1077 |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1078 void MongooseServer::SetKeepAliveEnabled(bool enabled) |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1079 { |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1080 Stop(); |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1081 keepAlive_ = enabled; |
2069
fabf7820d1f1
New configuration options: "DicomScuTimeout" and "DicomScpTimeout" + validation of non-negative options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1082 LOG(INFO) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled"); |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1083 } |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1084 |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1085 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1086 void MongooseServer::SetAuthenticationEnabled(bool enabled) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1087 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1088 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1089 authentication_ = enabled; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1090 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1091 |
23 | 1092 void MongooseServer::SetSslCertificate(const char* path) |
1093 { | |
1094 Stop(); | |
1095 certificate_ = path; | |
1096 } | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1097 |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1098 void MongooseServer::SetRemoteAccessAllowed(bool allowed) |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1099 { |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1100 Stop(); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1101 remoteAllowed_ = allowed; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1102 } |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1103 |
1517 | 1104 void MongooseServer::SetHttpCompressionEnabled(bool enabled) |
1105 { | |
1106 Stop(); | |
1107 httpCompression_ = enabled; | |
1518 | 1108 LOG(WARNING) << "HTTP compression is " << (enabled ? "enabled" : "disabled"); |
1517 | 1109 } |
1592
d73124f6b439
configuration option HttpDescribeErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
1110 |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1111 void MongooseServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1112 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1113 Stop(); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1114 filter_ = &filter; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
1115 } |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
1116 |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1117 |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1118 void MongooseServer::SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter) |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1119 { |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1120 Stop(); |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1121 exceptionFormatter_ = &formatter; |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1122 } |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1123 |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
1124 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1125 bool MongooseServer::IsValidBasicHttpAuthentication(const std::string& basic) const |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1126 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1127 return registeredUsers_.find(basic) != registeredUsers_.end(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1128 } |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1129 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1130 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1131 void MongooseServer::Register(IHttpHandler& handler) |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1132 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1133 Stop(); |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1134 handler_ = &handler; |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1135 } |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1136 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1137 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1138 IHttpHandler& MongooseServer::GetHandler() const |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1139 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1140 if (handler_ == NULL) |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1141 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1142 throw OrthancException(ErrorCode_InternalError); |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1143 } |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1144 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1145 return *handler_; |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1146 } |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1147 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1148 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1149 void MongooseServer::SetThreadsCount(unsigned int threads) |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1150 { |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1151 if (threads <= 0) |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1152 { |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1153 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1154 } |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1155 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1156 Stop(); |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1157 threadsCount_ = threads; |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1158 } |
0 | 1159 } |