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) {
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