Mercurial > hg > orthanc
comparison Core/HttpServer/HttpServer.h @ 3138:ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Jan 2019 18:29:16 +0100 |
parents | Core/HttpServer/MongooseServer.h@5a3b961e9524 |
children | 9cc09f4c0fa9 |
comparison
equal
deleted
inserted
replaced
3137:5a3b961e9524 | 3138:ab46e537f92e |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #if !defined(ORTHANC_ENABLE_MONGOOSE) | |
37 # error Macro ORTHANC_ENABLE_MONGOOSE must be defined to include this file | |
38 #endif | |
39 | |
40 #if !defined(ORTHANC_ENABLE_CIVETWEB) | |
41 # error Macro ORTHANC_ENABLE_CIVETWEB must be defined to include this file | |
42 #endif | |
43 | |
44 #if (ORTHANC_ENABLE_MONGOOSE == 0 && \ | |
45 ORTHANC_ENABLE_CIVETWEB == 0) | |
46 # error Either ORTHANC_ENABLE_MONGOOSE or ORTHANC_ENABLE_CIVETWEB must be set to 1 | |
47 #endif | |
48 | |
49 | |
50 #include "IIncomingHttpRequestFilter.h" | |
51 | |
52 #include <list> | |
53 #include <map> | |
54 #include <set> | |
55 #include <stdint.h> | |
56 #include <boost/shared_ptr.hpp> | |
57 | |
58 namespace Orthanc | |
59 { | |
60 class ChunkStore; | |
61 class OrthancException; | |
62 | |
63 class IHttpExceptionFormatter : public boost::noncopyable | |
64 { | |
65 public: | |
66 virtual ~IHttpExceptionFormatter() | |
67 { | |
68 } | |
69 | |
70 virtual void Format(HttpOutput& output, | |
71 const OrthancException& exception, | |
72 HttpMethod method, | |
73 const char* uri) = 0; | |
74 }; | |
75 | |
76 | |
77 class HttpServer | |
78 { | |
79 private: | |
80 // http://stackoverflow.com/questions/311166/stdauto-ptr-or-boostshared-ptr-for-pimpl-idiom | |
81 struct PImpl; | |
82 boost::shared_ptr<PImpl> pimpl_; | |
83 | |
84 IHttpHandler *handler_; | |
85 | |
86 typedef std::set<std::string> RegisteredUsers; | |
87 RegisteredUsers registeredUsers_; | |
88 | |
89 bool remoteAllowed_; | |
90 bool authentication_; | |
91 bool ssl_; | |
92 std::string certificate_; | |
93 uint16_t port_; | |
94 IIncomingHttpRequestFilter* filter_; | |
95 bool keepAlive_; | |
96 bool httpCompression_; | |
97 IHttpExceptionFormatter* exceptionFormatter_; | |
98 std::string realm_; | |
99 unsigned int threadsCount_; | |
100 bool tcpNoDelay_; | |
101 | |
102 bool IsRunning() const; | |
103 | |
104 public: | |
105 HttpServer(); | |
106 | |
107 ~HttpServer(); | |
108 | |
109 void SetPortNumber(uint16_t port); | |
110 | |
111 uint16_t GetPortNumber() const | |
112 { | |
113 return port_; | |
114 } | |
115 | |
116 void Start(); | |
117 | |
118 void Stop(); | |
119 | |
120 void ClearUsers(); | |
121 | |
122 void RegisterUser(const char* username, | |
123 const char* password); | |
124 | |
125 bool IsAuthenticationEnabled() const | |
126 { | |
127 return authentication_; | |
128 } | |
129 | |
130 void SetAuthenticationEnabled(bool enabled); | |
131 | |
132 bool IsSslEnabled() const | |
133 { | |
134 return ssl_; | |
135 } | |
136 | |
137 void SetSslEnabled(bool enabled); | |
138 | |
139 bool IsKeepAliveEnabled() const | |
140 { | |
141 return keepAlive_; | |
142 } | |
143 | |
144 void SetKeepAliveEnabled(bool enabled); | |
145 | |
146 const std::string& GetSslCertificate() const | |
147 { | |
148 return certificate_; | |
149 } | |
150 | |
151 void SetSslCertificate(const char* path); | |
152 | |
153 bool IsRemoteAccessAllowed() const | |
154 { | |
155 return remoteAllowed_; | |
156 } | |
157 | |
158 void SetRemoteAccessAllowed(bool allowed); | |
159 | |
160 bool IsHttpCompressionEnabled() const | |
161 { | |
162 return httpCompression_;; | |
163 } | |
164 | |
165 void SetHttpCompressionEnabled(bool enabled); | |
166 | |
167 IIncomingHttpRequestFilter* GetIncomingHttpRequestFilter() const | |
168 { | |
169 return filter_; | |
170 } | |
171 | |
172 void SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter); | |
173 | |
174 ChunkStore& GetChunkStore(); | |
175 | |
176 bool IsValidBasicHttpAuthentication(const std::string& basic) const; | |
177 | |
178 void Register(IHttpHandler& handler); | |
179 | |
180 bool HasHandler() const | |
181 { | |
182 return handler_ != NULL; | |
183 } | |
184 | |
185 IHttpHandler& GetHandler() const; | |
186 | |
187 void SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter); | |
188 | |
189 IHttpExceptionFormatter* GetExceptionFormatter() | |
190 { | |
191 return exceptionFormatter_; | |
192 } | |
193 | |
194 const std::string& GetRealm() const | |
195 { | |
196 return realm_; | |
197 } | |
198 | |
199 void SetRealm(const std::string& realm) | |
200 { | |
201 realm_ = realm; | |
202 } | |
203 | |
204 void SetThreadsCount(unsigned int threads); | |
205 | |
206 unsigned int GetThreadsCount() const | |
207 { | |
208 return threadsCount_; | |
209 } | |
210 | |
211 // New in Orthanc 1.5.2, not available for Mongoose | |
212 void SetTcpNoDelay(bool tcpNoDelay); | |
213 | |
214 bool IsTcpNoDelay() const | |
215 { | |
216 return tcpNoDelay_; | |
217 } | |
218 }; | |
219 } |