mirror of
https://github.com/esphome/esphome.git
synced 2025-10-18 01:33:51 +01:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -193,7 +193,7 @@ void MDNSComponent::dump_config() {
|
||||
ESP_LOGV(TAG, " - %s, %s, %d", service.service_type.c_str(), service.proto.c_str(),
|
||||
const_cast<TemplatableValue<uint16_t> &>(service.port).value());
|
||||
for (const auto &record : service.txt_records) {
|
||||
ESP_LOGV(TAG, " TXT: %s = %s", record.key.c_str(),
|
||||
ESP_LOGV(TAG, " TXT: %s = %s", record.key,
|
||||
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ namespace mdns {
|
||||
// MDNS_SERVICE_COUNT will always be defined
|
||||
|
||||
struct MDNSTXTRecord {
|
||||
std::string key;
|
||||
const char *key;
|
||||
TemplatableValue<std::string> value;
|
||||
};
|
||||
|
||||
|
@@ -26,16 +26,24 @@ void MDNSComponent::setup() {
|
||||
mdns_instance_name_set(this->hostname_.c_str());
|
||||
|
||||
for (const auto &service : this->services_) {
|
||||
std::vector<mdns_txt_item_t> txt_records(service.txt_records.size());
|
||||
for (size_t i = 0; i < service.txt_records.size(); i++) {
|
||||
// mdns_service_add copies the strings internally, no need to strdup
|
||||
txt_records[i].key = service.txt_records[i].key.c_str();
|
||||
txt_records[i].value = const_cast<TemplatableValue<std::string> &>(service.txt_records[i].value).value().c_str();
|
||||
std::vector<mdns_txt_item_t> txt_records;
|
||||
for (const auto &record : service.txt_records) {
|
||||
mdns_txt_item_t it{};
|
||||
// key is a compile-time string literal in flash, no need to strdup
|
||||
it.key = record.key;
|
||||
// value is a temporary from TemplatableValue, must strdup to keep it alive
|
||||
it.value = strdup(const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
|
||||
txt_records.push_back(it);
|
||||
}
|
||||
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
|
||||
err = mdns_service_add(nullptr, service.service_type.c_str(), service.proto.c_str(), port, txt_records.data(),
|
||||
txt_records.size());
|
||||
|
||||
// free records
|
||||
for (const auto &it : txt_records) {
|
||||
free((void *) it.value); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-pro-type-cstyle-cast)
|
||||
}
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Failed to register service %s: %s", service.service_type.c_str(), esp_err_to_name(err));
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ void MDNSComponent::setup() {
|
||||
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
|
||||
MDNS.addService(service_type, proto, port);
|
||||
for (const auto &record : service.txt_records) {
|
||||
MDNS.addServiceTxt(service_type, proto, record.key.c_str(),
|
||||
MDNS.addServiceTxt(service_type, proto, record.key,
|
||||
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ void MDNSComponent::setup() {
|
||||
uint16_t port_ = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
|
||||
MDNS.addService(service_type, proto, port_);
|
||||
for (const auto &record : service.txt_records) {
|
||||
MDNS.addServiceTxt(service_type, proto, record.key.c_str(),
|
||||
MDNS.addServiceTxt(service_type, proto, record.key,
|
||||
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ void MDNSComponent::setup() {
|
||||
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
|
||||
MDNS.addService(service_type, proto, port);
|
||||
for (const auto &record : service.txt_records) {
|
||||
MDNS.addServiceTxt(service_type, proto, record.key.c_str(),
|
||||
MDNS.addServiceTxt(service_type, proto, record.key,
|
||||
const_cast<TemplatableValue<std::string> &>(record.value).value().c_str());
|
||||
}
|
||||
}
|
||||
|
@@ -181,7 +181,7 @@ void OpenThreadSrpComponent::setup() {
|
||||
for (size_t i = 0; i < service.txt_records.size(); i++) {
|
||||
const auto &txt = service.txt_records[i];
|
||||
auto value = const_cast<TemplatableValue<std::string> &>(txt.value).value();
|
||||
txt_entries[i].mKey = strdup(txt.key.c_str());
|
||||
txt_entries[i].mKey = txt.key; // Compile-time string literal in flash
|
||||
txt_entries[i].mValue = reinterpret_cast<const uint8_t *>(strdup(value.c_str()));
|
||||
txt_entries[i].mValueLength = value.size();
|
||||
}
|
||||
|
Reference in New Issue
Block a user