fail UFSServe if Webserver is null. (#21467)

This commit is contained in:
btsimonh 2024-05-22 15:26:26 +01:00 committed by GitHub
parent a14aad93cb
commit 522f6c5e00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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