uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
httpd.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  * This version of the file has been modified by Texas Instruments to offer
32  * simple server-side-include (SSI) and Common Gateway Interface (CGI)
33  * capability.
34  */
35 
36 #ifndef __HTTPD_H__
37 #define __HTTPD_H__
38 
39 #include "lwip/opt.h"
40 #include "lwip/err.h"
41 #include "lwip/pbuf.h"
42 
43 
45 #ifndef LWIP_HTTPD_CGI
46 #define LWIP_HTTPD_CGI 1
47 #endif
48 
50 #ifndef LWIP_HTTPD_SSI
51 #define LWIP_HTTPD_SSI 0
52 #endif
53 
55 #ifndef LWIP_HTTPD_SUPPORT_POST
56 #define LWIP_HTTPD_SUPPORT_POST 0
57 #endif
58 
59 
60 #if LWIP_HTTPD_CGI
61 
62 /*
63  * Function pointer for a CGI script handler.
64  *
65  * This function is called each time the HTTPD server is asked for a file
66  * whose name was previously registered as a CGI function using a call to
67  * http_set_cgi_handler. The iIndex parameter provides the index of the
68  * CGI within the ppcURLs array passed to http_set_cgi_handler. Parameters
69  * pcParam and pcValue provide access to the parameters provided along with
70  * the URI. iNumParams provides a count of the entries in the pcParam and
71  * pcValue arrays. Each entry in the pcParam array contains the name of a
72  * parameter with the corresponding entry in the pcValue array containing the
73  * value for that parameter. Note that pcParam may contain multiple elements
74  * with the same name if, for example, a multi-selection list control is used
75  * in the form generating the data.
76  *
77  * The function should return a pointer to a character string which is the
78  * path and filename of the response that is to be sent to the connected
79  * browser, for example "/thanks.htm" or "/response/error.ssi".
80  *
81  * The maximum number of parameters that will be passed to this function via
82  * iNumParams is defined by LWIP_HTTPD_MAX_CGI_PARAMETERS. Any parameters in the incoming
83  * HTTP request above this number will be discarded.
84  *
85  * Requests intended for use by this CGI mechanism must be sent using the GET
86  * method (which encodes all parameters within the URI rather than in a block
87  * later in the request). Attempts to use the POST method will result in the
88  * request being ignored.
89  *
90  */
91 typedef const char *(*tCGIHandler)(int iIndex, int iNumParams, char *pcParam[],
92  char *pcValue[]);
93 
94 /*
95  * Structure defining the base filename (URL) of a CGI and the associated
96  * function which is to be called when that URL is requested.
97  */
98 typedef struct
99 {
100  const char *pcCGIName;
102 } tCGI;
103 
104 void http_set_cgi_handlers(const tCGI *pCGIs, int iNumHandlers);
105 
106 
107 /* The maximum number of parameters that the CGI handler can be sent. */
108 #ifndef LWIP_HTTPD_MAX_CGI_PARAMETERS
109 #define LWIP_HTTPD_MAX_CGI_PARAMETERS 16
110 #endif
111 
112 #endif /* LWIP_HTTPD_CGI */
113 
114 #if LWIP_HTTPD_SSI
115 
120 #ifndef LWIP_HTTPD_SSI_MULTIPART
121 #define LWIP_HTTPD_SSI_MULTIPART 0
122 #endif
123 
124 /*
125  * Function pointer for the SSI tag handler callback.
126  *
127  * This function will be called each time the HTTPD server detects a tag of the
128  * form <!--#name--> in a .shtml, .ssi or .shtm file where "name" appears as
129  * one of the tags supplied to http_set_ssi_handler in the ppcTags array. The
130  * returned insert string, which will be appended after the the string
131  * "<!--#name-->" in file sent back to the client,should be written to pointer
132  * pcInsert. iInsertLen contains the size of the buffer pointed to by
133  * pcInsert. The iIndex parameter provides the zero-based index of the tag as
134  * found in the ppcTags array and identifies the tag that is to be processed.
135  *
136  * The handler returns the number of characters written to pcInsert excluding
137  * any terminating NULL or a negative number to indicate a failure (tag not
138  * recognized, for example).
139  *
140  * Note that the behavior of this SSI mechanism is somewhat different from the
141  * "normal" SSI processing as found in, for example, the Apache web server. In
142  * this case, the inserted text is appended following the SSI tag rather than
143  * replacing the tag entirely. This allows for an implementation that does not
144  * require significant additional buffering of output data yet which will still
145  * offer usable SSI functionality. One downside to this approach is when
146  * attempting to use SSI within JavaScript. The SSI tag is structured to
147  * resemble an HTML comment but this syntax does not constitute a comment
148  * within JavaScript and, hence, leaving the tag in place will result in
149  * problems in these cases. To work around this, any SSI tag which needs to
150  * output JavaScript code must do so in an encapsulated way, sending the whole
151  * HTML <script>...</script> section as a single include.
152  */
153 typedef u16_t (*tSSIHandler)(int iIndex, char *pcInsert, int iInsertLen
154 #if LWIP_HTTPD_SSI_MULTIPART
155  , u16_t current_tag_part, u16_t *next_tag_part
156 #endif /* LWIP_HTTPD_SSI_MULTIPART */
157 #if LWIP_HTTPD_FILE_STATE
158  , void *connection_state
159 #endif /* LWIP_HTTPD_FILE_STATE */
160  );
161 
162 void http_set_ssi_handler(tSSIHandler pfnSSIHandler,
163  const char **ppcTags, int iNumTags);
164 
165 /* The maximum length of the string comprising the tag name */
166 #ifndef LWIP_HTTPD_MAX_TAG_NAME_LEN
167 #define LWIP_HTTPD_MAX_TAG_NAME_LEN 8
168 #endif
169 
170 /* The maximum length of string that can be returned to replace any given tag */
171 #ifndef LWIP_HTTPD_MAX_TAG_INSERT_LEN
172 #define LWIP_HTTPD_MAX_TAG_INSERT_LEN 192
173 #endif
174 
175 #endif /* LWIP_HTTPD_SSI */
176 
177 #if LWIP_HTTPD_SUPPORT_POST
178 
179 /* These functions must be implemented by the application */
180 
199 err_t httpd_post_begin(void *connection, const char *uri, const char *http_request,
200  u16_t http_request_len, int content_len, char *response_uri,
201  u16_t response_uri_len, u8_t *post_auto_wnd);
202 
211 err_t httpd_post_receive_data(void *connection, struct pbuf *p);
212 
222 void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len);
223 
224 #ifndef LWIP_HTTPD_POST_MANUAL_WND
225 #define LWIP_HTTPD_POST_MANUAL_WND 0
226 #endif
227 
228 #if LWIP_HTTPD_POST_MANUAL_WND
229 void httpd_post_data_recved(void *connection, u16_t recved_len);
230 #endif /* LWIP_HTTPD_POST_MANUAL_WND */
231 
232 #endif /* LWIP_HTTPD_SUPPORT_POST */
233 
234 void httpd_init(const u8_t * romfs);
235 
236 #endif /* __HTTPD_H__ */