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.
This commit is contained in:
parent
d9c5f2eaa2
commit
024fbd0cf2
1 changed files with 20 additions and 17 deletions
|
@ -1841,8 +1841,11 @@ static void server_task(void *pvParameters)
|
||||||
value = skip_whitespace(value);
|
value = skip_whitespace(value);
|
||||||
switch (header) {
|
switch (header) {
|
||||||
case HTTP_HEADER_HOST:
|
case HTTP_HEADER_HOST:
|
||||||
if (hostname_local && host_is_name(value) &&
|
if (!host_is_name(value)) {
|
||||||
strcmp(value, hostname_local)) {
|
break;
|
||||||
|
}
|
||||||
|
if (!hostname_local ||
|
||||||
|
(hostname_local && strcmp(value, hostname_local))) {
|
||||||
host_redirect = true;
|
host_redirect = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2006,6 +2009,21 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Default a hostname. */
|
||||||
|
char *hostname = NULL;
|
||||||
|
sysparam_get_string("hostname", &hostname);
|
||||||
|
if (!hostname && wificfg_default_hostname) {
|
||||||
|
uint8_t macaddr[6];
|
||||||
|
char name[32];
|
||||||
|
sdk_wifi_get_macaddr(1, macaddr);
|
||||||
|
snprintf(name, sizeof(name), wificfg_default_hostname, macaddr[3],
|
||||||
|
macaddr[4], macaddr[5]);
|
||||||
|
sysparam_set_string("hostname", name);
|
||||||
|
}
|
||||||
|
if (hostname) {
|
||||||
|
free(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
sysparam_get_string("wifi_ap_ssid", &wifi_ap_ssid);
|
sysparam_get_string("wifi_ap_ssid", &wifi_ap_ssid);
|
||||||
sysparam_get_string("wifi_ap_password", &wifi_ap_password);
|
sysparam_get_string("wifi_ap_password", &wifi_ap_password);
|
||||||
sysparam_get_string("wifi_sta_ssid", &wifi_sta_ssid);
|
sysparam_get_string("wifi_sta_ssid", &wifi_sta_ssid);
|
||||||
|
@ -2077,21 +2095,6 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
|
||||||
sdk_wifi_set_opmode(wifi_mode);
|
sdk_wifi_set_opmode(wifi_mode);
|
||||||
|
|
||||||
if (wifi_sta_enable) {
|
if (wifi_sta_enable) {
|
||||||
/* Default a hostname. */
|
|
||||||
char *hostname = NULL;
|
|
||||||
sysparam_get_string("hostname", &hostname);
|
|
||||||
if (!hostname && wificfg_default_hostname) {
|
|
||||||
uint8_t macaddr[6];
|
|
||||||
char name[32];
|
|
||||||
sdk_wifi_get_macaddr(1, macaddr);
|
|
||||||
snprintf(name, sizeof(name), wificfg_default_hostname, macaddr[3],
|
|
||||||
macaddr[4], macaddr[5]);
|
|
||||||
sysparam_set_string("hostname", name);
|
|
||||||
}
|
|
||||||
if (hostname) {
|
|
||||||
free(hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sdk_station_config config;
|
struct sdk_station_config config;
|
||||||
strcpy((char *)config.ssid, wifi_sta_ssid);
|
strcpy((char *)config.ssid, wifi_sta_ssid);
|
||||||
strcpy((char *)config.password, wifi_sta_password);
|
strcpy((char *)config.password, wifi_sta_password);
|
||||||
|
|
Loading…
Reference in a new issue