comparison OrthancFramework/Sources/HttpServer/HttpServer.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Core/HttpServer/HttpServer.h@f9863630ec7f
children bf7b9edf6b81
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 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 // To have ORTHANC_ENABLE_xxx defined if using the shared library
37 #include "../OrthancFramework.h"
38
39 #if !defined(ORTHANC_ENABLE_MONGOOSE)
40 # error Macro ORTHANC_ENABLE_MONGOOSE must be defined to include this file
41 #endif
42
43 #if !defined(ORTHANC_ENABLE_CIVETWEB)
44 # error Macro ORTHANC_ENABLE_CIVETWEB must be defined to include this file
45 #endif
46
47 #if (ORTHANC_ENABLE_MONGOOSE == 0 && \
48 ORTHANC_ENABLE_CIVETWEB == 0)
49 # error Either ORTHANC_ENABLE_MONGOOSE or ORTHANC_ENABLE_CIVETWEB must be set to 1
50 #endif
51
52
53 #include "IIncomingHttpRequestFilter.h"
54
55 #include <list>
56 #include <map>
57 #include <set>
58 #include <stdint.h>
59 #include <boost/shared_ptr.hpp>
60
61 namespace Orthanc
62 {
63 class ChunkStore;
64 class OrthancException;
65
66 class IHttpExceptionFormatter : public boost::noncopyable
67 {
68 public:
69 virtual ~IHttpExceptionFormatter()
70 {
71 }
72
73 virtual void Format(HttpOutput& output,
74 const OrthancException& exception,
75 HttpMethod method,
76 const char* uri) = 0;
77 };
78
79
80 class ORTHANC_PUBLIC HttpServer : public boost::noncopyable
81 {
82 private:
83 // http://stackoverflow.com/questions/311166/stdauto-ptr-or-boostshared-ptr-for-pimpl-idiom
84 struct PImpl;
85 boost::shared_ptr<PImpl> pimpl_;
86
87 IHttpHandler *handler_;
88
89 typedef std::set<std::string> RegisteredUsers;
90 RegisteredUsers registeredUsers_;
91
92 bool remoteAllowed_;
93 bool authentication_;
94 bool ssl_;
95 std::string certificate_;
96 uint16_t port_;
97 IIncomingHttpRequestFilter* filter_;
98 bool keepAlive_;
99 bool httpCompression_;
100 IHttpExceptionFormatter* exceptionFormatter_;
101 std::string realm_;
102 unsigned int threadsCount_;
103 bool tcpNoDelay_;
104 unsigned int requestTimeout_; // In seconds
105
106 bool IsRunning() const;
107
108 public:
109 HttpServer();
110
111 ~HttpServer();
112
113 void SetPortNumber(uint16_t port);
114
115 uint16_t GetPortNumber() const
116 {
117 return port_;
118 }
119
120 void Start();
121
122 void Stop();
123
124 void ClearUsers();
125
126 void RegisterUser(const char* username,
127 const char* password);
128
129 bool IsAuthenticationEnabled() const
130 {
131 return authentication_;
132 }
133
134 void SetAuthenticationEnabled(bool enabled);
135
136 bool IsSslEnabled() const
137 {
138 return ssl_;
139 }
140
141 void SetSslEnabled(bool enabled);
142
143 bool IsKeepAliveEnabled() const
144 {
145 return keepAlive_;
146 }
147
148 void SetKeepAliveEnabled(bool enabled);
149
150 const std::string& GetSslCertificate() const
151 {
152 return certificate_;
153 }
154
155 void SetSslCertificate(const char* path);
156
157 bool IsRemoteAccessAllowed() const
158 {
159 return remoteAllowed_;
160 }
161
162 void SetRemoteAccessAllowed(bool allowed);
163
164 bool IsHttpCompressionEnabled() const
165 {
166 return httpCompression_;;
167 }
168
169 void SetHttpCompressionEnabled(bool enabled);
170
171 IIncomingHttpRequestFilter* GetIncomingHttpRequestFilter() const
172 {
173 return filter_;
174 }
175
176 void SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter);
177
178 ChunkStore& GetChunkStore();
179
180 bool IsValidBasicHttpAuthentication(const std::string& basic) const;
181
182 void Register(IHttpHandler& handler);
183
184 bool HasHandler() const
185 {
186 return handler_ != NULL;
187 }
188
189 IHttpHandler& GetHandler() const;
190
191 void SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter);
192
193 IHttpExceptionFormatter* GetExceptionFormatter()
194 {
195 return exceptionFormatter_;
196 }
197
198 const std::string& GetRealm() const
199 {
200 return realm_;
201 }
202
203 void SetRealm(const std::string& realm)
204 {
205 realm_ = realm;
206 }
207
208 void SetThreadsCount(unsigned int threads);
209
210 unsigned int GetThreadsCount() const
211 {
212 return threadsCount_;
213 }
214
215 // New in Orthanc 1.5.2, not available for Mongoose
216 void SetTcpNoDelay(bool tcpNoDelay);
217
218 bool IsTcpNoDelay() const
219 {
220 return tcpNoDelay_;
221 }
222
223 void SetRequestTimeout(unsigned int seconds);
224
225 unsigned int GetRequestTimeout() const
226 {
227 return requestTimeout_;
228 }
229 };
230 }