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
This commit is contained in:
David Crocker 2016-12-18 15:46:03 +00:00
parent da3d67403f
commit 90c4e1a53a
9 changed files with 36 additions and 33 deletions

View file

@ -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"

View file

@ -471,7 +471,7 @@ void Network::Spin()
{
if (!ethernetStarted)
{
start_ethernet(platform->IPAddress(), platform->NetMask(), platform->GateWay(), &ethernet_status_callback);
start_ethernet(platform->GetIPAddress(), platform->NetMask(), platform->GateWay(), &ethernet_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();
}

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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