http_server.h
Go to the documentation of this file.
1 /**
2  * @file http_server.h
3  * @brief HTTP server (HyperText Transfer Protocol)
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _HTTP_SERVER_H
30 #define _HTTP_SERVER_H
31 
32 //Dependencies
33 #include "os_port.h"
34 #include "core/socket.h"
35 #include "web_socket/web_socket.h"
36 
37 //HTTP server support
38 #ifndef HTTP_SERVER_SUPPORT
39  #define HTTP_SERVER_SUPPORT ENABLED
40 #elif (HTTP_SERVER_SUPPORT != ENABLED && HTTP_SERVER_SUPPORT != DISABLED)
41  #error HTTP_SERVER_SUPPORT parameter is not valid
42 #endif
43 
44 //Support for persistent connections
45 #ifndef HTTP_SERVER_PERSISTENT_CONN_SUPPORT
46  #define HTTP_SERVER_PERSISTENT_CONN_SUPPORT DISABLED
47 #elif (HTTP_SERVER_PERSISTENT_CONN_SUPPORT != ENABLED && HTTP_SERVER_PERSISTENT_CONN_SUPPORT != DISABLED)
48  #error HTTP_SERVER_PERSISTENT_CONN_SUPPORT parameter is not valid
49 #endif
50 
51 //File system support
52 #ifndef HTTP_SERVER_FS_SUPPORT
53  #define HTTP_SERVER_FS_SUPPORT DISABLED
54 #elif (HTTP_SERVER_FS_SUPPORT != ENABLED && HTTP_SERVER_FS_SUPPORT != DISABLED)
55  #error HTTP_SERVER_FS_SUPPORT parameter is not valid
56 #endif
57 
58 //Server Side Includes support
59 #ifndef HTTP_SERVER_SSI_SUPPORT
60  #define HTTP_SERVER_SSI_SUPPORT DISABLED
61 #elif (HTTP_SERVER_SSI_SUPPORT != ENABLED && HTTP_SERVER_SSI_SUPPORT != DISABLED)
62  #error HTTP_SERVER_SSI_SUPPORT parameter is not valid
63 #endif
64 
65 //HTTP over TLS
66 #ifndef HTTP_SERVER_TLS_SUPPORT
67  #define HTTP_SERVER_TLS_SUPPORT DISABLED
68 #elif (HTTP_SERVER_TLS_SUPPORT != ENABLED && HTTP_SERVER_TLS_SUPPORT != DISABLED)
69  #error HTTP_SERVER_TLS_SUPPORT parameter is not valid
70 #endif
71 
72 //Basic access authentication support
73 #ifndef HTTP_SERVER_BASIC_AUTH_SUPPORT
74  #define HTTP_SERVER_BASIC_AUTH_SUPPORT DISABLED
75 #elif (HTTP_SERVER_BASIC_AUTH_SUPPORT != ENABLED && HTTP_SERVER_BASIC_AUTH_SUPPORT != DISABLED)
76  #error HTTP_SERVER_BASIC_AUTH_SUPPORT parameter is not valid
77 #endif
78 
79 //Digest access authentication support
80 #ifndef HTTP_SERVER_DIGEST_AUTH_SUPPORT
81  #define HTTP_SERVER_DIGEST_AUTH_SUPPORT DISABLED
82 #elif (HTTP_SERVER_DIGEST_AUTH_SUPPORT != ENABLED && HTTP_SERVER_DIGEST_AUTH_SUPPORT != DISABLED)
83  #error HTTP_SERVER_DIGEST_AUTH_SUPPORT parameter is not valid
84 #endif
85 
86 //WebSocket support
87 #ifndef HTTP_SERVER_WEB_SOCKET_SUPPORT
88  #define HTTP_SERVER_WEB_SOCKET_SUPPORT DISABLED
89 #elif (HTTP_SERVER_WEB_SOCKET_SUPPORT != ENABLED && HTTP_SERVER_WEB_SOCKET_SUPPORT != DISABLED)
90  #error HTTP_SERVER_WEB_SOCKET_SUPPORT parameter is not valid
91 #endif
92 
93 //Gzip content type support
94 #ifndef HTTP_SERVER_GZIP_TYPE_SUPPORT
95  #define HTTP_SERVER_GZIP_TYPE_SUPPORT DISABLED
96 #elif (HTTP_SERVER_GZIP_TYPE_SUPPORT != ENABLED && HTTP_SERVER_GZIP_TYPE_SUPPORT != DISABLED)
97  #error HTTP_SERVER_GZIP_TYPE_SUPPORT parameter is not valid
98 #endif
99 
100 //Multipart content type support
101 #ifndef HTTP_SERVER_MULTIPART_TYPE_SUPPORT
102  #define HTTP_SERVER_MULTIPART_TYPE_SUPPORT DISABLED
103 #elif (HTTP_SERVER_MULTIPART_TYPE_SUPPORT != ENABLED && HTTP_SERVER_MULTIPART_TYPE_SUPPORT != DISABLED)
104  #error HTTP_SERVER_MULTIPART_TYPE_SUPPORT parameter is not valid
105 #endif
106 
107 //Stack size required to run the HTTP server
108 #ifndef HTTP_SERVER_STACK_SIZE
109  #define HTTP_SERVER_STACK_SIZE 650
110 #elif (HTTP_SERVER_STACK_SIZE < 1)
111  #error HTTP_SERVER_STACK_SIZE parameter is not valid
112 #endif
113 
114 //Priority at which the HTTP server should run
115 #ifndef HTTP_SERVER_PRIORITY
116  #define HTTP_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL
117 #endif
118 
119 //HTTP connection timeout
120 #ifndef HTTP_SERVER_TIMEOUT
121  #define HTTP_SERVER_TIMEOUT 10000
122 #elif (HTTP_SERVER_TIMEOUT < 1000)
123  #error HTTP_SERVER_TIMEOUT parameter is not valid
124 #endif
125 
126 //Maximum time the server will wait for a subsequent
127 //request before closing the connection
128 #ifndef HTTP_SERVER_IDLE_TIMEOUT
129  #define HTTP_SERVER_IDLE_TIMEOUT 5000
130 #elif (HTTP_SERVER_IDLE_TIMEOUT < 1000)
131  #error HTTP_SERVER_IDLE_TIMEOUT parameter is not valid
132 #endif
133 
134 //Maximum length of the pending connection queue
135 #ifndef HTTP_SERVER_BACKLOG
136  #define HTTP_SERVER_BACKLOG 4
137 #elif (HTTP_SERVER_BACKLOG < 1)
138  #error HTTP_SERVER_BACKLOG parameter is not valid
139 #endif
140 
141 //Maximum number of requests per connection
142 #ifndef HTTP_SERVER_MAX_REQUESTS
143  #define HTTP_SERVER_MAX_REQUESTS 1000
144 #elif (HTTP_SERVER_MAX_REQUESTS < 1)
145  #error HTTP_SERVER_MAX_REQUESTS parameter is not valid
146 #endif
147 
148 //Size of buffer used for input/output operations
149 #ifndef HTTP_SERVER_BUFFER_SIZE
150  #define HTTP_SERVER_BUFFER_SIZE 1024
151 #elif (HTTP_SERVER_BUFFER_SIZE < 128)
152  #error HTTP_SERVER_BUFFER_SIZE parameter is not valid
153 #endif
154 
155 //Maximum size of root directory
156 #ifndef HTTP_SERVER_ROOT_DIR_MAX_LEN
157  #define HTTP_SERVER_ROOT_DIR_MAX_LEN 31
158 #elif (HTTP_SERVER_ROOT_DIR_MAX_LEN < 7)
159  #error HTTP_SERVER_ROOT_DIR_MAX_LEN parameter is not valid
160 #endif
161 
162 //Maximum size of default index file
163 #ifndef HTTP_SERVER_DEFAULT_DOC_MAX_LEN
164  #define HTTP_SERVER_DEFAULT_DOC_MAX_LEN 31
165 #elif (HTTP_SERVER_DEFAULT_DOC_MAX_LEN < 7)
166  #error HTTP_SERVER_DEFAULT_DOC_MAX_LEN parameter is not valid
167 #endif
168 
169 //Maximum length of HTTP method
170 #ifndef HTTP_SERVER_METHOD_MAX_LEN
171  #define HTTP_SERVER_METHOD_MAX_LEN 7
172 #elif (HTTP_SERVER_METHOD_MAX_LEN < 1)
173  #error HTTP_SERVER_METHOD_MAX_LEN parameter is not valid
174 #endif
175 
176 //Maximum length of URI
177 #ifndef HTTP_SERVER_URI_MAX_LEN
178  #define HTTP_SERVER_URI_MAX_LEN 255
179 #elif (HTTP_SERVER_URI_MAX_LEN < 31)
180  #error HTTP_SERVER_URI_MAX_LEN parameter is not valid
181 #endif
182 
183 //Maximum length of query strings
184 #ifndef HTTP_SERVER_QUERY_STRING_MAX_LEN
185  #define HTTP_SERVER_QUERY_STRING_MAX_LEN 255
186 #elif (HTTP_SERVER_QUERY_STRING_MAX_LEN < 7)
187  #error HTTP_SERVER_QUERY_STRING_MAX_LEN parameter is not valid
188 #endif
189 
190 //Maximum host name length
191 #ifndef HTTP_SERVER_HOST_MAX_LEN
192  #define HTTP_SERVER_HOST_MAX_LEN 31
193 #elif (HTTP_SERVER_HOST_MAX_LEN < 7)
194  #error HTTP_SERVER_HOST_MAX_LEN parameter is not valid
195 #endif
196 
197 //Maximum user name length
198 #ifndef HTTP_SERVER_USERNAME_MAX_LEN
199  #define HTTP_SERVER_USERNAME_MAX_LEN 31
200 #elif (HTTP_SERVER_USERNAME_MAX_LEN < 7)
201  #error HTTP_SERVER_USERNAME_MAX_LEN parameter is not valid
202 #endif
203 
204 //Maximum length of CGI parameters
205 #ifndef HTTP_SERVER_CGI_PARAM_MAX_LEN
206  #define HTTP_SERVER_CGI_PARAM_MAX_LEN 31
207 #elif (HTTP_SERVER_CGI_PARAM_MAX_LEN < 7)
208  #error HTTP_SERVER_CGI_PARAM_MAX_LEN parameter is not valid
209 #endif
210 
211 //Maximum recursion limit
212 #ifndef HTTP_SERVER_SSI_MAX_RECURSION
213  #define HTTP_SERVER_SSI_MAX_RECURSION 3
214 #elif (HTTP_SERVER_SSI_MAX_RECURSION < 1 || HTTP_SERVER_SSI_MAX_RECURSION > 8)
215  #error HTTP_SERVER_SSI_MAX_RECURSION parameter is not valid
216 #endif
217 
218 //Maximum age for static resources
219 #ifndef HTTP_SERVER_MAX_AGE
220  #define HTTP_SERVER_MAX_AGE 0
221 #elif (HTTP_SERVER_MAX_AGE < 0)
222  #error HTTP_SERVER_MAX_AGE parameter is not valid
223 #endif
224 
225 //Nonce cache size
226 #ifndef HTTP_SERVER_NONCE_CACHE_SIZE
227  #define HTTP_SERVER_NONCE_CACHE_SIZE 8
228 #elif (HTTP_SERVER_NONCE_CACHE_SIZE < 1)
229  #error HTTP_SERVER_NONCE_CACHE_SIZE parameter is not valid
230 #endif
231 
232 //Lifetime of nonces
233 #ifndef HTTP_SERVER_NONCE_LIFETIME
234  #define HTTP_SERVER_NONCE_LIFETIME 60000
235 #elif (HTTP_SERVER_NONCE_LIFETIME < 1000)
236  #error HTTP_SERVER_NONCE_LIFETIME parameter is not valid
237 #endif
238 
239 //Nonce size
240 #ifndef HTTP_SERVER_NONCE_SIZE
241  #define HTTP_SERVER_NONCE_SIZE 16
242 #elif (HTTP_SERVER_NONCE_SIZE < 1)
243  #error HTTP_SERVER_NONCE_SIZE parameter is not valid
244 #endif
245 
246 //Maximum length for boundary string
247 #ifndef HTTP_SERVER_BOUNDARY_MAX_LEN
248  #define HTTP_SERVER_BOUNDARY_MAX_LEN 70
249 #elif (HTTP_SERVER_BOUNDARY_MAX_LEN < 1)
250  #error HTTP_SERVER_BOUNDARY_MAX_LEN parameter is not valid
251 #endif
252 
253 //File system support?
254 #if (HTTP_SERVER_FS_SUPPORT == ENABLED)
255  #include "fs_port.h"
256 #else
257  #include "resource_manager.h"
258 #endif
259 
260 //HTTP over TLS supported?
261 #if (HTTP_SERVER_TLS_SUPPORT == ENABLED)
262  #include "core/crypto.h"
263  #include "tls.h"
264  #include "tls_ticket.h"
265 #endif
266 
267 //Basic authentication supported?
268 #if (HTTP_SERVER_BASIC_AUTH_SUPPORT == ENABLED)
269  #include "core/crypto.h"
270  #include "encoding/base64.h"
271 #endif
272 
273 //Digest authentication supported?
274 #if (HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
275  #include "core/crypto.h"
276  #include "hash/md5.h"
277 #endif
278 
279 //WebSocket supported?
280 #if (HTTP_SERVER_WEB_SOCKET_SUPPORT == ENABLED)
281  #include "core/crypto.h"
282  #include "encoding/base64.h"
283 #endif
284 
285 //HTTP port number
286 #define HTTP_PORT 80
287 //HTTPS port number (HTTP over TLS)
288 #define HTTPS_PORT 443
289 
290 //Forward declaration of HttpServerContext structure
291 struct _HttpServerContext;
292 #define HttpServerContext struct _HttpServerContext
293 
294 //Forward declaration of HttpConnection structure
295 struct _HttpConnection;
296 #define HttpConnection struct _HttpConnection
297 
298 //C++ guard
299 #ifdef __cplusplus
300  extern "C" {
301 #endif
302 
303 
304 /**
305  * @brief HTTP version numbers
306  **/
307 
308 typedef enum
309 {
313 } HttpVersion;
314 
315 
316 /**
317  * @brief HTTP authentication schemes
318  **/
319 
320 typedef enum
321 {
325 } HttpAuthMode;
326 
327 
328 /**
329  * @brief Access status
330  **/
331 
332 typedef enum
333 {
339 
340 
341 /**
342  * @brief Flags used by I/O functions
343  **/
344 
345 typedef enum
346 {
353 } HttpFlags;
354 
355 
356 /**
357  * @brief HTTP connection states
358  **/
359 
360 typedef enum
361 {
370 } HttpConnState;
371 
372 
373 //The HTTP_FLAG_BREAK macro causes the httpReadStream() function to stop
374 //reading data whenever the specified break character is encountered
375 #define HTTP_FLAG_BREAK(c) (HTTP_FLAG_BREAK_CHAR | LSB(c))
376 
377 
378 //HTTP over TLS supported?
379 #if (HTTP_SERVER_TLS_SUPPORT == ENABLED)
380 
381 /**
382  * @brief TLS initialization callback function
383  **/
384 
385 typedef error_t (*TlsInitCallback)(HttpConnection *connection,
387 
388 #endif
389 
390 
391 /**
392  * @brief Random data generation callback function
393  **/
394 
395 typedef error_t (*HttpRandCallback)(uint8_t *data, size_t length);
396 
397 
398 /**
399  * @brief HTTP authentication callback function
400  **/
401 
403  const char_t *user, const char_t *uri);
404 
405 
406 /**
407  * @brief CGI callback function
408  **/
409 
410 typedef error_t (*HttpCgiCallback)(HttpConnection *connection,
411  const char_t *param);
412 
413 
414 /**
415  * @brief HTTP request callback function
416  **/
417 
419  const char_t *uri);
420 
421 
422 /**
423  * @brief URI not found callback function
424  **/
425 
427  const char_t *uri);
428 
429 
430 /**
431  * @brief HTTP status code
432  **/
433 
434 typedef struct
435 {
437  const char_t message[28];
439 
440 
441 /**
442  * @brief Authorization header
443  **/
444 
445 typedef struct
446 {
447  bool_t found; ///<The Authorization header has been found
448  HttpAuthMode mode; ///<Authentication scheme
449  char_t user[HTTP_SERVER_USERNAME_MAX_LEN + 1]; ///<User name
450 #if (HTTP_SERVER_BASIC_AUTH_SUPPORT == ENABLED)
451  const char_t *password; ///<Password
452 #endif
453 #if (HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
454  const char_t *realm;
455  const char_t *nonce; ///<Server nonce
456  const char_t *uri; ///<Digest URI
457  const char_t *qop;
458  const char_t *nc; ///<Nonce count
459  const char_t *cnonce; ///<Client nonce
460  const char_t *response;
461  const char_t *opaque;
462 #endif
464 
465 
466 /**
467  * @brief Authenticate header
468  **/
469 
470 typedef struct
471 {
472  HttpAuthMode mode; ///<Authentication scheme
473 #if (HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
474  bool_t stale; ///<STALE flag
475 #endif
477 
478 
479 /**
480  * @brief HTTP request
481  **/
482 
483 typedef struct
484 {
485  uint_t version; ///<HTTP version number
486  char_t method[HTTP_SERVER_METHOD_MAX_LEN + 1]; ///<HTTP method
487  char_t uri[HTTP_SERVER_URI_MAX_LEN + 1]; ///<Resource identifier
488  char_t queryString[HTTP_SERVER_QUERY_STRING_MAX_LEN + 1]; ///<Query string
489  char_t host[HTTP_SERVER_HOST_MAX_LEN + 1]; ///<Host name
493  size_t byteCount;
496 #if (HTTP_SERVER_BASIC_AUTH_SUPPORT == ENABLED || HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
497  HttpAuthorizationHeader auth; ///<Authorization header
498 #endif
499 #if (HTTP_SERVER_WEB_SOCKET_SUPPORT == ENABLED)
503 #endif
504 #if (HTTP_SERVER_GZIP_TYPE_SUPPORT == ENABLED)
506 #endif
507 #if (HTTP_SERVER_MULTIPART_TYPE_SUPPORT == ENABLED)
508  char_t boundary[HTTP_SERVER_BOUNDARY_MAX_LEN + 1]; ///<Boundary string
509  size_t boundaryLength; ///<Boundary string length
510 #endif
511 } HttpRequest;
512 
513 
514 /**
515  * @brief HTTP response
516  **/
517 
518 typedef struct
519 {
520  uint_t version; ///<HTTP version number
521  uint_t statusCode; ///<HTTP status code
525  const char_t *location;
529  size_t byteCount;
530 #if (HTTP_SERVER_BASIC_AUTH_SUPPORT == ENABLED || HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
531  HttpAuthenticateHeader auth; ///<Authenticate header
532 #endif
533 #if (HTTP_SERVER_GZIP_TYPE_SUPPORT == ENABLED)
535 #endif
536 } HttpResponse;
537 
538 
539 /**
540  * @brief HTTP server settings
541  **/
542 
543 typedef struct
544 {
545  NetInterface *interface; ///<Underlying network interface
546  uint16_t port; ///<HTTP server port number
547  uint_t backlog; ///<Maximum length of the pending connection queue
548  uint_t maxConnections; ///<Maximum number of simultaneous connections
549  HttpConnection *connections; ///<HTTP client connections
550  char_t rootDirectory[HTTP_SERVER_ROOT_DIR_MAX_LEN + 1]; ///<Web root directory
551  char_t defaultDocument[HTTP_SERVER_DEFAULT_DOC_MAX_LEN + 1]; ///<Default home page
552 #if (HTTP_SERVER_TLS_SUPPORT == ENABLED)
553  bool_t useTls; ///<HTTP over TLS
554  TlsInitCallback tlsInitCallback; ///<TLS initialization callback function
555 #endif
556 #if (HTTP_SERVER_BASIC_AUTH_SUPPORT == ENABLED || HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
557  HttpRandCallback randCallback; ///<Random data generation callback function
558  HttpAuthCallback authCallback; ///<HTTP authentication callback function
559 #endif
560  HttpCgiCallback cgiCallback; ///<CGI callback function
561  HttpRequestCallback requestCallback; ///<HTTP request callback function
562  HttpUriNotFoundCallback uriNotFoundCallback; ///<URI not found callback function
564 
565 
566 /**
567  * @brief Nonce cache entry
568  **/
569 
570 typedef struct
571 {
572  char_t nonce[HTTP_SERVER_NONCE_SIZE * 2 + 1]; ///<Nonce
573  uint32_t count; ///<Nonce count
574  systime_t timestamp; ///<Time stamp to manage entry lifetime
576 
577 
578 /**
579  * @brief HTTP server context
580  **/
581 
583 {
584  HttpServerSettings settings; ///<User settings
585  OsTask *taskHandle; ///<Listener task handle
586  OsSemaphore semaphore; ///<Semaphore limiting the number of connections
587  Socket *socket; ///<Listening socket
588  HttpConnection *connections; ///<HTTP client connections
589 #if (HTTP_SERVER_TLS_SUPPORT == ENABLED && TLS_TICKET_SUPPORT == ENABLED)
590  TlsTicketContext tlsTicketContext; ///<TLS ticket encryption context
591 #endif
592 #if (HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
593  OsMutex nonceCacheMutex; ///<Mutex preventing simultaneous access to the nonce cache
595 #endif
596 };
597 
598 
599 /**
600  * @brief HTTP connection
601  *
602  * An HttpConnection instance represents one
603  * transaction with an HTTP client
604  *
605  **/
606 
608 {
609  HttpServerSettings *settings; ///<Reference to the HTTP server settings
610  HttpServerContext *serverContext; ///<Reference to the HTTP server context
611  OsTask *taskHandle; ///<Client task handle
614  Socket *socket; ///<Socket
615 #if (HTTP_SERVER_TLS_SUPPORT == ENABLED)
616  TlsContext *tlsContext; ///<TLS context
617 #endif
618  HttpRequest request; ///<Incoming HTTP request header
619  HttpResponse response; ///<HTTP response header
620  HttpAccessStatus status; ///<Access status
622  uint32_t dummy; ///<Force alignment of the buffer on 32-bit boundaries
623  char_t buffer[HTTP_SERVER_BUFFER_SIZE]; ///<Memory buffer for input/output operations
624 #if (NET_RTOS_SUPPORT == DISABLED)
625  HttpConnState state; ///<Connection state
627  size_t bufferPos;
628  size_t bufferLen;
629  uint8_t *bodyStart;
630  size_t bodyPos;
631  size_t bodyLen;
632 #endif
633 };
634 
635 
636 //HTTP server related functions
640 
641 void httpListenerTask(void *param);
642 void httpConnectionTask(void *param);
643 
645 
647  void *data, size_t size, size_t *received, uint_t flags);
648 
650  const void *data, size_t length);
651 
653 
654 error_t httpSendResponse(HttpConnection *connection, const char_t *uri);
655 
657  uint_t statusCode, const char_t *message);
658 
660  uint_t statusCode, const char_t *uri);
661 
662 //HTTP authentication related functions
664  const char_t *password, HttpAuthMode mode);
665 
666 //WebSocket related functions
669 
670 //Miscellaneous functions
672  char_t *output, size_t outputSize);
673 
674 //C++ guard
675 #ifdef __cplusplus
676  }
677 #endif
678 
679 #endif
TLS (Transport Layer Security)
#define WEB_SOCKET_CLIENT_KEY_SIZE
Definition: web_socket.h:169
#define HTTP_SERVER_CGI_PARAM_MAX_LEN
Definition: http_server.h:206
size_t byteCount
Definition: http_server.h:493
size_t contentLength
Definition: http_server.h:528
bool_t useTls
HTTP over TLS.
Definition: http_server.h:553
#define HttpServerContext
Definition: http_server.h:292
uint32_t systime_t
Definition: compiler_port.h:44
bool_t chunkedEncoding
Definition: http_server.h:527
HttpAuthenticateHeader auth
Authenticate header.
Definition: http_server.h:531
NetInterface * interface
Underlying network interface.
Definition: http_server.h:545
bool_t stale
STALE flag.
Definition: http_server.h:474
const char_t * response
Definition: http_server.h:460
char char_t
Definition: compiler_port.h:41
HttpServerSettings settings
User settings.
Definition: http_server.h:584
uint8_t flags
Definition: tcp.h:312
HttpConnection * connections
HTTP client connections.
Definition: http_server.h:588
Authorization header.
Definition: http_server.h:445
OsSemaphore semaphore
Semaphore limiting the number of connections.
Definition: http_server.h:586
uint32_t dummy
Force alignment of the buffer on 32-bit boundaries.
Definition: http_server.h:622
#define HTTP_SERVER_DEFAULT_DOC_MAX_LEN
Definition: http_server.h:164
error_t httpSendResponse(HttpConnection *connection, const char_t *uri)
Send HTTP response.
Definition: http_server.c:849
WebSocket * httpUpgradeToWebSocket(HttpConnection *connection)
Upgrade an existing HTTP connection to a WebSocket.
Definition: http_server.c:1214
HttpAccessStatus(* HttpAuthCallback)(HttpConnection *connection, const char_t *user, const char_t *uri)
HTTP authentication callback function.
Definition: http_server.h:402
error_t httpWriteHeader(HttpConnection *connection)
Send HTTP response header.
Definition: http_server.c:617
const char_t * cnonce
Client nonce.
Definition: http_server.h:459
error_t httpDecodePercentEncodedString(const char_t *input, char_t *output, size_t outputSize)
Decode a percent-encoded string.
bool_t upgradeWebSocket
Definition: http_server.h:500
const char_t * realm
Definition: http_server.h:454
HttpAccessStatus status
Access status.
Definition: http_server.h:620
HttpAuthorizationHeader auth
Authorization header.
Definition: http_server.h:497
HttpRandCallback randCallback
Random data generation callback function.
Definition: http_server.h:557
#define HTTP_SERVER_NONCE_CACHE_SIZE
Definition: http_server.h:227
bool_t gzipEncoding
Definition: http_server.h:534
#define WebSocket
Definition: web_socket.h:175
const char_t * contentType
Definition: http_server.h:526
uint8_t message[]
Definition: chap.h:150
bool_t httpCheckWebSocketHandshake(HttpConnection *connection)
Check whether the client&#39;s handshake is valid.
Definition: http_server.c:1165
General definitions for cryptographic algorithms.
#define HTTP_SERVER_BUFFER_SIZE
Definition: http_server.h:150
HttpConnState state
Connection state.
Definition: http_server.h:625
HttpConnection * connections
HTTP client connections.
Definition: http_server.h:549
char_t cgiParam[HTTP_SERVER_CGI_PARAM_MAX_LEN+1]
CGI parameter.
Definition: http_server.h:621
error_t(* HttpRequestCallback)(HttpConnection *connection, const char_t *uri)
HTTP request callback function.
Definition: http_server.h:418
systime_t timestamp
Definition: http_server.h:626
uint16_t statusCode
bool_t keepAlive
Definition: http_server.h:522
error_t httpSendErrorResponse(HttpConnection *connection, uint_t statusCode, const char_t *message)
Send error response to the client.
Definition: http_server.c:1054
HttpRequestCallback requestCallback
HTTP request callback function.
Definition: http_server.h:561
HttpAuthMode mode
Authentication scheme.
Definition: http_server.h:448
uint32_t count
Nonce count.
Definition: http_server.h:573
#define HTTP_SERVER_URI_MAX_LEN
Definition: http_server.h:178
TlsInitCallback tlsInitCallback
TLS initialization callback function.
Definition: http_server.h:554
uint_t version
HTTP version number.
Definition: http_server.h:520
Socket * socket
Listening socket.
Definition: http_server.h:587
Event object.
#define HTTP_SERVER_HOST_MAX_LEN
Definition: http_server.h:192
error_t httpServerStart(HttpServerContext *context)
Start HTTP server.
Definition: http_server.c:204
HTTP connection.
Definition: http_server.h:607
bool_t lastChunk
Definition: http_server.h:495
char_t buffer[HTTP_SERVER_BUFFER_SIZE]
Memory buffer for input/output operations.
Definition: http_server.h:623
HttpCgiCallback cgiCallback
CGI callback function.
Definition: http_server.h:560
OsMutex nonceCacheMutex
Mutex preventing simultaneous access to the nonce cache.
Definition: http_server.h:593
void httpServerGetDefaultSettings(HttpServerSettings *settings)
Initialize settings with default values.
Definition: http_server.c:61
bool_t keepAlive
Definition: http_server.h:490
Socket * socket
Socket.
Definition: http_server.h:614
bool_t firstChunk
Definition: http_server.h:494
bool_t noCache
Definition: http_server.h:523
HTTP response.
Definition: http_server.h:518
Nonce cache entry.
Definition: http_server.h:570
#define Socket
Definition: socket.h:34
bool_t found
The Authorization header has been found.
Definition: http_server.h:447
error_t(* HttpCgiCallback)(HttpConnection *connection, const char_t *param)
CGI callback function.
Definition: http_server.h:410
TlsContext * tlsContext
TLS context.
Definition: http_server.h:616
error_t httpSendRedirectResponse(HttpConnection *connection, uint_t statusCode, const char_t *uri)
Send redirect response to the client.
Definition: http_server.c:1110
OsEvent startEvent
Definition: http_server.h:612
Task object.
TLS session tickets.
uint_t version
HTTP version number.
Definition: http_server.h:485
Session ticket encryption context.
Definition: tls_ticket.h:88
#define HTTP_SERVER_ROOT_DIR_MAX_LEN
Definition: http_server.h:157
bool_t connectionUpgrade
Definition: http_server.h:501
uint16_t port
HTTP server port number.
Definition: http_server.h:546
HttpNonceCacheEntry nonceCache[HTTP_SERVER_NONCE_CACHE_SIZE]
Nonce cache.
Definition: http_server.h:594
RTOS abstraction layer.
const char_t * nc
Nonce count.
Definition: http_server.h:458
const char_t * opaque
Definition: http_server.h:461
const char_t * qop
Definition: http_server.h:457
const char_t * nonce
Server nonce.
Definition: http_server.h:455
HttpVersion
HTTP version numbers.
Definition: http_server.h:308
error_t httpCloseStream(HttpConnection *connection)
Close output stream.
Definition: http_server.c:821
uint_t maxConnections
Maximum number of simultaneous connections.
Definition: http_server.h:548
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: http_server.h:574
HttpServerContext * serverContext
Reference to the HTTP server context.
Definition: http_server.h:610
#define HTTP_SERVER_USERNAME_MAX_LEN
Definition: http_server.h:199
File system abstraction layer.
HttpAuthCallback authCallback
HTTP authentication callback function.
Definition: http_server.h:558
#define HTTP_SERVER_QUERY_STRING_MAX_LEN
Definition: http_server.h:185
HttpAuthMode mode
Authentication scheme.
Definition: http_server.h:472
const char_t * password
Password.
Definition: http_server.h:451
TlsTicketContext tlsTicketContext
TLS ticket encryption context.
Definition: http_server.h:590
HttpServerSettings * settings
Reference to the HTTP server settings.
Definition: http_server.h:609
HttpRequest request
Incoming HTTP request header.
Definition: http_server.h:618
HTTP request.
Definition: http_server.h:483
HTTP server context.
Definition: http_server.h:582
HTTP server settings.
Definition: http_server.h:543
HttpFlags
Flags used by I/O functions.
Definition: http_server.h:345
error_t(* HttpRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
Definition: http_server.h:395
error_t
Error codes.
Definition: error.h:40
Base64 encoding scheme.
bool_t acceptGzipEncoding
Definition: http_server.h:505
size_t byteCount
Definition: http_server.h:529
unsigned int uint_t
Definition: compiler_port.h:43
error_t(* TlsInitCallback)(HttpConnection *connection, TlsContext *tlsContext)
TLS initialization callback function.
Definition: http_server.h:385
error_t(* HttpUriNotFoundCallback)(HttpConnection *connection, const char_t *uri)
URI not found callback function.
Definition: http_server.h:426
uint8_t data[]
Definition: dtls_misc.h:167
OsTask * taskHandle
Listener task handle.
Definition: http_server.h:585
#define HttpConnection
Definition: http_server.h:296
#define NetInterface
Definition: net.h:34
HTTP status code.
Definition: http_server.h:434
uint8_t mode
Definition: sntp_client.h:143
uint_t backlog
Maximum length of the pending connection queue.
Definition: http_server.h:547
const char_t * uri
Digest URI.
Definition: http_server.h:456
HttpConnState
HTTP connection states.
Definition: http_server.h:360
Mutex object.
HttpAccessStatus
Access status.
Definition: http_server.h:332
uint8_t * bodyStart
Definition: http_server.h:629
size_t boundaryLength
Boundary string length.
Definition: http_server.h:509
#define HTTP_SERVER_BOUNDARY_MAX_LEN
Definition: http_server.h:248
void httpConnectionTask(void *param)
Task that services requests from an active connection.
Definition: http_server.c:316
Embedded resource management.
bool_t chunkedEncoding
Definition: http_server.h:491
OsTask * taskHandle
Client task handle.
Definition: http_server.h:611
bool_t httpCheckPassword(HttpConnection *connection, const char_t *password, HttpAuthMode mode)
Password verification.
HttpResponse response
HTTP response header.
Definition: http_server.h:619
uint_t maxAge
Definition: http_server.h:524
size_t contentLength
Definition: http_server.h:492
Socket API.
uint8_t length
Definition: dtls_misc.h:140
MD5 (Message-Digest Algorithm)
error_t httpServerInit(HttpServerContext *context, const HttpServerSettings *settings)
HTTP server initialization.
Definition: http_server.c:106
error_t httpReadStream(HttpConnection *connection, void *data, size_t size, size_t *received, uint_t flags)
Read data from client request.
Definition: http_server.c:650
void httpListenerTask(void *param)
HTTP server listener task.
Definition: http_server.c:246
error_t httpWriteStream(HttpConnection *connection, const void *data, size_t length)
Write data to the client.
Definition: http_server.c:756
Semaphore object.
HttpUriNotFoundCallback uriNotFoundCallback
URI not found callback function.
Definition: http_server.h:562
#define TlsContext
Definition: tls.h:34
int bool_t
Definition: compiler_port.h:47
#define HTTP_SERVER_NONCE_SIZE
Definition: http_server.h:241
Authenticate header.
Definition: http_server.h:470
uint_t statusCode
HTTP status code.
Definition: http_server.h:521
HttpAuthMode
HTTP authentication schemes.
Definition: http_server.h:320
const char_t * location
Definition: http_server.h:525
WebSocket API (client and server)
#define HTTP_SERVER_METHOD_MAX_LEN
Definition: http_server.h:171