@@ -7521,6 +7521,21 @@ static mdns_browse_t *_mdns_browse_find_from(mdns_browse_t *b, mdns_name_t *name
7521
7521
return b ;
7522
7522
}
7523
7523
7524
+ static bool is_txt_item_in_list (mdns_txt_item_t txt , uint8_t txt_value_len , mdns_txt_item_t * txt_list , uint8_t * txt_value_len_list , size_t txt_count )
7525
+ {
7526
+ for (size_t i = 0 ; i < txt_count ; i ++ ) {
7527
+ if (strcmp (txt .key , txt_list [i ].key ) == 0 ) {
7528
+ if (txt_value_len == txt_value_len_list [i ] && memcmp (txt .value , txt_list [i ].value , txt_value_len ) == 0 ) {
7529
+ return true;
7530
+ } else {
7531
+ // The key value is unique, so there is no need to continue searching.
7532
+ return false;
7533
+ }
7534
+ }
7535
+ }
7536
+ return false;
7537
+ }
7538
+
7524
7539
/**
7525
7540
* @brief Called from parser to add TXT data to search result
7526
7541
*/
@@ -7541,9 +7556,20 @@ static void _mdns_browse_result_add_txt(mdns_browse_t *browse, const char *insta
7541
7556
!_str_null_or_empty (r -> instance_name ) && !strcasecmp (instance , r -> instance_name ) &&
7542
7557
!_str_null_or_empty (r -> service_type ) && !strcasecmp (service , r -> service_type ) &&
7543
7558
!_str_null_or_empty (r -> proto ) && !strcasecmp (proto , r -> proto )) {
7559
+ bool should_update = false;
7544
7560
if (r -> txt ) {
7561
+ // Check if txt changed
7562
+ if (txt_count != r -> txt_count ) {
7563
+ should_update = true;
7564
+ } else {
7565
+ for (size_t txt_index = 0 ; txt_index < txt_count ; txt_index ++ ) {
7566
+ if (!is_txt_item_in_list (txt [txt_index ], txt_value_len [txt_index ], r -> txt , r -> txt_value_len , r -> txt_count )) {
7567
+ should_update = true;
7568
+ break ;
7569
+ }
7570
+ }
7571
+ }
7545
7572
// If the result has a previous txt entry, we delete it and re-add.
7546
- // TODO: we need to check if txt changes.
7547
7573
for (size_t i = 0 ; i < r -> txt_count ; i ++ ) {
7548
7574
free ((char * )(r -> txt [i ].key ));
7549
7575
free ((char * )(r -> txt [i ].value ));
@@ -7562,9 +7588,12 @@ static void _mdns_browse_result_add_txt(mdns_browse_t *browse, const char *insta
7562
7588
_mdns_result_update_ttl (r , ttl );
7563
7589
}
7564
7590
if (previous_ttl != r -> ttl ) {
7565
- if (_mdns_add_browse_result (out_sync_browse , r ) != ESP_OK ) {
7566
- return ;
7567
- }
7591
+ should_update = true;
7592
+ }
7593
+ }
7594
+ if (should_update ) {
7595
+ if (_mdns_add_browse_result (out_sync_browse , r ) != ESP_OK ) {
7596
+ return ;
7568
7597
}
7569
7598
}
7570
7599
return ;
0 commit comments