Fawkes API Fawkes Development Version
server.h
1
2/***************************************************************************
3 * server.h - Web server encapsulation around libmicrohttpd
4 *
5 * Created: Sun Aug 30 17:38:37 2009
6 * Copyright 2006-2018 Tim Niemueller [www.niemueller.de]
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#ifndef _LIBS_WEBVIEW_SERVER_H_
23#define _LIBS_WEBVIEW_SERVER_H_
24
25#include <sys/types.h>
26
27#include <memory>
28#include <string>
29#include <vector>
30
31struct MHD_Daemon;
32
33namespace fawkes {
34
35class Logger;
36class Time;
37class WebRequestDispatcher;
38class WebUserVerifier;
39class WebRequestManager;
40
41#define WEBVIEW_DEFAULT_CIPHERS "SECURE128:-VERS-SSL3.0:-VERS-TLS-ALL:+VERS-TLS1.2"
42
44{
45public:
46 WebServer(unsigned short int port, WebRequestDispatcher *dispatcher, fawkes::Logger *logger = 0);
47 ~WebServer();
48
49 WebServer &setup_tls(const char *key_pem_filepath,
50 const char *cert_pem_filepath,
51 const char *cipher_suite = WEBVIEW_DEFAULT_CIPHERS);
52 WebServer &setup_ipv(bool enable_ipv4, bool enable_ipv6);
53 WebServer &setup_thread_pool(unsigned int num_threads);
54
55 WebServer &setup_cors(bool allow_all, std::vector<std::string> &&origins, unsigned int max_age);
56 WebServer &setup_basic_auth(const char *realm, WebUserVerifier *verifier);
58 WebServer &setup_access_log(const char *filename);
59
60 void start();
61 void process();
62
63 unsigned int active_requests() const;
65
66private:
67 std::string read_file(const char *filename);
68
69private:
70 struct MHD_Daemon * daemon_;
71 WebRequestDispatcher *dispatcher_;
72 WebRequestManager * request_manager_;
73 fawkes::Logger * logger_;
74
75 unsigned short int port_;
76
77 bool tls_enabled_;
78 std::string tls_key_mem_;
79 std::string tls_cert_mem_;
80 std::string tls_cipher_suite_;
81
82 bool enable_ipv4_;
83 bool enable_ipv6_;
84 unsigned int num_threads_;
85 bool cors_allow_all_;
86 std::vector<std::string> cors_origins_;
87 unsigned int cors_max_age_;
88};
89
90} // end namespace fawkes
91
92#endif
Interface for logging.
Definition: logger.h:42
A class for handling time.
Definition: time.h:93
Web request dispatcher.
Probides information about ongoing requests.
Encapsulation of the libmicrohttpd webserver.
Definition: server.h:44
WebServer & setup_access_log(const char *filename)
Setup access log.
Definition: server.cpp:276
void process()
Process requests.
Definition: server.cpp:322
WebServer(unsigned short int port, WebRequestDispatcher *dispatcher, fawkes::Logger *logger=0)
Constructor.
Definition: server.cpp:53
WebServer & setup_ipv(bool enable_ipv4, bool enable_ipv6)
Setup protocols, i.e., IPv4 and/or IPv6.
Definition: server.cpp:98
~WebServer()
Destructor.
Definition: server.cpp:207
WebServer & setup_cors(bool allow_all, std::vector< std::string > &&origins, unsigned int max_age)
Setup cross-origin resource sharing.
Definition: server.cpp:113
Time last_request_completion_time() const
Get time when last request was completed.
Definition: server.cpp:308
WebServer & setup_tls(const char *key_pem_filepath, const char *cert_pem_filepath, const char *cipher_suite=WEBVIEW_DEFAULT_CIPHERS)
Setup Transport Layer Security (encryption),.
Definition: server.cpp:76
unsigned int active_requests() const
Get number of active requests.
Definition: server.cpp:299
WebServer & setup_thread_pool(unsigned int num_threads)
Setup thread pool.
Definition: server.cpp:130
WebServer & setup_basic_auth(const char *realm, WebUserVerifier *verifier)
Setup basic authentication.
Definition: server.cpp:265
void start()
Start daemon and enable processing requests.
Definition: server.cpp:140
WebServer & setup_request_manager(WebRequestManager *request_manager)
Setup this server as request manager.
Definition: server.cpp:288
Interface for user verification.
Definition: user_verifier.h:29
Fawkes library namespace.