Skip to content

Commit ee00e97

Browse files
committed
feat(mdns): Console test: add subtype for service
1 parent 07b79ab commit ee00e97

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

components/mdns/mdns_console.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,59 @@ static void register_mdns_undelegate_host(void)
12651265
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_undelegate_host) );
12661266
}
12671267

1268+
static struct {
1269+
struct arg_str *service;
1270+
struct arg_str *proto;
1271+
struct arg_str *sub;
1272+
struct arg_str *instance;
1273+
struct arg_str *host;
1274+
struct arg_end *end;
1275+
} mdns_service_subtype_args;
1276+
1277+
static int cmd_mdns_service_subtype(int argc, char **argv)
1278+
{
1279+
int nerrors = arg_parse(argc, argv, (void **) &mdns_service_subtype_args);
1280+
if (nerrors != 0) {
1281+
arg_print_errors(stderr, mdns_service_subtype_args.end, argv[0]);
1282+
return 1;
1283+
}
1284+
1285+
if (!mdns_service_subtype_args.service->sval[0] || !mdns_service_subtype_args.proto->sval[0] || !mdns_service_subtype_args.sub->sval[0]) {
1286+
printf("ERROR: Bad arguments!\n");
1287+
return 1;
1288+
}
1289+
const char *instance = NULL;
1290+
if (mdns_service_subtype_args.instance->count && mdns_service_subtype_args.instance->sval[0]) {
1291+
instance = mdns_service_subtype_args.instance->sval[0];
1292+
}
1293+
const char *host = NULL;
1294+
if (mdns_service_subtype_args.host->count && mdns_service_subtype_args.host->sval[0]) {
1295+
host = mdns_service_subtype_args.host->sval[0];
1296+
}
1297+
ESP_ERROR_CHECK( mdns_service_subtype_add_for_host(instance, mdns_service_subtype_args.service->sval[0], mdns_service_subtype_args.proto->sval[0], host, mdns_service_subtype_args.sub->sval[0]) );
1298+
return 0;
1299+
}
1300+
1301+
static void register_mdns_service_subtype_set(void)
1302+
{
1303+
mdns_service_subtype_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
1304+
mdns_service_subtype_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
1305+
mdns_service_subtype_args.sub = arg_str1(NULL, NULL, "<sub>", "Subtype");
1306+
mdns_service_subtype_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
1307+
mdns_service_subtype_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
1308+
mdns_service_subtype_args.end = arg_end(5);
1309+
1310+
const esp_console_cmd_t cmd_service_sub = {
1311+
.command = "mdns_service_subtype",
1312+
.help = "Adds subtype for service",
1313+
.hint = NULL,
1314+
.func = &cmd_mdns_service_subtype,
1315+
.argtable = &mdns_service_subtype_args
1316+
};
1317+
1318+
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_service_sub) );
1319+
}
1320+
12681321
void mdns_console_register(void)
12691322
{
12701323
register_mdns_init();
@@ -1283,6 +1336,7 @@ void mdns_console_register(void)
12831336
register_mdns_lookup_service();
12841337
register_mdns_delegate_host();
12851338
register_mdns_undelegate_host();
1339+
register_mdns_service_subtype_set();
12861340

12871341
#ifdef CONFIG_LWIP_IPV4
12881342
register_mdns_query_a();

components/mdns/tests/host_test/pytest_mdns.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,13 @@ def test_service_port_set(mdns_console, dig_app):
147147
dig_app.check_record('extern._test2._tcp.local', query_type='SRV', expected=True, expect='83')
148148

149149

150+
def test_service_subtype(mdns_console, dig_app):
151+
dig_app.check_record('local._test._tcp.local', query_type='SRV', expected=True)
152+
mdns_console.send_input('mdns_service_subtype _test _tcp _subtest -i local')
153+
dig_app.check_record('_subtest._sub._test._tcp.local', query_type='PTR', expected=True)
154+
mdns_console.send_input('mdns_service_subtype _test2 _tcp _subtest2 -i extern -h delegated')
155+
dig_app.check_record('_subtest2._sub._test2._tcp.local', query_type='PTR', expected=True)
156+
157+
150158
if __name__ == '__main__':
151159
pytest.main(['-s', 'test_mdns.py'])

0 commit comments

Comments
 (0)