Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
httpd.h
00001 /** 00002 * @file 00003 * HTTP server 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 * This version of the file has been modified by Texas Instruments to offer 00037 * simple server-side-include (SSI) and Common Gateway Interface (CGI) 00038 * capability. 00039 */ 00040 00041 #ifndef LWIP_HDR_APPS_HTTPD_H 00042 #define LWIP_HDR_APPS_HTTPD_H 00043 00044 #include "httpd_opts.h" 00045 #include "lwip/err.h" 00046 #include "lwip/pbuf.h" 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00052 #if LWIP_HTTPD_CGI 00053 00054 /** 00055 * @ingroup httpd 00056 * Function pointer for a CGI script handler. 00057 * 00058 * This function is called each time the HTTPD server is asked for a file 00059 * whose name was previously registered as a CGI function using a call to 00060 * http_set_cgi_handlers. The iIndex parameter provides the index of the 00061 * CGI within the cgis array passed to http_set_cgi_handlers. Parameters 00062 * pcParam and pcValue provide access to the parameters provided along with 00063 * the URI. iNumParams provides a count of the entries in the pcParam and 00064 * pcValue arrays. Each entry in the pcParam array contains the name of a 00065 * parameter with the corresponding entry in the pcValue array containing the 00066 * value for that parameter. Note that pcParam may contain multiple elements 00067 * with the same name if, for example, a multi-selection list control is used 00068 * in the form generating the data. 00069 * 00070 * The function should return a pointer to a character string which is the 00071 * path and filename of the response that is to be sent to the connected 00072 * browser, for example "/thanks.htm" or "/response/error.ssi". 00073 * 00074 * The maximum number of parameters that will be passed to this function via 00075 * iNumParams is defined by LWIP_HTTPD_MAX_CGI_PARAMETERS. Any parameters in 00076 * the incoming HTTP request above this number will be discarded. 00077 * 00078 * Requests intended for use by this CGI mechanism must be sent using the GET 00079 * method (which encodes all parameters within the URI rather than in a block 00080 * later in the request). Attempts to use the POST method will result in the 00081 * request being ignored. 00082 * 00083 */ 00084 typedef const char *(*tCGIHandler)(int iIndex, int iNumParams, char *pcParam[], 00085 char *pcValue[]); 00086 00087 /** 00088 * @ingroup httpd 00089 * Structure defining the base filename (URL) of a CGI and the associated 00090 * function which is to be called when that URL is requested. 00091 */ 00092 typedef struct 00093 { 00094 const char *pcCGIName; 00095 tCGIHandler pfnCGIHandler; 00096 } tCGI; 00097 00098 void http_set_cgi_handlers(const tCGI *pCGIs, int iNumHandlers); 00099 00100 #endif /* LWIP_HTTPD_CGI */ 00101 00102 #if LWIP_HTTPD_CGI || LWIP_HTTPD_CGI_SSI 00103 00104 #if LWIP_HTTPD_CGI_SSI 00105 /* we have to prototype this struct here to make it available for the handler */ 00106 struct fs_file; 00107 00108 /** Define this generic CGI handler in your application. 00109 * It is called once for every URI with parameters. 00110 * The parameters can be stored to the object passed as connection_state, which 00111 * is allocated to file->state via fs_state_init() from fs_open() or fs_open_custom(). 00112 * Content creation via SSI or complete dynamic files can retrieve the CGI params from there. 00113 */ 00114 extern void httpd_cgi_handler(struct fs_file *file, const char* uri, int iNumParams, 00115 char **pcParam, char **pcValue 00116 #if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE 00117 , void *connection_state 00118 #endif /* LWIP_HTTPD_FILE_STATE */ 00119 ); 00120 #endif /* LWIP_HTTPD_CGI_SSI */ 00121 00122 #endif /* LWIP_HTTPD_CGI || LWIP_HTTPD_CGI_SSI */ 00123 00124 #if LWIP_HTTPD_SSI 00125 00126 /** 00127 * @ingroup httpd 00128 * Function pointer for the SSI tag handler callback. 00129 * 00130 * This function will be called each time the HTTPD server detects a tag of the 00131 * form <!--#name--> in files with extensions mentioned in the g_pcSSIExtensions 00132 * array (currently .shtml, .shtm, .ssi, .xml, .json) where "name" appears as 00133 * one of the tags supplied to http_set_ssi_handler in the tags array. The 00134 * returned insert string, which will be appended after the the string 00135 * "<!--#name-->" in file sent back to the client, should be written to pointer 00136 * pcInsert. iInsertLen contains the size of the buffer pointed to by 00137 * pcInsert. The iIndex parameter provides the zero-based index of the tag as 00138 * found in the tags array and identifies the tag that is to be processed. 00139 * 00140 * The handler returns the number of characters written to pcInsert excluding 00141 * any terminating NULL or HTTPD_SSI_TAG_UNKNOWN when tag is not recognized. 00142 * 00143 * Note that the behavior of this SSI mechanism is somewhat different from the 00144 * "normal" SSI processing as found in, for example, the Apache web server. In 00145 * this case, the inserted text is appended following the SSI tag rather than 00146 * replacing the tag entirely. This allows for an implementation that does not 00147 * require significant additional buffering of output data yet which will still 00148 * offer usable SSI functionality. One downside to this approach is when 00149 * attempting to use SSI within JavaScript. The SSI tag is structured to 00150 * resemble an HTML comment but this syntax does not constitute a comment 00151 * within JavaScript and, hence, leaving the tag in place will result in 00152 * problems in these cases. In order to avoid these problems, define 00153 * LWIP_HTTPD_SSI_INCLUDE_TAG as zero in your lwip options file, or use JavaScript 00154 * style block comments in the form / * # name * / (without the spaces). 00155 */ 00156 typedef u16_t (*tSSIHandler)( 00157 #if LWIP_HTTPD_SSI_RAW 00158 const char* ssi_tag_name, 00159 #else /* LWIP_HTTPD_SSI_RAW */ 00160 int iIndex, 00161 #endif /* LWIP_HTTPD_SSI_RAW */ 00162 char *pcInsert, int iInsertLen 00163 #if LWIP_HTTPD_SSI_MULTIPART 00164 , u16_t current_tag_part, u16_t *next_tag_part 00165 #endif /* LWIP_HTTPD_SSI_MULTIPART */ 00166 #if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE 00167 , void *connection_state 00168 #endif /* LWIP_HTTPD_FILE_STATE */ 00169 ); 00170 00171 /** Set the SSI handler function 00172 * (if LWIP_HTTPD_SSI_RAW==1, only the first argument is used) 00173 */ 00174 void http_set_ssi_handler(tSSIHandler pfnSSIHandler, 00175 const char **ppcTags, int iNumTags); 00176 00177 /** For LWIP_HTTPD_SSI_RAW==1, return this to indicate the tag is unknown. 00178 * In this case, the webserver writes a warning into the page. 00179 * You can also just return 0 to write nothing for unknown tags. 00180 */ 00181 #define HTTPD_SSI_TAG_UNKNOWN 0xFFFF 00182 00183 #endif /* LWIP_HTTPD_SSI */ 00184 00185 #if LWIP_HTTPD_SUPPORT_POST 00186 00187 /* These functions must be implemented by the application */ 00188 00189 /** 00190 * @ingroup httpd 00191 * Called when a POST request has been received. The application can decide 00192 * whether to accept it or not. 00193 * 00194 * @param connection Unique connection identifier, valid until httpd_post_end 00195 * is called. 00196 * @param uri The HTTP header URI receiving the POST request. 00197 * @param http_request The raw HTTP request (the first packet, normally). 00198 * @param http_request_len Size of 'http_request'. 00199 * @param content_len Content-Length from HTTP header. 00200 * @param response_uri Filename of response file, to be filled when denying the 00201 * request 00202 * @param response_uri_len Size of the 'response_uri' buffer. 00203 * @param post_auto_wnd Set this to 0 to let the callback code handle window 00204 * updates by calling 'httpd_post_data_recved' (to throttle rx speed) 00205 * default is 1 (httpd handles window updates automatically) 00206 * @return ERR_OK: Accept the POST request, data may be passed in 00207 * another err_t: Deny the POST request, send back 'bad request'. 00208 */ 00209 err_t httpd_post_begin(void *connection, const char *uri, const char *http_request, 00210 u16_t http_request_len, int content_len, char *response_uri, 00211 u16_t response_uri_len, u8_t *post_auto_wnd); 00212 00213 /** 00214 * @ingroup httpd 00215 * Called for each pbuf of data that has been received for a POST. 00216 * ATTENTION: The application is responsible for freeing the pbufs passed in! 00217 * 00218 * @param connection Unique connection identifier. 00219 * @param p Received data. 00220 * @return ERR_OK: Data accepted. 00221 * another err_t: Data denied, http_post_get_response_uri will be called. 00222 */ 00223 err_t httpd_post_receive_data(void *connection, struct pbuf *p); 00224 00225 /** 00226 * @ingroup httpd 00227 * Called when all data is received or when the connection is closed. 00228 * The application must return the filename/URI of a file to send in response 00229 * to this POST request. If the response_uri buffer is untouched, a 404 00230 * response is returned. 00231 * 00232 * @param connection Unique connection identifier. 00233 * @param response_uri Filename of response file, to be filled when denying the request 00234 * @param response_uri_len Size of the 'response_uri' buffer. 00235 */ 00236 void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len); 00237 00238 #if LWIP_HTTPD_POST_MANUAL_WND 00239 void httpd_post_data_recved(void *connection, u16_t recved_len); 00240 #endif /* LWIP_HTTPD_POST_MANUAL_WND */ 00241 00242 #endif /* LWIP_HTTPD_SUPPORT_POST */ 00243 00244 void httpd_init(void); 00245 00246 #if HTTPD_ENABLE_HTTPS 00247 struct altcp_tls_config; 00248 void httpd_inits(struct altcp_tls_config *conf); 00249 #endif 00250 00251 #ifdef __cplusplus 00252 } 00253 #endif 00254 00255 #endif /* LWIP_HDR_APPS_HTTPD_H */
Generated on Tue Jul 12 2022 13:54:24 by
