1 /**
2  * @file
3  * HTTP server options list
4  */
5 
6 /*
7  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  *    this list of conditions and the following disclaimer in the documentation
17  *    and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Adam Dunkels <adam@sics.se>
35  *
36  * This version of the file has been modified by Texas Instruments to offer
37  * simple server-side-include (SSI) and Common Gateway Interface (CGI)
38  * capability.
39  */
40 
41 #ifndef LWIP_HDR_APPS_HTTPD_OPTS_H
42 #define LWIP_HDR_APPS_HTTPD_OPTS_H
43 
44 #include "lwip/opt.h"
45 #include "lwip/prot/iana.h"
46 
47 /**
48  * @defgroup httpd_opts Options
49  * @ingroup httpd
50  * @{
51  */
52 
53 /** Set this to 1 to support CGI (old style).
54  *
55  * This old style CGI support works by registering an array of URLs and
56  * associated CGI handler functions (@ref http_set_cgi_handlers).
57  * This list is scanned just before fs_open is called from request handling.
58  * The handler can return a new URL that is used internally by the httpd to
59  * load the returned page (passed to fs_open).
60  *
61  * Use this CGI type e.g. to execute specific actions and return a page that
62  * does not depend on the CGI parameters.
63  */
64 #if !defined LWIP_HTTPD_CGI || defined __DOXYGEN__
65 #define LWIP_HTTPD_CGI            0
66 #endif
67 
68 /** Set this to 1 to support CGI (new style).
69  *
70  * This new style CGI support works by calling a global function
71  * (@ref tCGIHandler) for all URLs that are found. fs_open is called first
72  * and the URL can not be written by the CGI handler. Instead, this handler gets
73  * passed the http file state, an object where it can store information derived
74  * from the CGI URL or parameters. This file state is later passed to SSI, so
75  * the SSI code can return data depending on CGI input.
76  *
77  * Use this CGI handler if you want CGI information passed on to SSI.
78  */
79 #if !defined LWIP_HTTPD_CGI_SSI || defined __DOXYGEN__
80 #define LWIP_HTTPD_CGI_SSI        0
81 #endif
82 
83 /** Set this to 1 to support SSI (Server-Side-Includes)
84  *
85  * In contrast to other http servers, this only calls a preregistered callback
86  * function (@see http_set_ssi_handler) for each tag (in the format of
87  * <!--#tag-->) encountered in SSI-enabled pages.
88  * SSI-enabled pages must have one of the predefined SSI-enabled file extensions.
89  * All files with one of these extensions are parsed when sent.
90  *
91  * A downside of the current SSI implementation is that persistent connections
92  * don't work, as the file length is not known in advance (and httpd currently
93  * relies on the Content-Length header for persistent connections).
94  *
95  * To save memory, the maximum tag length is limited (@see LWIP_HTTPD_MAX_TAG_NAME_LEN).
96  * To save memory, the maximum insertion string length is limited (@see
97  * LWIP_HTTPD_MAX_TAG_INSERT_LEN). If this is not enough, @ref LWIP_HTTPD_SSI_MULTIPART
98  * can be used.
99  */
100 #if !defined LWIP_HTTPD_SSI || defined __DOXYGEN__
101 #define LWIP_HTTPD_SSI            0
102 #endif
103 
104 /** Set this to 1 to implement an SSI tag handler callback that gets a const char*
105  * to the tag (instead of an index into a pre-registered array of known tags)
106  * If this is 0, the SSI handler callback function is only called pre-registered tags.
107  */
108 #if !defined LWIP_HTTPD_SSI_RAW || defined __DOXYGEN__
109 #define LWIP_HTTPD_SSI_RAW        0
110 #endif
111 
112 /** Set this to 0 to prevent parsing the file extension at runtime to decide
113  * if a file should be scanned for SSI tags or not.
114  * Default is 1 (file extensions are checked using the g_pcSSIExtensions array)
115  * Set to 2 to override this runtime test function. In this case, you have to
116  * provide an external function that does the check:
117  *   u8_t http_uri_is_ssi(struct fs_file *file, const char *uri)
118  *
119  * This is enabled by default, but if you only use a newer version of makefsdata
120  * supporting the "-ssi" option, this info is already present in
121  */
122 #if !defined LWIP_HTTPD_SSI_BY_FILE_EXTENSION || defined __DOXYGEN__
123 #define LWIP_HTTPD_SSI_BY_FILE_EXTENSION  1
124 #endif
125 
126 /** This is a list of file extensions handled as SSI files. This define
127  * is used to initialize a 'const char *const[]'. It is only used if
128  * LWIP_HTTPD_SSI_BY_FILE_EXTENSION != 0.
129  */
130 #if !defined LWIP_HTTPD_SSI_EXTENSIONS || defined __DOXYGEN__
131 #define LWIP_HTTPD_SSI_EXTENSIONS ".shtml", ".shtm", ".ssi", ".xml", ".json"
132 #endif
133 
134 /** Set this to 1 to support HTTP POST */
135 #if !defined LWIP_HTTPD_SUPPORT_POST || defined __DOXYGEN__
136 #define LWIP_HTTPD_SUPPORT_POST   0
137 #endif
138 
139 /* The maximum number of parameters that the CGI handler can be sent. */
140 #if !defined LWIP_HTTPD_MAX_CGI_PARAMETERS || defined __DOXYGEN__
141 #define LWIP_HTTPD_MAX_CGI_PARAMETERS 16
142 #endif
143 
144 /** LWIP_HTTPD_SSI_MULTIPART==1: SSI handler function is called with 2 more
145  * arguments indicating a counter for insert string that are too long to be
146  * inserted at once: the SSI handler function must then set 'next_tag_part'
147  * which will be passed back to it in the next call. */
148 #if !defined LWIP_HTTPD_SSI_MULTIPART || defined __DOXYGEN__
149 #define LWIP_HTTPD_SSI_MULTIPART    0
150 #endif
151 
152 /* The maximum length of the string comprising the SSI tag name
153  * ATTENTION: tags longer than this are ignored, not truncated!
154  */
155 #if !defined LWIP_HTTPD_MAX_TAG_NAME_LEN || defined __DOXYGEN__
156 #define LWIP_HTTPD_MAX_TAG_NAME_LEN 8
157 #endif
158 
159 /* The maximum length of string that can be returned to replace any given tag
160  * If this buffer is not long enough, use LWIP_HTTPD_SSI_MULTIPART.
161  */
162 #if !defined LWIP_HTTPD_MAX_TAG_INSERT_LEN || defined __DOXYGEN__
163 #define LWIP_HTTPD_MAX_TAG_INSERT_LEN 192
164 #endif
165 
166 #if !defined LWIP_HTTPD_POST_MANUAL_WND || defined __DOXYGEN__
167 #define LWIP_HTTPD_POST_MANUAL_WND  0
168 #endif
169 
170 /** This string is passed in the HTTP header as "Server: " */
171 #if !defined HTTPD_SERVER_AGENT || defined __DOXYGEN__
172 #define HTTPD_SERVER_AGENT "lwIP/" LWIP_VERSION_STRING " (http://savannah.nongnu.org/projects/lwip)"
173 #endif
174 
175 /** Set this to 1 if you want to include code that creates HTTP headers
176  * at runtime. Default is off: HTTP headers are then created statically
177  * by the makefsdata tool. Static headers mean smaller code size, but
178  * the (readonly) fsdata will grow a bit as every file includes the HTTP
179  * header. */
180 #if !defined LWIP_HTTPD_DYNAMIC_HEADERS || defined __DOXYGEN__
181 #define LWIP_HTTPD_DYNAMIC_HEADERS 0
182 #endif
183 
184 #if !defined HTTPD_DEBUG || defined __DOXYGEN__
185 #define HTTPD_DEBUG         LWIP_DBG_OFF
186 #endif
187 
188 /** Set this to 1 to use a memp pool for allocating
189  * struct http_state instead of the heap.
190  * If enabled, you'll need to define MEMP_NUM_PARALLEL_HTTPD_CONNS
191  * (and MEMP_NUM_PARALLEL_HTTPD_SSI_CONNS for SSI) to set the size of
192  * the pool(s).
193  */
194 #if !defined HTTPD_USE_MEM_POOL || defined __DOXYGEN__
195 #define HTTPD_USE_MEM_POOL  0
196 #endif
197 
198 /** The server port for HTTPD to use */
199 #if !defined HTTPD_SERVER_PORT || defined __DOXYGEN__
200 #define HTTPD_SERVER_PORT                   LWIP_IANA_PORT_HTTP
201 #endif
202 
203 /** The https server port for HTTPD to use */
204 #if !defined HTTPD_SERVER_PORT_HTTPS || defined __DOXYGEN__
205 #define HTTPD_SERVER_PORT_HTTPS             LWIP_IANA_PORT_HTTPS
206 #endif
207 
208 /** Enable https support? */
209 #if !defined HTTPD_ENABLE_HTTPS || defined __DOXYGEN__
210 #define HTTPD_ENABLE_HTTPS                  0
211 #endif
212 
213 /** Maximum retries before the connection is aborted/closed.
214  * - number of times pcb->poll is called -> default is 4*500ms = 2s;
215  * - reset when pcb->sent is called
216  */
217 #if !defined HTTPD_MAX_RETRIES || defined __DOXYGEN__
218 #define HTTPD_MAX_RETRIES                   4
219 #endif
220 
221 /** The poll delay is X*500ms */
222 #if !defined HTTPD_POLL_INTERVAL || defined __DOXYGEN__
223 #define HTTPD_POLL_INTERVAL                 4
224 #endif
225 
226 /** Priority for tcp pcbs created by HTTPD (very low by default).
227  *  Lower priorities get killed first when running out of memory.
228  */
229 #if !defined HTTPD_TCP_PRIO || defined __DOXYGEN__
230 #define HTTPD_TCP_PRIO                      TCP_PRIO_MIN
231 #endif
232 
233 /** Set this to 1 to enable timing each file sent */
234 #if !defined LWIP_HTTPD_TIMING || defined __DOXYGEN__
235 #define LWIP_HTTPD_TIMING                   0
236 #endif
237 /** Set this to 1 to enable timing each file sent */
238 #if !defined HTTPD_DEBUG_TIMING || defined __DOXYGEN__
239 #define HTTPD_DEBUG_TIMING                  LWIP_DBG_OFF
240 #endif
241 
242 /** Set this to one to show error pages when parsing a request fails instead
243     of simply closing the connection. */
244 #if !defined LWIP_HTTPD_SUPPORT_EXTSTATUS || defined __DOXYGEN__
245 #define LWIP_HTTPD_SUPPORT_EXTSTATUS        0
246 #endif
247 
248 /** Set this to 0 to drop support for HTTP/0.9 clients (to save some bytes) */
249 #if !defined LWIP_HTTPD_SUPPORT_V09 || defined __DOXYGEN__
250 #define LWIP_HTTPD_SUPPORT_V09              1
251 #endif
252 
253 /** Set this to 1 to enable HTTP/1.1 persistent connections.
254  * ATTENTION: If the generated file system includes HTTP headers, these must
255  * include the "Connection: keep-alive" header (pass argument "-11" to makefsdata).
256  */
257 #if !defined LWIP_HTTPD_SUPPORT_11_KEEPALIVE || defined __DOXYGEN__
258 #define LWIP_HTTPD_SUPPORT_11_KEEPALIVE     0
259 #endif
260 
261 /** Set this to 1 to support HTTP request coming in in multiple packets/pbufs */
262 #if !defined LWIP_HTTPD_SUPPORT_REQUESTLIST || defined __DOXYGEN__
263 #define LWIP_HTTPD_SUPPORT_REQUESTLIST      1
264 #endif
265 
266 #if LWIP_HTTPD_SUPPORT_REQUESTLIST
267 /** Number of rx pbufs to enqueue to parse an incoming request (up to the first
268     newline) */
269 #if !defined LWIP_HTTPD_REQ_QUEUELEN || defined __DOXYGEN__
270 #define LWIP_HTTPD_REQ_QUEUELEN             5
271 #endif
272 
273 /** Number of (TCP payload-) bytes (in pbufs) to enqueue to parse and incoming
274     request (up to the first double-newline) */
275 #if !defined LWIP_HTTPD_REQ_BUFSIZE || defined __DOXYGEN__
276 #define LWIP_HTTPD_REQ_BUFSIZE              LWIP_HTTPD_MAX_REQ_LENGTH
277 #endif
278 
279 /** Defines the maximum length of a HTTP request line (up to the first CRLF,
280     copied from pbuf into this a global buffer when pbuf- or packet-queues
281     are received - otherwise the input pbuf is used directly) */
282 #if !defined LWIP_HTTPD_MAX_REQ_LENGTH || defined __DOXYGEN__
283 #define LWIP_HTTPD_MAX_REQ_LENGTH           LWIP_MIN(1023, (LWIP_HTTPD_REQ_QUEUELEN * PBUF_POOL_BUFSIZE))
284 #endif
285 #endif /* LWIP_HTTPD_SUPPORT_REQUESTLIST */
286 
287 /** This is the size of a static buffer used when URIs end with '/'.
288  * In this buffer, the directory requested is concatenated with all the
289  * configured default file names.
290  * Set to 0 to disable checking default filenames on non-root directories.
291  */
292 #if !defined LWIP_HTTPD_MAX_REQUEST_URI_LEN || defined __DOXYGEN__
293 #define LWIP_HTTPD_MAX_REQUEST_URI_LEN      63
294 #endif
295 
296 /** Maximum length of the filename to send as response to a POST request,
297  * filled in by the application when a POST is finished.
298  */
299 #if !defined LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN || defined __DOXYGEN__
300 #define LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN 63
301 #endif
302 
303 /** Set this to 0 to not send the SSI tag (default is on, so the tag will
304  * be sent in the HTML page */
305 #if !defined LWIP_HTTPD_SSI_INCLUDE_TAG || defined __DOXYGEN__
306 #define LWIP_HTTPD_SSI_INCLUDE_TAG           1
307 #endif
308 
309 /** Set this to 1 to call tcp_abort when tcp_close fails with memory error.
310  * This can be used to prevent consuming all memory in situations where the
311  * HTTP server has low priority compared to other communication. */
312 #if !defined LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR || defined __DOXYGEN__
313 #define LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR  0
314 #endif
315 
316 /** Set this to 1 to kill the oldest connection when running out of
317  * memory for 'struct http_state' or 'struct http_ssi_state'.
318  * ATTENTION: This puts all connections on a linked list, so may be kind of slow.
319  */
320 #if !defined LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED || defined __DOXYGEN__
321 #define LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED 0
322 #endif
323 
324 /** Set this to 1 to send URIs without extension without headers
325  * (who uses this at all??) */
326 #if !defined LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI || defined __DOXYGEN__
327 #define LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI 0
328 #endif
329 
330 /** Default: Tags are sent from struct http_state and are therefore volatile */
331 #if !defined HTTP_IS_TAG_VOLATILE || defined __DOXYGEN__
332 #define HTTP_IS_TAG_VOLATILE(ptr) TCP_WRITE_FLAG_COPY
333 #endif
334 
335 /* By default, the httpd is limited to send 2*pcb->mss to keep resource usage low
336    when http is not an important protocol in the device. */
337 #if !defined HTTPD_LIMIT_SENDING_TO_2MSS || defined __DOXYGEN__
338 #define HTTPD_LIMIT_SENDING_TO_2MSS 1
339 #endif
340 
341 /* Define this to a function that returns the maximum amount of data to enqueue.
342    The function have this signature: u16_t fn(struct altcp_pcb* pcb);
343    The best place to define this is the hooks file (@see LWIP_HOOK_FILENAME) */
344 #if !defined HTTPD_MAX_WRITE_LEN || defined __DOXYGEN__
345 #if HTTPD_LIMIT_SENDING_TO_2MSS
346 #define HTTPD_MAX_WRITE_LEN(pcb)    ((u16_t)(2 * altcp_mss(pcb)))
347 #endif
348 #endif
349 
350 /*------------------- FS OPTIONS -------------------*/
351 
352 /** Set this to 1 and provide the functions:
353  * - "int fs_open_custom(struct fs_file *file, const char *name)"
354  *    Called first for every opened file to allow opening files
355  *    that are not included in fsdata(_custom).c
356  * - "void fs_close_custom(struct fs_file *file)"
357  *    Called to free resources allocated by fs_open_custom().
358  */
359 #if !defined LWIP_HTTPD_CUSTOM_FILES || defined __DOXYGEN__
360 #define LWIP_HTTPD_CUSTOM_FILES       0
361 #endif
362 
363 /** Set this to 1 to support fs_read() to dynamically read file data.
364  * Without this (default=off), only one-block files are supported,
365  * and the contents must be ready after fs_open().
366  */
367 #if !defined LWIP_HTTPD_DYNAMIC_FILE_READ || defined __DOXYGEN__
368 #define LWIP_HTTPD_DYNAMIC_FILE_READ  0
369 #endif
370 
371 /** Set this to 1 to include an application state argument per file
372  * that is opened. This allows to keep a state per connection/file.
373  */
374 #if !defined LWIP_HTTPD_FILE_STATE || defined __DOXYGEN__
375 #define LWIP_HTTPD_FILE_STATE         0
376 #endif
377 
378 /** Set this to 1 to add the pextension field to the fs_file structure.
379  * This is included here to retain compatibility with legacy code that
380  * relies on the presence of the pextension field.
381  * New code should use LWIP_HTTPD_FILE_STATE instead.
382  * This option may be removed in a future version of lwip.
383  */
384 #if !defined LWIP_HTTPD_FILE_EXTENSION || defined __DOXYGEN__
385 #define LWIP_HTTPD_FILE_EXTENSION     0
386 #endif
387 
388 /** HTTPD_PRECALCULATED_CHECKSUM==1: include precompiled checksums for
389  * predefined (MSS-sized) chunks of the files to prevent having to calculate
390  * the checksums at runtime. */
391 #if !defined HTTPD_PRECALCULATED_CHECKSUM || defined __DOXYGEN__
392 #define HTTPD_PRECALCULATED_CHECKSUM  0
393 #endif
394 
395 /** LWIP_HTTPD_FS_ASYNC_READ==1: support asynchronous read operations
396  * (fs_read_async returns FS_READ_DELAYED and calls a callback when finished).
397  */
398 #if !defined LWIP_HTTPD_FS_ASYNC_READ || defined __DOXYGEN__
399 #define LWIP_HTTPD_FS_ASYNC_READ      0
400 #endif
401 
402 /** Filename (including path) to use as FS data file */
403 #if !defined HTTPD_FSDATA_FILE || defined __DOXYGEN__
404 /* HTTPD_USE_CUSTOM_FSDATA: Compatibility with deprecated lwIP option */
405 #if defined(HTTPD_USE_CUSTOM_FSDATA) && (HTTPD_USE_CUSTOM_FSDATA != 0)
406 #define HTTPD_FSDATA_FILE "fsdata_custom.c"
407 #else
408 #define HTTPD_FSDATA_FILE "fsdata.c"
409 #endif
410 #endif
411 
412 /**
413  * @}
414  */
415 
416 #endif /* LWIP_HDR_APPS_HTTPD_OPTS_H */
417