11#ifdef USE_IMPROV_NEXT_URL
14static constexpr const char DEVICE_NAME_PLACEHOLDER[] =
"{{device_name}}";
15static constexpr size_t DEVICE_NAME_PLACEHOLDER_LEN =
sizeof(DEVICE_NAME_PLACEHOLDER) - 1;
16static constexpr const char IP_ADDRESS_PLACEHOLDER[] =
"{{ip_address}}";
17static constexpr size_t IP_ADDRESS_PLACEHOLDER_LEN =
sizeof(IP_ADDRESS_PLACEHOLDER) - 1;
20static char *copy_to_buffer(
char *dest,
const char *
end,
const char *
src) {
24 while (*
src !=
'\0' && dest <
end) {
31 if (this->
next_url_ ==
nullptr || buffer_size == 0) {
32 if (buffer_size > 0) {
39 const char *ip_str =
nullptr;
40 char ip_buffer[network::IP_ADDRESS_BUFFER_SIZE];
51 const char *
end =
buffer + buffer_size - 1;
55 if (strncmp(p, DEVICE_NAME_PLACEHOLDER, DEVICE_NAME_PLACEHOLDER_LEN) == 0) {
56 out = copy_to_buffer(
out,
end, device_name);
57 p += DEVICE_NAME_PLACEHOLDER_LEN;
58 }
else if (ip_str !=
nullptr && strncmp(p, IP_ADDRESS_PLACEHOLDER, IP_ADDRESS_PLACEHOLDER_LEN) == 0) {
60 p += IP_ADDRESS_PLACEHOLDER_LEN;
72 char url_buffer[256] = {};
79 if (
len > max_len || !builder.add_string(url_buffer,
len)) {
80 ESP_LOGW(TAG,
"Next URL too long; skipping");
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
constexpr const char * c_str() const
size_t get_formatted_next_url_(char *buffer, size_t buffer_size)
Format next_url_ into buffer, replacing placeholders. Returns length written.
void add_next_url_(improv::RpcResponseBuilder &builder, size_t max_len)
Append the formatted next_url to the RPC response, warning if it does not fit.
std::vector< uint8_t > & out
ESPHOME_LOG_TAG(TAG, "improv_base")
network::IPAddresses get_ip_addresses()
Application App
Global storage of Application pointer - only one Application can exist.