Skip to content

Commit

Permalink
Fxes for networking issue 6 - block disabling of websocket daemon fro…
Browse files Browse the repository at this point in the history
…m WebUI v3 and issue #11 - SSDP fails on Win 11/Android (ESP32 in SoftAP mode).
  • Loading branch information
terjeio committed May 2, 2023
1 parent d3a0416 commit 96f01ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
14 changes: 13 additions & 1 deletion commands_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,20 @@ static status_code_t set_setting (const struct webui_cmd_binding *command, uint_
value = uitoa(tmask);
}

if(ok)
if(ok) {

// Block disable of websocket daemon from WebUI
if(setting->id == Setting_NetworkServices) {
network_services_t services;
services.mask = (uint8_t)atoi(value);
if(!services.websocket) {
services.websocket = On;
value = uitoa(services.mask);
}
}

status = sys_set_setting(id, value);
}
}

if(json) {
Expand Down
26 changes: 14 additions & 12 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ void websocket_on_frame_received (websocket_t *websocket, void *data, size_t siz

static char *websocket_protocol_select (websocket_t *websocket, char *protocols, bool *is_binary)
{
if((is_v3 = strlookup(protocols, "webui-v3", ',') >= 0)) {
network_info_t *network = networking_get_info();

if(network->status.services.http && (is_v3 = strlookup(protocols, "webui-v3", ',') >= 0)) {
*is_binary = true;
client.websocket = websocket;
websocket_set_stream_flags(websocket, (io_stream_state_t){ .connected = true, .webui_connected = true });
Expand Down Expand Up @@ -721,7 +723,7 @@ bool file_search (char *path, const char *uri, vfs_file_t **file, const char *mo
#endif
}

return file != NULL;
return *file != NULL;
}

const char *file_redirect (http_request_t *request, const char *uri, vfs_file_t **file, const char *mode)
Expand Down Expand Up @@ -782,7 +784,7 @@ static void webui_options (bool newopt)
on_report_options(newopt);

if(!newopt)
hal.stream.write("[PLUGIN:WebUI v0.16]" ASCII_EOL);
hal.stream.write("[PLUGIN:WebUI v0.17]" ASCII_EOL);
}

void webui_init (void)
Expand Down Expand Up @@ -826,6 +828,9 @@ void webui_init (void)
#if WEBUI_AUTH_ENABLE
{ .uri = "/login", .method = HTTP_Post, .handler = login_handler_post },
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
#if WIFI_ENABLE && WIFI_SOFTAP
{ .uri = "/wifi", .method = HTTP_Get, .handler = wifi_scan_handler },
{ .uri = "/wifi", .method = HTTP_Post, .handler = wifi_connect_handler },
Expand All @@ -834,9 +839,6 @@ void webui_init (void)
{ .uri = "/wifi", .method = HTTP_Options, .handler = wifi_options_handler },
#endif
{ .uri = "/*", .method = HTTP_Get, .handler = get_handler }, // Must be last!
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
};

Expand All @@ -859,6 +861,9 @@ void webui_init (void)
#if WEBUI_AUTH_ENABLE
{ .uri = "/login", .method = HTTP_Post, .handler = login_handler_post },
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
#if WIFI_ENABLE && WIFI_SOFTAP
{ .uri = "/wifi", .method = HTTP_Get, .handler = wifi_scan_handler },
{ .uri = "/wifi", .method = HTTP_Post, .handler = wifi_connect_handler },
Expand All @@ -867,9 +872,6 @@ void webui_init (void)
{ .uri = "/wifi", .method = HTTP_Options, .handler = wifi_options_handler },
#endif
{ .uri = "/*", .method = HTTP_Get, .handler = get_handler }, // Must be last!
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
};

Expand All @@ -892,6 +894,9 @@ void webui_init (void)
#if WEBUI_AUTH_ENABLE
{ .uri = "/login", .method = HTTP_Post, .handler = login_handler_post },
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
#if WIFI_ENABLE && WIFI_SOFTAP
{ .uri = "/wifi", .method = HTTP_Get, .handler = wifi_scan_handler },
{ .uri = "/wifi", .method = HTTP_Post, .handler = wifi_connect_handler },
Expand All @@ -900,9 +905,6 @@ void webui_init (void)
{ .uri = "/wifi", .method = HTTP_Options, .handler = wifi_options_handler },
#endif
{ .uri = "/*", .method = HTTP_Get, .handler = get_handler }, // Must be last!
#endif
#if SSDP_ENABLE
{ .uri = "/" SSDP_LOCATION_DOC, .method = HTTP_Get, .handler = ssdp_handler_get },
#endif
};

Expand Down

0 comments on commit 96f01ec

Please sign in to comment.