annotate OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 4544:ae63b301d522 Orthanc-1.7.4

close branch
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Mar 2021 16:52:26 +0100
parents 2d5209153b32
children 7bd5eab3ba25
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3537
diff changeset
5 * Copyright (C) 2017-2020 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"
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
34
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
35 #if ORTHANC_ENABLE_MONGOOSE == 1
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
36 # 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
37
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
38 #elif ORTHANC_ENABLE_CIVETWEB == 1
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
39 # 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
40 # 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
41 # 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
42 # 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
43 # endif
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 #else
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
46 # 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
47 #endif
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
48
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #include <algorithm>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 #include <boost/algorithm/string.hpp>
3672
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
53 #include <boost/filesystem.hpp>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 #include <iostream>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 #include <stdio.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 #include <boost/thread.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
2137
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
59 #if !defined(ORTHANC_ENABLE_SSL)
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
60 # error The macro ORTHANC_ENABLE_SSL must be defined
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
61 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
62
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
63 #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
64 # 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
65 # 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
66 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
68 #define ORTHANC_REALM "Orthanc Secure Area"
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
69
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
70
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
71 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
73 static const char MULTIPART_FORM[] = "multipart/form-data; boundary=";
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
74 static unsigned int MULTIPART_FORM_LENGTH = sizeof(MULTIPART_FORM) / sizeof(char) - 1;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 namespace
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 // Anonymous namespace to avoid clashes between compilation modules
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
80 class MongooseOutputStream : public IHttpOutputStream
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 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 struct mg_connection* connection_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
85 public:
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
86 explicit MongooseOutputStream(struct mg_connection* connection) :
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
87 connection_(connection)
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
88 {
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
89 }
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
90
909
ef71057d8b26 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
91 virtual void Send(bool isHeader, const void* buffer, size_t length)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
93 if (length > 0)
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
94 {
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
95 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
96 if (status != static_cast<int>(length))
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
97 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
98 // 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
99 throw OrthancException(ErrorCode_NetworkProtocol);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
100 }
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
101 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 901
diff changeset
103
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
104 virtual void OnHttpStatusReceived(HttpStatus status)
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 901
diff changeset
105 {
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
106 // Ignore this
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 901
diff changeset
107 }
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
108
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
109 virtual void DisableKeepAlive()
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
110 {
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
111 #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
112 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
113 "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
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 #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
116 # if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
117 mg_disable_keep_alive(connection_);
3178
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
118 # else
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
119 # warning The function "mg_disable_keep_alive()" is not available, DICOMweb might run slowly
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
120 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
121 "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
122 # endif
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
123
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
124 #else
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
125 # 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
126 #endif
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
127 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 enum PostDataStatus
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 PostDataStatus_Success,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 PostDataStatus_NoLength,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 PostDataStatus_Pending,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 PostDataStatus_Failure
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 // TODO Move this to external file
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 class ChunkedFile : public ChunkedBuffer
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 std::string filename_;
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 public:
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
150 explicit ChunkedFile(const std::string& filename) :
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 filename_(filename)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 const std::string& GetFilename() const
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 return filename_;
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 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
3836
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3801
diff changeset
163 class ChunkStore : public boost::noncopyable
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 typedef std::list<ChunkedFile*> Content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 Content content_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 unsigned int numPlaces_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 boost::mutex mutex_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 std::set<std::string> discardedFiles_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 void Clear()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 for (Content::iterator it = content_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
176 it != content_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 delete *it;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 Content::iterator Find(const std::string& filename)
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 for (Content::iterator it = content_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
185 it != content_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 if ((*it)->GetFilename() == filename)
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 return it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 return content_.end();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 void Remove(const std::string& filename)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 Content::iterator it = Find(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 if (it != content_.end())
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 delete *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 content_.erase(it);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
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 public:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 ChunkStore()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 numPlaces_ = 10;
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 ~ChunkStore()
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 Clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
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 PostDataStatus Store(std::string& completed,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 const char* chunkData,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 size_t chunkSize,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 const std::string& filename,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 size_t filesize)
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 boost::mutex::scoped_lock lock(mutex_);
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 std::set<std::string>::iterator wasDiscarded = discardedFiles_.find(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 if (wasDiscarded != discardedFiles_.end())
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 discardedFiles_.erase(wasDiscarded);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 return PostDataStatus_Failure;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 ChunkedFile* f;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 Content::iterator it = Find(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 if (it == content_.end())
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 f = new ChunkedFile(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 // Make some room
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 if (content_.size() >= numPlaces_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 discardedFiles_.insert(content_.front()->GetFilename());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 delete content_.front();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 content_.pop_front();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 content_.push_back(f);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 else
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 f = *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 f->AddChunk(chunkData, chunkSize);
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 if (f->GetNumBytes() > filesize)
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 Remove(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 else if (f->GetNumBytes() == filesize)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 f->Flatten(completed);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 Remove(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 return PostDataStatus_Success;
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 return PostDataStatus_Pending;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
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 /*void Print()
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 boost::mutex::scoped_lock lock(mutex_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 printf("ChunkStore status:\n");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 for (Content::const_iterator i = content_.begin();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 i != content_.end(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 printf(" [%s]: %d\n", (*i)->GetFilename().c_str(), (*i)->GetNumBytes());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 printf("-----\n");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }*/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
284 struct HttpServer::PImpl
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 struct mg_context *context_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 ChunkStore chunkStore_;
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
288
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
289 PImpl() :
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
290 context_(NULL)
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
291 {
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
292 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
296 ChunkStore& HttpServer::GetChunkStore()
0
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 return pimpl_->chunkStore_;
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
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
302 static PostDataStatus ReadBodyWithContentLength(std::string& body,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
303 struct mg_connection *connection,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
304 const std::string& contentLength)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
4152
36257d6f348f Support of multipart messages larger than 2GB in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
306 size_t length;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
307 try
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
308 {
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
309 int64_t tmp = boost::lexical_cast<int64_t>(contentLength);
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
310 if (tmp < 0)
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
311 {
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
312 return PostDataStatus_NoLength;
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
313 }
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
314
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
315 length = static_cast<size_t>(tmp);
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
316 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
317 catch (boost::bad_lexical_cast&)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
318 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
319 return PostDataStatus_NoLength;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
320 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
321
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
322 body.resize(length);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
323
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
324 size_t pos = 0;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
325 while (length > 0)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
327 int r = mg_read(connection, &body[pos], length);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
328 if (r <= 0)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
329 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
330 return PostDataStatus_Failure;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
331 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
332
4152
36257d6f348f Support of multipart messages larger than 2GB in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
333 assert(static_cast<size_t>(r) <= length);
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
334 length -= r;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
335 pos += r;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
336 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
337
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
338 return PostDataStatus_Success;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
339 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
340
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
341
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
342 static PostDataStatus ReadBodyToString(std::string& body,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
343 struct mg_connection *connection,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
344 const IHttpHandler::Arguments& headers)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
345 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
346 IHttpHandler::Arguments::const_iterator contentLength = headers.find("content-length");
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
347
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
348 if (contentLength != headers.end())
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
349 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
350 // "Content-Length" is available
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
351 return ReadBodyWithContentLength(body, connection, contentLength->second);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
352 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
353 else
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
354 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
355 // No Content-Length. Store the individual chunks in a temporary
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
356 // file, then read it back into the memory buffer "body"
3357
c0aa5f1cf2f5 new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3356
diff changeset
357 FileBuffer buffer;
c0aa5f1cf2f5 new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3356
diff changeset
358
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
359 std::string tmp(1024 * 1024, 0);
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
360
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
361 for (;;)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 {
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
363 int r = mg_read(connection, &tmp[0], tmp.size());
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
364 if (r < 0)
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
365 {
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
366 return PostDataStatus_Failure;
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
367 }
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
368 else if (r == 0)
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
369 {
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
370 break;
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
371 }
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
372 else
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
373 {
3357
c0aa5f1cf2f5 new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3356
diff changeset
374 buffer.Append(tmp.c_str(), r);
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
375 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
418
b79bf2f4ab2e execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
377
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
378 buffer.Read(body);
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
379
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
380 return PostDataStatus_Success;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
382 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
383
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
384
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
385 static PostDataStatus ReadBodyToStream(IHttpHandler::IChunkedRequestReader& stream,
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
386 struct mg_connection *connection,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
387 const IHttpHandler::Arguments& headers)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
388 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
389 IHttpHandler::Arguments::const_iterator contentLength = headers.find("content-length");
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
390
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
391 if (contentLength != headers.end())
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
392 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
393 // "Content-Length" is available
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
394 std::string body;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
395 PostDataStatus status = ReadBodyWithContentLength(body, connection, contentLength->second);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
396
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
397 if (status == PostDataStatus_Success &&
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
398 !body.empty())
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
399 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
400 stream.AddBodyChunk(body.c_str(), body.size());
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
401 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
402
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
403 return status;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
404 }
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
405 else
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
406 {
3404
e280ced38a4c ErrorCode_UnsupportedMediaType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3395
diff changeset
407 // 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
408 std::string tmp(1024 * 1024, 0);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
409
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
410 for (;;)
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
411 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
412 int r = mg_read(connection, &tmp[0], tmp.size());
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
413 if (r < 0)
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
414 {
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
415 return PostDataStatus_Failure;
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
416 }
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
417 else if (r == 0)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
418 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
419 break;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
420 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
421 else
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
422 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
423 stream.AddBodyChunk(tmp.c_str(), r);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
424 }
3356
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
425 }
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
426
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
427 return PostDataStatus_Success;
f744730c294b Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3330
diff changeset
428 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
432 static PostDataStatus ParseMultipartForm(std::string &completedFile,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 struct mg_connection *connection,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
434 const IHttpHandler::Arguments& headers,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 const std::string& contentType,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 ChunkStore& chunkStore)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
438 std::string boundary = "--" + contentType.substr(MULTIPART_FORM_LENGTH);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
440 std::string body;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
441 PostDataStatus status = ReadBodyToString(body, connection, headers);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 if (status != PostDataStatus_Success)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 return status;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
448 /*for (IHttpHandler::Arguments::const_iterator i = headers.begin(); i != headers.end(); i++)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 std::cout << "Header [" << i->first << "] = " << i->second << "\n";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 printf("CHUNK\n");*/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
454 typedef IHttpHandler::Arguments::const_iterator ArgumentIterator;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 ArgumentIterator requestedWith = headers.find("x-requested-with");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 ArgumentIterator fileName = headers.find("x-file-name");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 ArgumentIterator fileSizeStr = headers.find("x-file-size");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
338
3a3b3ba8c1e0 fix for uploads through internet explorer 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 333
diff changeset
460 if (requestedWith != headers.end() &&
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 requestedWith->second != "XMLHttpRequest")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 size_t fileSize = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 if (fileSizeStr != headers.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 fileSize = boost::lexical_cast<size_t>(fileSizeStr->second);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2790
diff changeset
473 catch (boost::bad_lexical_cast&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 typedef boost::find_iterator<std::string::iterator> FindIterator;
10
27e2bbc11200 Better signal handling
Administrator@jodogne-w01
parents: 8
diff changeset
480 typedef boost::iterator_range<char*> Range;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 //chunkStore.Print();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483
3445
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
484 // TODO - Refactor using class "MultipartStreamReader"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 FindIterator last;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 for (FindIterator it =
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
489 make_find_iterator(body, boost::first_finder(boundary));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 it!=FindIterator();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 ++it)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 if (last != FindIterator())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 {
10
27e2bbc11200 Better signal handling
Administrator@jodogne-w01
parents: 8
diff changeset
495 Range part(&last->back(), &it->front());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 Range content = boost::find_first(part, "\r\n\r\n");
345
jodogne
parents: 338
diff changeset
497 if (/*content != Range()*/!content.empty())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 Range c(&content.back() + 1, &it->front() - 2);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 size_t chunkSize = c.size();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 if (chunkSize > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 const char* chunkData = &c.front();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 if (fileName == headers.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 // This file is stored in a single chunk
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 completedFile.resize(chunkSize);
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
510 memcpy(&completedFile[0], chunkData, chunkSize);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 return PostDataStatus_Success;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 }
10
27e2bbc11200 Better signal handling
Administrator@jodogne-w01
parents: 8
diff changeset
518 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 last = it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2790
diff changeset
524 catch (std::length_error&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 return PostDataStatus_Pending;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
533 static bool IsAccessGranted(const HttpServer& that,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
534 const IHttpHandler::Arguments& headers)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
535 {
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
536 bool granted = false;
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
537
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
538 IHttpHandler::Arguments::const_iterator auth = headers.find("authorization");
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
539 if (auth != headers.end())
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
540 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
541 std::string s = auth->second;
1213
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
542 if (s.size() > 6 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
543 s.substr(0, 6) == "Basic ")
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
544 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
545 std::string b64 = s.substr(6);
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
546 granted = that.IsValidBasicHttpAuthentication(b64);
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
547 }
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
548 }
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
549
1202
476a17cfdf42 Fix crash when bad HTTP credentials are provided
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
550 return granted;
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
551 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
552
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
553
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
554 static std::string GetAuthenticatedUsername(const IHttpHandler::Arguments& headers)
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
555 {
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
556 IHttpHandler::Arguments::const_iterator auth = headers.find("authorization");
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
557
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
558 if (auth == headers.end())
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
559 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
560 return "";
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
561 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
562
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
563 std::string s = auth->second;
1213
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
564 if (s.size() <= 6 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
565 s.substr(0, 6) != "Basic ")
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
566 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
567 return "";
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
568 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
569
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
570 std::string b64 = s.substr(6);
809
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
571 std::string decoded;
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
572 Toolbox::DecodeBase64(decoded, b64);
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
573 size_t semicolons = decoded.find(':');
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
574
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
575 if (semicolons == std::string::npos)
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
576 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
577 // Bad-formatted request
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
578 return "";
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
579 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
580 else
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
581 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
582 return decoded.substr(0, semicolons);
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
583 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
584 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
585
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
586
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
587 static bool ExtractMethod(HttpMethod& method,
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
588 const struct mg_request_info *request,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
589 const IHttpHandler::Arguments& headers,
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
590 const IHttpHandler::GetArguments& argumentsGET)
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
591 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
592 std::string overriden;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
593
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
594 // Check whether some PUT/DELETE faking is done
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
595
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
596 // 1. Faking with Google's approach
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
597 IHttpHandler::Arguments::const_iterator methodOverride =
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
598 headers.find("x-http-method-override");
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
599
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
600 if (methodOverride != headers.end())
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
601 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
602 overriden = methodOverride->second;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
603 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
604 else if (!strcmp(request->request_method, "GET"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
605 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
606 // 2. Faking with Ruby on Rail's approach
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
607 // 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
608 for (size_t i = 0; i < argumentsGET.size(); i++)
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
609 {
1363
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
610 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
611 {
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
612 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
613 break;
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
614 }
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
615 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
616 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
617
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
618 if (overriden.size() > 0)
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
619 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
620 // A faking has been done within this request
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
621 Toolbox::ToUpperCase(overriden);
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
622
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
623 LOG(INFO) << "HTTP method faking has been detected for " << overriden;
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
624
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
625 if (overriden == "PUT")
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
626 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
627 method = HttpMethod_Put;
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
628 return true;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
629 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
630 else if (overriden == "DELETE")
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
631 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
632 method = HttpMethod_Delete;
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
633 return true;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
634 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
635 else
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
636 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
637 return false;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
638 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
639 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
640
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
641 // No PUT/DELETE faking was present
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
642 if (!strcmp(request->request_method, "GET"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
643 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
644 method = HttpMethod_Get;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
645 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
646 else if (!strcmp(request->request_method, "POST"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
647 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
648 method = HttpMethod_Post;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
649 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
650 else if (!strcmp(request->request_method, "DELETE"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
651 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
652 method = HttpMethod_Delete;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
653 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
654 else if (!strcmp(request->request_method, "PUT"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
655 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
656 method = HttpMethod_Put;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
657 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
658 else
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
659 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
660 return false;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
661 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
662
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
663 return true;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
664 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
665
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
666
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
667 static void ConfigureHttpCompression(HttpOutput& output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
668 const IHttpHandler::Arguments& headers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
669 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
670 // Look if the client wishes HTTP compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
671 // https://en.wikipedia.org/wiki/HTTP_compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
672 IHttpHandler::Arguments::const_iterator it = headers.find("accept-encoding");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
673 if (it != headers.end())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
674 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
675 std::vector<std::string> encodings;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
676 Toolbox::TokenizeString(encodings, it->second, ',');
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
677
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
678 for (size_t i = 0; i < encodings.size(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
679 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
680 std::string s = Toolbox::StripSpaces(encodings[i]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
681
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
682 if (s == "deflate")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
683 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
684 output.SetDeflateAllowed(true);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
685 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
686 else if (s == "gzip")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
687 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
688 output.SetGzipAllowed(true);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
689 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
690 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
691 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
692 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
693
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
694
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
695 static void InternalCallback(HttpOutput& output /* out */,
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
696 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
697 HttpServer& server,
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
698 struct mg_connection *connection,
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
699 const struct mg_request_info *request)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
700 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
701 bool localhost;
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
702
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
703 #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
704 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
705 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
706 #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
707 // 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
708 // 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
709 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
710 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
711 # error
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
712 #endif
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
713
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
714 // Check remote calls
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
715 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
716 !localhost)
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
717 {
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
718 output.SendUnauthorized(server.GetRealm());
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
719 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
720 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
721
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
722
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
723 // Extract the HTTP headers
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
724 IHttpHandler::Arguments headers;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
725 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
726 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
727 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
728 std::string value = request->http_headers[i].value;
ad95331c526a trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1963
diff changeset
729
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
730 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
731 headers.insert(std::make_pair(name, value));
ad95331c526a trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1963
diff changeset
732 VLOG(1) << "HTTP header: [" << name << "]: [" << value << "]";
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
733 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
734
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
735 if (server.IsHttpCompressionEnabled())
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
736 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
737 ConfigureHttpCompression(output, headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
738 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
739
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
740
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
741 // Extract the GET arguments
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
742 IHttpHandler::GetArguments argumentsGET;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
743 if (!strcmp(request->request_method, "GET"))
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
744 {
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
745 HttpToolbox::ParseGetArguments(argumentsGET, request->query_string);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
746 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
747
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
748
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
749 // Compute the HTTP method, taking method faking into consideration
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
750 method = HttpMethod_Get;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
751 if (!ExtractMethod(method, request, headers, argumentsGET))
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
752 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
753 output.SendStatus(HttpStatus_400_BadRequest);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
754 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
755 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
756
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
757
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
758 // Authenticate this connection
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
759 if (server.IsAuthenticationEnabled() &&
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
760 !IsAccessGranted(server, headers))
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
761 {
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
762 output.SendUnauthorized(server.GetRealm());
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
763 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
764 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
765
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
766
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
767 #if ORTHANC_ENABLE_MONGOOSE == 1
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
768 // 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
769 char remoteIp[24];
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
770 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
771 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
772 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
773 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
774 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
775
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
776 const char* requestUri = request->uri;
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
777
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
778 #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
779 const char* remoteIp = request->remote_addr;
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
780 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
781 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
782 # error
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
783 #endif
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
784
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
785 if (requestUri == NULL)
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
786 {
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
787 requestUri = "";
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
788 }
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
789
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
790 std::string username = GetAuthenticatedUsername(headers);
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
791
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
792 IIncomingHttpRequestFilter *filter = server.GetIncomingHttpRequestFilter();
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
793 if (filter != NULL)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
794 {
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
795 if (!filter->IsAllowed(method, requestUri, remoteIp,
2268
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
796 username.c_str(), headers, argumentsGET))
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
797 {
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
798 //output.SendUnauthorized(server.GetRealm());
1963
af0c90ae0915 Use 403 Forbidden status if the incoming HTTP request is disallowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1959
diff changeset
799 output.SendStatus(HttpStatus_403_Forbidden);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
800 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
801 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
802 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
803
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
804
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
805 // Decompose the URI into its components
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
806 UriComponents uri;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
807 try
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
808 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
809 Toolbox::SplitUriComponents(uri, requestUri);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
810 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
811 catch (OrthancException&)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
812 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
813 output.SendStatus(HttpStatus_400_BadRequest);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
814 return;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
815 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
816
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
817 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
818
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
819
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
820 bool found = false;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
821
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
822 // 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
823 // 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
824
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
825 // TODO Avoid unneccessary memcopy of the body
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
826
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
827 std::string body;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
828 if (method == HttpMethod_Post ||
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
829 method == HttpMethod_Put)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
830 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
831 PostDataStatus status;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
832
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
833 bool isMultipartForm = false;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
834
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
835 IHttpHandler::Arguments::const_iterator ct = headers.find("content-type");
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
836 if (ct != headers.end() &&
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
837 ct->second.size() >= MULTIPART_FORM_LENGTH &&
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
838 !memcmp(ct->second.c_str(), MULTIPART_FORM, MULTIPART_FORM_LENGTH))
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
839 {
3445
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
840 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
841 * The user uses the "upload" form of Orthanc Explorer, for
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
842 * file uploads through a HTML form.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
843 **/
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
844 status = ParseMultipartForm(body, connection, headers, ct->second, server.GetChunkStore());
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
845 isMultipartForm = true;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
846 }
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
847
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
848 if (!isMultipartForm)
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
849 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3672
diff changeset
850 std::unique_ptr<IHttpHandler::IChunkedRequestReader> stream;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
851
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
852 if (server.HasHandler())
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
853 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
854 found = server.GetHandler().CreateChunkedRequestReader
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
855 (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
856 }
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
857
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
858 if (found)
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
859 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
860 if (stream.get() == NULL)
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
861 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
862 throw OrthancException(ErrorCode_InternalError);
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
863 }
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
864
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
865 status = ReadBodyToStream(*stream, connection, headers);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
866
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
867 if (status == PostDataStatus_Success)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
868 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
869 stream->Execute(output);
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
870 }
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
871 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
872 else
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
873 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
874 status = ReadBodyToString(body, connection, headers);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
875 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
876 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
877
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
878 switch (status)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
879 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
880 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
881 output.SendStatus(HttpStatus_411_LengthRequired);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
882 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
883
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
884 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
885 output.SendStatus(HttpStatus_400_BadRequest);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
886 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
887
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
888 case PostDataStatus_Pending:
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
889 output.AnswerEmpty();
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
890 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
891
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
892 case PostDataStatus_Success:
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
893 break;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
894
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
895 default:
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
896 throw OrthancException(ErrorCode_InternalError);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
897 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
898 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
899
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
900 if (!found &&
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3357
diff changeset
901 server.HasHandler())
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
902 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
903 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
904 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
905 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
906
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
907 if (!found)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
908 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
909 throw OrthancException(ErrorCode_UnknownResource);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
910 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
911 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
912
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
913
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
914 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
915 const struct mg_request_info *request)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
916 {
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
917 try
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
918 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
919 #if ORTHANC_ENABLE_MONGOOSE == 1
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
920 void *that = request->user_data;
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
921 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
922 #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
923 // 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
924 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
925 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
926 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
927 # error
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
928 #endif
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
929
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
930 if (requestUri == NULL)
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
931 {
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
932 requestUri = "";
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
933 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
934
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
935 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
936
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
937 if (server == NULL)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
938 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
939 MongooseOutputStream stream(connection);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
940 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
941 output.SendStatus(HttpStatus_500_InternalServerError);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
942 return;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
943 }
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
944
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
945 MongooseOutputStream stream(connection);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
946 HttpOutput output(stream, server->IsKeepAliveEnabled());
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
947 HttpMethod method = HttpMethod_Get;
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1568
diff changeset
948
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1568
diff changeset
949 try
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
950 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
951 try
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
952 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
953 InternalCallback(output, method, *server, connection, request);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
954 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
955 catch (OrthancException&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
956 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
957 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
958 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
959 // Now convert native exceptions as OrthancException
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
960 catch (boost::bad_lexical_cast&)
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
961 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
962 throw OrthancException(ErrorCode_BadParameterType,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
963 "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
964 }
3672
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
965 catch (boost::filesystem::filesystem_error& e)
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
966 {
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
967 throw OrthancException(ErrorCode_InternalError,
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
968 "Error while accessing the filesystem: " + e.path1().string());
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
969 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
970 catch (std::runtime_error&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
971 {
3672
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
972 throw OrthancException(ErrorCode_BadRequest,
ea8c1c0e81eb Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
973 "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
974 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
975 catch (std::bad_alloc&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
976 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
977 throw OrthancException(ErrorCode_NotEnoughMemory,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
978 "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
979 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
980 catch (...)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
981 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
982 throw OrthancException(ErrorCode_InternalError,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
983 "An unhandled exception was generated inside the HTTP server");
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
984 }
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
985 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
986 catch (OrthancException& e)
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
987 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
988 assert(server != NULL);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1568
diff changeset
989
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
990 // 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
991 try
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
992 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
993 if (server->GetExceptionFormatter() == NULL)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
994 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
995 LOG(ERROR) << "Exception in the HTTP handler: " << e.What();
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
996 output.SendStatus(e.GetHttpStatus());
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
997 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
998 else
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
999 {
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
1000 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
1001 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1002 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1003 catch (OrthancException&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1004 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1005 // 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
1006 // 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
1007 }
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
1008 }
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1009 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1010 catch (...)
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1011 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1012 // We should never arrive at this point, where it is even impossible to send an answer
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1013 LOG(ERROR) << "Catastrophic error inside the HTTP server, giving up";
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1014 }
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1015 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1016
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1017
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1018 #if MONGOOSE_USE_CALLBACKS == 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 static void* Callback(enum mg_event event,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 struct mg_connection *connection,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 const struct mg_request_info *request)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 if (event == MG_NEW_REQUEST)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1025 ProtectedCallback(connection, request);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 // Mark as processed
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 return (void*) "";
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1029 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1030 else
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1036 #elif MONGOOSE_USE_CALLBACKS == 1
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1037 static int Callback(struct mg_connection *connection)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1038 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1039 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
1040
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
1041 ProtectedCallback(connection, request);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1042
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1043 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
1044 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1045
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1046 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
1047 # error Please set MONGOOSE_USE_CALLBACKS
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1048 #endif
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1049
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1050
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1051
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1052
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1054 bool HttpServer::IsRunning() const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 return (pimpl_->context_ != NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1060 HttpServer::HttpServer() :
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1061 pimpl_(new PImpl),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1062 handler_(NULL),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1063 remoteAllowed_(false),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1064 authentication_(false),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1065 sslVerifyPeers_(false),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1066 ssl_(false),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1067 port_(8000),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1068 filter_(NULL),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1069 keepAlive_(false),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1070 httpCompression_(true),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1071 exceptionFormatter_(NULL),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1072 realm_(ORTHANC_REALM),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1073 threadsCount_(50), // Default value in mongoose
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1074 tcpNoDelay_(true),
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1075 requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 {
3145
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1077 #if ORTHANC_ENABLE_MONGOOSE == 1
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1078 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server";
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1079 #endif
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1080
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1081 #if ORTHANC_ENABLE_CIVETWEB == 1
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1082 LOG(INFO) << "This Orthanc server uses CivetWeb as its embedded HTTP server";
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1083 #endif
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
1084
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
1085 #if ORTHANC_ENABLE_SSL == 1
749
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
1086 // 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
1087 // 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
1088 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
1089 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
1090 {
749
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
1091 LOG(WARNING) << "This version of OpenSSL is vulnerable to the Heartbleed exploit";
748
de9763f63510 upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1092 }
de9763f63510 upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1093 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1097 HttpServer::~HttpServer()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 Stop();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1103 void HttpServer::SetPortNumber(uint16_t port)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 Stop();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 port_ = port;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1109 void HttpServer::Start()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1111 #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
1112 LOG(INFO) << "Starting embedded Web server using Mongoose";
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1113 #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
1114 LOG(INFO) << "Starting embedded Web server using Civetweb";
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1115 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
1116 # error
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1117 #endif
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1118
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 if (!IsRunning())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 std::string port = boost::lexical_cast<std::string>(port_);
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1122 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
1123 std::string requestTimeoutMilliseconds = boost::lexical_cast<std::string>(requestTimeout_ * 1000);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1125 if (ssl_)
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1126 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1127 port += "s";
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1128 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1129
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1130 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
1131
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1132 // 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
1133 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
1134 options.push_back(port.c_str());
1110
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1135
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1136 // 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
1137 // 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
1138 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
1139 options.push_back(keepAlive_ ? "yes" : "no");
1110
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1140
2579
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2577
diff changeset
1141 #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
1142 // https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1143 options.push_back("keep_alive_timeout_ms");
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1144 options.push_back(keepAlive_ ? "500" : "0");
2577
6783a7c02990 keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1145 #endif
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1146
3136
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1147 #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
1148 // 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
1149 // 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
1150 // 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
1151 // 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
1152 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
1153 options.push_back(tcpNoDelay_ ? "1" : "0");
3136
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1154 #endif
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1155
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1156 // 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
1157 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
1158 options.push_back(numThreads.c_str());
2577
6783a7c02990 keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1159
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1160 // 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
1161 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
1162 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
1163
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1164 // Set the client authentication
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1165 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
1166 options.push_back(sslVerifyPeers_ ? "yes" : "no");
3537
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1167
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1168 if (sslVerifyPeers_)
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1169 {
4190
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1170 // 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
1171 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
1172 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
1173 }
4190
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1174
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1175 if (ssl_)
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1176 {
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1177 // 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
1178 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
1179 options.push_back(certificate_.c_str());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181
4193
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1182 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
1183 options.push_back(NULL);
ff24a06b3474 fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4190
diff changeset
1184
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1185 #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
1186 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
1187
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1188 #elif MONGOOSE_USE_CALLBACKS == 1
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1189 struct mg_callbacks callbacks;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1190 memset(&callbacks, 0, sizeof(callbacks));
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1191 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
1192 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
1193
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1194 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
1195 # error Please set MONGOOSE_USE_CALLBACKS
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1196 #endif
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1197
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 if (!pimpl_->context_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 {
3801
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1200 bool isSslError = false;
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1201
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1202 #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
1203 for (;;)
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1204 {
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1205 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
1206 if (code == 0)
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1207 {
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1208 break;
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1209 }
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1210 else
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1211 {
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1212 isSslError = true;
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1213 char message[1024];
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1214 ERR_error_string_n(code, message, sizeof(message) - 1);
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1215 LOG(ERROR) << "OpenSSL error: " << message;
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1216 }
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1217 }
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1218 #endif
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1219
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1220 if (isSslError)
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1221 {
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1222 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
1223 }
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1224 else
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1225 {
9fe1d64a748c upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1226 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
1227 " (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
1228 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 }
2633
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1230
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1231 LOG(WARNING) << "HTTP server listening on port: " << GetPortNumber()
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1232 << " (HTTPS encryption is "
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1233 << (IsSslEnabled() ? "enabled" : "disabled")
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1234 << ", remote access is "
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1235 << (IsRemoteAccessAllowed() ? "" : "not ")
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1236 << "allowed)";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1240 void HttpServer::Stop()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 if (IsRunning())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 mg_stop(pimpl_->context_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 pimpl_->context_ = NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1250 void HttpServer::ClearUsers()
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1251 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1252 Stop();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1253 registeredUsers_.clear();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1254 }
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1255
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1256
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1257 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
1258 const char* password)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1259 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1260 Stop();
24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
1261
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
1262 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
1263 std::string encoded;
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
1264 Toolbox::EncodeBase64(encoded, tag);
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
1265 registeredUsers_.insert(encoded);
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1266 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1267
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1268 void HttpServer::SetSslEnabled(bool enabled)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1269 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1270 Stop();
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1271
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
1272 #if ORTHANC_ENABLE_SSL == 0
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1273 if (enabled)
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1274 {
1674
4fc502d469f4 fix build if SSL is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1649
diff changeset
1275 throw OrthancException(ErrorCode_SslDisabled);
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1276 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1277 else
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1278 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1279 ssl_ = false;
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1280 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1281 #else
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1282 ssl_ = enabled;
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1283 #endif
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1284 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1285
4190
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1286 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
1287 {
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1288 Stop();
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1289
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1290 #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
1291 if (enabled)
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1292 {
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1293 throw OrthancException(ErrorCode_SslDisabled);
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1294 }
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1295 else
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1296 {
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1297 sslVerifyPeers_ = false;
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1298 }
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1299 #else
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1300 sslVerifyPeers_ = enabled;
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1301 #endif
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1302 }
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1303
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1304 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
1305 {
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1306 Stop();
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1307 keepAlive_ = enabled;
2069
fabf7820d1f1 New configuration options: "DicomScuTimeout" and "DicomScpTimeout" + validation of non-negative options
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1977
diff changeset
1308 LOG(INFO) << "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
1309
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1310 #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
1311 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
1312 {
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1313 LOG(WARNING) << "You should disable HTTP keep alive, as you are using Mongoose";
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1314 }
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1315 #endif
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1316 }
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1317
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1318
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1319 void HttpServer::SetAuthenticationEnabled(bool enabled)
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1320 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1321 Stop();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1322 authentication_ = enabled;
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1323 }
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1324
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1325 void HttpServer::SetSslCertificate(const char* path)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1326 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1327 Stop();
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1328 certificate_ = path;
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1329 }
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1330
4190
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1331 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
1332 {
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1333 Stop();
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1334 trustedClientCertificates_ = path;
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1335 }
9ce5c89328f5 New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents: 4152
diff changeset
1336
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1337 void HttpServer::SetRemoteAccessAllowed(bool allowed)
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1338 {
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1339 Stop();
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1340 remoteAllowed_ = allowed;
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1341 }
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1342
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1343 void HttpServer::SetHttpCompressionEnabled(bool enabled)
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1344 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1345 Stop();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1346 httpCompression_ = enabled;
1518
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
1347 LOG(WARNING) << "HTTP compression is " << (enabled ? "enabled" : "disabled");
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1348 }
1592
d73124f6b439 configuration option HttpDescribeErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
1349
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1350 void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter)
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1351 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1352 Stop();
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1353 filter_ = &filter;
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1354 }
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1355
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1356
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1357 void HttpServer::SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter)
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1358 {
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1359 Stop();
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1360 exceptionFormatter_ = &formatter;
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1361 }
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1362
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1363
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1364 bool HttpServer::IsValidBasicHttpAuthentication(const std::string& basic) const
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1365 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1366 return registeredUsers_.find(basic) != registeredUsers_.end();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1367 }
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1368
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1369
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1370 void HttpServer::Register(IHttpHandler& handler)
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1371 {
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1372 Stop();
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1373 handler_ = &handler;
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1374 }
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1375
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1376
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1377 IHttpHandler& HttpServer::GetHandler() const
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1378 {
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1379 if (handler_ == NULL)
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1380 {
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1381 throw OrthancException(ErrorCode_InternalError);
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1382 }
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1383
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1384 return *handler_;
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1385 }
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1386
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1387
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1388 void HttpServer::SetThreadsCount(unsigned int threads)
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1389 {
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1390 if (threads == 0)
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1391 {
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1392 throw OrthancException(ErrorCode_ParameterOutOfRange);
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1393 }
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1394
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1395 Stop();
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1396 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
1397
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
1398 LOG(INFO) << "The embedded HTTP server will use " << threads << " threads";
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1399 }
3137
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1400
3537
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1401
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1402 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
1403 {
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1404 Stop();
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1405 tcpNoDelay_ = tcpNoDelay;
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1406 LOG(INFO) << "TCP_NODELAY for the HTTP sockets is set to "
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1407 << (tcpNoDelay ? "true" : "false");
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1408 }
3537
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1409
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1410
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1411 void HttpServer::SetRequestTimeout(unsigned int seconds)
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1412 {
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4193
diff changeset
1413 if (seconds == 0)
3537
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1414 {
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1415 throw OrthancException(ErrorCode_ParameterOutOfRange,
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1416 "Request timeout must be a stricly positive integer");
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1417 }
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1418
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1419 Stop();
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1420 requestTimeout_ = seconds;
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1421 LOG(INFO) << "Request timeout in the HTTP server is set to " << seconds << " seconds";
9cc09f4c0fa9 New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3445
diff changeset
1422 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423 }