X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/42b850f2b94941066c36d85b4878d6a348260b4d..c58c53dba90fdc19d38f5e5d6957f2ede2a740f3:/Projects/Webserver/Lib/HTTPServerApp.c diff --git a/Projects/Webserver/Lib/HTTPServerApp.c b/Projects/Webserver/Lib/HTTPServerApp.c index b6277d3db..08d849433 100644 --- a/Projects/Webserver/Lib/HTTPServerApp.c +++ b/Projects/Webserver/Lib/HTTPServerApp.c @@ -56,12 +56,12 @@ const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n" "Content-Type: text/plain\r\n\r\n" "Error 404: File Not Found: /"; -/** Default MIME type sent if no other MIME type can be determined. */ -const char PROGMEM DefaultMIMEType[] = "text/plain"; - /** Default filename to fetch when a directory is requested */ const char PROGMEM DefaultDirFileName[] = "index.htm"; +/** Default MIME type sent if no other MIME type can be determined. */ +const char PROGMEM DefaultMIMEType[] = "text/plain"; + /** List of MIME types for each supported file extension. */ const MIME_Type_t MIMETypes[] = { @@ -77,7 +77,7 @@ const MIME_Type_t MIMETypes[] = {.Extension = "pdf", .MIMEType = "application/pdf"}, }; -/** FAT Fs structure to hold the internal state of the FAT driver for the dataflash contents. */ +/** FATFs structure to hold the internal state of the FAT driver for the dataflash contents. */ FATFS DiskFATState; @@ -100,13 +100,9 @@ void HTTPServerApp_Callback(void) if (uip_aborted() || uip_timedout() || uip_closed()) { - /* Connection is being terminated for some reason - close file handle */ - f_close(&AppState->HTTPServer.FileHandle); - AppState->HTTPServer.FileOpen = false; - /* Lock to the closed state so that no further processing will occur on the connection */ - AppState->HTTPServer.CurrentState = WEBSERVER_STATE_Closed; - AppState->HTTPServer.NextState = WEBSERVER_STATE_Closed; + AppState->HTTPServer.CurrentState = WEBSERVER_STATE_Closing; + AppState->HTTPServer.NextState = WEBSERVER_STATE_Closing; } if (uip_connected()) @@ -148,9 +144,15 @@ void HTTPServerApp_Callback(void) HTTPServerApp_SendData(); break; case WEBSERVER_STATE_Closing: + /* Connection is being terminated for some reason - close file handle */ + f_close(&AppState->HTTPServer.FileHandle); + AppState->HTTPServer.FileOpen = false; + + /* If connection is not already closed, close it */ uip_close(); - AppState->HTTPServer.NextState = WEBSERVER_STATE_Closed; + AppState->HTTPServer.CurrentState = WEBSERVER_STATE_Closed; + AppState->HTTPServer.NextState = WEBSERVER_STATE_Closed; break; } } @@ -172,7 +174,7 @@ static void HTTPServerApp_OpenRequestedFile(void) char* RequestedFileName = strtok(NULL, " "); /* Must be a GET request, abort otherwise */ - if (strcmp(RequestToken, "GET") != 0) + if (strcmp_P(RequestToken, PSTR("GET")) != 0) { uip_abort(); return; @@ -255,7 +257,7 @@ static void HTTPServerApp_SendResponseHeader(void) } /* Add the end-of-line terminator and end-of-headers terminator after the MIME type */ - strcpy(&AppData[strlen(AppData)], "\r\n\r\n"); + strcpy_P(&AppData[strlen(AppData)], PSTR("\r\n\r\n")); /* Send the MIME header to the receiving client */ uip_send(AppData, strlen(AppData));