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 
46 /**
47  * @defgroup httpd_opts Options
48  * @ingroup httpd
49  * @{
50  */
51 
52 /** Set this to 1 to support CGI (old style) */
53 #if !defined LWIP_HTTPD_CGI || defined __DOXYGEN__
54 #define LWIP_HTTPD_CGI            0
55 #endif
56 
57 /** Set this to 1 to support CGI (new style) */
58 #if !defined LWIP_HTTPD_CGI_SSI || defined __DOXYGEN__
59 #define LWIP_HTTPD_CGI_SSI        0
60 #endif
61 
62 /** Set this to 1 to support SSI (Server-Side-Includes) */
63 #if !defined LWIP_HTTPD_SSI || defined __DOXYGEN__
64 #define LWIP_HTTPD_SSI            0
65 #endif
66 
67 /** Set this to 1 to implement an SSI tag handler callback that gets a const char*
68  * to the tag (instead of an index into a pre-registered array of known tags) */
69 #if !defined LWIP_HTTPD_SSI_RAW || defined __DOXYGEN__
70 #define LWIP_HTTPD_SSI_RAW        0
71 #endif
72 
73 /** Set this to 1 to support HTTP POST */
74 #if !defined LWIP_HTTPD_SUPPORT_POST || defined __DOXYGEN__
75 #define LWIP_HTTPD_SUPPORT_POST   0
76 #endif
77 
78 /* The maximum number of parameters that the CGI handler can be sent. */
79 #if !defined LWIP_HTTPD_MAX_CGI_PARAMETERS || defined __DOXYGEN__
80 #define LWIP_HTTPD_MAX_CGI_PARAMETERS 16
81 #endif
82 
83 /** LWIP_HTTPD_SSI_MULTIPART==1: SSI handler function is called with 2 more
84  * arguments indicating a counter for insert string that are too long to be
85  * inserted at once: the SSI handler function must then set 'next_tag_part'
86  * which will be passed back to it in the next call. */
87 #if !defined LWIP_HTTPD_SSI_MULTIPART || defined __DOXYGEN__
88 #define LWIP_HTTPD_SSI_MULTIPART    0
89 #endif
90 
91 /* The maximum length of the string comprising the tag name */
92 #if !defined LWIP_HTTPD_MAX_TAG_NAME_LEN || defined __DOXYGEN__
93 #define LWIP_HTTPD_MAX_TAG_NAME_LEN 8
94 #endif
95 
96 /* The maximum length of string that can be returned to replace any given tag */
97 #if !defined LWIP_HTTPD_MAX_TAG_INSERT_LEN || defined __DOXYGEN__
98 #define LWIP_HTTPD_MAX_TAG_INSERT_LEN 192
99 #endif
100 
101 #if !defined LWIP_HTTPD_POST_MANUAL_WND || defined __DOXYGEN__
102 #define LWIP_HTTPD_POST_MANUAL_WND  0
103 #endif
104 
105 /** This string is passed in the HTTP header as "Server: " */
106 #if !defined HTTPD_SERVER_AGENT || defined __DOXYGEN__
107 #define HTTPD_SERVER_AGENT "lwIP/" LWIP_VERSION_STRING " (http://savannah.nongnu.org/projects/lwip)"
108 #endif
109 
110 /** Set this to 1 if you want to include code that creates HTTP headers
111  * at runtime. Default is off: HTTP headers are then created statically
112  * by the makefsdata tool. Static headers mean smaller code size, but
113  * the (readonly) fsdata will grow a bit as every file includes the HTTP
114  * header. */
115 #if !defined LWIP_HTTPD_DYNAMIC_HEADERS || defined __DOXYGEN__
116 #define LWIP_HTTPD_DYNAMIC_HEADERS 0
117 #endif
118 
119 #if !defined HTTPD_DEBUG || defined __DOXYGEN__
120 #define HTTPD_DEBUG         LWIP_DBG_OFF
121 #endif
122 
123 /** Set this to 1 to use a memp pool for allocating
124  * struct http_state instead of the heap.
125  */
126 #if !defined HTTPD_USE_MEM_POOL || defined __DOXYGEN__
127 #define HTTPD_USE_MEM_POOL  0
128 #endif
129 
130 /** The server port for HTTPD to use */
131 #if !defined HTTPD_SERVER_PORT || defined __DOXYGEN__
132 #define HTTPD_SERVER_PORT                   80
133 #endif
134 
135 /** Maximum retries before the connection is aborted/closed.
136  * - number of times pcb->poll is called -> default is 4*500ms = 2s;
137  * - reset when pcb->sent is called
138  */
139 #if !defined HTTPD_MAX_RETRIES || defined __DOXYGEN__
140 #define HTTPD_MAX_RETRIES                   4
141 #endif
142 
143 /** The poll delay is X*500ms */
144 #if !defined HTTPD_POLL_INTERVAL || defined __DOXYGEN__
145 #define HTTPD_POLL_INTERVAL                 4
146 #endif
147 
148 /** Priority for tcp pcbs created by HTTPD (very low by default).
149  *  Lower priorities get killed first when running out of memory.
150  */
151 #if !defined HTTPD_TCP_PRIO || defined __DOXYGEN__
152 #define HTTPD_TCP_PRIO                      TCP_PRIO_MIN
153 #endif
154 
155 /** Set this to 1 to enable timing each file sent */
156 #if !defined LWIP_HTTPD_TIMING || defined __DOXYGEN__
157 #define LWIP_HTTPD_TIMING                   0
158 #endif
159 /** Set this to 1 to enable timing each file sent */
160 #if !defined HTTPD_DEBUG_TIMING || defined __DOXYGEN__
161 #define HTTPD_DEBUG_TIMING                  LWIP_DBG_OFF
162 #endif
163 
164 /** Set this to one to show error pages when parsing a request fails instead
165     of simply closing the connection. */
166 #if !defined LWIP_HTTPD_SUPPORT_EXTSTATUS || defined __DOXYGEN__
167 #define LWIP_HTTPD_SUPPORT_EXTSTATUS        0
168 #endif
169 
170 /** Set this to 0 to drop support for HTTP/0.9 clients (to save some bytes) */
171 #if !defined LWIP_HTTPD_SUPPORT_V09 || defined __DOXYGEN__
172 #define LWIP_HTTPD_SUPPORT_V09              1
173 #endif
174 
175 /** Set this to 1 to enable HTTP/1.1 persistent connections.
176  * ATTENTION: If the generated file system includes HTTP headers, these must
177  * include the "Connection: keep-alive" header (pass argument "-11" to makefsdata).
178  */
179 #if !defined LWIP_HTTPD_SUPPORT_11_KEEPALIVE || defined __DOXYGEN__
180 #define LWIP_HTTPD_SUPPORT_11_KEEPALIVE     0
181 #endif
182 
183 /** Set this to 1 to support HTTP request coming in in multiple packets/pbufs */
184 #if !defined LWIP_HTTPD_SUPPORT_REQUESTLIST || defined __DOXYGEN__
185 #define LWIP_HTTPD_SUPPORT_REQUESTLIST      1
186 #endif
187 
188 #if LWIP_HTTPD_SUPPORT_REQUESTLIST
189 /** Number of rx pbufs to enqueue to parse an incoming request (up to the first
190     newline) */
191 #if !defined LWIP_HTTPD_REQ_QUEUELEN || defined __DOXYGEN__
192 #define LWIP_HTTPD_REQ_QUEUELEN             5
193 #endif
194 
195 /** Number of (TCP payload-) bytes (in pbufs) to enqueue to parse and incoming
196     request (up to the first double-newline) */
197 #if !defined LWIP_HTTPD_REQ_BUFSIZE || defined __DOXYGEN__
198 #define LWIP_HTTPD_REQ_BUFSIZE              LWIP_HTTPD_MAX_REQ_LENGTH
199 #endif
200 
201 /** Defines the maximum length of a HTTP request line (up to the first CRLF,
202     copied from pbuf into this a global buffer when pbuf- or packet-queues
203     are received - otherwise the input pbuf is used directly) */
204 #if !defined LWIP_HTTPD_MAX_REQ_LENGTH || defined __DOXYGEN__
205 #define LWIP_HTTPD_MAX_REQ_LENGTH           LWIP_MIN(1023, (LWIP_HTTPD_REQ_QUEUELEN * PBUF_POOL_BUFSIZE))
206 #endif
207 #endif /* LWIP_HTTPD_SUPPORT_REQUESTLIST */
208 
209 /** This is the size of a static buffer used when URIs end with '/'.
210  * In this buffer, the directory requested is concatenated with all the
211  * configured default file names.
212  * Set to 0 to disable checking default filenames on non-root directories.
213  */
214 #if !defined LWIP_HTTPD_MAX_REQUEST_URI_LEN || defined __DOXYGEN__
215 #define LWIP_HTTPD_MAX_REQUEST_URI_LEN      63
216 #endif
217 
218 /** Maximum length of the filename to send as response to a POST request,
219  * filled in by the application when a POST is finished.
220  */
221 #if !defined LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN || defined __DOXYGEN__
222 #define LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN 63
223 #endif
224 
225 /** Set this to 0 to not send the SSI tag (default is on, so the tag will
226  * be sent in the HTML page */
227 #if !defined LWIP_HTTPD_SSI_INCLUDE_TAG || defined __DOXYGEN__
228 #define LWIP_HTTPD_SSI_INCLUDE_TAG           1
229 #endif
230 
231 /** Set this to 1 to call tcp_abort when tcp_close fails with memory error.
232  * This can be used to prevent consuming all memory in situations where the
233  * HTTP server has low priority compared to other communication. */
234 #if !defined LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR || defined __DOXYGEN__
235 #define LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR  0
236 #endif
237 
238 /** Set this to 1 to kill the oldest connection when running out of
239  * memory for 'struct http_state' or 'struct http_ssi_state'.
240  * ATTENTION: This puts all connections on a linked list, so may be kind of slow.
241  */
242 #if !defined LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED || defined __DOXYGEN__
243 #define LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED 0
244 #endif
245 
246 /** Set this to 1 to send URIs without extension without headers
247  * (who uses this at all??) */
248 #if !defined LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI || defined __DOXYGEN__
249 #define LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI 0
250 #endif
251 
252 /** Default: Tags are sent from struct http_state and are therefore volatile */
253 #if !defined HTTP_IS_TAG_VOLATILE || defined __DOXYGEN__
254 #define HTTP_IS_TAG_VOLATILE(ptr) TCP_WRITE_FLAG_COPY
255 #endif
256 
257 /* By default, the httpd is limited to send 2*pcb->mss to keep resource usage low
258    when http is not an important protocol in the device. */
259 #if !defined HTTPD_LIMIT_SENDING_TO_2MSS || defined __DOXYGEN__
260 #define HTTPD_LIMIT_SENDING_TO_2MSS 1
261 #endif
262 
263 /* Define this to a function that returns the maximum amount of data to enqueue.
264    The function have this signature: u16_t fn(struct tcp_pcb* pcb); */
265 #if !defined HTTPD_MAX_WRITE_LEN || defined __DOXYGEN__
266 #if HTTPD_LIMIT_SENDING_TO_2MSS
267 #define HTTPD_MAX_WRITE_LEN(pcb)    (2 * tcp_mss(pcb))
268 #endif
269 #endif
270 
271 /*------------------- FS OPTIONS -------------------*/
272 
273 /** Set this to 1 and provide the functions:
274  * - "int fs_open_custom(struct fs_file *file, const char *name)"
275  *    Called first for every opened file to allow opening files
276  *    that are not included in fsdata(_custom).c
277  * - "void fs_close_custom(struct fs_file *file)"
278  *    Called to free resources allocated by fs_open_custom().
279  */
280 #if !defined LWIP_HTTPD_CUSTOM_FILES || defined __DOXYGEN__
281 #define LWIP_HTTPD_CUSTOM_FILES       0
282 #endif
283 
284 /** Set this to 1 to support fs_read() to dynamically read file data.
285  * Without this (default=off), only one-block files are supported,
286  * and the contents must be ready after fs_open().
287  */
288 #if !defined LWIP_HTTPD_DYNAMIC_FILE_READ || defined __DOXYGEN__
289 #define LWIP_HTTPD_DYNAMIC_FILE_READ  0
290 #endif
291 
292 /** Set this to 1 to include an application state argument per file
293  * that is opened. This allows to keep a state per connection/file.
294  */
295 #if !defined LWIP_HTTPD_FILE_STATE || defined __DOXYGEN__
296 #define LWIP_HTTPD_FILE_STATE         0
297 #endif
298 
299 /** HTTPD_PRECALCULATED_CHECKSUM==1: include precompiled checksums for
300  * predefined (MSS-sized) chunks of the files to prevent having to calculate
301  * the checksums at runtime. */
302 #if !defined HTTPD_PRECALCULATED_CHECKSUM || defined __DOXYGEN__
303 #define HTTPD_PRECALCULATED_CHECKSUM  0
304 #endif
305 
306 /** LWIP_HTTPD_FS_ASYNC_READ==1: support asynchronous read operations
307  * (fs_read_async returns FS_READ_DELAYED and calls a callback when finished).
308  */
309 #if !defined LWIP_HTTPD_FS_ASYNC_READ || defined __DOXYGEN__
310 #define LWIP_HTTPD_FS_ASYNC_READ      0
311 #endif
312 
313 /** Filename (including path) to use as FS data file */
314 #if !defined HTTPD_FSDATA_FILE || defined __DOXYGEN__
315 /* HTTPD_USE_CUSTOM_FSDATA: Compatibility with deprecated lwIP option */
316 #if defined(HTTPD_USE_CUSTOM_FSDATA) && (HTTPD_USE_CUSTOM_FSDATA != 0)
317 #define HTTPD_FSDATA_FILE "fsdata_custom.c"
318 #else
319 #define HTTPD_FSDATA_FILE "fsdata.c"
320 #endif
321 #endif
322 
323 /**
324  * @}
325  */
326 
327 #endif /* LWIP_HDR_APPS_HTTPD_OPTS_H */
328