Skip to content

Commit 024fbd0

Browse files
committed
wificfg: default the hostname in all modes.
A hostname is also useful in AP mode, so also default it in AP mode - it was previously only defaulted in station mode. Correct the host redirection logic, to work when no hostname is defined.
1 parent d9c5f2e commit 024fbd0

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

extras/wificfg/wificfg.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,8 +1841,11 @@ static void server_task(void *pvParameters)
18411841
value = skip_whitespace(value);
18421842
switch (header) {
18431843
case HTTP_HEADER_HOST:
1844-
if (hostname_local && host_is_name(value) &&
1845-
strcmp(value, hostname_local)) {
1844+
if (!host_is_name(value)) {
1845+
break;
1846+
}
1847+
if (!hostname_local ||
1848+
(hostname_local && strcmp(value, hostname_local))) {
18461849
host_redirect = true;
18471850
}
18481851
break;
@@ -2006,6 +2009,21 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
20062009
return;
20072010
}
20082011

2012+
/* Default a hostname. */
2013+
char *hostname = NULL;
2014+
sysparam_get_string("hostname", &hostname);
2015+
if (!hostname && wificfg_default_hostname) {
2016+
uint8_t macaddr[6];
2017+
char name[32];
2018+
sdk_wifi_get_macaddr(1, macaddr);
2019+
snprintf(name, sizeof(name), wificfg_default_hostname, macaddr[3],
2020+
macaddr[4], macaddr[5]);
2021+
sysparam_set_string("hostname", name);
2022+
}
2023+
if (hostname) {
2024+
free(hostname);
2025+
}
2026+
20092027
sysparam_get_string("wifi_ap_ssid", &wifi_ap_ssid);
20102028
sysparam_get_string("wifi_ap_password", &wifi_ap_password);
20112029
sysparam_get_string("wifi_sta_ssid", &wifi_sta_ssid);
@@ -2077,21 +2095,6 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
20772095
sdk_wifi_set_opmode(wifi_mode);
20782096

20792097
if (wifi_sta_enable) {
2080-
/* Default a hostname. */
2081-
char *hostname = NULL;
2082-
sysparam_get_string("hostname", &hostname);
2083-
if (!hostname && wificfg_default_hostname) {
2084-
uint8_t macaddr[6];
2085-
char name[32];
2086-
sdk_wifi_get_macaddr(1, macaddr);
2087-
snprintf(name, sizeof(name), wificfg_default_hostname, macaddr[3],
2088-
macaddr[4], macaddr[5]);
2089-
sysparam_set_string("hostname", name);
2090-
}
2091-
if (hostname) {
2092-
free(hostname);
2093-
}
2094-
20952098
struct sdk_station_config config;
20962099
strcpy((char *)config.ssid, wifi_sta_ssid);
20972100
strcpy((char *)config.password, wifi_sta_password);

0 commit comments

Comments
 (0)