forked from espressif/esp-protocols
Merge pull request #618 from david-cermak/feat/mdns_console_host_more_tests
[mdns]: More console tests
This commit is contained in:
@ -6079,7 +6079,7 @@ esp_err_t mdns_instance_name_set(const char *instance)
|
|||||||
esp_err_t mdns_service_add_for_host(const char *instance, const char *service, const char *proto, const char *hostname,
|
esp_err_t mdns_service_add_for_host(const char *instance, const char *service, const char *proto, const char *hostname,
|
||||||
uint16_t port, mdns_txt_item_t txt[], size_t num_items)
|
uint16_t port, mdns_txt_item_t txt[], size_t num_items)
|
||||||
{
|
{
|
||||||
if (!_mdns_server || _str_null_or_empty(service) || _str_null_or_empty(proto) || !port || !hostname) {
|
if (!_mdns_server || _str_null_or_empty(service) || _str_null_or_empty(proto) || !port || !_mdns_server->hostname) {
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6089,6 +6089,10 @@ esp_err_t mdns_service_add_for_host(const char *instance, const char *service, c
|
|||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hostname) {
|
||||||
|
hostname = _mdns_server->hostname;
|
||||||
|
}
|
||||||
|
|
||||||
mdns_srv_item_t *item = _mdns_get_service_item_instance(instance, service, proto, hostname);
|
mdns_srv_item_t *item = _mdns_get_service_item_instance(instance, service, proto, hostname);
|
||||||
MDNS_SERVICE_UNLOCK();
|
MDNS_SERVICE_UNLOCK();
|
||||||
if (item) {
|
if (item) {
|
||||||
|
@ -19,7 +19,10 @@ static void mdns_print_results(mdns_result_t *results)
|
|||||||
mdns_ip_addr_t *a = NULL;
|
mdns_ip_addr_t *a = NULL;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (r) {
|
while (r) {
|
||||||
printf("%d: Interface: %s, Type: %s\n", i++, esp_netif_get_ifkey(r->esp_netif), ip_protocol_str[r->ip_protocol]);
|
if (r->esp_netif) {
|
||||||
|
printf("%d: Interface: %s, Type: %s, TTL: %" PRIu32 "\n", i++, esp_netif_get_ifkey(r->esp_netif),
|
||||||
|
ip_protocol_str[r->ip_protocol], r->ttl);
|
||||||
|
}
|
||||||
if (r->instance_name) {
|
if (r->instance_name) {
|
||||||
printf(" PTR : %s\n", r->instance_name);
|
printf(" PTR : %s\n", r->instance_name);
|
||||||
}
|
}
|
||||||
@ -694,6 +697,7 @@ static struct {
|
|||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
struct arg_int *port;
|
struct arg_int *port;
|
||||||
struct arg_str *instance;
|
struct arg_str *instance;
|
||||||
|
struct arg_str *host;
|
||||||
struct arg_str *txt;
|
struct arg_str *txt;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} mdns_add_args;
|
} mdns_add_args;
|
||||||
@ -715,6 +719,11 @@ static int cmd_mdns_service_add(int argc, char **argv)
|
|||||||
instance = mdns_add_args.instance->sval[0];
|
instance = mdns_add_args.instance->sval[0];
|
||||||
printf("MDNS: Service Instance: %s\n", instance);
|
printf("MDNS: Service Instance: %s\n", instance);
|
||||||
}
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_add_args.host->count && mdns_add_args.host->sval[0]) {
|
||||||
|
host = mdns_add_args.host->sval[0];
|
||||||
|
printf("MDNS: Service for delegated host: %s\n", host);
|
||||||
|
}
|
||||||
mdns_txt_item_t *items = NULL;
|
mdns_txt_item_t *items = NULL;
|
||||||
if (mdns_add_args.txt->count) {
|
if (mdns_add_args.txt->count) {
|
||||||
items = _convert_items(mdns_add_args.txt->sval, mdns_add_args.txt->count);
|
items = _convert_items(mdns_add_args.txt->sval, mdns_add_args.txt->count);
|
||||||
@ -725,7 +734,8 @@ static int cmd_mdns_service_add(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK( mdns_service_add(instance, mdns_add_args.service->sval[0], mdns_add_args.proto->sval[0], mdns_add_args.port->ival[0], items, mdns_add_args.txt->count) );
|
ESP_ERROR_CHECK( mdns_service_add_for_host(instance, mdns_add_args.service->sval[0], mdns_add_args.proto->sval[0],
|
||||||
|
host, mdns_add_args.port->ival[0], items, mdns_add_args.txt->count) );
|
||||||
free(items);
|
free(items);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -736,6 +746,7 @@ static void register_mdns_service_add(void)
|
|||||||
mdns_add_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_add_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
mdns_add_args.port = arg_int1(NULL, NULL, "<port>", "Service Port");
|
mdns_add_args.port = arg_int1(NULL, NULL, "<port>", "Service Port");
|
||||||
mdns_add_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
mdns_add_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_add_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
mdns_add_args.txt = arg_strn(NULL, NULL, "item", 0, 30, "TXT Items (name=value)");
|
mdns_add_args.txt = arg_strn(NULL, NULL, "item", 0, 30, "TXT Items (name=value)");
|
||||||
mdns_add_args.end = arg_end(2);
|
mdns_add_args.end = arg_end(2);
|
||||||
|
|
||||||
@ -751,8 +762,10 @@ static void register_mdns_service_add(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
struct arg_str *instance;
|
||||||
struct arg_str *service;
|
struct arg_str *service;
|
||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
|
struct arg_str *host;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} mdns_remove_args;
|
} mdns_remove_args;
|
||||||
|
|
||||||
@ -769,7 +782,16 @@ static int cmd_mdns_service_remove(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK( mdns_service_remove(mdns_remove_args.service->sval[0], mdns_remove_args.proto->sval[0]) );
|
const char *instance = NULL;
|
||||||
|
if (mdns_remove_args.instance->count && mdns_remove_args.instance->sval[0]) {
|
||||||
|
instance = mdns_remove_args.instance->sval[0];
|
||||||
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_remove_args.host->count && mdns_remove_args.host->sval[0]) {
|
||||||
|
host = mdns_remove_args.host->sval[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( mdns_service_remove_for_host(instance, mdns_remove_args.service->sval[0], mdns_remove_args.proto->sval[0], host) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,7 +799,9 @@ static void register_mdns_service_remove(void)
|
|||||||
{
|
{
|
||||||
mdns_remove_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
mdns_remove_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
mdns_remove_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_remove_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
mdns_remove_args.end = arg_end(2);
|
mdns_remove_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
|
mdns_remove_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_remove_args.end = arg_end(4);
|
||||||
|
|
||||||
const esp_console_cmd_t cmd_remove = {
|
const esp_console_cmd_t cmd_remove = {
|
||||||
.command = "mdns_service_remove",
|
.command = "mdns_service_remove",
|
||||||
@ -794,6 +818,8 @@ static struct {
|
|||||||
struct arg_str *service;
|
struct arg_str *service;
|
||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
struct arg_str *instance;
|
struct arg_str *instance;
|
||||||
|
struct arg_str *host;
|
||||||
|
struct arg_str *old_instance;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} mdns_service_instance_set_args;
|
} mdns_service_instance_set_args;
|
||||||
|
|
||||||
@ -809,8 +835,20 @@ static int cmd_mdns_service_instance_set(int argc, char **argv)
|
|||||||
printf("ERROR: Bad arguments!\n");
|
printf("ERROR: Bad arguments!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_service_instance_set_args.host->count && mdns_service_instance_set_args.host->sval[0]) {
|
||||||
|
host = mdns_service_instance_set_args.host->sval[0];
|
||||||
|
}
|
||||||
|
const char *old_instance = NULL;
|
||||||
|
if (mdns_service_instance_set_args.old_instance->count && mdns_service_instance_set_args.old_instance->sval[0]) {
|
||||||
|
old_instance = mdns_service_instance_set_args.old_instance->sval[0];
|
||||||
|
}
|
||||||
|
esp_err_t err = mdns_service_instance_name_set_for_host(old_instance, mdns_service_instance_set_args.service->sval[0], mdns_service_instance_set_args.proto->sval[0], host, mdns_service_instance_set_args.instance->sval[0]);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
printf("mdns_service_instance_name_set_for_host() failed with %s\n", esp_err_to_name(err));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK( mdns_service_instance_name_set(mdns_service_instance_set_args.service->sval[0], mdns_service_instance_set_args.proto->sval[0], mdns_service_instance_set_args.instance->sval[0]) );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,7 +857,9 @@ static void register_mdns_service_instance_set(void)
|
|||||||
mdns_service_instance_set_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
mdns_service_instance_set_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
mdns_service_instance_set_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_service_instance_set_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
mdns_service_instance_set_args.instance = arg_str1(NULL, NULL, "<instance>", "Instance name");
|
mdns_service_instance_set_args.instance = arg_str1(NULL, NULL, "<instance>", "Instance name");
|
||||||
mdns_service_instance_set_args.end = arg_end(2);
|
mdns_service_instance_set_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
|
mdns_service_instance_set_args.old_instance = arg_str0("i", "old_instance", "<old_instance>", "Instance name before update");
|
||||||
|
mdns_service_instance_set_args.end = arg_end(4);
|
||||||
|
|
||||||
const esp_console_cmd_t cmd_add = {
|
const esp_console_cmd_t cmd_add = {
|
||||||
.command = "mdns_service_instance_set",
|
.command = "mdns_service_instance_set",
|
||||||
@ -836,6 +876,8 @@ static struct {
|
|||||||
struct arg_str *service;
|
struct arg_str *service;
|
||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
struct arg_int *port;
|
struct arg_int *port;
|
||||||
|
struct arg_str *host;
|
||||||
|
struct arg_str *instance;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} mdns_service_port_set_args;
|
} mdns_service_port_set_args;
|
||||||
|
|
||||||
@ -852,7 +894,19 @@ static int cmd_mdns_service_port_set(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK( mdns_service_port_set(mdns_service_port_set_args.service->sval[0], mdns_service_port_set_args.proto->sval[0], mdns_service_port_set_args.port->ival[0]) );
|
const char *host = NULL;
|
||||||
|
if (mdns_service_port_set_args.host->count && mdns_service_port_set_args.host->sval[0]) {
|
||||||
|
host = mdns_service_port_set_args.host->sval[0];
|
||||||
|
}
|
||||||
|
const char *instance = NULL;
|
||||||
|
if (mdns_service_port_set_args.instance->count && mdns_service_port_set_args.instance->sval[0]) {
|
||||||
|
instance = mdns_service_port_set_args.instance->sval[0];
|
||||||
|
}
|
||||||
|
esp_err_t err = mdns_service_port_set_for_host(instance, mdns_service_port_set_args.service->sval[0], mdns_service_port_set_args.proto->sval[0], host, mdns_service_port_set_args.port->ival[0]);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
printf("mdns_service_port_set_for_host() failed with %s\n", esp_err_to_name(err));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,6 +915,8 @@ static void register_mdns_service_port_set(void)
|
|||||||
mdns_service_port_set_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
mdns_service_port_set_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
mdns_service_port_set_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_service_port_set_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
mdns_service_port_set_args.port = arg_int1(NULL, NULL, "<port>", "Service Port");
|
mdns_service_port_set_args.port = arg_int1(NULL, NULL, "<port>", "Service Port");
|
||||||
|
mdns_service_port_set_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
|
mdns_service_port_set_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
mdns_service_port_set_args.end = arg_end(2);
|
mdns_service_port_set_args.end = arg_end(2);
|
||||||
|
|
||||||
const esp_console_cmd_t cmd_add = {
|
const esp_console_cmd_t cmd_add = {
|
||||||
@ -877,6 +933,8 @@ static void register_mdns_service_port_set(void)
|
|||||||
static struct {
|
static struct {
|
||||||
struct arg_str *service;
|
struct arg_str *service;
|
||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
|
struct arg_str *instance;
|
||||||
|
struct arg_str *host;
|
||||||
struct arg_str *txt;
|
struct arg_str *txt;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} mdns_txt_replace_args;
|
} mdns_txt_replace_args;
|
||||||
@ -894,7 +952,16 @@ static int cmd_mdns_service_txt_replace(int argc, char **argv)
|
|||||||
printf("ERROR: Bad arguments!\n");
|
printf("ERROR: Bad arguments!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
const char *instance = NULL;
|
||||||
|
if (mdns_txt_replace_args.instance->count && mdns_txt_replace_args.instance->sval[0]) {
|
||||||
|
instance = mdns_txt_replace_args.instance->sval[0];
|
||||||
|
printf("MDNS: Service Instance: %s\n", instance);
|
||||||
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_txt_replace_args.host->count && mdns_txt_replace_args.host->sval[0]) {
|
||||||
|
host = mdns_txt_replace_args.host->sval[0];
|
||||||
|
printf("MDNS: Service for delegated host: %s\n", host);
|
||||||
|
}
|
||||||
if (mdns_txt_replace_args.txt->count) {
|
if (mdns_txt_replace_args.txt->count) {
|
||||||
items = _convert_items(mdns_txt_replace_args.txt->sval, mdns_txt_replace_args.txt->count);
|
items = _convert_items(mdns_txt_replace_args.txt->sval, mdns_txt_replace_args.txt->count);
|
||||||
if (!items) {
|
if (!items) {
|
||||||
@ -903,7 +970,7 @@ static int cmd_mdns_service_txt_replace(int argc, char **argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK( mdns_service_txt_set(mdns_txt_replace_args.service->sval[0], mdns_txt_replace_args.proto->sval[0], items, mdns_txt_replace_args.txt->count) );
|
ESP_ERROR_CHECK( mdns_service_txt_set_for_host(instance, mdns_txt_replace_args.service->sval[0], mdns_txt_replace_args.proto->sval[0], host, items, mdns_txt_replace_args.txt->count) );
|
||||||
free(items);
|
free(items);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -912,8 +979,10 @@ static void register_mdns_service_txt_replace(void)
|
|||||||
{
|
{
|
||||||
mdns_txt_replace_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
mdns_txt_replace_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
mdns_txt_replace_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_txt_replace_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
|
mdns_txt_replace_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_txt_replace_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
mdns_txt_replace_args.txt = arg_strn(NULL, NULL, "item", 0, 30, "TXT Items (name=value)");
|
mdns_txt_replace_args.txt = arg_strn(NULL, NULL, "item", 0, 30, "TXT Items (name=value)");
|
||||||
mdns_txt_replace_args.end = arg_end(2);
|
mdns_txt_replace_args.end = arg_end(5);
|
||||||
|
|
||||||
const esp_console_cmd_t cmd_txt_set = {
|
const esp_console_cmd_t cmd_txt_set = {
|
||||||
.command = "mdns_service_txt_replace",
|
.command = "mdns_service_txt_replace",
|
||||||
@ -929,6 +998,8 @@ static void register_mdns_service_txt_replace(void)
|
|||||||
static struct {
|
static struct {
|
||||||
struct arg_str *service;
|
struct arg_str *service;
|
||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
|
struct arg_str *instance;
|
||||||
|
struct arg_str *host;
|
||||||
struct arg_str *var;
|
struct arg_str *var;
|
||||||
struct arg_str *value;
|
struct arg_str *value;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
@ -946,8 +1017,18 @@ static int cmd_mdns_service_txt_set(int argc, char **argv)
|
|||||||
printf("ERROR: Bad arguments!\n");
|
printf("ERROR: Bad arguments!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
const char *instance = NULL;
|
||||||
|
if (mdns_txt_set_args.instance->count && mdns_txt_set_args.instance->sval[0]) {
|
||||||
|
instance = mdns_txt_set_args.instance->sval[0];
|
||||||
|
printf("MDNS: Service Instance: %s\n", instance);
|
||||||
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_txt_set_args.host->count && mdns_txt_set_args.host->sval[0]) {
|
||||||
|
host = mdns_txt_set_args.host->sval[0];
|
||||||
|
printf("MDNS: Service for delegated host: %s\n", host);
|
||||||
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK( mdns_service_txt_item_set(mdns_txt_set_args.service->sval[0], mdns_txt_set_args.proto->sval[0], mdns_txt_set_args.var->sval[0], mdns_txt_set_args.value->sval[0]) );
|
ESP_ERROR_CHECK( mdns_service_txt_item_set_for_host(instance, mdns_txt_set_args.service->sval[0], mdns_txt_set_args.proto->sval[0], host, mdns_txt_set_args.var->sval[0], mdns_txt_set_args.value->sval[0]) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -957,7 +1038,9 @@ static void register_mdns_service_txt_set(void)
|
|||||||
mdns_txt_set_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_txt_set_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
mdns_txt_set_args.var = arg_str1(NULL, NULL, "<var>", "Item Name");
|
mdns_txt_set_args.var = arg_str1(NULL, NULL, "<var>", "Item Name");
|
||||||
mdns_txt_set_args.value = arg_str1(NULL, NULL, "<value>", "Item Value");
|
mdns_txt_set_args.value = arg_str1(NULL, NULL, "<value>", "Item Value");
|
||||||
mdns_txt_set_args.end = arg_end(2);
|
mdns_txt_set_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_txt_set_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
|
mdns_txt_set_args.end = arg_end(6);
|
||||||
|
|
||||||
const esp_console_cmd_t cmd_txt_set = {
|
const esp_console_cmd_t cmd_txt_set = {
|
||||||
.command = "mdns_service_txt_set",
|
.command = "mdns_service_txt_set",
|
||||||
@ -974,6 +1057,8 @@ static struct {
|
|||||||
struct arg_str *service;
|
struct arg_str *service;
|
||||||
struct arg_str *proto;
|
struct arg_str *proto;
|
||||||
struct arg_str *var;
|
struct arg_str *var;
|
||||||
|
struct arg_str *instance;
|
||||||
|
struct arg_str *host;
|
||||||
struct arg_end *end;
|
struct arg_end *end;
|
||||||
} mdns_txt_remove_args;
|
} mdns_txt_remove_args;
|
||||||
|
|
||||||
@ -989,8 +1074,15 @@ static int cmd_mdns_service_txt_remove(int argc, char **argv)
|
|||||||
printf("ERROR: Bad arguments!\n");
|
printf("ERROR: Bad arguments!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
const char *instance = NULL;
|
||||||
ESP_ERROR_CHECK( mdns_service_txt_item_remove(mdns_txt_remove_args.service->sval[0], mdns_txt_remove_args.proto->sval[0], mdns_txt_remove_args.var->sval[0]) );
|
if (mdns_txt_remove_args.instance->count && mdns_txt_remove_args.instance->sval[0]) {
|
||||||
|
instance = mdns_txt_remove_args.instance->sval[0];
|
||||||
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_txt_remove_args.host->count && mdns_txt_remove_args.host->sval[0]) {
|
||||||
|
host = mdns_txt_remove_args.host->sval[0];
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK( mdns_service_txt_item_remove_for_host(instance, mdns_txt_remove_args.service->sval[0], mdns_txt_remove_args.proto->sval[0], host, mdns_txt_remove_args.var->sval[0]) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -999,6 +1091,8 @@ static void register_mdns_service_txt_remove(void)
|
|||||||
mdns_txt_remove_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
mdns_txt_remove_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
mdns_txt_remove_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
mdns_txt_remove_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
mdns_txt_remove_args.var = arg_str1(NULL, NULL, "<var>", "Item Name");
|
mdns_txt_remove_args.var = arg_str1(NULL, NULL, "<var>", "Item Name");
|
||||||
|
mdns_txt_remove_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_txt_remove_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
mdns_txt_remove_args.end = arg_end(2);
|
mdns_txt_remove_args.end = arg_end(2);
|
||||||
|
|
||||||
const esp_console_cmd_t cmd_txt_remove = {
|
const esp_console_cmd_t cmd_txt_remove = {
|
||||||
@ -1031,6 +1125,294 @@ static void register_mdns_service_remove_all(void)
|
|||||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_free) );
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_free) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MDNS_MAX_LOOKUP_RESULTS CONFIG_MDNS_MAX_SERVICES
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_str *instance;
|
||||||
|
struct arg_str *service;
|
||||||
|
struct arg_str *proto;
|
||||||
|
struct arg_lit *delegated;
|
||||||
|
struct arg_end *end;
|
||||||
|
} mdns_lookup_service_args;
|
||||||
|
|
||||||
|
static esp_err_t lookup_service(const char *instance, const char *service, const char *proto, size_t max_results,
|
||||||
|
mdns_result_t **result, bool delegated)
|
||||||
|
{
|
||||||
|
if (delegated) {
|
||||||
|
return mdns_lookup_delegated_service(instance, service, proto, max_results, result);
|
||||||
|
}
|
||||||
|
return mdns_lookup_selfhosted_service(instance, service, proto, max_results, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_mdns_lookup_service(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **) &mdns_lookup_service_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, mdns_lookup_service_args.end, argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mdns_lookup_service_args.instance->sval[0] || !mdns_lookup_service_args.service->sval[0] || !mdns_lookup_service_args.proto->sval[0]) {
|
||||||
|
printf("ERROR: Bad arguments!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mdns_result_t *results = NULL;
|
||||||
|
esp_err_t err = lookup_service(mdns_lookup_service_args.instance->count ? mdns_lookup_service_args.instance->sval[0] : NULL,
|
||||||
|
mdns_lookup_service_args.service->sval[0], mdns_lookup_service_args.proto->sval[0],
|
||||||
|
MDNS_MAX_LOOKUP_RESULTS, &results, mdns_lookup_service_args.delegated->count);
|
||||||
|
if (err) {
|
||||||
|
printf("Service lookup failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!results) {
|
||||||
|
printf("No results found!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
mdns_print_results(results);
|
||||||
|
mdns_query_results_free(results);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_mdns_lookup_service(void)
|
||||||
|
{
|
||||||
|
mdns_lookup_service_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
|
mdns_lookup_service_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
|
mdns_lookup_service_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_lookup_service_args.delegated = arg_lit0("d", "delegated", "Lookup delegated services");
|
||||||
|
mdns_lookup_service_args.end = arg_end(4);
|
||||||
|
|
||||||
|
const esp_console_cmd_t cmd_lookup_service = {
|
||||||
|
.command = "mdns_service_lookup",
|
||||||
|
.help = "Lookup registered service",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &cmd_mdns_lookup_service,
|
||||||
|
.argtable = &mdns_lookup_service_args
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_lookup_service) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_str *hostname;
|
||||||
|
struct arg_str *address;
|
||||||
|
struct arg_end *end;
|
||||||
|
} mdns_delegate_host_args;
|
||||||
|
|
||||||
|
static int cmd_mdns_delegate_host(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **) &mdns_delegate_host_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, mdns_delegate_host_args.end, argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mdns_delegate_host_args.hostname->sval[0] || !mdns_delegate_host_args.address->sval[0]) {
|
||||||
|
printf("ERROR: Bad arguments!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mdns_ip_addr_t addr = { .next = NULL};
|
||||||
|
esp_netif_str_to_ip4(mdns_delegate_host_args.address->sval[0], &addr.addr.u_addr.ip4);
|
||||||
|
addr.addr.type = ESP_IPADDR_TYPE_V4;
|
||||||
|
|
||||||
|
esp_err_t err = mdns_delegate_hostname_add(mdns_delegate_host_args.hostname->sval[0], &addr);
|
||||||
|
if (err) {
|
||||||
|
printf("mdns_delegate_hostname_add() failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_mdns_delegate_host(void)
|
||||||
|
{
|
||||||
|
mdns_delegate_host_args.hostname = arg_str1(NULL, NULL, "<hostname>", "Delegated hostname");
|
||||||
|
mdns_delegate_host_args.address = arg_str1(NULL, NULL, "<address>", "Delegated hosts address");
|
||||||
|
mdns_delegate_host_args.end = arg_end(2);
|
||||||
|
|
||||||
|
const esp_console_cmd_t cmd_delegate_host = {
|
||||||
|
.command = "mdns_delegate_host",
|
||||||
|
.help = "Add delegated hostname",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &cmd_mdns_delegate_host,
|
||||||
|
.argtable = &mdns_delegate_host_args
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_delegate_host) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_str *hostname;
|
||||||
|
struct arg_end *end;
|
||||||
|
} mdns_undelegate_host_args;
|
||||||
|
|
||||||
|
static int cmd_mdns_undelegate_host(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **) &mdns_undelegate_host_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, mdns_undelegate_host_args.end, argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mdns_undelegate_host_args.hostname->sval[0]) {
|
||||||
|
printf("ERROR: Bad arguments!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mdns_delegate_hostname_remove(mdns_undelegate_host_args.hostname->sval[0]) != ESP_OK) {
|
||||||
|
printf("mdns_delegate_hostname_remove() failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_mdns_undelegate_host(void)
|
||||||
|
{
|
||||||
|
mdns_undelegate_host_args.hostname = arg_str1(NULL, NULL, "<hostname>", "Delegated hostname");
|
||||||
|
mdns_undelegate_host_args.end = arg_end(2);
|
||||||
|
|
||||||
|
const esp_console_cmd_t cmd_undelegate_host = {
|
||||||
|
.command = "mdns_undelegate_host",
|
||||||
|
.help = "Remove delegated hostname",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &cmd_mdns_undelegate_host,
|
||||||
|
.argtable = &mdns_undelegate_host_args
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_undelegate_host) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_str *service;
|
||||||
|
struct arg_str *proto;
|
||||||
|
struct arg_str *sub;
|
||||||
|
struct arg_str *instance;
|
||||||
|
struct arg_str *host;
|
||||||
|
struct arg_end *end;
|
||||||
|
} mdns_service_subtype_args;
|
||||||
|
|
||||||
|
static int cmd_mdns_service_subtype(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **) &mdns_service_subtype_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, mdns_service_subtype_args.end, argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mdns_service_subtype_args.service->sval[0] || !mdns_service_subtype_args.proto->sval[0] || !mdns_service_subtype_args.sub->sval[0]) {
|
||||||
|
printf("ERROR: Bad arguments!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const char *instance = NULL;
|
||||||
|
if (mdns_service_subtype_args.instance->count && mdns_service_subtype_args.instance->sval[0]) {
|
||||||
|
instance = mdns_service_subtype_args.instance->sval[0];
|
||||||
|
}
|
||||||
|
const char *host = NULL;
|
||||||
|
if (mdns_service_subtype_args.host->count && mdns_service_subtype_args.host->sval[0]) {
|
||||||
|
host = mdns_service_subtype_args.host->sval[0];
|
||||||
|
}
|
||||||
|
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]) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_mdns_service_subtype_set(void)
|
||||||
|
{
|
||||||
|
mdns_service_subtype_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
|
mdns_service_subtype_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
|
mdns_service_subtype_args.sub = arg_str1(NULL, NULL, "<sub>", "Subtype");
|
||||||
|
mdns_service_subtype_args.instance = arg_str0("i", "instance", "<instance>", "Instance name");
|
||||||
|
mdns_service_subtype_args.host = arg_str0("h", "host", "<hostname>", "Service for this (delegated) host");
|
||||||
|
mdns_service_subtype_args.end = arg_end(5);
|
||||||
|
|
||||||
|
const esp_console_cmd_t cmd_service_sub = {
|
||||||
|
.command = "mdns_service_subtype",
|
||||||
|
.help = "Adds subtype for service",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &cmd_mdns_service_subtype,
|
||||||
|
.argtable = &mdns_service_subtype_args
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_service_sub) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
struct arg_str *service;
|
||||||
|
struct arg_str *proto;
|
||||||
|
struct arg_end *end;
|
||||||
|
} mdns_browse_args;
|
||||||
|
|
||||||
|
static void mdns_browse_notifier(mdns_result_t *result)
|
||||||
|
{
|
||||||
|
if (result) {
|
||||||
|
mdns_print_results(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_mdns_browse(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **) &mdns_browse_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, mdns_browse_args.end, argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mdns_browse_args.service->sval[0] || !mdns_browse_args.proto->sval[0]) {
|
||||||
|
printf("ERROR: Bad arguments!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mdns_browse_t *handle = mdns_browse_new(mdns_browse_args.service->sval[0], mdns_browse_args.proto->sval[0], mdns_browse_notifier);
|
||||||
|
return handle ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_mdns_browse(void)
|
||||||
|
{
|
||||||
|
mdns_browse_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
|
mdns_browse_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
|
mdns_browse_args.end = arg_end(2);
|
||||||
|
|
||||||
|
const esp_console_cmd_t cmd_browse = {
|
||||||
|
.command = "mdns_browse",
|
||||||
|
.help = "Start browsing",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &cmd_mdns_browse,
|
||||||
|
.argtable = &mdns_browse_args
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_browse) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_mdns_browse_del(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int nerrors = arg_parse(argc, argv, (void **) &mdns_browse_args);
|
||||||
|
if (nerrors != 0) {
|
||||||
|
arg_print_errors(stderr, mdns_browse_args.end, argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mdns_browse_args.service->sval[0] || !mdns_browse_args.proto->sval[0]) {
|
||||||
|
printf("ERROR: Bad arguments!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
esp_err_t err = mdns_browse_delete(mdns_browse_args.service->sval[0], mdns_browse_args.proto->sval[0]);
|
||||||
|
return err == ESP_OK ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_mdns_browse_del(void)
|
||||||
|
{
|
||||||
|
mdns_browse_args.service = arg_str1(NULL, NULL, "<service>", "MDNS Service");
|
||||||
|
mdns_browse_args.proto = arg_str1(NULL, NULL, "<proto>", "IP Protocol");
|
||||||
|
mdns_browse_args.end = arg_end(2);
|
||||||
|
|
||||||
|
const esp_console_cmd_t cmd_browse_del = {
|
||||||
|
.command = "mdns_browse_del",
|
||||||
|
.help = "Stop browsing",
|
||||||
|
.hint = NULL,
|
||||||
|
.func = &cmd_mdns_browse_del,
|
||||||
|
.argtable = &mdns_browse_args
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd_browse_del) );
|
||||||
|
}
|
||||||
|
|
||||||
void mdns_console_register(void)
|
void mdns_console_register(void)
|
||||||
{
|
{
|
||||||
register_mdns_init();
|
register_mdns_init();
|
||||||
@ -1046,6 +1428,14 @@ void mdns_console_register(void)
|
|||||||
register_mdns_service_txt_remove();
|
register_mdns_service_txt_remove();
|
||||||
register_mdns_service_remove_all();
|
register_mdns_service_remove_all();
|
||||||
|
|
||||||
|
register_mdns_lookup_service();
|
||||||
|
register_mdns_delegate_host();
|
||||||
|
register_mdns_undelegate_host();
|
||||||
|
register_mdns_service_subtype_set();
|
||||||
|
|
||||||
|
register_mdns_browse();
|
||||||
|
register_mdns_browse_del();
|
||||||
|
|
||||||
#ifdef CONFIG_LWIP_IPV4
|
#ifdef CONFIG_LWIP_IPV4
|
||||||
register_mdns_query_a();
|
register_mdns_query_a();
|
||||||
#endif
|
#endif
|
||||||
|
@ -182,3 +182,16 @@ const char *esp_netif_get_ifkey(esp_netif_t *esp_netif)
|
|||||||
{
|
{
|
||||||
return esp_netif->if_key;
|
return esp_netif->if_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_netif_str_to_ip4(const char *src, esp_ip4_addr_t *dst)
|
||||||
|
{
|
||||||
|
if (src == NULL || dst == NULL) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
struct in_addr addr;
|
||||||
|
if (inet_pton(AF_INET, src, &addr) != 1) {
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
dst->addr = addr.s_addr;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
@ -85,14 +85,16 @@ class DnsPythonWrapper:
|
|||||||
answers.append(full_answer)
|
answers.append(full_answer)
|
||||||
return answers
|
return answers
|
||||||
|
|
||||||
def check_record(self, name, query_type, expected=True):
|
def check_record(self, name, query_type, expected=True, expect=None):
|
||||||
output = self.run_query(name, query_type=query_type)
|
output = self.run_query(name, query_type=query_type)
|
||||||
answers = self.parse_answer_section(output, query_type)
|
answers = self.parse_answer_section(output, query_type)
|
||||||
logger.info(f'answers: {answers}')
|
logger.info(f'answers: {answers}')
|
||||||
|
if expect is None:
|
||||||
|
expect = name
|
||||||
if expected:
|
if expected:
|
||||||
assert any(name in answer for answer in answers), f"Expected service '{name}' not found in answer section"
|
assert any(expect in answer for answer in answers), f"Expected record '{expect}' not found in answer section"
|
||||||
else:
|
else:
|
||||||
assert not any(name in answer for answer in answers), f"Unexpected service '{name}' found in answer section"
|
assert not any(expect in answer for answer in answers), f"Unexpected record '{expect}' found in answer section"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -60,13 +60,121 @@ def test_mdns_init(mdns_console, dig_app):
|
|||||||
def test_add_service(mdns_console, dig_app):
|
def test_add_service(mdns_console, dig_app):
|
||||||
mdns_console.send_input('mdns_service_add _http _tcp 80 -i test_service')
|
mdns_console.send_input('mdns_service_add _http _tcp 80 -i test_service')
|
||||||
mdns_console.get_output('MDNS: Service Instance: test_service')
|
mdns_console.get_output('MDNS: Service Instance: test_service')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _http _tcp')
|
||||||
|
mdns_console.get_output('PTR : test_service')
|
||||||
dig_app.check_record('_http._tcp.local', query_type='PTR', expected=True)
|
dig_app.check_record('_http._tcp.local', query_type='PTR', expected=True)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_service(mdns_console, dig_app):
|
def test_remove_service(mdns_console, dig_app):
|
||||||
mdns_console.send_input('mdns_service_remove _http _tcp')
|
mdns_console.send_input('mdns_service_remove _http _tcp')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _http _tcp')
|
||||||
|
mdns_console.get_output('No results found!')
|
||||||
dig_app.check_record('_http._tcp.local', query_type='PTR', expected=False)
|
dig_app.check_record('_http._tcp.local', query_type='PTR', expected=False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_delegate_host(mdns_console, dig_app):
|
||||||
|
mdns_console.send_input('mdns_delegate_host delegated 1.2.3.4')
|
||||||
|
dig_app.check_record('delegated.local', query_type='A', expected=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_undelegate_host(mdns_console, dig_app):
|
||||||
|
mdns_console.send_input('mdns_undelegate_host delegated')
|
||||||
|
dig_app.check_record('delegated.local', query_type='A', expected=False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_delegated_service(mdns_console, dig_app):
|
||||||
|
mdns_console.send_input('mdns_delegate_host delegated 1.2.3.4')
|
||||||
|
dig_app.check_record('delegated.local', query_type='A', expected=True)
|
||||||
|
mdns_console.send_input('mdns_service_add _test _tcp 80 -i local')
|
||||||
|
mdns_console.get_output('MDNS: Service Instance: local')
|
||||||
|
mdns_console.send_input('mdns_service_add _test2 _tcp 80 -i extern -h delegated')
|
||||||
|
mdns_console.get_output('MDNS: Service Instance: extern')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _test _tcp')
|
||||||
|
mdns_console.get_output('PTR : local')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _test2 _tcp -d')
|
||||||
|
mdns_console.get_output('PTR : extern')
|
||||||
|
dig_app.check_record('_test2._tcp.local', query_type='PTR', expected=True)
|
||||||
|
dig_app.check_record('extern._test2._tcp.local', query_type='SRV', expected=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_delegated_service(mdns_console, dig_app):
|
||||||
|
mdns_console.send_input('mdns_service_remove _test2 _tcp -h delegated')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _test2 _tcp -d')
|
||||||
|
mdns_console.get_output('No results found!')
|
||||||
|
dig_app.check_record('_test2._tcp.local', query_type='PTR', expected=False)
|
||||||
|
# add the delegated service again, would be used in the TXT test
|
||||||
|
mdns_console.send_input('mdns_service_add _test2 _tcp 80 -i extern -h delegated')
|
||||||
|
mdns_console.get_output('MDNS: Service Instance: extern')
|
||||||
|
|
||||||
|
|
||||||
|
def check_txt_for_service(instance, service, proto, mdns_console, dig_app, host=None, with_inst=False):
|
||||||
|
for_host_arg = f'-h {host}' if host is not None else ''
|
||||||
|
for_inst_arg = f'-i {instance}' if with_inst else ''
|
||||||
|
mdns_console.send_input(f'mdns_service_txt_set {service} {proto} {for_host_arg} {for_inst_arg} key1 value1')
|
||||||
|
dig_app.check_record(f'{instance}.{service}.{proto}.local', query_type='SRV', expected=True)
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=True, expect='key1=value1')
|
||||||
|
mdns_console.send_input(f'mdns_service_txt_set {service} {proto} {for_host_arg} {for_inst_arg} key2 value2')
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=True, expect='key2=value2')
|
||||||
|
mdns_console.send_input(f'mdns_service_txt_remove {service} {proto} {for_host_arg} {for_inst_arg} key2')
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=False, expect='key2=value2')
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=True, expect='key1=value1')
|
||||||
|
mdns_console.send_input(f'mdns_service_txt_replace {service} {proto} {for_host_arg} {for_inst_arg} key3=value3 key4=value4')
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=False, expect='key1=value1')
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=True, expect='key3=value3')
|
||||||
|
dig_app.check_record(f'{service}.{proto}.local', query_type='TXT', expected=True, expect='key4=value4')
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_txt(mdns_console, dig_app):
|
||||||
|
check_txt_for_service('local', '_test', '_tcp', mdns_console=mdns_console, dig_app=dig_app)
|
||||||
|
check_txt_for_service('local', '_test', '_tcp', mdns_console=mdns_console, dig_app=dig_app, with_inst=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_delegated_txt(mdns_console, dig_app):
|
||||||
|
check_txt_for_service('extern', '_test2', '_tcp', mdns_console=mdns_console, dig_app=dig_app, host='delegated')
|
||||||
|
check_txt_for_service('extern', '_test2', '_tcp', mdns_console=mdns_console, dig_app=dig_app, host='delegated', with_inst=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_service_port_set(mdns_console, dig_app):
|
||||||
|
dig_app.check_record('local._test._tcp.local', query_type='SRV', expected=True, expect='80')
|
||||||
|
mdns_console.send_input('mdns_service_port_set _test _tcp 81')
|
||||||
|
dig_app.check_record('local._test._tcp.local', query_type='SRV', expected=True, expect='81')
|
||||||
|
mdns_console.send_input('mdns_service_port_set _test2 _tcp -h delegated 82')
|
||||||
|
dig_app.check_record('extern._test2._tcp.local', query_type='SRV', expected=True, expect='82')
|
||||||
|
mdns_console.send_input('mdns_service_port_set _test2 _tcp -h delegated -i extern 83')
|
||||||
|
dig_app.check_record('extern._test2._tcp.local', query_type='SRV', expected=True, expect='83')
|
||||||
|
mdns_console.send_input('mdns_service_port_set _test2 _tcp -h delegated -i invalid_inst 84')
|
||||||
|
mdns_console.get_output('ESP_ERR_NOT_FOUND')
|
||||||
|
dig_app.check_record('extern._test2._tcp.local', query_type='SRV', expected=True, expect='83')
|
||||||
|
|
||||||
|
|
||||||
|
def test_service_subtype(mdns_console, dig_app):
|
||||||
|
dig_app.check_record('local._test._tcp.local', query_type='SRV', expected=True)
|
||||||
|
mdns_console.send_input('mdns_service_subtype _test _tcp _subtest -i local')
|
||||||
|
dig_app.check_record('_subtest._sub._test._tcp.local', query_type='PTR', expected=True)
|
||||||
|
mdns_console.send_input('mdns_service_subtype _test2 _tcp _subtest2 -i extern -h delegated')
|
||||||
|
dig_app.check_record('_subtest2._sub._test2._tcp.local', query_type='PTR', expected=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_service_set_instance(mdns_console, dig_app):
|
||||||
|
dig_app.check_record('local._test._tcp.local', query_type='SRV', expected=True)
|
||||||
|
mdns_console.send_input('mdns_service_instance_set _test _tcp local2')
|
||||||
|
dig_app.check_record('local2._test._tcp.local', query_type='SRV', expected=True)
|
||||||
|
mdns_console.send_input('mdns_service_instance_set _test2 _tcp extern2 -h delegated')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _test2 _tcp -d')
|
||||||
|
mdns_console.get_output('PTR : extern2')
|
||||||
|
dig_app.check_record('extern2._test2._tcp.local', query_type='SRV', expected=True)
|
||||||
|
mdns_console.send_input('mdns_service_instance_set _test2 _tcp extern3 -h delegated -i extern')
|
||||||
|
mdns_console.get_output('ESP_ERR_NOT_FOUND')
|
||||||
|
|
||||||
|
|
||||||
|
def test_service_remove_all(mdns_console, dig_app):
|
||||||
|
mdns_console.send_input('mdns_service_remove_all')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _test2 _tcp -d')
|
||||||
|
mdns_console.get_output('No results found!')
|
||||||
|
mdns_console.send_input('mdns_service_lookup _test _tcp')
|
||||||
|
mdns_console.get_output('No results found!')
|
||||||
|
dig_app.check_record('_test._tcp.local', query_type='PTR', expected=False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pytest.main(['-s', 'test_mdns.py'])
|
pytest.main(['-s', 'test_mdns.py'])
|
||||||
|
Reference in New Issue
Block a user