diff options
Diffstat (limited to 'src/Duet/Webserver.cpp')
-rw-r--r-- | src/Duet/Webserver.cpp | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/src/Duet/Webserver.cpp b/src/Duet/Webserver.cpp index 1756e324..e35bfc5d 100644 --- a/src/Duet/Webserver.cpp +++ b/src/Duet/Webserver.cpp @@ -127,14 +127,12 @@ void Webserver::Spin() // Check if we can actually send something back to the client if (OutputBuffer::GetBytesLeft(nullptr) == 0) { - platform->ClassReport(longWait); return; } // We must ensure that we have exclusive access to LWIP if (!network->Lock()) { - platform->ClassReport(longWait); return; } @@ -238,7 +236,6 @@ void Webserver::Spin() } network->Unlock(); // unlock LWIP again } - platform->ClassReport(longWait); } void Webserver::Exit() @@ -794,11 +791,9 @@ void Webserver::HttpInterpreter::SendJsonResponse(const char* command) if (StringEquals(command, "configfile")) // rr_configfile [DEPRECATED] { - const char *configPath = platform->GetMassStorage()->CombineName(platform->GetSysDir(), platform->GetConfigFile()); - char fileName[MaxFilenameLength]; - SafeStrncpy(fileName, configPath, MaxFilenameLength); - - SendFile(fileName, false); + String<MaxFilenameLength> fileName; + MassStorage::CombineName(fileName.GetRef(), platform->GetSysDir(), platform->GetConfigFile()); + SendFile(fileName.c_str(), false); return; } @@ -939,7 +934,7 @@ void Webserver::HttpInterpreter::GetJsonResponse(const char* request, OutputBuff } else if (StringEquals(request, "gcode") && GetKeyValue("gcode") != nullptr) { - RegularGCodeInput * const httpInput = reprap.GetGCodes().GetHTTPInput(); + NetworkGCodeInput * const httpInput = reprap.GetGCodes().GetHTTPInput(); httpInput->Put(HttpMessage, GetKeyValue("gcode")); response->printf("{\"buff\":%u}", httpInput->BufferSpaceLeft()); } @@ -1721,7 +1716,7 @@ void Webserver::HttpInterpreter::ProcessDeferredRequest() // At the moment only file info requests are deferred. // Parsing the file may take a while, so keep LwIP running while we're waiting network->Unlock(); - bool gotFileInfo = reprap.GetPrintMonitor().GetFileInfoResponse(filenameBeingProcessed, jsonResponse); + bool gotFileInfo = reprap.GetFileInfoResponse(filenameBeingProcessed, jsonResponse, false); while (!network->Lock()); // Because LwIP was unlocked before, there is a chance that the ConnectionLost() call has already @@ -1993,7 +1988,7 @@ void Webserver::FtpInterpreter::ProcessLine() else if (StringStartsWith(clientMessage, "CWD")) { ReadFilename(3); - ChangeDirectory(filename); + ChangeDirectory(filename.c_str()); } // change to parent of current directory else if (StringEquals(clientMessage, "CDUP")) @@ -2048,7 +2043,7 @@ void Webserver::FtpInterpreter::ProcessLine() else if (StringStartsWith(clientMessage, "DELE")) { ReadFilename(4); - if (platform->GetMassStorage()->Delete(currentDir, filename)) + if (platform->GetMassStorage()->Delete(currentDir, filename.c_str())) { SendReply(250, "Delete operation successful."); } @@ -2061,7 +2056,7 @@ void Webserver::FtpInterpreter::ProcessLine() else if (StringStartsWith(clientMessage, "RMD")) { ReadFilename(3); - if (platform->GetMassStorage()->Delete(currentDir, filename)) + if (platform->GetMassStorage()->Delete(currentDir, filename.c_str())) { SendReply(250, "Remove directory operation successful."); } @@ -2074,11 +2069,17 @@ void Webserver::FtpInterpreter::ProcessLine() else if (StringStartsWith(clientMessage, "MKD")) { ReadFilename(3); - const char *location = (filename[0] == '/') - ? filename - : platform->GetMassStorage()->CombineName(currentDir, filename); + String<MaxFilenameLength> location; + if (filename[0] == '/') + { + location.copy(filename.c_str()); + } + else + { + MassStorage::CombineName(location.GetRef(), currentDir, filename.c_str()); + } - if (platform->GetMassStorage()->MakeDirectory(location)) + if (platform->GetMassStorage()->MakeDirectory(location.c_str())) { NetworkTransaction *transaction = webserver->currentTransaction; transaction->Printf("257 \"%s\" created\r\n", location); @@ -2095,12 +2096,12 @@ void Webserver::FtpInterpreter::ProcessLine() ReadFilename(4); if (filename[0] != '/') { - const char *temp = platform->GetMassStorage()->CombineName(currentDir, filename); - SafeStrncpy(filename, temp, MaxFilenameLength); - filename[MaxFilenameLength - 1] = 0; + String<MaxFilenameLength> temp; + MassStorage::CombineName(temp.GetRef(), currentDir, filename.c_str()); + filename.copy(temp.c_str()); } - if (platform->GetMassStorage()->FileExists(filename)) + if (platform->GetMassStorage()->FileExists(filename.c_str())) { SendReply(350, "Ready to RNTO."); } @@ -2112,13 +2113,13 @@ void Webserver::FtpInterpreter::ProcessLine() else if (StringStartsWith(clientMessage, "RNTO")) { // Copy origin path to temp oldFilename and read new path - char oldFilename[MaxFilenameLength]; - SafeStrncpy(oldFilename, filename, MaxFilenameLength); - oldFilename[MaxFilenameLength - 1] = 0; + String<MaxFilenameLength> oldFilename; + oldFilename.copy(filename.c_str()); ReadFilename(4); - const char *newFilename = platform->GetMassStorage()->CombineName(currentDir, filename); - if (platform->GetMassStorage()->Rename(oldFilename, newFilename)) + String<MaxFilenameLength> newFilename; + MassStorage::CombineName(newFilename.GetRef(), currentDir, filename.c_str()); + if (platform->GetMassStorage()->Rename(oldFilename.c_str(), newFilename.c_str())) { SendReply(250, "Rename successful."); } @@ -2223,8 +2224,8 @@ void Webserver::FtpInterpreter::ProcessLine() { ReadFilename(4); - FileStore *file = platform->OpenFile(currentDir, filename, OpenMode::write); - if (StartUpload(file, filename)) + FileStore *file = platform->OpenFile(currentDir, filename.c_str(), OpenMode::write); + if (StartUpload(file, filename.c_str())) { SendReply(150, "OK to send data."); state = doingPasvIO; @@ -2241,7 +2242,7 @@ void Webserver::FtpInterpreter::ProcessLine() { ReadFilename(4); - FileStore *file = platform->OpenFile(currentDir, filename, OpenMode::read); + FileStore *file = platform->OpenFile(currentDir, filename.c_str(), OpenMode::read); if (file == nullptr) { SendReply(550, "Failed to open file."); @@ -2642,7 +2643,7 @@ bool Webserver::TelnetInterpreter::ProcessLine() } // All other codes are stored for the GCodes class - RegularGCodeInput * const telnetInput = reprap.GetGCodes().GetTelnetInput(); + NetworkGCodeInput * const telnetInput = reprap.GetGCodes().GetTelnetInput(); telnetInput->Put(TelnetMessage, clientMessage); break; } |