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-2014 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 #include <memory>
27 
28 struct MHD_Daemon;
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 class Logger;
36 class Time;
37 class WebRequestDispatcher;
38 class WebUserVerifier;
39 class WebRequestManager;
40 
41 #define WEBVIEW_DEFAULT_CIPHERS "SECURE128:-VERS-SSL3.0:-VERS-TLS-ALL:+VERS-TLS1.2"
42 
43 class WebServer {
44  public:
45  WebServer(unsigned short int port, WebRequestDispatcher *dispatcher,
46  fawkes::Logger *logger = 0,
47  bool enable_ipv4 = true, bool enable_ipv6 = true);
48 
49  WebServer(unsigned short int port, WebRequestDispatcher *dispatcher,
50  const char *key_pem_filepath, const char *cert_pem_filepath,
51  const char *cipher_suite = WEBVIEW_DEFAULT_CIPHERS,
52  fawkes::Logger *logger = 0,
53  bool enable_ipv4 = true, bool enable_ipv6 = true);
54  ~WebServer();
55 
56  void process();
57 
58  void setup_basic_auth(const char *realm, WebUserVerifier *verifier);
59  void setup_request_manager(WebRequestManager *request_manager);
60  void setup_access_log(const char *filename);
61 
62  unsigned int active_requests() const;
64 
65  private:
66  static char * read_file(const char *filename);
67 
68  private:
69  struct MHD_Daemon *__daemon;
70  WebRequestDispatcher *__dispatcher;
71  WebRequestManager *__request_manager;
72  fawkes::Logger *__logger;
73 
74  unsigned short int __port;
75 
76  char *__ssl_key_mem;
77  char *__ssl_cert_mem;
78 };
79 
80 } // end namespace fawkes
81 
82 #endif
unsigned int active_requests() const
Get number of active requests.
Definition: server.cpp:252
void setup_basic_auth(const char *realm, WebUserVerifier *verifier)
Setup basic authentication.
Definition: server.cpp:221
Web request dispatcher.
Encapsulation of the libmicrohttpd webserver.
Definition: server.h:43
WebServer(unsigned short int port, WebRequestDispatcher *dispatcher, fawkes::Logger *logger=0, bool enable_ipv4=true, bool enable_ipv6=true)
Constructor.
Definition: server.cpp:58
Fawkes library namespace.
void process()
Process requests.
Definition: server.cpp:271
A class for handling time.
Definition: time.h:91
Interface for user verification.
Definition: user_verifier.h:31
~WebServer()
Destructor.
Definition: server.cpp:159
void setup_request_manager(WebRequestManager *request_manager)
Setup this server as request manager.
Definition: server.cpp:242
Probides information about ongoing requests.
Time last_request_completion_time() const
Get time when last request was completed.
Definition: server.cpp:261
void setup_access_log(const char *filename)
Setup access log.
Definition: server.cpp:231
Interface for logging.
Definition: logger.h:34