Reformat httpd* using astylerc

This commit is contained in:
Dirk Ziegelmeier 2017-09-17 17:58:36 +02:00
parent c35b1099a4
commit 6164f0cd34
5 changed files with 344 additions and 352 deletions

View File

@ -1,8 +1,8 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -11,21 +11,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
@ -59,7 +59,7 @@ fs_open(struct fs_file *file, const char *name)
const struct fsdata_file *f;
if ((file == NULL) || (name == NULL)) {
return ERR_ARG;
return ERR_ARG;
}
#if LWIP_HTTPD_CUSTOM_FILES
@ -116,7 +116,7 @@ fs_read(struct fs_file *file, char *buffer, int count)
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
{
int read;
if(file->index == file->len) {
if (file->index == file->len) {
return FS_READ_EOF;
}
#if LWIP_HTTPD_FS_ASYNC_READ
@ -134,14 +134,14 @@ fs_read(struct fs_file *file, char *buffer, int count)
#endif /* LWIP_HTTPD_CUSTOM_FILES */
read = file->len - file->index;
if(read > count) {
if (read > count) {
read = count;
}
MEMCPY(buffer, (file->data + file->index), read);
file->index += read;
return(read);
return (read);
}
#endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */
/*-----------------------------------------------------------------------------------*/

View File

@ -1,8 +1,8 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@ -11,21 +11,21 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/

View File

@ -142,8 +142,7 @@
#define HTTP_DATA_TO_SEND_CONTINUE 1
#define HTTP_NO_DATA_TO_SEND 0
typedef struct
{
typedef struct {
const char *name;
u8_t shtml;
} default_filename;
@ -161,7 +160,7 @@ const default_filename g_psDefaultFilenames[] = {
#if LWIP_HTTPD_SUPPORT_REQUESTLIST
/** HTTP request is copied here from pbufs for simple parsing */
static char httpd_req_buf[LWIP_HTTPD_MAX_REQ_LENGTH+1];
static char httpd_req_buf[LWIP_HTTPD_MAX_REQ_LENGTH + 1];
#endif /* LWIP_HTTPD_SUPPORT_REQUESTLIST */
#if LWIP_HTTPD_SUPPORT_POST
@ -175,7 +174,7 @@ static char httpd_req_buf[LWIP_HTTPD_MAX_REQ_LENGTH+1];
#if LWIP_HTTPD_URI_BUF_LEN
/* Filename for response file to send when POST is finished or
* search for default files when a directory is requested. */
static char http_uri_buf[LWIP_HTTPD_URI_BUF_LEN+1];
static char http_uri_buf[LWIP_HTTPD_URI_BUF_LEN + 1];
#endif
#if LWIP_HTTPD_DYNAMIC_HEADERS
@ -299,7 +298,7 @@ LWIP_MEMPOOL_DECLARE(HTTPD_SSI_STATE, MEMP_NUM_PARALLEL_HTTPD_SSI_CONNS, sizeof(
static err_t http_close_conn(struct altcp_pcb *pcb, struct http_state *hs);
static err_t http_close_or_abort_conn(struct altcp_pcb *pcb, struct http_state *hs, u8_t abort_conn);
static err_t http_find_file(struct http_state *hs, const char *uri, int is_09);
static err_t http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const char *uri, u8_t tag_check, char* params);
static err_t http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const char *uri, u8_t tag_check, char *params);
static err_t http_poll(void *arg, struct altcp_pcb *pcb);
static u8_t http_check_eof(struct altcp_pcb *pcb, struct http_state *hs);
#if LWIP_HTTPD_FS_ASYNC_READ
@ -315,10 +314,10 @@ const char **g_ppcTags;
#endif /* !LWIP_HTTPD_SSI_RAW */
#define LEN_TAG_LEAD_IN 5
const char * const g_pcTagLeadIn = "<!--#";
const char *const g_pcTagLeadIn = "<!--#";
#define LEN_TAG_LEAD_OUT 3
const char * const g_pcTagLeadOut = "-->";
const char *const g_pcTagLeadOut = "-->";
#endif /* LWIP_HTTPD_SSI */
#if LWIP_HTTPD_CGI
@ -355,7 +354,7 @@ http_remove_connection(struct http_state *hs)
http_connections = hs->next;
} else {
struct http_state *last;
for(last = http_connections; last->next != NULL; last = last->next) {
for (last = http_connections; last->next != NULL; last = last->next) {
if (last->next == hs) {
last->next = hs->next;
break;
@ -370,7 +369,7 @@ http_kill_oldest_connection(u8_t ssi_required)
{
struct http_state *hs = http_connections;
struct http_state *hs_free_next = NULL;
while(hs && hs->next) {
while (hs && hs->next) {
#if LWIP_HTTPD_SSI
if (ssi_required) {
if (hs->next->ssi != NULL) {
@ -402,7 +401,7 @@ http_kill_oldest_connection(u8_t ssi_required)
#if LWIP_HTTPD_SSI
/** Allocate as struct http_ssi_state. */
static struct http_ssi_state*
static struct http_ssi_state *
http_ssi_state_alloc(void)
{
struct http_ssi_state *ret = HTTP_ALLOC_SSI_STATE();
@ -431,7 +430,7 @@ http_ssi_state_free(struct http_ssi_state *ssi)
/** Initialize a struct http_state.
*/
static void
http_state_init(struct http_state* hs)
http_state_init(struct http_state *hs)
{
/* Initialize the structure. */
memset(hs, 0, sizeof(struct http_state));
@ -442,7 +441,7 @@ http_state_init(struct http_state* hs)
}
/** Allocate a struct http_state. */
static struct http_state*
static struct http_state *
http_state_alloc(void)
{
struct http_state *ret = HTTP_ALLOC_HTTP_STATE();
@ -465,12 +464,12 @@ http_state_alloc(void)
static void
http_state_eof(struct http_state *hs)
{
if(hs->handle) {
if (hs->handle) {
#if LWIP_HTTPD_TIMING
u32_t ms_needed = sys_now() - hs->time_started;
u32_t needed = LWIP_MAX(1, (ms_needed/100));
u32_t needed = LWIP_MAX(1, (ms_needed / 100));
LWIP_DEBUGF(HTTPD_DEBUG_TIMING, ("httpd: needed %"U32_F" ms to send file of %d bytes -> %"U32_F" bytes/sec\n",
ms_needed, hs->handle->len, ((((u32_t)hs->handle->len) * 10) / needed)));
ms_needed, hs->handle->len, ((((u32_t)hs->handle->len) * 10) / needed)));
#endif /* LWIP_HTTPD_TIMING */
fs_close(hs->handle);
hs->handle = NULL;
@ -518,7 +517,7 @@ http_state_free(struct http_state *hs)
* @return the return value of tcp_write
*/
static err_t
http_write(struct altcp_pcb *pcb, const void* ptr, u16_t *length, u8_t apiflags)
http_write(struct altcp_pcb *pcb, const void *ptr, u16_t *length, u8_t apiflags)
{
u16_t len, max_len;
err_t err;
@ -535,7 +534,7 @@ http_write(struct altcp_pcb *pcb, const void* ptr, u16_t *length, u8_t apiflags)
#ifdef HTTPD_MAX_WRITE_LEN
/* Additional limitation: e.g. don't enqueue more than 2*mss at once */
max_len = HTTPD_MAX_WRITE_LEN(pcb);
if(len > max_len) {
if (len > max_len) {
len = max_len;
}
#endif /* HTTPD_MAX_WRITE_LEN */
@ -544,14 +543,14 @@ http_write(struct altcp_pcb *pcb, const void* ptr, u16_t *length, u8_t apiflags)
err = altcp_write(pcb, ptr, len, apiflags);
if (err == ERR_MEM) {
if ((altcp_sndbuf(pcb) == 0) ||
(altcp_sndqueuelen(pcb) >= TCP_SND_QUEUELEN)) {
/* no need to try smaller sizes */
len = 1;
(altcp_sndqueuelen(pcb) >= TCP_SND_QUEUELEN)) {
/* no need to try smaller sizes */
len = 1;
} else {
len /= 2;
}
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE,
("Send failed, trying less (%d bytes)\n", len));
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE,
("Send failed, trying less (%d bytes)\n", len));
}
} while ((err == ERR_MEM) && (len > 1));
@ -564,10 +563,10 @@ http_write(struct altcp_pcb *pcb, const void* ptr, u16_t *length, u8_t apiflags)
}
#if LWIP_HTTPD_SUPPORT_11_KEEPALIVE
/* ensure nagle is normally enabled (only disabled for persistent connections
when all data has been enqueued but the connection stays open for the next
request */
altcp_nagle_enable(pcb);
/* ensure nagle is normally enabled (only disabled for persistent connections
when all data has been enqueued but the connection stays open for the next
request */
altcp_nagle_enable(pcb);
#endif
return err;
@ -584,13 +583,13 @@ static err_t
http_close_or_abort_conn(struct altcp_pcb *pcb, struct http_state *hs, u8_t abort_conn)
{
err_t err;
LWIP_DEBUGF(HTTPD_DEBUG, ("Closing connection %p\n", (void*)pcb));
LWIP_DEBUGF(HTTPD_DEBUG, ("Closing connection %p\n", (void *)pcb));
#if LWIP_HTTPD_SUPPORT_POST
if (hs != NULL) {
if ((hs->post_content_len_left != 0)
#if LWIP_HTTPD_POST_MANUAL_WND
|| ((hs->no_auto_wnd != 0) && (hs->unrecved_bytes != 0))
|| ((hs->no_auto_wnd != 0) && (hs->unrecved_bytes != 0))
#endif /* LWIP_HTTPD_POST_MANUAL_WND */
) {
/* make sure the post code knows that the connection is closed */
@ -616,7 +615,7 @@ http_close_or_abort_conn(struct altcp_pcb *pcb, struct http_state *hs, u8_t abor
}
err = altcp_close(pcb);
if (err != ERR_OK) {
LWIP_DEBUGF(HTTPD_DEBUG, ("Error %d closing %p\n", err, (void*)pcb));
LWIP_DEBUGF(HTTPD_DEBUG, ("Error %d closing %p\n", err, (void *)pcb));
/* error closing, try again later in poll */
altcp_poll(pcb, http_poll, HTTPD_POLL_INTERVAL);
}
@ -633,7 +632,7 @@ http_close_or_abort_conn(struct altcp_pcb *pcb, struct http_state *hs, u8_t abor
static err_t
http_close_conn(struct altcp_pcb *pcb, struct http_state *hs)
{
return http_close_or_abort_conn(pcb, hs, 0);
return http_close_or_abort_conn(pcb, hs, 0);
}
/** End of file: either close the connection (Connection: close) or
@ -682,8 +681,8 @@ extract_uri_parameters(struct http_state *hs, char *params)
LWIP_UNUSED_ARG(hs);
/* If we have no parameters at all, return immediately. */
if(!params || (params[0] == '\0')) {
return(0);
if (!params || (params[0] == '\0')) {
return (0);
}
/* Get a pointer to our first parameter */
@ -691,7 +690,7 @@ extract_uri_parameters(struct http_state *hs, char *params)
/* Parse up to LWIP_HTTPD_MAX_CGI_PARAMETERS from the passed string and ignore the
* remainder (if any) */
for(loop = 0; (loop < LWIP_HTTPD_MAX_CGI_PARAMETERS) && pair; loop++) {
for (loop = 0; (loop < LWIP_HTTPD_MAX_CGI_PARAMETERS) && pair; loop++) {
/* Save the name of the parameter */
http_cgi_params[loop] = pair;
@ -702,25 +701,25 @@ extract_uri_parameters(struct http_state *hs, char *params)
/* Find the start of the next name=value pair and replace the delimiter
* with a 0 to terminate the previous pair string. */
pair = strchr(pair, '&');
if(pair) {
if (pair) {
*pair = '\0';
pair++;
} else {
/* We didn't find a new parameter so find the end of the URI and
* replace the space with a '\0' */
pair = strchr(equals, ' ');
if(pair) {
*pair = '\0';
}
/* We didn't find a new parameter so find the end of the URI and
* replace the space with a '\0' */
pair = strchr(equals, ' ');
if (pair) {
*pair = '\0';
}
/* Revert to NULL so that we exit the loop as expected. */
pair = NULL;
/* Revert to NULL so that we exit the loop as expected. */
pair = NULL;
}
/* Now find the '=' in the previous pair, replace it with '\0' and save
* the parameter value string. */
equals = strchr(equals, '=');
if(equals) {
if (equals) {
*equals = '\0';
http_cgi_param_vals[loop] = equals + 1;
} else {
@ -747,7 +746,7 @@ static void
get_tag_insert(struct http_state *hs)
{
#if LWIP_HTTPD_SSI_RAW
const char* tag;
const char *tag;
#else /* LWIP_HTTPD_SSI_RAW */
int tag;
#endif /* LWIP_HTTPD_SSI_RAW */
@ -768,9 +767,9 @@ get_tag_insert(struct http_state *hs)
tag = ssi->tag_name;
#endif
if(g_pfnSSIHandler
if (g_pfnSSIHandler
#if !LWIP_HTTPD_SSI_RAW
&& g_ppcTags && g_iNumTags
&& g_ppcTags && g_iNumTags
#endif /* !LWIP_HTTPD_SSI_RAW */
) {
@ -778,19 +777,19 @@ get_tag_insert(struct http_state *hs)
#if LWIP_HTTPD_SSI_RAW
{
#else /* LWIP_HTTPD_SSI_RAW */
for(tag = 0; tag < g_iNumTags; tag++) {
if(strcmp(ssi->tag_name, g_ppcTags[tag]) == 0)
for (tag = 0; tag < g_iNumTags; tag++) {
if (strcmp(ssi->tag_name, g_ppcTags[tag]) == 0)
#endif /* LWIP_HTTPD_SSI_RAW */
{
ssi->tag_insert_len = g_pfnSSIHandler(tag, ssi->tag_insert,
LWIP_HTTPD_MAX_TAG_INSERT_LEN
LWIP_HTTPD_MAX_TAG_INSERT_LEN
#if LWIP_HTTPD_SSI_MULTIPART
, current_tag_part, &ssi->tag_part
, current_tag_part, &ssi->tag_part
#endif /* LWIP_HTTPD_SSI_MULTIPART */
#if LWIP_HTTPD_FILE_STATE
, (hs->handle ? hs->handle->state : NULL)
, (hs->handle ? hs->handle->state : NULL)
#endif /* LWIP_HTTPD_FILE_STATE */
);
);
#if LWIP_HTTPD_SSI_RAW
if (ssi->tag_insert_len != HTTPD_SSI_TAG_UNKNOWN)
#endif /* LWIP_HTTPD_SSI_RAW */
@ -809,7 +808,7 @@ get_tag_insert(struct http_state *hs)
#define UNKNOWN_TAG2_TEXT "***</b>"
#define UNKNOWN_TAG2_LEN 7
len = LWIP_MIN(sizeof(ssi->tag_name), LWIP_MIN(strlen(ssi->tag_name),
LWIP_HTTPD_MAX_TAG_INSERT_LEN - (UNKNOWN_TAG1_LEN + UNKNOWN_TAG2_LEN)));
LWIP_HTTPD_MAX_TAG_INSERT_LEN - (UNKNOWN_TAG1_LEN + UNKNOWN_TAG2_LEN)));
MEMCPY(ssi->tag_insert, UNKNOWN_TAG1_TEXT, UNKNOWN_TAG1_LEN);
MEMCPY(&ssi->tag_insert[UNKNOWN_TAG1_LEN], ssi->tag_name, len);
MEMCPY(&ssi->tag_insert[UNKNOWN_TAG1_LEN + len], UNKNOWN_TAG2_TEXT, UNKNOWN_TAG2_LEN);
@ -873,10 +872,10 @@ get_http_headers(struct http_state *hs, const char *uri)
hs->hdrs[HDR_STRINGS_IDX_HTTP_STATUS] = g_psHTTPHeaderStrings[HTTP_HDR_OK];
}
/* Determine if the URI has any variables and, if so, temporarily remove
/* Determine if the URI has any variables and, if so, temporarily remove
them. */
vars = strchr(uri, '?');
if(vars) {
if (vars) {
*vars = '\0';
}
@ -892,7 +891,7 @@ get_http_headers(struct http_state *hs, const char *uri)
/* Now determine the content type and add the relevant header for that. */
for (content_type = 0; content_type < NUM_HTTP_HEADERS; content_type++) {
/* Have we found a matching extension? */
if(!lwip_stricmp(g_psHTTPHeaders[content_type].extension, ext)) {
if (!lwip_stricmp(g_psHTTPHeaders[content_type].extension, ext)) {
break;
}
}
@ -918,7 +917,7 @@ get_http_headers(struct http_state *hs, const char *uri)
#endif /* LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI */
add_content_len = 1;
/* Did we find a matching extension? */
if(content_type < NUM_HTTP_HEADERS) {
if (content_type < NUM_HTTP_HEADERS) {
/* yes, store it */
hs->hdrs[HDR_STRINGS_IDX_CONTENT_TYPE] = g_psHTTPHeaders[content_type].content_type;
} else if (!ext) {
@ -934,14 +933,14 @@ get_http_headers(struct http_state *hs, const char *uri)
add_content_len = 0; /* @todo: get maximum file length from SSI */
} else
#endif /* LWIP_HTTPD_SSI */
if ((hs->handle == NULL) ||
((hs->handle->flags & (FS_FILE_FLAGS_HEADER_INCLUDED|FS_FILE_FLAGS_HEADER_PERSISTENT)) == FS_FILE_FLAGS_HEADER_INCLUDED)) {
add_content_len = 0;
}
if ((hs->handle == NULL) ||
((hs->handle->flags & (FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT)) == FS_FILE_FLAGS_HEADER_INCLUDED)) {
add_content_len = 0;
}
if (add_content_len) {
size_t len;
lwip_itoa(hs->hdr_content_len, (size_t)LWIP_HTTPD_MAX_CONTENT_LEN_SIZE,
hs->handle->len);
hs->handle->len);
len = strlen(hs->hdr_content_len);
if (len <= LWIP_HTTPD_MAX_CONTENT_LEN_SIZE - LWIP_HTTPD_MAX_CONTENT_LEN_OFFSET) {
SMEMCPY(&hs->hdr_content_len[len], CRLF, 3);
@ -986,7 +985,7 @@ http_send_headers(struct altcp_pcb *pcb, struct http_state *hs)
len = altcp_sndbuf(pcb);
sendlen = len;
while(len && (hs->hdr_index < NUM_FILE_HDR_STRINGS) && sendlen) {
while (len && (hs->hdr_index < NUM_FILE_HDR_STRINGS) && sendlen) {
const void *ptr;
u16_t old_sendlen;
u8_t apiflags;
@ -1013,7 +1012,7 @@ http_send_headers(struct altcp_pcb *pcb, struct http_state *hs)
/* Remember that we added some more data to be transmitted. */
data_to_send = HTTP_DATA_TO_SEND_CONTINUE;
} else if (err != ERR_OK) {
/* special case: http_write does not try to send 1 byte */
/* special case: http_write does not try to send 1 byte */
sendlen = 0;
}
@ -1022,12 +1021,12 @@ http_send_headers(struct altcp_pcb *pcb, struct http_state *hs)
len -= sendlen;
/* Have we finished sending this string? */
if(hs->hdr_pos == hdrlen) {
if (hs->hdr_pos == hdrlen) {
/* Yes - move on to the next one */
hs->hdr_index++;
/* skip headers that are NULL (not all headers are required) */
while ((hs->hdr_index < NUM_FILE_HDR_STRINGS) &&
(hs->hdrs[hs->hdr_index] == NULL)) {
(hs->hdrs[hs->hdr_index] == NULL)) {
hs->hdr_index++;
}
hs->hdr_pos = 0;
@ -1038,7 +1037,7 @@ http_send_headers(struct altcp_pcb *pcb, struct http_state *hs)
/* When we are at the end of the headers, check for data to send
* instead of waiting for ACK from remote side to continue
* (which would happen when sending files from async read). */
if(http_check_eof(pcb, hs)) {
if (http_check_eof(pcb, hs)) {
data_to_send = HTTP_DATA_TO_SEND_CONTINUE;
}
}
@ -1046,7 +1045,7 @@ http_send_headers(struct altcp_pcb *pcb, struct http_state *hs)
* the header information we just wrote immediately. If there are no
* more headers to send, but we do have file data to send, drop through
* to try to send some file data too. */
if((hs->hdr_index < NUM_FILE_HDR_STRINGS) || !hs->file) {
if ((hs->hdr_index < NUM_FILE_HDR_STRINGS) || !hs->file) {
LWIP_DEBUGF(HTTPD_DEBUG, ("tcp_output\n"));
return HTTP_DATA_TO_SEND_BREAK;
}
@ -1086,13 +1085,13 @@ http_check_eof(struct altcp_pcb *pcb, struct http_state *hs)
}
#if LWIP_HTTPD_DYNAMIC_FILE_READ
/* Do we already have a send buffer allocated? */
if(hs->buf) {
if (hs->buf) {
/* Yes - get the length of the buffer */
count = LWIP_MIN(hs->buf_len, bytes_left);
} else {
/* We don't have a send buffer so allocate one now */
count = altcp_sndbuf(pcb);
if(bytes_left < count) {
if (bytes_left < count) {
count = bytes_left;
}
#ifdef HTTPD_MAX_WRITE_LEN
@ -1103,7 +1102,7 @@ http_check_eof(struct altcp_pcb *pcb, struct http_state *hs)
}
#endif /* HTTPD_MAX_WRITE_LEN */
do {
hs->buf = (char*)mem_malloc((mem_size_t)count);
hs->buf = (char *)mem_malloc((mem_size_t)count);
if (hs->buf != NULL) {
hs->buf_len = count;
break;
@ -1204,7 +1203,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
len = altcp_sndbuf(pcb);
/* Do we have remaining data to send before parsing more? */
if(ssi->parsed > hs->file) {
if (ssi->parsed > hs->file) {
len = (u16_t)LWIP_MIN(ssi->parsed - hs->file, 0xffff);
err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
@ -1215,7 +1214,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
}
/* If the send buffer is full, return now. */
if(altcp_sndbuf(pcb) == 0) {
if (altcp_sndbuf(pcb) == 0) {
return data_to_send;
}
}
@ -1224,15 +1223,15 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
/* We have sent all the data that was already parsed so continue parsing
* the buffer contents looking for SSI tags. */
while(((ssi->tag_state == TAG_SENDING) || ssi->parse_left) && (err == ERR_OK)) {
while (((ssi->tag_state == TAG_SENDING) || ssi->parse_left) && (err == ERR_OK)) {
if (len == 0) {
return data_to_send;
}
switch(ssi->tag_state) {
switch (ssi->tag_state) {
case TAG_NONE:
/* We are not currently processing an SSI tag so scan for the
* start of the lead-in marker. */
if(*ssi->parsed == g_pcTagLeadIn[0]) {
if (*ssi->parsed == g_pcTagLeadIn[0]) {
/* We found what could be the lead-in for a new tag so change
* state appropriately. */
ssi->tag_state = TAG_LEADIN;
@ -1252,12 +1251,12 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
* the tag name. */
/* Have we reached the end of the leadin? */
if(ssi->tag_index == LEN_TAG_LEAD_IN) {
if (ssi->tag_index == LEN_TAG_LEAD_IN) {
ssi->tag_index = 0;
ssi->tag_state = TAG_FOUND;
} else {
/* Have we found the next character we expect for the tag leadin? */
if(*ssi->parsed == g_pcTagLeadIn[ssi->tag_index]) {
if (*ssi->parsed == g_pcTagLeadIn[ssi->tag_index]) {
/* Yes - move to the next one unless we have found the complete
* leadin, in which case we start looking for the tag itself */
ssi->tag_index++;
@ -1279,9 +1278,9 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
/* Remove leading whitespace between the tag leading and the first
* tag name character. */
if((ssi->tag_index == 0) && ((*ssi->parsed == ' ') ||
(*ssi->parsed == '\t') || (*ssi->parsed == '\n') ||
(*ssi->parsed == '\r'))) {
if ((ssi->tag_index == 0) && ((*ssi->parsed == ' ') ||
(*ssi->parsed == '\t') || (*ssi->parsed == '\n') ||
(*ssi->parsed == '\r'))) {
/* Move on to the next character in the buffer */
ssi->parse_left--;
ssi->parsed++;
@ -1290,11 +1289,11 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
/* Have we found the end of the tag name? This is signalled by
* us finding the first leadout character or whitespace */
if((*ssi->parsed == g_pcTagLeadOut[0]) ||
(*ssi->parsed == ' ') || (*ssi->parsed == '\t') ||
(*ssi->parsed == '\n') || (*ssi->parsed == '\r')) {
if ((*ssi->parsed == g_pcTagLeadOut[0]) ||
(*ssi->parsed == ' ') || (*ssi->parsed == '\t') ||
(*ssi->parsed == '\n') || (*ssi->parsed == '\r')) {
if(ssi->tag_index == 0) {
if (ssi->tag_index == 0) {
/* We read a zero length tag so ignore it. */
ssi->tag_state = TAG_NONE;
} else {
@ -1304,7 +1303,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
LWIP_ASSERT("ssi->tag_index <= 0xff", ssi->tag_index <= 0xff);
ssi->tag_name_len = (u8_t)ssi->tag_index;
ssi->tag_name[ssi->tag_index] = '\0';
if(*ssi->parsed == g_pcTagLeadOut[0]) {
if (*ssi->parsed == g_pcTagLeadOut[0]) {
ssi->tag_index = 1;
} else {
ssi->tag_index = 0;
@ -1312,7 +1311,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
}
} else {
/* This character is part of the tag name so save it */
if(ssi->tag_index < LWIP_HTTPD_MAX_TAG_NAME_LEN) {
if (ssi->tag_index < LWIP_HTTPD_MAX_TAG_NAME_LEN) {
ssi->tag_name[ssi->tag_index++] = *ssi->parsed;
} else {
/* The tag was too long so ignore it. */
@ -1330,9 +1329,9 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
case TAG_LEADOUT:
/* Remove leading whitespace between the tag leading and the first
* tag leadout character. */
if((ssi->tag_index == 0) && ((*ssi->parsed == ' ') ||
(*ssi->parsed == '\t') || (*ssi->parsed == '\n') ||
(*ssi->parsed == '\r'))) {
if ((ssi->tag_index == 0) && ((*ssi->parsed == ' ') ||
(*ssi->parsed == '\t') || (*ssi->parsed == '\n') ||
(*ssi->parsed == '\r'))) {
/* Move on to the next character in the buffer */
ssi->parse_left--;
ssi->parsed++;
@ -1340,7 +1339,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
}
/* Have we found the next character we expect for the tag leadout? */
if(*ssi->parsed == g_pcTagLeadOut[ssi->tag_index]) {
if (*ssi->parsed == g_pcTagLeadOut[ssi->tag_index]) {
/* Yes - move to the next one unless we have found the complete
* leadout, in which case we need to call the client to process
* the tag. */
@ -1349,7 +1348,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
ssi->parse_left--;
ssi->parsed++;
if(ssi->tag_index == (LEN_TAG_LEAD_OUT - 1)) {
if (ssi->tag_index == (LEN_TAG_LEAD_OUT - 1)) {
/* Call the client to ask for the insert string for the
* tag we just found. */
#if LWIP_HTTPD_SSI_MULTIPART
@ -1382,7 +1381,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
if (err == ERR_OK) {
data_to_send = 1;
#if !LWIP_HTTPD_SSI_INCLUDE_TAG
if(ssi->tag_started <= hs->file) {
if (ssi->tag_started <= hs->file) {
/* pretend to have sent the tag, too */
len += (u16_t)(ssi->tag_end - ssi->tag_started);
}
@ -1411,7 +1410,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
case TAG_SENDING:
/* Do we have any remaining file data to send from the buffer prior
* to the tag? */
if(ssi->tag_end > hs->file) {
if (ssi->tag_end > hs->file) {
/* How much of the data can we send? */
#if LWIP_HTTPD_SSI_INCLUDE_TAG
len = (u16_t)LWIP_MIN(ssi->tag_end - hs->file, 0xffff);
@ -1428,7 +1427,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
if (err == ERR_OK) {
data_to_send = 1;
#if !LWIP_HTTPD_SSI_INCLUDE_TAG
if(ssi->tag_started <= hs->file) {
if (ssi->tag_started <= hs->file) {
/* pretend to have sent the tag, too */
len += (u16_t)(ssi->tag_end - ssi->tag_started);
}
@ -1438,7 +1437,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
}
} else {
#if LWIP_HTTPD_SSI_MULTIPART
if(ssi->tag_index >= ssi->tag_insert_len) {
if (ssi->tag_index >= ssi->tag_insert_len) {
/* Did the last SSIHandler have more to send? */
if (ssi->tag_part != HTTPD_LAST_TAG_PART) {
/* If so, call it again */
@ -1449,7 +1448,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
#endif /* LWIP_HTTPD_SSI_MULTIPART */
/* Do we still have insert data left to send? */
if(ssi->tag_index < ssi->tag_insert_len) {
if (ssi->tag_index < ssi->tag_insert_len) {
/* We are sending the insert string itself. How much of the
* insert can we send? */
len = (ssi->tag_insert_len - ssi->tag_index);
@ -1483,14 +1482,14 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
break;
default:
break;
}
}
}
}
/* If we drop out of the end of the for loop, this implies we must have
* file data to send so send it now. In TAG_SENDING state, we've already
* handled this so skip the send if that's the case. */
if((ssi->tag_state != TAG_SENDING) && (ssi->parsed > hs->file)) {
if ((ssi->tag_state != TAG_SENDING) && (ssi->parsed > hs->file)) {
#if LWIP_HTTPD_DYNAMIC_FILE_READ && !LWIP_HTTPD_SSI_INCLUDE_TAG
if ((ssi->tag_state != TAG_NONE) && (ssi->tag_started > ssi->tag_end)) {
/* If we found tag on the edge of the read buffer: just throw away the first part
@ -1527,8 +1526,8 @@ http_send(struct altcp_pcb *pcb, struct http_state *hs)
{
u8_t data_to_send = HTTP_NO_DATA_TO_SEND;
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_send: pcb=%p hs=%p left=%d\n", (void*)pcb,
(void*)hs, hs != NULL ? (int)hs->left : 0));
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_send: pcb=%p hs=%p left=%d\n", (void *)pcb,
(void *)hs, hs != NULL ? (int)hs->left : 0));
#if LWIP_HTTPD_SUPPORT_POST && LWIP_HTTPD_POST_MANUAL_WND
if (hs->unrecved_bytes != 0) {
@ -1569,7 +1568,7 @@ http_send(struct altcp_pcb *pcb, struct http_state *hs)
}
#if LWIP_HTTPD_SSI
if(hs->ssi) {
if (hs->ssi) {
data_to_send = http_send_data_ssi(pcb, hs);
} else
#endif /* LWIP_HTTPD_SSI */
@ -1577,7 +1576,7 @@ http_send(struct altcp_pcb *pcb, struct http_state *hs)
data_to_send = http_send_data_nonssi(pcb, hs);
}
if((hs->left == 0) && (fs_bytes_left(hs->handle) <= 0)) {
if ((hs->left == 0) && (fs_bytes_left(hs->handle) <= 0)) {
/* We reached the end of the file so this request is done.
* This adds the FIN flag right into the last data segment. */
LWIP_DEBUGF(HTTPD_DEBUG, ("End of file.\n"));
@ -1619,7 +1618,7 @@ http_find_error_file(struct http_state *hs, u16_t error_nr)
err = fs_open(&hs->file_handle, uri3);
if (err != ERR_OK) {
LWIP_DEBUGF(HTTPD_DEBUG, ("Error page for error %"U16_F" not found\n",
error_nr));
error_nr));
return ERR_ARG;
}
}
@ -1721,7 +1720,7 @@ http_post_rxpbuf(struct http_state *hs, struct pbuf *p)
if (hs->post_content_len_left == 0) {
#if LWIP_HTTPD_SUPPORT_POST && LWIP_HTTPD_POST_MANUAL_WND
if (hs->unrecved_bytes != 0) {
return ERR_OK;
return ERR_OK;
}
#endif /* LWIP_HTTPD_SUPPORT_POST && LWIP_HTTPD_POST_MANUAL_WND */
/* application error or POST finished */
@ -1751,7 +1750,7 @@ http_post_request(struct pbuf *inp, struct http_state *hs,
{
err_t err;
/* search for end-of-header (first double-CRLF) */
char* crlfcrlf = lwip_strnstr(uri_end + 1, CRLF CRLF, data_len - (uri_end + 1 - data));
char *crlfcrlf = lwip_strnstr(uri_end + 1, CRLF CRLF, data_len - (uri_end + 1 - data));
if (crlfcrlf != NULL) {
/* search for "Content-Length: " */
@ -1781,7 +1780,7 @@ http_post_request(struct pbuf *inp, struct http_state *hs,
/* trim http header */
*crlfcrlf = 0;
err = httpd_post_begin(hs, uri, hdr_start_after_uri, hdr_data_len, content_len,
http_uri_buf, LWIP_HTTPD_URI_BUF_LEN, &post_auto_wnd);
http_uri_buf, LWIP_HTTPD_URI_BUF_LEN, &post_auto_wnd);
if (err == ERR_OK) {
/* try to pass in data of the first pbuf(s) */
struct pbuf *q = inp;
@ -1793,7 +1792,7 @@ http_post_request(struct pbuf *inp, struct http_state *hs,
hs->post_content_len_left = (u32_t)content_len;
/* get to the pbuf where the body starts */
while((q != NULL) && (q->len <= start_offset)) {
while ((q != NULL) && (q->len <= start_offset)) {
start_offset -= q->len;
q = q->next;
}
@ -1820,7 +1819,7 @@ http_post_request(struct pbuf *inp, struct http_state *hs,
}
} else {
LWIP_DEBUGF(HTTPD_DEBUG, ("POST received invalid Content-Length: %s\n",
content_len_num));
content_len_num));
return ERR_ARG;
}
}
@ -1850,7 +1849,7 @@ http_post_request(struct pbuf *inp, struct http_state *hs,
*/
void httpd_post_data_recved(void *connection, u16_t recved_len)
{
struct http_state *hs = (struct http_state*)connection;
struct http_state *hs = (struct http_state *)connection;
if (hs != NULL) {
if (hs->no_auto_wnd) {
u16_t len = recved_len;
@ -1885,7 +1884,7 @@ void httpd_post_data_recved(void *connection, u16_t recved_len)
static void
http_continue(void *connection)
{
struct http_state *hs = (struct http_state*)connection;
struct http_state *hs = (struct http_state *)connection;
if (hs && (hs->pcb) && (hs->handle)) {
LWIP_ASSERT("hs->pcb != NULL", hs->pcb != NULL);
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("httpd_continue: try to send more data\n"));
@ -1996,11 +1995,11 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct altcp_pcb *pc
data[4] = 0;
/* unsupported method! */
LWIP_DEBUGF(HTTPD_DEBUG, ("Unsupported request method (not implemented): \"%s\"\n",
data));
data));
return http_find_error_file(hs, 501);
}
/* if we come here, method is OK, parse URI */
left_len = (u16_t)(data_len - ((sp1 +1) - data));
left_len = (u16_t)(data_len - ((sp1 + 1) - data));
sp2 = lwip_strnstr(sp1 + 1, " ", left_len);
#if LWIP_HTTPD_SUPPORT_V09
if (sp2 == NULL) {
@ -2024,7 +2023,7 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct altcp_pcb *pc
/* This is HTTP/1.0 compatible: for strict 1.1, a connection
would always be persistent unless "close" was specified. */
if (!is_09 && (lwip_strnstr(data, HTTP11_CONNECTIONKEEPALIVE, data_len) ||
lwip_strnstr(data, HTTP11_CONNECTIONKEEPALIVE2, data_len))) {
lwip_strnstr(data, HTTP11_CONNECTIONKEEPALIVE2, data_len))) {
hs->keepalive = 1;
} else {
hs->keepalive = 0;
@ -2034,7 +2033,7 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct altcp_pcb *pc
*sp1 = 0;
uri[uri_len] = 0;
LWIP_DEBUGF(HTTPD_DEBUG, ("Received \"%s\" request for URI: \"%s\"\n",
data, uri));
data, uri));
#if LWIP_HTTPD_SUPPORT_POST
if (is_post) {
#if LWIP_HTTPD_SUPPORT_REQUESTLIST
@ -2068,7 +2067,7 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct altcp_pcb *pc
#if LWIP_HTTPD_SUPPORT_REQUESTLIST
clen = pbuf_clen(hs->req);
if ((hs->req->tot_len <= LWIP_HTTPD_REQ_BUFSIZE) &&
(clen <= LWIP_HTTPD_REQ_QUEUELEN)) {
(clen <= LWIP_HTTPD_REQ_QUEUELEN)) {
/* request not fully received (too short or CRLF is missing) */
return ERR_INPROGRESS;
} else
@ -2111,7 +2110,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
/* Have we been asked for the default file (in root or a directory) ? */
#if LWIP_HTTPD_MAX_REQUEST_URI_LEN
size_t uri_len = strlen(uri);
if ((uri_len > 0) && (uri[uri_len-1] == '/') &&
if ((uri_len > 0) && (uri[uri_len - 1] == '/') &&
((uri != http_uri_buf) || (uri_len == 1))) {
size_t copy_len = LWIP_MIN(sizeof(http_uri_buf) - 1, uri_len - 1);
if (copy_len > 0) {
@ -2124,7 +2123,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
/* Try each of the configured default filenames until we find one
that exists. */
for (loop = 0; loop < NUM_DEFAULT_FILENAMES; loop++) {
const char* file_name;
const char *file_name;
#if LWIP_HTTPD_MAX_REQUEST_URI_LEN
if (copy_len > 0) {
size_t len_left = sizeof(http_uri_buf) - copy_len - 1;
@ -2141,7 +2140,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
}
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("Looking for %s...\n", file_name));
err = fs_open(&hs->file_handle, file_name);
if(err == ERR_OK) {
if (err == ERR_OK) {
uri = file_name;
file = &hs->file_handle;
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("Opened.\n"));
@ -2172,10 +2171,10 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
* We found a CGI that handles this URI so extract the
* parameters and call the handler.
*/
http_cgi_paramcount = extract_uri_parameters(hs, params);
uri = g_pCGIs[i].pfnCGIHandler(i, http_cgi_paramcount, hs->params,
hs->param_vals);
break;
http_cgi_paramcount = extract_uri_parameters(hs, params);
uri = g_pCGIs[i].pfnCGIHandler(i, http_cgi_paramcount, hs->params,
hs->param_vals);
break;
}
}
}
@ -2185,7 +2184,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
err = fs_open(&hs->file_handle, uri);
if (err == ERR_OK) {
file = &hs->file_handle;
file = &hs->file_handle;
} else {
file = http_get_404_file(hs, &uri);
}
@ -2193,18 +2192,17 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
if (file != NULL) {
/* See if we have been asked for an shtml file and, if so,
enable tag checking. */
const char* ext = NULL, *sub;
char* param = (char*)strstr(uri, "?");
const char *ext = NULL, *sub;
char *param = (char *)strstr(uri, "?");
if (param != NULL) {
/* separate uri from parameters for now, set back later */
*param = 0;
/* separate uri from parameters for now, set back later */
*param = 0;
}
sub = uri;
ext = uri;
for (sub = strstr(sub, "."); sub != NULL; sub = strstr(sub, "."))
{
ext = sub;
sub++;
for (sub = strstr(sub, "."); sub != NULL; sub = strstr(sub, ".")) {
ext = sub;
sub++;
}
tag_check = 0;
for (loop = 0; loop < NUM_SHTML_EXTENSIONS; loop++) {
@ -2214,7 +2212,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
}
}
if (param != NULL) {
*param = '?';
*param = '?';
}
}
#endif /* LWIP_HTTPD_SSI */
@ -2240,7 +2238,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09)
*/
static err_t
http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const char *uri,
u8_t tag_check, char* params)
u8_t tag_check, char *params)
{
if (file != NULL) {
/* file opened, initialise struct http_state */
@ -2277,7 +2275,7 @@ http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const cha
#endif /* LWIP_HTTPD_TIMING */
#if !LWIP_HTTPD_DYNAMIC_HEADERS
LWIP_ASSERT("HTTP headers not included in file system",
(hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) != 0);
(hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) != 0);
#endif /* !LWIP_HTTPD_DYNAMIC_HEADERS */
#if LWIP_HTTPD_SUPPORT_V09
if (is_09 && ((hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) != 0)) {
@ -2305,9 +2303,9 @@ http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const cha
}
httpd_cgi_handler(uri, count, http_cgi_params, http_cgi_param_vals
#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
, hs->handle->state
, hs->handle->state
#endif /* LWIP_HTTPD_FILE_STATE */
);
);
}
#else /* LWIP_HTTPD_CGI_SSI */
LWIP_UNUSED_ARG(params);
@ -2330,16 +2328,16 @@ http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const cha
#if LWIP_HTTPD_SUPPORT_11_KEEPALIVE
if (hs->keepalive) {
#if LWIP_HTTPD_SSI
if (hs->ssi != NULL) {
hs->keepalive = 0;
} else
if (hs->ssi != NULL) {
hs->keepalive = 0;
} else
#endif /* LWIP_HTTPD_SSI */
{
if ((hs->handle != NULL) &&
((hs->handle->flags & (FS_FILE_FLAGS_HEADER_INCLUDED|FS_FILE_FLAGS_HEADER_PERSISTENT)) == FS_FILE_FLAGS_HEADER_INCLUDED)) {
hs->keepalive = 0;
}
}
{
if ((hs->handle != NULL) &&
((hs->handle->flags & (FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT)) == FS_FILE_FLAGS_HEADER_INCLUDED)) {
hs->keepalive = 0;
}
}
}
#endif /* LWIP_HTTPD_SUPPORT_11_KEEPALIVE */
return ERR_OK;
@ -2371,7 +2369,7 @@ http_sent(void *arg, struct altcp_pcb *pcb, u16_t len)
{
struct http_state *hs = (struct http_state *)arg;
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_sent %p\n", (void*)pcb));
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_sent %p\n", (void *)pcb));
LWIP_UNUSED_ARG(len);
@ -2398,7 +2396,7 @@ http_poll(void *arg, struct altcp_pcb *pcb)
{
struct http_state *hs = (struct http_state *)arg;
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_poll: pcb=%p hs=%p pcb_state=%s\n",
(void*)pcb, (void*)hs, tcp_debug_state_str(altcp_dbg_get_tcp_state(pcb))));
(void *)pcb, (void *)hs, tcp_debug_state_str(altcp_dbg_get_tcp_state(pcb))));
if (hs == NULL) {
err_t closed;
@ -2408,8 +2406,8 @@ http_poll(void *arg, struct altcp_pcb *pcb)
LWIP_UNUSED_ARG(closed);
#if LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR
if (closed == ERR_MEM) {
altcp_abort(pcb);
return ERR_ABRT;
altcp_abort(pcb);
return ERR_ABRT;
}
#endif /* LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR */
return ERR_OK;
@ -2424,9 +2422,9 @@ http_poll(void *arg, struct altcp_pcb *pcb)
/* If this connection has a file open, try to send some more data. If
* it has not yet received a GET request, don't do this since it will
* cause the connection to close immediately. */
if(hs && (hs->handle)) {
if (hs && (hs->handle)) {
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_poll: try to send more data\n"));
if(http_send(pcb, hs)) {
if (http_send(pcb, hs)) {
/* If we wrote anything to be sent, go ahead and send it now. */
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("tcp_output\n"));
altcp_output(pcb);
@ -2445,8 +2443,8 @@ static err_t
http_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err)
{
struct http_state *hs = (struct http_state *)arg;
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_recv: pcb=%p pbuf=%p err=%s\n", (void*)pcb,
(void*)p, lwip_strerr(err)));
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_recv: pcb=%p pbuf=%p err=%s\n", (void *)pcb,
(void *)p, lwip_strerr(err)));
if ((err != ERR_OK) || (p == NULL) || (hs == NULL)) {
/* error or closed by other side? */
@ -2465,7 +2463,7 @@ http_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err)
#if LWIP_HTTPD_SUPPORT_POST && LWIP_HTTPD_POST_MANUAL_WND
if (hs->no_auto_wnd) {
hs->unrecved_bytes += p->tot_len;
hs->unrecved_bytes += p->tot_len;
} else
#endif /* LWIP_HTTPD_SUPPORT_POST && LWIP_HTTPD_POST_MANUAL_WND */
{
@ -2491,7 +2489,7 @@ http_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err)
if (hs->handle == NULL) {
err_t parsed = http_parse_request(p, hs, pcb);
LWIP_ASSERT("http_parse_request: unexpected return value", parsed == ERR_OK
|| parsed == ERR_INPROGRESS ||parsed == ERR_ARG || parsed == ERR_USE);
|| parsed == ERR_INPROGRESS || parsed == ERR_ARG || parsed == ERR_USE);
#if LWIP_HTTPD_SUPPORT_REQUESTLIST
if (parsed != ERR_INPROGRESS) {
/* request fully parsed or error */
@ -2504,10 +2502,10 @@ http_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err)
pbuf_free(p);
if (parsed == ERR_OK) {
#if LWIP_HTTPD_SUPPORT_POST
if (hs->post_content_len_left == 0)
if (hs->post_content_len_left == 0)
#endif /* LWIP_HTTPD_SUPPORT_POST */
{
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_recv: data %p len %"S32_F"\n", (const void*)hs->file, hs->left));
LWIP_DEBUGF(HTTPD_DEBUG | LWIP_DBG_TRACE, ("http_recv: data %p len %"S32_F"\n", (const void *)hs->file, hs->left));
http_send(pcb, hs);
}
} else if (parsed == ERR_ARG) {
@ -2532,7 +2530,7 @@ http_accept(void *arg, struct altcp_pcb *pcb, err_t err)
struct http_state *hs;
LWIP_UNUSED_ARG(err);
LWIP_UNUSED_ARG(arg);
LWIP_DEBUGF(HTTPD_DEBUG, ("http_accept %p / %p\n", (void*)pcb, arg));
LWIP_DEBUGF(HTTPD_DEBUG, ("http_accept %p / %p\n", (void *)pcb, arg));
if ((err != ERR_OK) || (pcb == NULL)) {
return ERR_VAL;

View File

@ -6,32 +6,30 @@
#if LWIP_HTTPD_DYNAMIC_HEADERS
/** This struct is used for a list of HTTP header strings for various
* filename extensions. */
typedef struct
{
typedef struct {
const char *extension;
const char *content_type;
} tHTTPHeader;
/** A list of strings used in HTTP headers (see RFC 1945 HTTP/1.0 and
* RFC 2616 HTTP/1.1 for header field definitions) */
static const char * const g_psHTTPHeaderStrings[] =
{
"HTTP/1.0 200 OK\r\n",
"HTTP/1.0 404 File not found\r\n",
"HTTP/1.0 400 Bad Request\r\n",
"HTTP/1.0 501 Not Implemented\r\n",
"HTTP/1.1 200 OK\r\n",
"HTTP/1.1 404 File not found\r\n",
"HTTP/1.1 400 Bad Request\r\n",
"HTTP/1.1 501 Not Implemented\r\n",
"Content-Length: ",
"Connection: Close\r\n",
"Connection: keep-alive\r\n",
"Connection: keep-alive\r\nContent-Length: ",
"Server: "HTTPD_SERVER_AGENT"\r\n",
"\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
static const char *const g_psHTTPHeaderStrings[] = {
"HTTP/1.0 200 OK\r\n",
"HTTP/1.0 404 File not found\r\n",
"HTTP/1.0 400 Bad Request\r\n",
"HTTP/1.0 501 Not Implemented\r\n",
"HTTP/1.1 200 OK\r\n",
"HTTP/1.1 404 File not found\r\n",
"HTTP/1.1 400 Bad Request\r\n",
"HTTP/1.1 501 Not Implemented\r\n",
"Content-Length: ",
"Connection: Close\r\n",
"Connection: keep-alive\r\n",
"Connection: keep-alive\r\nContent-Length: ",
"Server: "HTTPD_SERVER_AGENT"\r\n",
"\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
#if LWIP_HTTPD_SUPPORT_11_KEEPALIVE
,"Connection: keep-alive\r\nContent-Length: 77\r\n\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
, "Connection: keep-alive\r\nContent-Length: 77\r\n\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
#endif
};
@ -82,33 +80,32 @@ static const char * const g_psHTTPHeaderStrings[] =
/** A list of extension-to-HTTP header strings (see outdated RFC 1700 MEDIA TYPES
* and http://www.iana.org/assignments/media-types for registered content types
* and subtypes) */
static const tHTTPHeader g_psHTTPHeaders[] =
{
{ "html", HTTP_HDR_HTML},
{ "htm", HTTP_HDR_HTML},
{ "shtml",HTTP_HDR_SSI},
{ "shtm", HTTP_HDR_SSI},
{ "ssi", HTTP_HDR_SSI},
{ "gif", HTTP_HDR_GIF},
{ "png", HTTP_HDR_PNG},
{ "jpg", HTTP_HDR_JPG},
{ "bmp", HTTP_HDR_BMP},
{ "ico", HTTP_HDR_ICO},
{ "class",HTTP_HDR_APP},
{ "cls", HTTP_HDR_APP},
{ "js", HTTP_HDR_JS},
{ "ram", HTTP_HDR_RA},
{ "css", HTTP_HDR_CSS},
{ "swf", HTTP_HDR_SWF},
{ "xml", HTTP_HDR_XML},
{ "xsl", HTTP_HDR_XML},
{ "pdf", HTTP_HDR_PDF},
{ "json", HTTP_HDR_JSON},
static const tHTTPHeader g_psHTTPHeaders[] = {
{ "html", HTTP_HDR_HTML},
{ "htm", HTTP_HDR_HTML},
{ "shtml", HTTP_HDR_SSI},
{ "shtm", HTTP_HDR_SSI},
{ "ssi", HTTP_HDR_SSI},
{ "gif", HTTP_HDR_GIF},
{ "png", HTTP_HDR_PNG},
{ "jpg", HTTP_HDR_JPG},
{ "bmp", HTTP_HDR_BMP},
{ "ico", HTTP_HDR_ICO},
{ "class", HTTP_HDR_APP},
{ "cls", HTTP_HDR_APP},
{ "js", HTTP_HDR_JS},
{ "ram", HTTP_HDR_RA},
{ "css", HTTP_HDR_CSS},
{ "swf", HTTP_HDR_SWF},
{ "xml", HTTP_HDR_XML},
{ "xsl", HTTP_HDR_XML},
{ "pdf", HTTP_HDR_PDF},
{ "json", HTTP_HDR_JSON},
#ifdef HTTPD_ADDITIONAL_CONTENT_TYPES
/* If you need to add content types not listed here:
* #define HTTPD_ADDITIONAL_CONTENT_TYPES {"ct1", HTTP_CONTENT_TYPE("text/ct1")}, {"exe", HTTP_CONTENT_TYPE("application/exe")}
*/
, HTTPD_ADDITIONAL_CONTENT_TYPES
/* If you need to add content types not listed here:
* #define HTTPD_ADDITIONAL_CONTENT_TYPES {"ct1", HTTP_CONTENT_TYPE("text/ct1")}, {"exe", HTTP_CONTENT_TYPE("application/exe")}
*/
, HTTPD_ADDITIONAL_CONTENT_TYPES
#endif
};
@ -117,7 +114,7 @@ static const tHTTPHeader g_psHTTPHeaders[] =
#endif /* LWIP_HTTPD_DYNAMIC_HEADERS */
#if LWIP_HTTPD_SSI
static const char * const g_pcSSIExtensions[] = {
static const char *const g_pcSSIExtensions[] = {
".shtml", ".shtm", ".ssi", ".xml"
};
#define NUM_SHTML_EXTENSIONS (sizeof(g_pcSSIExtensions) / sizeof(const char *))

View File

@ -107,10 +107,9 @@ static int payload_alingment_dummy_counter = 0;
#define MAX_PATH_LEN 256
struct file_entry
{
struct file_entry* next;
const char* filename_c;
struct file_entry {
struct file_entry *next;
const char *filename_c;
};
int process_sub(FILE *data_file, FILE *struct_file);
@ -120,7 +119,7 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i);
int s_put_ascii(char *buf, const char *ascii_string, int len, int *i);
void concat_files(const char *file1, const char *file2, const char *targetfile);
int check_path(char* path, size_t size);
int check_path(char *path, size_t size);
/* 5 bytes per char + 3 bytes per line */
static char file_buffer_c[COPY_BUFSIZE * 5 + ((COPY_BUFSIZE / HEX_BYTES_PER_LINE) * 3)];
@ -141,8 +140,8 @@ size_t deflatedBytesReduced = 0;
size_t overallDataBytes = 0;
#endif
struct file_entry* first_file = NULL;
struct file_entry* last_file = NULL;
struct file_entry *first_file = NULL;
struct file_entry *last_file = NULL;
static void print_usage(void)
{
@ -212,7 +211,7 @@ int main(int argc, char *argv[])
includeLastModified = 1;
} else if (strstr(argv[i], "-defl") == argv[i]) {
#if MAKEFS_SUPPORT_DEFLATE
char* colon = strstr(argv[i], ":");
char *colon = strstr(argv[i], ":");
if (colon) {
if (colon[1] != 0) {
int defl_level = atoi(&colon[1]);
@ -237,8 +236,8 @@ int main(int argc, char *argv[])
print_usage();
exit(0);
} else {
strncpy(path, argv[i], sizeof(path)-1);
path[sizeof(path)-1] = 0;
strncpy(path, argv[i], sizeof(path) - 1);
path[sizeof(path) - 1] = 0;
}
}
@ -258,8 +257,8 @@ int main(int argc, char *argv[])
CHDIR(appPath);
printf("HTTP %sheader will %s statically included." NEWLINE,
(includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""),
(includeHttpHeader ? "be" : "not be"));
(includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""),
(includeHttpHeader ? "be" : "not be"));
curSubdir[0] = '\0'; /* start off in web page's root directory - relative paths */
printf(" Processing all files in directory %s", path);
@ -332,21 +331,21 @@ int main(int argc, char *argv[])
#if MAKEFS_SUPPORT_DEFLATE
if (deflateNonSsiFiles) {
printf("(Deflated total byte reduction: %d bytes -> %d bytes (%.02f%%)" NEWLINE,
(int)overallDataBytes, (int)deflatedBytesReduced, (float)((deflatedBytesReduced*100.0)/overallDataBytes));
(int)overallDataBytes, (int)deflatedBytesReduced, (float)((deflatedBytesReduced * 100.0) / overallDataBytes));
}
#endif
printf(NEWLINE);
while (first_file != NULL) {
struct file_entry* fe = first_file;
first_file = fe->next;
free(fe);
struct file_entry *fe = first_file;
first_file = fe->next;
free(fe);
}
return 0;
}
int check_path(char* path, size_t size)
int check_path(char *path, size_t size)
{
size_t slen;
if (path[0] == 0) {
@ -373,7 +372,7 @@ static void copy_file(const char *filename_in, FILE *fout)
{
FILE *fin;
size_t len;
void* buf;
void *buf;
fin = fopen(filename_in, "rb");
if (fin == NULL) {
printf("Failed to open file \"%s\"\n", filename_in);
@ -445,8 +444,7 @@ int process_sub(FILE *data_file, FILE *struct_file)
filesProcessed += process_sub(data_file, struct_file);
CHDIR("..");
curSubdir[sublen] = 0;
}
else {
} else {
printf("WARNING: cannot process sub due to path length restrictions: \"%s/%s\"\n", curSubdir, currName);
}
}
@ -494,11 +492,11 @@ int process_sub(FILE *data_file, FILE *struct_file)
return filesProcessed;
}
static u8_t* get_file_data(const char* filename, int* file_size, int can_be_compressed, int* is_compressed)
static u8_t *get_file_data(const char *filename, int *file_size, int can_be_compressed, int *is_compressed)
{
FILE *inFile;
size_t fsize = 0;
u8_t* buf;
u8_t *buf;
size_t r;
int rs;
inFile = fopen(filename, "rb");
@ -509,12 +507,12 @@ static u8_t* get_file_data(const char* filename, int* file_size, int can_be_comp
fseek(inFile, 0, SEEK_END);
rs = ftell(inFile);
if (rs < 0) {
printf("ftell failed with %d\n", errno);
exit(-1);
printf("ftell failed with %d\n", errno);
exit(-1);
}
fsize = (size_t)rs;
fseek(inFile, 0, SEEK_SET);
buf = (u8_t*)malloc(fsize);
buf = (u8_t *)malloc(fsize);
LWIP_ASSERT("buf != NULL", buf != NULL);
r = fread(buf, 1, fsize, inFile);
LWIP_ASSERT("r == fsize", r == fsize);
@ -525,7 +523,7 @@ static u8_t* get_file_data(const char* filename, int* file_size, int can_be_comp
if (deflateNonSsiFiles) {
if (can_be_compressed) {
if (fsize < OUT_BUF_SIZE) {
u8_t* ret_buf;
u8_t *ret_buf;
tdefl_status status;
size_t in_bytes = fsize;
size_t out_bytes = OUT_BUF_SIZE;
@ -549,7 +547,7 @@ static u8_t* get_file_data(const char* filename, int* file_size, int can_be_comp
}
LWIP_ASSERT("out_bytes <= COPY_BUFSIZE", out_bytes <= OUT_BUF_SIZE);
if (out_bytes < fsize) {
ret_buf = (u8_t*)malloc(out_bytes);
ret_buf = (u8_t *)malloc(out_bytes);
LWIP_ASSERT("ret_buf != NULL", ret_buf != NULL);
memcpy(ret_buf, s_outbuf, out_bytes);
{
@ -571,7 +569,7 @@ static u8_t* get_file_data(const char* filename, int* file_size, int can_be_comp
free(buf);
buf = ret_buf;
*file_size = out_bytes;
printf(" - deflate: %d bytes -> %d bytes (%.02f%%)" NEWLINE, (int)fsize, (int)out_bytes, (float)((out_bytes*100.0)/fsize));
printf(" - deflate: %d bytes -> %d bytes (%.02f%%)" NEWLINE, (int)fsize, (int)out_bytes, (float)((out_bytes * 100.0) / fsize));
deflatedBytesReduced += (size_t)(fsize - out_bytes);
*is_compressed = 1;
} else {
@ -591,9 +589,9 @@ static u8_t* get_file_data(const char* filename, int* file_size, int can_be_comp
return buf;
}
static void process_file_data(FILE* data_file, u8_t* file_data, size_t file_size)
static void process_file_data(FILE *data_file, u8_t *file_data, size_t file_size)
{
size_t written, i, src_off=0;
size_t written, i, src_off = 0;
size_t off = 0;
for (i = 0; i < file_size; i++) {
@ -616,7 +614,7 @@ static void process_file_data(FILE* data_file, u8_t* file_data, size_t file_size
}
static int write_checksums(FILE *struct_file, const char *varname,
u16_t hdr_len, u16_t hdr_chksum, const u8_t* file_data, size_t file_size)
u16_t hdr_len, u16_t hdr_chksum, const u8_t *file_data, size_t file_size)
{
int chunk_size = TCP_MSS;
int offset, src_offset;
@ -638,7 +636,7 @@ static int write_checksums(FILE *struct_file, const char *varname,
src_offset = 0;
for (offset = hdr_len; ; offset += len) {
unsigned short chksum;
const void* data = (const void*)&file_data[src_offset];
const void *data = (const void *)&file_data[src_offset];
len = LWIP_MIN(chunk_size, (int)file_size - src_offset);
if (len == 0) {
break;
@ -655,67 +653,67 @@ static int write_checksums(FILE *struct_file, const char *varname,
static int is_valid_char_for_c_var(char x)
{
if (((x >= 'A') && (x <= 'Z')) ||
((x >= 'a') && (x <= 'z')) ||
((x >= '0') && (x <= '9')) ||
(x == '_')) {
return 1;
}
return 0;
if (((x >= 'A') && (x <= 'Z')) ||
((x >= 'a') && (x <= 'z')) ||
((x >= '0') && (x <= '9')) ||
(x == '_')) {
return 1;
}
return 0;
}
static void fix_filename_for_c(char* qualifiedName, size_t max_len)
static void fix_filename_for_c(char *qualifiedName, size_t max_len)
{
struct file_entry* f;
size_t len = strlen(qualifiedName);
char *new_name = (char*)malloc(len + 2);
int filename_ok;
int cnt = 0;
size_t i;
if (len + 3 == max_len) {
printf("File name too long: \"%s\"\n", qualifiedName);
exit(-1);
}
strcpy(new_name, qualifiedName);
for (i = 0; i < len; i++) {
if (!is_valid_char_for_c_var(new_name[i])) {
new_name[i] = '_';
struct file_entry *f;
size_t len = strlen(qualifiedName);
char *new_name = (char *)malloc(len + 2);
int filename_ok;
int cnt = 0;
size_t i;
if (len + 3 == max_len) {
printf("File name too long: \"%s\"\n", qualifiedName);
exit(-1);
}
strcpy(new_name, qualifiedName);
for (i = 0; i < len; i++) {
if (!is_valid_char_for_c_var(new_name[i])) {
new_name[i] = '_';
}
}
do {
filename_ok = 1;
for (f = first_file; f != NULL; f = f->next) {
if (!strcmp(f->filename_c, new_name)) {
filename_ok = 0;
cnt++;
/* try next unique file name */
sprintf(&new_name[len], "%d", cnt);
break;
}
}
do {
filename_ok = 1;
for (f = first_file; f != NULL; f = f->next) {
if (!strcmp(f->filename_c, new_name)) {
filename_ok = 0;
cnt++;
/* try next unique file name */
sprintf(&new_name[len], "%d", cnt);
break;
}
}
} while (!filename_ok && (cnt < 999));
if (!filename_ok) {
printf("Failed to get unique file name: \"%s\"\n", qualifiedName);
exit(-1);
}
strcpy(qualifiedName, new_name);
free(new_name);
}
} while (!filename_ok && (cnt < 999));
if (!filename_ok) {
printf("Failed to get unique file name: \"%s\"\n", qualifiedName);
exit(-1);
}
strcpy(qualifiedName, new_name);
free(new_name);
}
static void register_filename(const char* qualifiedName)
static void register_filename(const char *qualifiedName)
{
struct file_entry* fe = (struct file_entry*)malloc(sizeof(struct file_entry));
fe->filename_c = strdup(qualifiedName);
fe->next = NULL;
if (first_file == NULL) {
first_file = last_file = fe;
} else {
last_file->next = fe;
last_file = fe;
}
struct file_entry *fe = (struct file_entry *)malloc(sizeof(struct file_entry));
fe->filename_c = strdup(qualifiedName);
fe->next = NULL;
if (first_file == NULL) {
first_file = last_file = fe;
} else {
last_file->next = fe;
last_file = fe;
}
}
static int is_ssi_file(const char* filename)
static int is_ssi_file(const char *filename)
{
size_t loop;
for (loop = 0; loop < NUM_SHTML_EXTENSIONS; loop++) {
@ -736,13 +734,13 @@ int process_file(FILE *data_file, FILE *struct_file, const char *filename)
u16_t http_hdr_len = 0;
int chksum_count = 0;
u8_t flags = 0;
const char* flags_str;
const char *flags_str;
u8_t has_content_len;
u8_t* file_data;
u8_t *file_data;
int is_compressed = 0;
/* create qualified name (@todo: prepend slash or not?) */
sprintf(qualifiedName,"%s/%s", curSubdir, filename);
sprintf(qualifiedName, "%s/%s", curSubdir, filename);
/* create C variable name */
strcpy(varname, qualifiedName);
/* convert slashes & dots to underscores */
@ -756,11 +754,11 @@ int process_file(FILE *data_file, FILE *struct_file, const char *filename)
#endif /* ALIGN_PAYLOAD */
fprintf(data_file, "static const unsigned char FSDATA_ALIGN_PRE data_%s[] FSDATA_ALIGN_POST = {" NEWLINE, varname);
/* encode source file name (used by file system, not returned to browser) */
fprintf(data_file, "/* %s (%"SZT_F" chars) */" NEWLINE, qualifiedName, strlen(qualifiedName)+1);
file_put_ascii(data_file, qualifiedName, strlen(qualifiedName)+1, &i);
fprintf(data_file, "/* %s (%"SZT_F" chars) */" NEWLINE, qualifiedName, strlen(qualifiedName) + 1);
file_put_ascii(data_file, qualifiedName, strlen(qualifiedName) + 1, &i);
#if ALIGN_PAYLOAD
/* pad to even number of bytes to assure payload is on aligned boundary */
while(i % PAYLOAD_ALIGNMENT != 0) {
while (i % PAYLOAD_ALIGNMENT != 0) {
fprintf(data_file, "0x%02x,", 0);
i++;
}
@ -786,20 +784,19 @@ int process_file(FILE *data_file, FILE *struct_file, const char *filename)
fprintf(struct_file, "data_%s," NEWLINE, varname);
fprintf(struct_file, "data_%s + %d," NEWLINE, varname, i);
fprintf(struct_file, "sizeof(data_%s) - %d," NEWLINE, varname, i);
switch(flags)
{
case(FS_FILE_FLAGS_HEADER_INCLUDED):
flags_str = "FS_FILE_FLAGS_HEADER_INCLUDED";
break;
case(FS_FILE_FLAGS_HEADER_PERSISTENT):
flags_str = "FS_FILE_FLAGS_HEADER_PERSISTENT";
break;
case(FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT):
flags_str = "FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT";
break;
default:
flags_str = "0";
break;
switch (flags) {
case (FS_FILE_FLAGS_HEADER_INCLUDED):
flags_str = "FS_FILE_FLAGS_HEADER_INCLUDED";
break;
case (FS_FILE_FLAGS_HEADER_PERSISTENT):
flags_str = "FS_FILE_FLAGS_HEADER_PERSISTENT";
break;
case (FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT):
flags_str = "FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT";
break;
default:
flags_str = "0";
break;
}
fprintf(struct_file, "%s," NEWLINE, flags_str);
if (precalcChksum) {
@ -824,7 +821,7 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
{
int i = 0;
int response_type = HTTP_HDR_OK;
const char* file_type;
const char *file_type;
const char *cur_string;
size_t cur_len;
int written = 0;
@ -879,7 +876,7 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
file_ext = filename;
if (file_ext != NULL) {
while(strstr(file_ext, ".") != NULL) {
while (strstr(file_ext, ".") != NULL) {
file_ext = strstr(file_ext, ".");
file_ext++;
}
@ -910,7 +907,7 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
memset(intbuf, 0, sizeof(intbuf));
cur_string = g_psHTTPHeaderStrings[HTTP_HDR_CONTENT_LENGTH];
cur_len = strlen(cur_string);
fprintf(data_file, NEWLINE "/* \"%s%d\r\n\" (%"SZT_F"+ bytes) */" NEWLINE, cur_string, content_len, cur_len+2);
fprintf(data_file, NEWLINE "/* \"%s%d\r\n\" (%"SZT_F"+ bytes) */" NEWLINE, cur_string, content_len, cur_len + 2);
written += file_put_ascii(data_file, cur_string, cur_len, &i);
if (precalcChksum) {
memcpy(&hdr_buf[hdr_len], cur_string, cur_len);
@ -930,23 +927,23 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
if (provide_last_modified) {
char modbuf[256];
struct stat stat_data;
struct tm* t;
struct tm *t;
memset(modbuf, 0, sizeof(modbuf));
memset(&stat_data, 0, sizeof(stat_data));
cur_string = modbuf;
strcpy(modbuf, "Last-Modified: ");
if (stat(filename, &stat_data) != 0) {
printf("stat(%s) failed with error %d\n", filename, errno);
exit(-1);
printf("stat(%s) failed with error %d\n", filename, errno);
exit(-1);
}
t = gmtime(&stat_data.st_mtime);
if (t == NULL) {
printf("gmtime() failed with error %d\n", errno);
exit(-1);
printf("gmtime() failed with error %d\n", errno);
exit(-1);
}
strftime(&modbuf[15], sizeof(modbuf)-15, "%a, %d %b %Y %H:%M:%S GMT", t);
strftime(&modbuf[15], sizeof(modbuf) - 15, "%a, %d %b %Y %H:%M:%S GMT", t);
cur_len = strlen(cur_string);
fprintf(data_file, NEWLINE "/* \"%s\"\r\n\" (%"SZT_F"+ bytes) */" NEWLINE, cur_string, cur_len+2);
fprintf(data_file, NEWLINE "/* \"%s\"\r\n\" (%"SZT_F"+ bytes) */" NEWLINE, cur_string, cur_len + 2);
written += file_put_ascii(data_file, cur_string, cur_len, &i);
if (precalcChksum) {
memcpy(&hdr_buf[hdr_len], cur_string, cur_len);
@ -1020,7 +1017,7 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size,
return written;
}
int file_put_ascii(FILE *file, const char* ascii_string, int len, int *i)
int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i)
{
int x;
for (x = 0; x < len; x++) {