Fixed compilation for CGI, SSI and DYNAMIC_HEADERS, renamed variables, added comments

This commit is contained in:
goldsimon 2010-03-18 06:31:18 +00:00
parent 2bb5d99ffc
commit 111004caa9
2 changed files with 31 additions and 21 deletions

View File

@ -507,9 +507,9 @@ get_http_headers(struct http_state *pState, char *pszURI)
/* Now determine the content type and add the relevant header for that. */
for(iLoop = 0; (iLoop < NUM_HTTP_HEADERS) && pszExt; iLoop++) {
/* Have we found a matching extension? */
if(!strcmp(g_psHTTPHeaders[iLoop].pszExtension, pszExt)) {
if(!strcmp(g_psHTTPHeaders[iLoop].extension, pszExt)) {
pState->hdrs[2] =
g_psHTTPHeaderStrings[g_psHTTPHeaders[iLoop].ulHeaderIndex];
g_psHTTPHeaderStrings[g_psHTTPHeaders[iLoop].headerIndex];
break;
}
}
@ -566,7 +566,7 @@ http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
#if LWIP_HTTPD_DYNAMIC_HEADERS
/* If we were passed a NULL state structure pointer, ignore the call. */
if (hs == NULL) {
return;
return 0;
}
/* Assume no error until we find otherwise */
@ -621,8 +621,7 @@ http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
*/
if((hs->hdr_index < NUM_FILE_HDR_STRINGS) || !hs->file) {
LWIP_DEBUGF(HTTPD_DEBUG, ("tcp_output\n"));
tcp_output(pcb);
return;
return 1;
}
}
#else /* LWIP_HTTPD_DYNAMIC_HEADERS */
@ -669,7 +668,7 @@ http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
/* Did we get a send buffer? If not, return immediately. */
if (hs->buf == NULL) {
LWIP_DEBUGF(HTTPD_DEBUG, ("No buff\n"));
return;
return 0;
}
}
@ -681,7 +680,7 @@ http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
/* We reached the end of the file so this request is done */
LWIP_DEBUGF(HTTPD_DEBUG, ("End of file.\n"));
http_close_conn(pcb, hs);
return;
return 1;
}
/* Set up to send the block of data we just read */
@ -779,11 +778,7 @@ http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
/* If the send buffer is full, return now. */
if(tcp_sndbuf(pcb) == 0) {
if(data_to_send) {
tcp_output(pcb);
LWIP_DEBUGF(HTTPD_DEBUG, ("Output\n"));
}
return;
return data_to_send;
}
}
@ -1034,7 +1029,7 @@ http_send_data(struct tcp_pcb *pcb, struct http_state *hs)
if (err == ERR_OK) {
data_to_send = true;
hs->tag_index += len;
return;
return 1;
}
} else {
/* We have sent all the insert data so go back to looking for

View File

@ -3,26 +3,31 @@
#include "httpd.h"
/** This string is passed in the HTTP header as "Server: " */
#ifndef HTTPD_SERVER_AGENT
#define HTTPD_SERVER_AGENT "lwIP/1.3.1 (http://savannah.nongnu.org/projects/lwip)"
#endif
/** Set this to 1 if you want to include code that creates HTTP headers
* at runtime. Default is off: HTTP headers are then created statically
* by the makefsdata tool. Static headers mean smaller code size, but
* the (readonly) fsdata will grow a bit as every file includes the HTTP
* header. */
#ifndef LWIP_HTTPD_DYNAMIC_HEADERS
#define LWIP_HTTPD_DYNAMIC_HEADERS 0
#endif
#if LWIP_HTTPD_DYNAMIC_HEADERS
/*****************************************************************************
* HTTP header strings for various filename extensions.
*
*****************************************************************************/
/** This struct is used for a list of HTTP header strings for various
* filename extensions. */
typedef struct
{
const char *pszExtension;
unsigned long ulHeaderIndex;
const char *extension;
int headerIndex;
} tHTTPHeader;
/** A list of strings used in HTTP headers */
static const char *g_psHTTPHeaderStrings[] =
{
"Content-type: text/html\r\n\r\n",
@ -42,11 +47,16 @@ static const char *g_psHTTPHeaderStrings[] =
"Content-type: text/plain\r\n\r\n",
"HTTP/1.0 200 OK\r\n",
"HTTP/1.0 404 File not found\r\n",
"HTTP/1.1 200 OK\r\n",
"HTTP/1.1 404 File not found\r\n",
"Content-Length: ",
"Connection: Close\r\n",
"Server: "HTTPD_SERVER_AGENT"\r\n",
"\r\n<html><body><h2>404: The requested file cannot be found." \
"</h2></body></html>\r\n"
};
/* Indexes into the g_psHTTPHeaderStrings array */
#define HTTP_HDR_HTML 0 /* text/html */
#define HTTP_HDR_SSI 1 /* text/html Expires... */
#define HTTP_HDR_GIF 2 /* image/gif */
@ -63,9 +73,14 @@ static const char *g_psHTTPHeaderStrings[] =
#define HTTP_HDR_DEFAULT_TYPE 13 /* text/plain */
#define HTTP_HDR_OK 14 /* 200 OK */
#define HTTP_HDR_NOT_FOUND 15 /* 404 File not found */
#define HTTP_HDR_SERVER 16 /* Server: HTTPD_SERVER_AGENT */
#define DEFAULT_404_HTML 17 /* default 404 body */
#define HTTP_HDR_OK_11 16 /* 200 OK */
#define HTTP_HDR_NOT_FOUND_11 17 /* 404 File not found */
#define HTTP_HDR_CONTENT_LENGTH 18 /* 200 OK (HTTP 1.1) */
#define HTTP_HDR_CONN_CLOSE 19 /* 404 File not found (HTTP 1.1) */
#define HTTP_HDR_SERVER 20 /* Server: HTTPD_SERVER_AGENT */
#define DEFAULT_404_HTML 21 /* default 404 body */
/** A list of extension-to-HTTP header strings */
static tHTTPHeader g_psHTTPHeaders[] =
{
{ "html", HTTP_HDR_HTML},