EVE 1.0
http-server.h
1 #ifndef HTTP_SERVER_H_INCLUDED
2 #define HTTP_SERVER_H_INCLUDED
3 
4 /**
5  * \addtogroup http
6  * \{
7  */
8 
9 /**
10  * Default HTTP server configuration
11  */
12 #define HTTP_SERVER_CONF_DEFAULTS \
13  .ConnectionPoolSize = 5, \
14  .TlsConnPoolSize = 1, \
15  .ThreadPoolSize = 1, \
16  .HandshakePoolSize = 1, \
17  .ParserPoolSize = 1, \
18  .SocketBacklogSize = 8, \
19  .HandshakeTimeout = MS_TO_TICKS(10000), \
20  .KeepaliveTimeout = MS_TO_TICKS(5000), \
21  .CloseTimeout = MS_TO_TICKS(2000), \
22  .TransportTimeout = MS_TO_TICKS(7000)
23 
24 /**
25  * Authentication operation type
26  */
28 {
29  HTTP_AUTH_QUERY_AUTHENTICATION, /*!< Query if authentication is required */
30  HTTP_AUTH_GET_REALM, /*!< Query a realm string from an application */
31  HTTP_AUTH_GET_PASSWORD_HASH, /*!< Query a password hash for the selected user */
32  HTTP_AUTH_GET_PASSWORD, /*!< Query a plaintext password for the user*/
33 };
34 
35 /**
36  * Authentication operation
37  */
39 {
40  enum http_auth_op_type_t Type; /*!< Type of operation */
41  const char *In; /*!< Input data. Username for password queries */
42  uint32_t InLen; /*!< Length of input data */
43  uint8_t *Out; /*!< Output data buffer */
44  uint32_t OutLen; /*!< At the function call it contains size of the output data buffer.
45  Callback must update the field with real size of the output
46  parameter, which can be greater than size of the buffer. */
47 };
48 
49 /**
50  * Authentication callback
51  */
52 typedef bool (*http_auth_callback_t)(struct http_auth_op_t *Op);
53 
54 /**
55  * HTTP server general configuration
56  *
57  * TlsConnPoolSize <= ConnectionPoolSize;
58  * ThreadPoolSize <= ConnectionPoolSize;
59  * ParserPoolSize <= ThreadPoolSize;
60  * HandshakePoolSize <= ThreadPoolSize;
61  * HandshakePoolSize <= TlsConnPoolSize;
62  * SocketBacklogSize >= 2
63  */
65 {
66  http_auth_callback_t AuthCb; /*!< Authentication callback */
67  uint8_t ConnectionPoolSize; /*!< Max number of concurrent HTTP + HTTPS connections */
68  uint8_t TlsConnPoolSize; /*!< Max number of concurrent HTTPS connections */
69  uint8_t ThreadPoolSize; /*!< Number of parallel processing threads */
70  uint8_t HandshakePoolSize; /*!< HTTPS handshake pool size */
71  uint8_t ParserPoolSize; /*!< Number of concurrent HTTP request parsers */
72  uint8_t SocketBacklogSize; /*!< Total number of sockets in both HTTP and HTTPS listen backlog */
73  bool UseHttps; /*!< Use HTTPS */
74  bool ForceHttps; /*!< Redirect HTTP requests to HTTPS port */
75  bool ForceIpAddr; /*!< Redirect HTTP(S) requests to an IP address */
76  uint16_t HandshakeTimeout; /*!< HTTPS handshake timeout */
77  uint16_t KeepaliveTimeout; /*!< HTTP / HTTPS keep-alive timeout */
78  uint16_t CloseTimeout; /*!< Socket close timeout */
79  uint16_t TransportTimeout; /*!< TCP send / recv timeout */
80 };
81 
82 /**
83  * HTTP server security configuration
84  */
86 {
87  const char *RsaCert; /*!< RSA certificate */
88  const char *RsaKey; /*!< RSA key */
89  uint16_t RsaCertSize; /*!< Length of RSA certificate, including terminal \0 */
90  uint16_t RsaKeySize; /*!< Length of RSA key, including terminal \0 */
91 };
92 
93 /**
94  * Start HTTP/HTTPS server
95  *
96  * \note Caller must ensure persistence of the server general configuration through the server livetime,
97  * bit there is no such restrictions for the security configuration.
98  *
99  * @param Config Server general configuration
100  * @param Security Server security configuration
101  * @return true if server was started, false otherwise
102  */
103 bool HttpServerStart(const struct http_server_conf_t *Config, struct http_server_security_t *Security);
104 
105 /**
106  * Stop HTTP/HTTPS server
107  */
108 void HttpServerStop(void);
109 
110 /** \} */
111 
112 #endif
uint8_t * Out
Definition: http-server.h:43
uint8_t TlsConnPoolSize
Definition: http-server.h:68
uint8_t ThreadPoolSize
Definition: http-server.h:69
uint16_t TransportTimeout
Definition: http-server.h:79
bool HttpServerStart(const struct http_server_conf_t *Config, struct http_server_security_t *Security)
uint32_t InLen
Definition: http-server.h:42
uint16_t CloseTimeout
Definition: http-server.h:78
const char * In
Definition: http-server.h:41
uint16_t KeepaliveTimeout
Definition: http-server.h:77
enum http_auth_op_type_t Type
Definition: http-server.h:40
uint8_t SocketBacklogSize
Definition: http-server.h:72
bool(* http_auth_callback_t)(struct http_auth_op_t *Op)
Definition: http-server.h:52
uint8_t ParserPoolSize
Definition: http-server.h:71
void HttpServerStop(void)
uint8_t HandshakePoolSize
Definition: http-server.h:70
const char * RsaCert
Definition: http-server.h:87
uint8_t ConnectionPoolSize
Definition: http-server.h:67
uint32_t OutLen
Definition: http-server.h:44
http_auth_callback_t AuthCb
Definition: http-server.h:66
const char * RsaKey
Definition: http-server.h:88
uint16_t HandshakeTimeout
Definition: http-server.h:76
http_auth_op_type_t
Definition: http-server.h:27