annotate OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 4706:dbee8bd8ee1f

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