Skip to content

Commit

Permalink
fail UFSServe if Webserver is null. (#21467)
Browse files Browse the repository at this point in the history
  • Loading branch information
btsimonh committed May 22, 2024
1 parent a14aad9 commit 522f6c5
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -950,34 +950,32 @@ public:
};

void UFSServe(void) {
bool result = false;
if (XdrvMailbox.data_len > 0) {
bool result = false;
char *fpath = strtok(XdrvMailbox.data, ",");
char *url = strtok(nullptr, ",");
char *noauth = strtok(nullptr, ",");
if (fpath && url) {
char t[] = "";
StaticRequestHandlerAuth *staticHandler;
if (noauth && *noauth == '1'){
staticHandler = (StaticRequestHandlerAuth *) new StaticRequestHandler(*ffsp, fpath, url, (char *)nullptr);
} else {
staticHandler = new StaticRequestHandlerAuth(*ffsp, fpath, url, (char *)nullptr);
}
if (staticHandler) {
//Webserver->serveStatic(url, *ffsp, fpath);
Webserver->addHandler(staticHandler);
Webserver->enableCORS(true);
result = true;
} else {
// could this happen? only lack of memory.
result = false;
if (Webserver) { // fail if no Webserver yet.
StaticRequestHandlerAuth *staticHandler;
if (noauth && *noauth == '1'){
staticHandler = (StaticRequestHandlerAuth *) new StaticRequestHandler(*ffsp, fpath, url, (char *)nullptr);
} else {
staticHandler = new StaticRequestHandlerAuth(*ffsp, fpath, url, (char *)nullptr);
}
if (staticHandler) {
//Webserver->serveStatic(url, *ffsp, fpath);
Webserver->addHandler(staticHandler);
Webserver->enableCORS(true);
result = true;
}
}
}
if (!result) {
ResponseCmndFailed();
} else {
ResponseCmndDone();
}
}
if (!result) {
ResponseCmndFailed();
} else {
ResponseCmndDone();
}
}
#endif // UFILESYS_STATIC_SERVING
Expand Down

0 comments on commit 522f6c5

Please sign in to comment.