@@ -5200,28 +5200,57 @@ static void _mdns_execute_action(mdns_action_t *action)
5200
5200
break ;
5201
5201
case ACTION_SERVICE_DEL :
5202
5202
a = _mdns_server -> services ;
5203
- if (action -> data .srv_del .service ) {
5204
- if (_mdns_server -> services == action -> data .srv_del .service ) {
5205
- _mdns_server -> services = a -> next ;
5206
- _mdns_send_bye (& a , 1 , false);
5207
- _mdns_remove_scheduled_service_packets (a -> service );
5208
- _mdns_free_service (a -> service );
5209
- free (a );
5210
- } else {
5211
- while (a -> next && a -> next != action -> data .srv_del .service ) {
5212
- a = a -> next ;
5203
+ mdns_srv_item_t * b = a ;
5204
+ if (action -> data .srv_del .instance ) {
5205
+ while (a ) {
5206
+ if (_mdns_service_match_instance (a -> service , action -> data .srv_del .instance ,
5207
+ action -> data .srv_del .service , action -> data .srv_del .proto ,
5208
+ action -> data .srv_del .hostname )) {
5209
+ if (_mdns_server -> services != a ) {
5210
+ b -> next = a -> next ;
5211
+ } else {
5212
+ _mdns_server -> services = a -> next ;
5213
+ }
5214
+ _mdns_send_bye (& a , 1 , false);
5215
+ _mdns_remove_scheduled_service_packets (a -> service );
5216
+ _mdns_free_service (a -> service );
5217
+ free (a );
5218
+ break ;
5213
5219
}
5214
- if (a -> next == action -> data .srv_del .service ) {
5215
- mdns_srv_item_t * b = a -> next ;
5216
- a -> next = a -> next -> next ;
5217
- _mdns_send_bye (& b , 1 , false);
5218
- _mdns_remove_scheduled_service_packets (b -> service );
5219
- _mdns_free_service (b -> service );
5220
- free (b );
5220
+ b = a ;
5221
+ a = a -> next ;
5222
+ }
5223
+ } else {
5224
+ while (a ) {
5225
+ if (_mdns_service_match (a -> service , action -> data .srv_del .service , action -> data .srv_del .proto ,
5226
+ action -> data .srv_del .hostname )) {
5227
+ if (_mdns_server -> services != a ) {
5228
+ b -> next = a -> next ;
5229
+ _mdns_send_bye (& a , 1 , false);
5230
+ _mdns_remove_scheduled_service_packets (a -> service );
5231
+ _mdns_free_service (a -> service );
5232
+ free (a );
5233
+ a = b -> next ;
5234
+ continue ;
5235
+ } else {
5236
+ _mdns_server -> services = a -> next ;
5237
+ _mdns_send_bye (& a , 1 , false);
5238
+ _mdns_remove_scheduled_service_packets (a -> service );
5239
+ _mdns_free_service (a -> service );
5240
+ free (a );
5241
+ a = _mdns_server -> services ;
5242
+ b = a ;
5243
+ continue ;
5244
+ }
5221
5245
}
5246
+ b = a ;
5247
+ a = a -> next ;
5222
5248
}
5223
5249
}
5224
-
5250
+ free ((char * )action -> data .srv_del .instance );
5251
+ free ((char * )action -> data .srv_del .service );
5252
+ free ((char * )action -> data .srv_del .proto );
5253
+ free ((char * )action -> data .srv_del .hostname );
5225
5254
break ;
5226
5255
case ACTION_SERVICES_CLEAR :
5227
5256
_mdns_send_final_bye (false);
@@ -6401,6 +6430,16 @@ esp_err_t mdns_service_subtype_add_for_host(const char *instance_name, const cha
6401
6430
if (!s ) {
6402
6431
return ESP_ERR_NOT_FOUND ;
6403
6432
}
6433
+
6434
+ mdns_subtype_t * srv_subtype = s -> service -> subtype ;
6435
+ while (srv_subtype ) {
6436
+ if (strcmp (srv_subtype -> subtype , subtype ) == 0 ) {
6437
+ // The same subtype has already been added
6438
+ return ESP_ERR_INVALID_ARG ;
6439
+ }
6440
+ srv_subtype = srv_subtype -> next ;
6441
+ }
6442
+
6404
6443
mdns_action_t * action = (mdns_action_t * )malloc (sizeof (mdns_action_t ));
6405
6444
if (!action ) {
6406
6445
HOOK_MALLOC_FAILED ;
@@ -6489,12 +6528,40 @@ esp_err_t mdns_service_remove_for_host(const char *instance, const char *service
6489
6528
return ESP_ERR_NO_MEM ;
6490
6529
}
6491
6530
action -> type = ACTION_SERVICE_DEL ;
6492
- action -> data .srv_del .service = s ;
6531
+ action -> data .srv_del .instance = NULL ;
6532
+ action -> data .srv_del .hostname = NULL ;
6533
+ if (!_str_null_or_empty (instance )) {
6534
+ action -> data .srv_del .instance = strndup (instance , MDNS_NAME_BUF_LEN - 1 );
6535
+ if (!action -> data .srv_del .instance ) {
6536
+ goto fail ;
6537
+ }
6538
+ }
6539
+
6540
+ if (!_str_null_or_empty (hostname )) {
6541
+ action -> data .srv_del .hostname = strndup (hostname , MDNS_NAME_BUF_LEN - 1 );
6542
+ if (!action -> data .srv_del .hostname ) {
6543
+ goto fail ;
6544
+ }
6545
+ }
6546
+
6547
+ action -> data .srv_del .service = strndup (service , MDNS_NAME_BUF_LEN - 1 );
6548
+ action -> data .srv_del .proto = strndup (proto , MDNS_NAME_BUF_LEN - 1 );
6549
+ if (!action -> data .srv_del .service || !action -> data .srv_del .proto ) {
6550
+ goto fail ;
6551
+ }
6552
+
6493
6553
if (xQueueSend (_mdns_server -> action_queue , & action , (TickType_t )0 ) != pdPASS ) {
6494
- free (action );
6495
- return ESP_ERR_NO_MEM ;
6554
+ goto fail ;
6496
6555
}
6497
6556
return ESP_OK ;
6557
+
6558
+ fail :
6559
+ free ((char * )action -> data .srv_del .instance );
6560
+ free ((char * )action -> data .srv_del .service );
6561
+ free ((char * )action -> data .srv_del .proto );
6562
+ free ((char * )action -> data .srv_del .hostname );
6563
+ free (action );
6564
+ return ESP_ERR_NO_MEM ;
6498
6565
}
6499
6566
6500
6567
esp_err_t mdns_service_remove (const char * service_type , const char * proto )
0 commit comments