mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-03 00:21:44 +01:00
esp_local_ctrl: Add support for insecure HTTP server transport
This commit is contained in:
@@ -19,7 +19,19 @@
|
||||
#include <esp_netif.h>
|
||||
#include <protocomm_httpd.h>
|
||||
#include <esp_local_ctrl.h>
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
#include <esp_https_server.h>
|
||||
#else
|
||||
#include <esp_http_server.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
#define esp_local_ctrl_httpd_start httpd_ssl_start
|
||||
#define esp_local_ctrl_httpd_stop httpd_ssl_stop
|
||||
#else
|
||||
#define esp_local_ctrl_httpd_start httpd_start
|
||||
#define esp_local_ctrl_httpd_stop httpd_stop
|
||||
#endif
|
||||
|
||||
#include "esp_local_ctrl_priv.h"
|
||||
|
||||
@@ -38,12 +50,17 @@ static esp_err_t start_httpd_transport(protocomm_t *pc, const esp_local_ctrl_tra
|
||||
|
||||
esp_err_t err;
|
||||
#ifdef WITH_MDNS
|
||||
uint16_t port = 0;
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
/* Extract configured port */
|
||||
uint16_t port = (
|
||||
port = (
|
||||
config->httpd->transport_mode == HTTPD_SSL_TRANSPORT_SECURE ?
|
||||
config->httpd->port_secure :
|
||||
config->httpd->port_insecure
|
||||
);
|
||||
#else
|
||||
port = config->httpd->server_port;
|
||||
#endif
|
||||
err = mdns_service_add("Local Control Service", "_esp_local_ctrl",
|
||||
"_tcp", port, NULL, 0);
|
||||
if (err != ESP_OK) {
|
||||
@@ -64,9 +81,9 @@ static esp_err_t start_httpd_transport(protocomm_t *pc, const esp_local_ctrl_tra
|
||||
}
|
||||
}
|
||||
#endif
|
||||
err = httpd_ssl_start(&server_handle, config->httpd);
|
||||
err = esp_local_ctrl_httpd_start(&server_handle, config->httpd);
|
||||
if (ESP_OK != err) {
|
||||
ESP_LOGE(TAG, "Error starting HTTPS service!");
|
||||
ESP_LOGE(TAG, "Error starting HTTP/S service!");
|
||||
#ifdef WITH_MDNS
|
||||
mdns_service_remove("_esp_local_ctrl", "_tcp");
|
||||
#endif
|
||||
@@ -89,7 +106,7 @@ static void stop_httpd_transport(protocomm_t *pc)
|
||||
mdns_service_remove("_esp_local_ctrl", "_tcp");
|
||||
#endif
|
||||
protocomm_httpd_stop(pc);
|
||||
if (httpd_ssl_stop(server_handle) == ESP_OK) {
|
||||
if (esp_local_ctrl_httpd_stop(server_handle) == ESP_OK) {
|
||||
server_handle = NULL;
|
||||
}
|
||||
}
|
||||
@@ -101,14 +118,15 @@ static esp_err_t copy_httpd_config(esp_local_ctrl_transport_config_t *dest_confi
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
dest_config->httpd = calloc(1, sizeof(httpd_ssl_config_t));
|
||||
dest_config->httpd = calloc(1, sizeof(esp_local_ctrl_transport_config_httpd_t));
|
||||
if (!dest_config->httpd) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for HTTPD transport config");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
memcpy(dest_config->httpd,
|
||||
src_config->httpd,
|
||||
sizeof(httpd_ssl_config_t));
|
||||
sizeof(esp_local_ctrl_transport_config_httpd_t));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user