new release
This commit is contained in:
@@ -13,6 +13,23 @@
|
||||
|
||||
static const char *TAG = "network_api";
|
||||
|
||||
static bool mqtt_host_is_invalid(const char *host)
|
||||
{
|
||||
if (!host || host[0] == '\0')
|
||||
return true;
|
||||
|
||||
if (strcmp(host, "localhost") == 0)
|
||||
return true;
|
||||
|
||||
if (strcmp(host, "127.0.0.1") == 0)
|
||||
return true;
|
||||
|
||||
if (strcmp(host, "0.0.0.0") == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool enabled;
|
||||
@@ -225,10 +242,14 @@ static esp_err_t config_mqtt_post_handler(httpd_req_t *req)
|
||||
if (cJSON_IsNumber(j_periodicity))
|
||||
periodicity = j_periodicity->valueint;
|
||||
|
||||
// --- Regras: se vier NULL ou "" mantém o atual; se atual também estiver vazio, usa default
|
||||
const char *host =
|
||||
(host_in && host_in[0] != '\0') ? host_in : (current_host[0] != '\0') ? current_host
|
||||
: "mqtt.plixin.com";
|
||||
const char *candidate_host =
|
||||
(host_in && host_in[0] != '\0') ? host_in :
|
||||
(current_host[0] != '\0') ? current_host :
|
||||
"mqtt.plixin.com";
|
||||
|
||||
const char *host = mqtt_host_is_invalid(candidate_host)
|
||||
? "mqtt.plixin.com"
|
||||
: candidate_host;
|
||||
|
||||
const char *topic =
|
||||
(topic_in && topic_in[0] != '\0') ? topic_in : (current_topic[0] != '\0') ? current_topic
|
||||
@@ -298,4 +319,4 @@ void register_network_handlers(httpd_handle_t server, void *ctx)
|
||||
.handler = config_mqtt_post_handler,
|
||||
.user_ctx = ctx};
|
||||
httpd_register_uri_handler(server, &config_mqtt_post_uri);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user