@@ -5300,28 +5300,57 @@ static void _mdns_execute_action(mdns_action_t *action)
5300
5300
break ;
5301
5301
case ACTION_SERVICE_DEL :
5302
5302
a = _mdns_server -> services ;
5303
- if (action -> data .srv_del .service ) {
5304
- if (_mdns_server -> services == action -> data .srv_del .service ) {
5305
- _mdns_server -> services = a -> next ;
5306
- _mdns_send_bye (& a , 1 , false);
5307
- _mdns_remove_scheduled_service_packets (a -> service );
5308
- _mdns_free_service (a -> service );
5309
- free (a );
5310
- } else {
5311
- while (a -> next && a -> next != action -> data .srv_del .service ) {
5312
- a = a -> next ;
5303
+ mdns_srv_item_t * b = a ;
5304
+ if (action -> data .srv_del .instance ) {
5305
+ while (a ) {
5306
+ if (_mdns_service_match_instance (a -> service , action -> data .srv_del .instance ,
5307
+ action -> data .srv_del .service , action -> data .srv_del .proto ,
5308
+ action -> data .srv_del .hostname )) {
5309
+ if (_mdns_server -> services != a ) {
5310
+ b -> next = a -> next ;
5311
+ } else {
5312
+ _mdns_server -> services = a -> next ;
5313
+ }
5314
+ _mdns_send_bye (& a , 1 , false);
5315
+ _mdns_remove_scheduled_service_packets (a -> service );
5316
+ _mdns_free_service (a -> service );
5317
+ free (a );
5318
+ break ;
5313
5319
}
5314
- if (a -> next == action -> data .srv_del .service ) {
5315
- mdns_srv_item_t * b = a -> next ;
5316
- a -> next = a -> next -> next ;
5317
- _mdns_send_bye (& b , 1 , false);
5318
- _mdns_remove_scheduled_service_packets (b -> service );
5319
- _mdns_free_service (b -> service );
5320
- free (b );
5320
+ b = a ;
5321
+ a = a -> next ;
5322
+ }
5323
+ } else {
5324
+ while (a ) {
5325
+ if (_mdns_service_match (a -> service , action -> data .srv_del .service , action -> data .srv_del .proto ,
5326
+ action -> data .srv_del .hostname )) {
5327
+ if (_mdns_server -> services != a ) {
5328
+ b -> next = a -> next ;
5329
+ _mdns_send_bye (& a , 1 , false);
5330
+ _mdns_remove_scheduled_service_packets (a -> service );
5331
+ _mdns_free_service (a -> service );
5332
+ free (a );
5333
+ a = b -> next ;
5334
+ continue ;
5335
+ } else {
5336
+ _mdns_server -> services = a -> next ;
5337
+ _mdns_send_bye (& a , 1 , false);
5338
+ _mdns_remove_scheduled_service_packets (a -> service );
5339
+ _mdns_free_service (a -> service );
5340
+ free (a );
5341
+ a = _mdns_server -> services ;
5342
+ b = a ;
5343
+ continue ;
5344
+ }
5321
5345
}
5346
+ b = a ;
5347
+ a = a -> next ;
5322
5348
}
5323
5349
}
5324
-
5350
+ free ((char * )action -> data .srv_del .instance );
5351
+ free ((char * )action -> data .srv_del .service );
5352
+ free ((char * )action -> data .srv_del .proto );
5353
+ free ((char * )action -> data .srv_del .hostname );
5325
5354
break ;
5326
5355
case ACTION_SERVICES_CLEAR :
5327
5356
_mdns_send_final_bye (false);
@@ -6501,6 +6530,16 @@ esp_err_t mdns_service_subtype_add_for_host(const char *instance_name, const cha
6501
6530
if (!s ) {
6502
6531
return ESP_ERR_NOT_FOUND ;
6503
6532
}
6533
+
6534
+ mdns_subtype_t * srv_subtype = s -> service -> subtype ;
6535
+ while (srv_subtype ) {
6536
+ if (strcmp (srv_subtype -> subtype , subtype ) == 0 ) {
6537
+ // The same subtype has already been added
6538
+ return ESP_ERR_INVALID_ARG ;
6539
+ }
6540
+ srv_subtype = srv_subtype -> next ;
6541
+ }
6542
+
6504
6543
mdns_action_t * action = (mdns_action_t * )malloc (sizeof (mdns_action_t ));
6505
6544
if (!action ) {
6506
6545
HOOK_MALLOC_FAILED ;
@@ -6589,12 +6628,40 @@ esp_err_t mdns_service_remove_for_host(const char *instance, const char *service
6589
6628
return ESP_ERR_NO_MEM ;
6590
6629
}
6591
6630
action -> type = ACTION_SERVICE_DEL ;
6592
- action -> data .srv_del .service = s ;
6631
+ action -> data .srv_del .instance = NULL ;
6632
+ action -> data .srv_del .hostname = NULL ;
6633
+ if (!_str_null_or_empty (instance )) {
6634
+ action -> data .srv_del .instance = strndup (instance , MDNS_NAME_BUF_LEN - 1 );
6635
+ if (!action -> data .srv_del .instance ) {
6636
+ goto fail ;
6637
+ }
6638
+ }
6639
+
6640
+ if (!_str_null_or_empty (hostname )) {
6641
+ action -> data .srv_del .hostname = strndup (hostname , MDNS_NAME_BUF_LEN - 1 );
6642
+ if (!action -> data .srv_del .hostname ) {
6643
+ goto fail ;
6644
+ }
6645
+ }
6646
+
6647
+ action -> data .srv_del .service = strndup (service , MDNS_NAME_BUF_LEN - 1 );
6648
+ action -> data .srv_del .proto = strndup (proto , MDNS_NAME_BUF_LEN - 1 );
6649
+ if (!action -> data .srv_del .service || !action -> data .srv_del .proto ) {
6650
+ goto fail ;
6651
+ }
6652
+
6593
6653
if (xQueueSend (_mdns_server -> action_queue , & action , (TickType_t )0 ) != pdPASS ) {
6594
- free (action );
6595
- return ESP_ERR_NO_MEM ;
6654
+ goto fail ;
6596
6655
}
6597
6656
return ESP_OK ;
6657
+
6658
+ fail :
6659
+ free ((char * )action -> data .srv_del .instance );
6660
+ free ((char * )action -> data .srv_del .service );
6661
+ free ((char * )action -> data .srv_del .proto );
6662
+ free ((char * )action -> data .srv_del .hostname );
6663
+ free (action );
6664
+ return ESP_ERR_NO_MEM ;
6598
6665
}
6599
6666
6600
6667
esp_err_t mdns_service_remove (const char * service_type , const char * proto )
0 commit comments