From 90c4e1a53ab9fb40933259fa852b1498ecca0dc0 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Sun, 18 Dec 2016 15:46:03 +0000 Subject: [PATCH] Version 1.17RC2 Renamed function Network::IPAddress to GetIPAddress to avoid clash with IPAddress class used in DuetEthernet build Duet 0.8.5 web server now looks for a gzipped version of the file is a web file was not found Duet 0.8.5 web server only returns a 404 page of the file that was not found was a .html or .htm file --- src/Configuration.h | 4 +-- src/Duet/Network.cpp | 6 ++--- src/Duet/Network.h | 2 +- src/Duet/Webserver.cpp | 47 ++++++++++++++++++--------------- src/Duet/Webserver.h | 2 +- src/DuetNG/DuetWiFi/Network.cpp | 2 +- src/DuetNG/DuetWiFi/Network.h | 2 +- src/RADDS/Network.cpp | 2 +- src/RADDS/Network.h | 2 +- 9 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/Configuration.h b/src/Configuration.h index 4905cca..ead50a2 100644 --- a/src/Configuration.h +++ b/src/Configuration.h @@ -28,11 +28,11 @@ Licence: GPL // Firmware name is now defined in the Pins file #ifndef VERSION -# define VERSION "1.17RC1a" +# define VERSION "1.17RC2" #endif #ifndef DATE -# define DATE "2016-12-13" +# define DATE "2016-12-18" #endif #define AUTHORS "reprappro, dc42, zpl, t3p3, dnewman" diff --git a/src/Duet/Network.cpp b/src/Duet/Network.cpp index 157d381..f3ecfcf 100644 --- a/src/Duet/Network.cpp +++ b/src/Duet/Network.cpp @@ -471,7 +471,7 @@ void Network::Spin() { if (!ethernetStarted) { - start_ethernet(platform->IPAddress(), platform->NetMask(), platform->GateWay(), ðernet_status_callback); + start_ethernet(platform->GetIPAddress(), platform->NetMask(), platform->GateWay(), ðernet_status_callback); ethernetStarted = true; // Initialise this one here, because it requires a configured IGMP network interface @@ -479,7 +479,7 @@ void Network::Spin() } else { - ethernet_set_configuration(platform->IPAddress(), platform->NetMask(), platform->GateWay()); + ethernet_set_configuration(platform->GetIPAddress(), platform->NetMask(), platform->GateWay()); } state = NetworkObtainingIP; } @@ -736,7 +736,7 @@ bool Network::InLwip() const return lwipLocked; } -const uint8_t *Network::IPAddress() const +const uint8_t *Network::GetIPAddress() const { return ethernet_get_ipaddress(); } diff --git a/src/Duet/Network.h b/src/Duet/Network.h index 0d1f77c..cc09986 100644 --- a/src/Duet/Network.h +++ b/src/Duet/Network.h @@ -169,7 +169,7 @@ class Network // Global settings - const uint8_t *IPAddress() const; + const uint8_t *GetIPAddress() const; void SetIPAddress(const uint8_t ipAddress[], const uint8_t netmask[], const uint8_t gateway[]); void SetHostname(const char *name); diff --git a/src/Duet/Webserver.cpp b/src/Duet/Webserver.cpp index 69807ac..293b77e 100644 --- a/src/Duet/Webserver.cpp +++ b/src/Duet/Webserver.cpp @@ -617,7 +617,6 @@ void Webserver::HttpInterpreter::DoFastUpload() if (transaction->ReadBuffer(buffer, len)) { network->Unlock(); -#if 1 // Write data in sector-aligned chunks. This also means that the buffer in fatfs is only used to hold the FAT. static const size_t writeBufLength = 2048; // use a multiple of the 512b sector size static uint32_t writeBufStorage[writeBufLength/4]; // aligned buffer for file writes @@ -652,18 +651,6 @@ void Webserver::HttpInterpreter::DoFastUpload() } } } -#else - if (!fileBeingUploaded.Write(buffer, len)) - { - platform->Message(GENERIC_MESSAGE, "Error: Could not write upload data!\n"); - CancelUpload(); - - while (!network->Lock()); - SendJsonResponse("upload"); - return; - } - uploadedBytes += len; -#endif while (!network->Lock()); } @@ -710,6 +697,7 @@ void Webserver::HttpInterpreter::SendFile(const char* nameOfFileToSend, bool isW { NetworkTransaction *transaction = webserver->currentTransaction; FileStore *fileToSend; + bool zip = false; if (isWebFile) { @@ -722,15 +710,31 @@ void Webserver::HttpInterpreter::SendFile(const char* nameOfFileToSend, bool isW } } fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false); - if (fileToSend == nullptr) + + // If we failed to open the file, see if we can open a file with the same name and a ".gz" extension + if (fileToSend == nullptr && !StringEndsWith(nameOfFileToSend, ".gz") && strlen(nameOfFileToSend) + 3 <= FILENAME_LENGTH) + { + char nameBuf[FILENAME_LENGTH + 1]; + strcpy(nameBuf, nameOfFileToSend); + strcat(nameBuf, ".gz"); + fileToSend = platform->GetFileStore(platform->GetWebDir(), nameBuf, false); + if (fileToSend != nullptr) + { + zip = true; + } + } + + // If we still couldn't find the file and it was an HTML file, return the 404 error page + if (fileToSend == nullptr && (StringEndsWith(nameOfFileToSend, ".html") || StringEndsWith(nameOfFileToSend, ".htm"))) { nameOfFileToSend = FOUR04_PAGE_FILE; fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false); - if (fileToSend == nullptr) - { - RejectMessage("not found", 404); - return; - } + } + + if (fileToSend == nullptr) + { + RejectMessage("not found", 404); + return; } transaction->SetFileToWrite(fileToSend); } @@ -761,7 +765,6 @@ void Webserver::HttpInterpreter::SendFile(const char* nameOfFileToSend, bool isW } const char* contentType; - bool zip = false; if (StringEndsWith(nameOfFileToSend, ".png")) { contentType = "image/png"; @@ -1541,7 +1544,7 @@ bool Webserver::HttpInterpreter::ProcessMessage() } else { - SendFile(commandWords[1]); + SendFile(commandWords[1], true); } ResetState(); @@ -2175,7 +2178,7 @@ void Webserver::FtpInterpreter::ProcessLine() else if (StringEquals(clientMessage, "PASV")) { /* get local IP address */ - const byte *ip_address = network->IPAddress(); + const uint8_t * const ip_address = network->GetIPAddress(); /* open random port > 1023 */ //rand(); // TRNG doesn't require this diff --git a/src/Duet/Webserver.h b/src/Duet/Webserver.h index 01366e2..d2bab35 100644 --- a/src/Duet/Webserver.h +++ b/src/Duet/Webserver.h @@ -193,7 +193,7 @@ class Webserver const char* value; }; - void SendFile(const char* nameOfFileToSend, bool isWebFile = true); + void SendFile(const char* nameOfFileToSend, bool isWebFile); void SendGCodeReply(); void SendJsonResponse(const char* command); void GetJsonResponse(const char* request, OutputBuffer *&response, const char* key, const char* value, size_t valueLength, bool& keepOpen); diff --git a/src/DuetNG/DuetWiFi/Network.cpp b/src/DuetNG/DuetWiFi/Network.cpp index 7920ed3..3b9c622 100644 --- a/src/DuetNG/DuetWiFi/Network.cpp +++ b/src/DuetNG/DuetWiFi/Network.cpp @@ -736,7 +736,7 @@ bool Network::IsEnabled() const return state != disabled; } -const uint8_t *Network::IPAddress() const +const uint8_t *Network::GetIPAddress() const { return ipAddress; } diff --git a/src/DuetNG/DuetWiFi/Network.h b/src/DuetNG/DuetWiFi/Network.h index 7f4e66f..a4bf375 100644 --- a/src/DuetNG/DuetWiFi/Network.h +++ b/src/DuetNG/DuetWiFi/Network.h @@ -46,7 +46,7 @@ class Network }; public: - const uint8_t *IPAddress() const; + const uint8_t *GetIPAddress() const; void SetIPAddress(const uint8_t ipAddress[], const uint8_t netmask[], const uint8_t gateway[]); Network(Platform* p); diff --git a/src/RADDS/Network.cpp b/src/RADDS/Network.cpp index 901f3b4..13ff772 100644 --- a/src/RADDS/Network.cpp +++ b/src/RADDS/Network.cpp @@ -2,7 +2,7 @@ static const uint8_t dummy_ipv4[4] = { 0, 0, 0, 0 }; -const uint8_t *Network::IPAddress() const +const uint8_t *Network::GetIPAddress() const { return dummy_ipv4; } diff --git a/src/RADDS/Network.h b/src/RADDS/Network.h index 0cc3db5..564702c 100644 --- a/src/RADDS/Network.h +++ b/src/RADDS/Network.h @@ -28,7 +28,7 @@ public: void SetHostname(const char *name) const { }; void SetHttpPort(uint16_t port) const { }; uint16_t GetHttpPort() const { return (uint16_t)0; } - const uint8_t *IPAddress() const; + const uint8_t *GetIPAddress() const; }; #endif