Version 0.78o-dc42

Fix for uploading files that contain UTF-8 continuation characters
This commit is contained in:
David Crocker 2014-08-26 21:48:13 +01:00
parent 405c529b01
commit 3a815ccb7c
4 changed files with 20 additions and 6 deletions

View file

@ -24,7 +24,7 @@ Licence: GPL
#define CONFIGURATION_H #define CONFIGURATION_H
#define NAME "RepRapFirmware" #define NAME "RepRapFirmware"
#define VERSION "0.78n-dc42" #define VERSION "0.78o-dc42"
#define DATE "2014-08-26" #define DATE "2014-08-26"
#define AUTHORS "reprappro, dc42, zpl" #define AUTHORS "reprappro, dc42, zpl"

Binary file not shown.

View file

@ -555,6 +555,7 @@ ProtocolInterpreter::ProtocolInterpreter(Platform *p, Webserver *ws) : platform(
uploadState = notUploading; uploadState = notUploading;
uploadPointer = NULL; uploadPointer = NULL;
uploadLength = 0; uploadLength = 0;
numContinuationBytes = 0;
filenameBeingUploaded[0] = 0; filenameBeingUploaded[0] = 0;
} }
@ -562,6 +563,7 @@ ProtocolInterpreter::ProtocolInterpreter(Platform *p, Webserver *ws) : platform(
bool ProtocolInterpreter::StartUpload(FileStore *file) bool ProtocolInterpreter::StartUpload(FileStore *file)
{ {
CancelUpload(); CancelUpload();
numContinuationBytes = 0;
if (file != NULL) if (file != NULL)
{ {
@ -584,6 +586,17 @@ bool ProtocolInterpreter::StoreUploadData(const char* data, unsigned int len)
{ {
uploadPointer = data; uploadPointer = data;
uploadLength = len; uploadLength = len;
// Count the number of UTF8 continuation bytes. We will need it to adjust the expected file length.
while (len != 0)
{
if ((*data & 0xC0) == 0x80)
{
++numContinuationBytes;
}
++data;
--len;
}
return true; return true;
} }
return false; return false;
@ -628,7 +641,7 @@ void ProtocolInterpreter::CancelUpload()
uploadState = notUploading; uploadState = notUploading;
} }
void ProtocolInterpreter::FinishUpload(const long file_length) void ProtocolInterpreter::FinishUpload(uint32_t file_length)
{ {
// Write the remaining data // Write the remaining data
if (uploadState == uploadOK && uploadLength != 0) if (uploadState == uploadOK && uploadLength != 0)
@ -650,7 +663,7 @@ void ProtocolInterpreter::FinishUpload(const long file_length)
} }
// Check the file length is as expected // Check the file length is as expected
if (uploadState == uploadOK && file_length != 0 && fileBeingUploaded.Length() != file_length) if (uploadState == uploadOK && file_length != 0 && fileBeingUploaded.Length() != file_length + numContinuationBytes)
{ {
uploadState = uploadError; uploadState = uploadError;
platform->Message(HOST_MESSAGE, "Uploaded file size is different!\n"); platform->Message(HOST_MESSAGE, "Uploaded file size is different!\n");
@ -854,7 +867,7 @@ bool Webserver::HttpInterpreter::GetJsonResponse(const char* request, StringRef&
} }
else if (StringEquals(request, "upload_end") && StringEquals(key, "size")) else if (StringEquals(request, "upload_end") && StringEquals(key, "size"))
{ {
long file_length = strtoul(value, NULL, 10); uint32_t file_length = strtoul(value, NULL, 10);
FinishUpload(file_length); FinishUpload(file_length);
GetJsonUploadResponse(response); GetJsonUploadResponse(response);
@ -1683,7 +1696,7 @@ void Webserver::FtpInterpreter::ConnectionLost(uint16_t local_port)
// Do file handling // Do file handling
if (IsUploading()) if (IsUploading())
{ {
FinishUpload(0); FinishUpload(0U);
uploadState = notUploading; uploadState = notUploading;
} }
state = authenticated; state = authenticated;

View file

@ -114,9 +114,10 @@ class ProtocolInterpreter
char filenameBeingUploaded[maxFilenameLength + 1]; char filenameBeingUploaded[maxFilenameLength + 1];
const char *uploadPointer; // pointer to start of uploaded data not yet written to file const char *uploadPointer; // pointer to start of uploaded data not yet written to file
unsigned int uploadLength; // amount of data not yet written to file unsigned int uploadLength; // amount of data not yet written to file
uint32_t numContinuationBytes; // number of UTF-8 continuation bytes we have received
bool StartUpload(FileStore *file); bool StartUpload(FileStore *file);
void FinishUpload(const long file_length); void FinishUpload(uint32_t file_length);
}; };
class Webserver class Webserver