Skip to content

Commit 3e5946a

Browse files
committed
fix(mdns): Rename and cleanup
1 parent 28128a8 commit 3e5946a

17 files changed

+603
-470
lines changed

components/mdns/mdns.c

Lines changed: 50 additions & 56 deletions
Large diffs are not rendered by default.

components/mdns/mdns_browser.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mdns_debug.h"
1212
#include "mdns_utils.h"
1313
#include "mdns_querier.h"
14+
#include "mdns_netif.h"
1415
#include "esp_log.h"
1516

1617
static const char *TAG = "mdns_browser";
@@ -33,7 +34,7 @@ static esp_err_t _mdns_send_browse_action(mdns_action_type_t type, mdns_browse_t
3334

3435
action->type = type;
3536
action->data.browse_add.browse = browse;
36-
if (!mdns_action_queue(action)) {
37+
if (!mdns_priv_queue_action(action)) {
3738
mdns_mem_free(action);
3839
return ESP_ERR_NO_MEM;
3940
}
@@ -170,7 +171,7 @@ mdns_browse_t *mdns_browse_new(const char *service, const char *proto, mdns_brow
170171
{
171172
mdns_browse_t *browse = NULL;
172173

173-
if (is_mdns_server() || mdns_utils_str_null_or_empty(service) || mdns_utils_str_null_or_empty(proto)) {
174+
if (mdns_priv_is_server_init() || mdns_utils_str_null_or_empty(service) || mdns_utils_str_null_or_empty(proto)) {
174175
return NULL;
175176
}
176177

@@ -191,7 +192,7 @@ esp_err_t mdns_browse_delete(const char *service, const char *proto)
191192
{
192193
mdns_browse_t *browse = NULL;
193194

194-
if (!is_mdns_server() || mdns_utils_str_null_or_empty(service) || mdns_utils_str_null_or_empty(proto)) {
195+
if (!mdns_priv_is_server_init() || mdns_utils_str_null_or_empty(service) || mdns_utils_str_null_or_empty(proto)) {
195196
return ESP_FAIL;
196197
}
197198

@@ -258,7 +259,7 @@ mdns_browse_t *_mdns_browse_find(mdns_name_t *name, uint16_t type, mdns_if_t tcp
258259
} else if (type == MDNS_TYPE_A || type == MDNS_TYPE_AAAA) {
259260
r = b->result;
260261
while (r) {
261-
if (r->esp_netif == _mdns_get_esp_netif(tcpip_if) && r->ip_protocol == ip_protocol && !mdns_utils_str_null_or_empty(r->hostname) && !strcasecmp(name->host, r->hostname)) {
262+
if (r->esp_netif == mdns_netif_get_esp_netif(tcpip_if) && r->ip_protocol == ip_protocol && !mdns_utils_str_null_or_empty(r->hostname) && !strcasecmp(name->host, r->hostname)) {
262263
return b;
263264
}
264265
r = r->next;
@@ -366,7 +367,7 @@ void mdns_browse_result_add_ip(mdns_browse_t *browse, const char *hostname, esp_
366367
while (r) {
367368
if (r->ip_protocol == ip_protocol) {
368369
// Find the target result in browse result.
369-
if (r->esp_netif == _mdns_get_esp_netif(tcpip_if) && !mdns_utils_str_null_or_empty(r->hostname) && !strcasecmp(hostname, r->hostname)) {
370+
if (r->esp_netif == mdns_netif_get_esp_netif(tcpip_if) && !mdns_utils_str_null_or_empty(r->hostname) && !strcasecmp(hostname, r->hostname)) {
370371
r_a = r->addr;
371372
// Check if the address has already added in result.
372373
while (r_a) {
@@ -385,7 +386,7 @@ void mdns_browse_result_add_ip(mdns_browse_t *browse, const char *hostname, esp_
385386
if (!r_a) {
386387
// The current IP is a new one, add it to the link list.
387388
mdns_ip_addr_t *a = NULL;
388-
a = _mdns_result_addr_create_ip(ip);
389+
a = mdns_priv_result_addr_create_ip(ip);
389390
if (!a) {
390391
return;
391392
}
@@ -395,7 +396,7 @@ void mdns_browse_result_add_ip(mdns_browse_t *browse, const char *hostname, esp_
395396
if (r->ttl == 0) {
396397
r->ttl = ttl;
397398
} else {
398-
_mdns_result_update_ttl(r, ttl);
399+
mdns_priv_query_update_result_ttl(r, ttl);
399400
}
400401
}
401402
if (_mdns_add_browse_result(out_sync_browse, r) != ESP_OK) {
@@ -441,7 +442,7 @@ void mdns_browse_result_add_txt(mdns_browse_t *browse, const char *instance, con
441442
}
442443
mdns_result_t *r = browse->result;
443444
while (r) {
444-
if (r->esp_netif == _mdns_get_esp_netif(tcpip_if) && r->ip_protocol == ip_protocol &&
445+
if (r->esp_netif == mdns_netif_get_esp_netif(tcpip_if) && r->ip_protocol == ip_protocol &&
445446
!mdns_utils_str_null_or_empty(r->instance_name) && !strcasecmp(instance, r->instance_name) &&
446447
!mdns_utils_str_null_or_empty(r->service_type) && !strcasecmp(service, r->service_type) &&
447448
!mdns_utils_str_null_or_empty(r->proto) && !strcasecmp(proto, r->proto)) {
@@ -474,7 +475,7 @@ void mdns_browse_result_add_txt(mdns_browse_t *browse, const char *instance, con
474475
if (r->ttl == 0) {
475476
r->ttl = ttl;
476477
} else {
477-
_mdns_result_update_ttl(r, ttl);
478+
mdns_priv_query_update_result_ttl(r, ttl);
478479
}
479480
if (previous_ttl != r->ttl) {
480481
should_update = true;
@@ -508,7 +509,7 @@ void mdns_browse_result_add_txt(mdns_browse_t *browse, const char *instance, con
508509
r->txt = txt;
509510
r->txt_value_len = txt_value_len;
510511
r->txt_count = txt_count;
511-
r->esp_netif = _mdns_get_esp_netif(tcpip_if);
512+
r->esp_netif = mdns_netif_get_esp_netif(tcpip_if);
512513
r->ip_protocol = ip_protocol;
513514
r->ttl = ttl;
514515
r->next = browse->result;
@@ -532,7 +533,7 @@ static esp_err_t _mdns_copy_address_in_previous_result(mdns_result_t *result_lis
532533
if (!mdns_utils_str_null_or_empty(result_list->hostname) && !mdns_utils_str_null_or_empty(r->hostname) && !strcasecmp(result_list->hostname, r->hostname) &&
533534
result_list->ip_protocol == r->ip_protocol && result_list->addr && !r->addr) {
534535
// If there is a same hostname in previous result, we need to copy the address here.
535-
r->addr = copy_address_list(result_list->addr);
536+
r->addr = mdns_utils_copy_address_list(result_list->addr);
536537
if (!r->addr) {
537538
return ESP_ERR_NO_MEM;
538539
}
@@ -559,7 +560,7 @@ void mdns_browse_result_add_srv(mdns_browse_t *browse, const char *hostname, con
559560
}
560561
mdns_result_t *r = browse->result;
561562
while (r) {
562-
if (r->esp_netif == _mdns_get_esp_netif(tcpip_if) && r->ip_protocol == ip_protocol &&
563+
if (r->esp_netif == mdns_netif_get_esp_netif(tcpip_if) && r->ip_protocol == ip_protocol &&
563564
!mdns_utils_str_null_or_empty(r->instance_name) && !strcasecmp(instance, r->instance_name) &&
564565
!mdns_utils_str_null_or_empty(r->service_type) && !strcasecmp(service, r->service_type) &&
565566
!mdns_utils_str_null_or_empty(r->proto) && !strcasecmp(proto, r->proto)) {
@@ -585,7 +586,7 @@ void mdns_browse_result_add_srv(mdns_browse_t *browse, const char *hostname, con
585586
if (r->ttl == 0) {
586587
r->ttl = ttl;
587588
} else {
588-
_mdns_result_update_ttl(r, ttl);
589+
mdns_priv_query_update_result_ttl(r, ttl);
589590
}
590591
if (previous_ttl != r->ttl) {
591592
if (_mdns_add_browse_result(out_sync_browse, r) != ESP_OK) {
@@ -618,7 +619,7 @@ void mdns_browse_result_add_srv(mdns_browse_t *browse, const char *hostname, con
618619
return;
619620
}
620621
r->port = port;
621-
r->esp_netif = _mdns_get_esp_netif(tcpip_if);
622+
r->esp_netif = mdns_netif_get_esp_netif(tcpip_if);
622623
r->ip_protocol = ip_protocol;
623624
r->ttl = ttl;
624625
r->next = browse->result;

components/mdns/mdns_debug.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void static dbg_packet(const uint8_t *data, size_t len)
4545
uint8_t qs = header.questions;
4646

4747
while (qs--) {
48-
content = _mdns_parse_fqdn(data, content, name, len);
48+
content = mdns_utils_parse_fqdn(data, content, name, len);
4949
if (!content || content + MDNS_CLASS_OFFSET + 1 >= data + len) {
5050
header.answers = 0;
5151
header.additional = 0;
@@ -96,7 +96,7 @@ void static dbg_packet(const uint8_t *data, size_t len)
9696

9797
while (content < (data + len)) {
9898

99-
content = _mdns_parse_fqdn(data, content, name, len);
99+
content = mdns_utils_parse_fqdn(data, content, name, len);
100100
if (!content) {
101101
dbg_printf("ERROR: parse mdns records\n");
102102
break;
@@ -164,13 +164,13 @@ void static dbg_packet(const uint8_t *data, size_t len)
164164
dbg_printf("%" PRIu32, ttl);
165165
dbg_printf("[%u] ", data_len);
166166
if (type == MDNS_TYPE_PTR) {
167-
if (!_mdns_parse_fqdn(data, data_ptr, name, len)) {
167+
if (!mdns_utils_parse_fqdn(data, data_ptr, name, len)) {
168168
dbg_printf("ERROR: parse PTR\n");
169169
continue;
170170
}
171171
dbg_printf("%s.%s.%s.%s.\n", name->host, name->service, name->proto, name->domain);
172172
} else if (type == MDNS_TYPE_SRV) {
173-
if (!_mdns_parse_fqdn(data, data_ptr + MDNS_SRV_FQDN_OFFSET, name, len)) {
173+
if (!mdns_utils_parse_fqdn(data, data_ptr + MDNS_SRV_FQDN_OFFSET, name, len)) {
174174
dbg_printf("ERROR: parse SRV\n");
175175
continue;
176176
}
@@ -208,7 +208,7 @@ void static dbg_packet(const uint8_t *data, size_t len)
208208
dbg_printf(IPSTR "\n", IP2STR(&ip));
209209
} else if (type == MDNS_TYPE_NSEC) {
210210
const uint8_t *old_ptr = data_ptr;
211-
const uint8_t *new_ptr = _mdns_parse_fqdn(data, data_ptr, name, len);
211+
const uint8_t *new_ptr = mdns_utils_parse_fqdn(data, data_ptr, name, len);
212212
if (new_ptr) {
213213
dbg_printf("%s.%s.%s.%s. ", name->host, name->service, name->proto, name->domain);
214214
size_t diff = new_ptr - old_ptr;

components/mdns/mdns_netif.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,7 @@ static inline esp_netif_t *esp_netif_from_preset_if(mdns_predef_if_t predef_if)
117117
}
118118
}
119119

120-
/**
121-
* @brief Gets the actual esp_netif pointer from the internal network interface list
122-
*
123-
* The supplied ordinal number could
124-
* - point to a predef netif -> "STA", "AP", "ETH"
125-
* - if no entry in the list (NULL) -> check if the system added this netif
126-
* - point to a custom netif -> just return the entry in the list
127-
* - users is responsible for the lifetime of this netif (to be valid between mdns-init -> deinit)
128-
*
129-
* @param tcpip_if Ordinal number of the interface
130-
* @return Pointer ot the esp_netif object if the interface is available, NULL otherwise
131-
*/
132-
esp_netif_t *_mdns_get_esp_netif(mdns_if_t tcpip_if)
120+
esp_netif_t *mdns_netif_get_esp_netif(mdns_if_t tcpip_if)
133121
{
134122
if (tcpip_if < MDNS_MAX_INTERFACES) {
135123
if (s_esp_netifs[tcpip_if].netif == NULL && s_esp_netifs[tcpip_if].predefined) {
@@ -174,7 +162,7 @@ static mdns_if_t _mdns_get_if_from_esp_netif(esp_netif_t *esp_netif)
174162

175163
static esp_err_t mdns_post_custom_action_tcpip_if(mdns_if_t mdns_if, mdns_event_actions_t event_action)
176164
{
177-
if (!is_mdns_server() || mdns_if >= MDNS_MAX_INTERFACES) {
165+
if (!mdns_priv_is_server_init() || mdns_if >= MDNS_MAX_INTERFACES) {
178166
return ESP_ERR_INVALID_STATE;
179167
}
180168

@@ -187,7 +175,7 @@ static esp_err_t mdns_post_custom_action_tcpip_if(mdns_if_t mdns_if, mdns_event_
187175
action->data.sys_event.event_action = event_action;
188176
action->data.sys_event.interface = mdns_if;
189177

190-
if (!mdns_action_queue(action)) {
178+
if (!mdns_priv_queue_action(action)) {
191179
mdns_mem_free(action);
192180
}
193181
return ESP_OK;
@@ -216,7 +204,7 @@ static inline void post_mdns_announce_pcb(mdns_predef_if_t preset_if, mdns_ip_pr
216204
void mdns_preset_if_handle_system_event(void *arg, esp_event_base_t event_base,
217205
int32_t event_id, void *event_data)
218206
{
219-
if (!is_mdns_server()) {
207+
if (!mdns_priv_is_server_init()) {
220208
return;
221209
}
222210

@@ -339,15 +327,15 @@ esp_err_t mdns_netif_action(esp_netif_t *esp_netif, mdns_event_actions_t event_a
339327

340328
esp_err_t mdns_register_netif(esp_netif_t *esp_netif)
341329
{
342-
if (!is_mdns_server()) {
330+
if (!mdns_priv_is_server_init()) {
343331
return ESP_ERR_INVALID_STATE;
344332
}
345333

346334
esp_err_t err = ESP_ERR_NO_MEM;
347-
mdns_service_lock();
335+
mdns_priv_service_lock();
348336
for (mdns_if_t i = 0; i < MDNS_MAX_INTERFACES; ++i) {
349337
if (s_esp_netifs[i].netif == esp_netif) {
350-
mdns_service_unlock();
338+
mdns_priv_service_unlock();
351339
return ESP_ERR_INVALID_STATE;
352340
}
353341
}
@@ -359,26 +347,26 @@ esp_err_t mdns_register_netif(esp_netif_t *esp_netif)
359347
break;
360348
}
361349
}
362-
mdns_service_unlock();
350+
mdns_priv_service_unlock();
363351
return err;
364352
}
365353

366354
esp_err_t mdns_unregister_netif(esp_netif_t *esp_netif)
367355
{
368-
if (!is_mdns_server()) {
356+
if (!mdns_priv_is_server_init()) {
369357
return ESP_ERR_INVALID_STATE;
370358
}
371359

372360
esp_err_t err = ESP_ERR_NOT_FOUND;
373-
mdns_service_lock();
361+
mdns_priv_service_lock();
374362
for (mdns_if_t i = 0; i < MDNS_MAX_INTERFACES; ++i) {
375363
if (!s_esp_netifs[i].predefined && s_esp_netifs[i].netif == esp_netif) {
376364
s_esp_netifs[i].netif = NULL;
377365
err = ESP_OK;
378366
break;
379367
}
380368
}
381-
mdns_service_lock();
369+
mdns_priv_service_lock();
382370
return err;
383371
}
384372

@@ -419,12 +407,12 @@ esp_err_t mdns_netif_init(void)
419407

420408
for (i = 0; i < MDNS_MAX_INTERFACES; i++) {
421409
#ifdef CONFIG_LWIP_IPV6
422-
if (!esp_netif_get_ip6_linklocal(_mdns_get_esp_netif(i), &tmp_addr6) && !mdns_utils_ipv6_address_is_zero(tmp_addr6)) {
410+
if (!esp_netif_get_ip6_linklocal(mdns_netif_get_esp_netif(i), &tmp_addr6) && !mdns_utils_ipv6_address_is_zero(tmp_addr6)) {
423411
mdns_priv_pcb_enable(i, MDNS_IP_PROTOCOL_V6);
424412
}
425413
#endif
426414
#ifdef CONFIG_LWIP_IPV4
427-
if (!esp_netif_get_ip_info(_mdns_get_esp_netif(i), &if_ip_info) && if_ip_info.ip.addr) {
415+
if (!esp_netif_get_ip_info(mdns_netif_get_esp_netif(i), &if_ip_info) && if_ip_info.ip.addr) {
428416
mdns_priv_pcb_enable(i, MDNS_IP_PROTOCOL_V4);
429417
}
430418
#endif

components/mdns/mdns_networking_lwip.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void _udp_pcb_main_deinit(void)
107107
static esp_err_t _udp_join_group(mdns_if_t if_inx, mdns_ip_protocol_t ip_protocol, bool join)
108108
{
109109
struct netif *netif = NULL;
110-
esp_netif_t *tcpip_if = _mdns_get_esp_netif(if_inx);
110+
esp_netif_t *tcpip_if = mdns_netif_get_esp_netif(if_inx);
111111

112112
if (!esp_netif_is_netif_up(tcpip_if)) {
113113
// Network interface went down before event propagated, skipping IGMP config
@@ -208,7 +208,7 @@ static void _udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *pb, const ip
208208
struct netif *netif = NULL;
209209
bool found = false;
210210
for (i = 0; i < MDNS_MAX_INTERFACES; i++) {
211-
netif = esp_netif_get_netif_impl(_mdns_get_esp_netif(i));
211+
netif = esp_netif_get_netif_impl(mdns_netif_get_esp_netif(i));
212212
if (s_interfaces[i].proto && netif && netif == ip_current_input_netif()) {
213213
#if LWIP_IPV4
214214
if (packet->src.type == IPADDR_TYPE_V4) {
@@ -353,7 +353,7 @@ static err_t _mdns_udp_pcb_write_api(struct tcpip_api_call_data *api_call_msg)
353353
{
354354
void *nif = NULL;
355355
mdns_api_call_t *msg = (mdns_api_call_t *)api_call_msg;
356-
nif = esp_netif_get_netif_impl(_mdns_get_esp_netif(msg->tcpip_if));
356+
nif = esp_netif_get_netif_impl(mdns_netif_get_esp_netif(msg->tcpip_if));
357357
if (!nif || !mdns_is_netif_ready(msg->tcpip_if, msg->ip_protocol) || _pcb_main == NULL) {
358358
pbuf_free(msg->pbt);
359359
msg->err = ERR_IF;

components/mdns/mdns_networking_socket.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "esp_log.h"
2424
#include "mdns_mem_caps.h"
2525
#include "mdns_utils.h"
26+
#include "mdns_netif.h"
2627

2728
#if defined(CONFIG_IDF_TARGET_LINUX)
2829
#include <sys/ioctl.h>
@@ -71,7 +72,7 @@ static esp_err_t _mdns_send_rx_action(mdns_rx_packet_t *packet)
7172

7273
action->type = ACTION_RX_HANDLE;
7374
action->data.rx_handle.packet = packet;
74-
if (!mdns_action_queue(action)) {
75+
if (!mdns_priv_queue_action(action)) {
7576
mdns_mem_free(action);
7677
return ESP_ERR_NO_MEM;
7778
}
@@ -373,7 +374,7 @@ static bool create_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
373374
return true;
374375
}
375376
int sock = s_interfaces[tcpip_if].sock;
376-
esp_netif_t *netif = _mdns_get_esp_netif(tcpip_if);
377+
esp_netif_t *netif = mdns_netif_get_esp_netif(tcpip_if);
377378
if (sock < 0) {
378379
sock = create_socket(netif);
379380
}

0 commit comments

Comments
 (0)