diff --git a/code/components/jomjol_fileserver_ota/server_file.cpp b/code/components/jomjol_fileserver_ota/server_file.cpp index ff2240c6..974df682 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -639,10 +639,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req) int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path); ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found); directory = directory.substr(start_fn, found - start_fn + 1); - ESP_LOGD(TAG, "Directory danach 1: %s", directory.c_str()); - directory = "/fileserver" + directory; - ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str()); +// ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str()); /* Redirect onto root to see the updated file list */ httpd_resp_set_status(req, "303 See Other"); @@ -761,8 +759,6 @@ static esp_err_t delete_post_handler(httpd_req_t *req) int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path); ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found); directory = directory.substr(start_fn, found - start_fn + 1); - ESP_LOGD(TAG, "Directory danach 3: %s", directory.c_str()); - directory = "/fileserver" + directory; ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str()); } @@ -820,9 +816,9 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION); ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str()); - ESP_LOGD(TAG, "Target Dir ZIP: %s", _target_zip.c_str()); - ESP_LOGD(TAG, "Target Dir BIN: %s", _target_bin.c_str()); - ESP_LOGD(TAG, "Target Dir main: %s", _main.c_str()); +// ESP_LOGD(TAG, "Target Dir ZIP: %s", _target_zip.c_str()); +// ESP_LOGD(TAG, "Target Dir BIN: %s", _target_bin.c_str()); +// ESP_LOGD(TAG, "Target Dir main: %s", _main.c_str()); // Now try to open the archive. memset(&zip_archive, 0, sizeof(zip_archive)); @@ -892,17 +888,32 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st // extrahieren in zwischendatei DeleteFile(filename_zw); FILE* fpTargetFile = OpenFileAndWait(filename_zw.c_str(), "wb"); - fwrite(p, 1, (uint)uncomp_size, fpTargetFile); + uint writtenbytes = fwrite(p, 1, (uint)uncomp_size, fpTargetFile); fclose(fpTargetFile); + + bool isokay = true; - DeleteFile(zw); - RenameFile(filename_zw, zw); - DeleteFile(filename_zw); + if (writtenbytes == (uint)uncomp_size) + { + isokay = true; + } + else + { + isokay = false; + ESP_LOGE(TAG, "ERROR in writting extracted file (function fwrite) extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size); + } - ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size); - // ESP_LOGD(TAG, "File data: \"%s\"", (const char*)p); - // We're done. + isokay = isokay && RenameFile(filename_zw, zw); + isokay = isokay && DeleteFile(filename_zw); + + if (isokay) + ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size); + else + { + ESP_LOGE(TAG, "ERROR in extracting file \"%s\", size %u", archive_filename, (uint)uncomp_size); + ret = "ERROR"; + } mz_free(p); } } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 44ad50b0..03a14757 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -165,32 +165,20 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size) -FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec) +FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec, bool silent) { FILE *pfile; ESP_LOGD(TAG, "open file %s in mode %s", nm, _mode); if ((pfile = fopen(nm, _mode)) != NULL) { - ESP_LOGD(TAG, "File %s successfully opened", nm); + if (!silent) ESP_LOGD(TAG, "File %s successfully opened", nm); } else { - ESP_LOGD(TAG, "Error: file %s does not exist!", nm); + if (!silent) ESP_LOGD(TAG, "Error: file %s does not exist!", nm); return NULL; } -/* - if (pfile == NULL) - { - TickType_t xDelay; - xDelay = _waitsec * 1000 / portTICK_PERIOD_MS; - std::string zw = "File is locked: " + std::string(nm) + " - wait for " + std::to_string(_waitsec) + " seconds"; - LogFile.WriteToFile(ESP_LOG_INFO, zw); - vTaskDelay( xDelay ); - pfile = fopen(nm, _mode); - } -*/ - return pfile; } @@ -231,11 +219,15 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri } } -void MakeDir(std::string _what) +bool MakeDir(std::string _what) { -int mk_ret = mkdir(_what.c_str(), 0775); -if (mk_ret) - ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret); + int mk_ret = mkdir(_what.c_str(), 0775); + if (mk_ret) + { + ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret); + return false; + } + return true; } @@ -302,7 +294,7 @@ size_t findDelimiterPos(string input, string delimiter) } -void RenameFile(string from, string to) +bool RenameFile(string from, string to) { // ESP_LOGI(logTag, "Deleting file : %s", fn.c_str()); /* Delete file */ @@ -310,15 +302,16 @@ void RenameFile(string from, string to) if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! { ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", from.c_str()); - return; + return false; } fclose(fpSourceFile); rename(from.c_str(), to.c_str()); + return true; } -void DeleteFile(string fn) +bool DeleteFile(string fn) { // ESP_LOGI(logTag, "Deleting file : %s", fn.c_str()); /* Delete file */ @@ -326,15 +319,16 @@ void DeleteFile(string fn) if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! { ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str()); - return; + return false; } fclose(fpSourceFile); - unlink(fn.c_str()); + unlink(fn.c_str()); + return true; } -void CopyFile(string input, string output) +bool CopyFile(string input, string output) { input = FormatFileName(input); output = FormatFileName(output); @@ -342,7 +336,7 @@ void CopyFile(string input, string output) if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0) { ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!"); - return; + return false; } char cTemp; @@ -350,7 +344,7 @@ void CopyFile(string input, string output) if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! { ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str()); - return; + return false; } FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb"); @@ -368,6 +362,7 @@ void CopyFile(string input, string output) fclose(fpSourceFile); fclose(fpTargetFile); ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str()); + return true; } string getFileFullFileName(string filename) diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index aeb5054f..32d7d448 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -9,16 +9,16 @@ using namespace std; std::string FormatFileName(std::string input); void FindReplace(std::string& line, std::string& oldString, std::string& newString); -void CopyFile(string input, string output); -void DeleteFile(string fn); -void RenameFile(string from, string to); -void MakeDir(std::string _what); +bool CopyFile(string input, string output); +bool DeleteFile(string fn); +bool RenameFile(string from, string to); +bool MakeDir(std::string _what); string RundeOutput(double _in, int _anzNachkomma); -FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1); +FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1, bool silent = true); size_t findDelimiterPos(string input, string delimiter); //string trim(string istring); diff --git a/code/main/main.cpp b/code/main/main.cpp index 5f1da209..adff6cb0 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -195,7 +195,7 @@ extern "C" void app_main(void) ESP_LOGD(TAGMAIN, "No SSID and PASSWORD set!!!"); if (hostname != NULL) - ESP_LOGD(TAGMAIN, "Hostename: %s", hostname); + ESP_LOGD(TAGMAIN, "Hostname: %s", hostname); else ESP_LOGD(TAGMAIN, "Hostname not set"); diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 719bdd7a..8f1672d2 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -450,7 +450,7 @@ httpd_handle_t start_webserver(void) config.server_port = 80; config.ctrl_port = 32768; config.max_open_sockets = 5; //20210921 --> vorher 7 - config.max_uri_handlers = 30; // vorher 24 + config.max_uri_handlers = 35; // vorher 24, 20220511: 35 config.max_resp_headers = 8; config.backlog_conn = 5; config.lru_purge_enable = true; // dadurch werden alte Verbindungen gekappt, falls neue benögt werden.