Compare commits
4 Commits
mdns-big-t
...
cd28bebff9
| Author | SHA1 | Date | |
|---|---|---|---|
| cd28bebff9 | |||
| 8eafba6ea6 | |||
| 88f27e011f | |||
| a8aa758153 |
@@ -103,6 +103,8 @@
|
||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||
#define TAPIF_DEBUG LWIP_DBG_ON
|
||||
#define MDNS_DEBUG LWIP_DBG_ON
|
||||
#endif
|
||||
|
||||
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
|
||||
|
||||
@@ -36,9 +36,12 @@ srv_txt(struct mdns_service *service, void *txt_userdata)
|
||||
{
|
||||
err_t res;
|
||||
LWIP_UNUSED_ARG(txt_userdata);
|
||||
|
||||
|
||||
LWIP_DEBUGF(LWIP_DBG_ON, ("srv_txt called\n"));
|
||||
res = mdns_resp_add_service_txtitem(service, "path=/", 6);
|
||||
LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
|
||||
res = mdns_resp_add_service_txtitem(service, "package_import_url=github://dlitz/esphome-configs-dlitz/mini.yaml@wip", 69);
|
||||
LWIP_ERROR("mdns add big service txt failed\n", (res == ERR_OK), return);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ If this call returns successfully, the following queries will be answered:
|
||||
|
||||
Each item is encoded as a length byte followed by the data, so each single
|
||||
item can be max 255 bytes long, and the total max length (including length
|
||||
bytes for each item) is defined by MDNS_TXT_RDATA_SIZE (default 255).
|
||||
bytes for each item) is defined by MDNS_TXT_RDATA_MAXLEN (default 255).
|
||||
|
||||
If your device runs a webserver on port 80, an example call might be:
|
||||
|
||||
|
||||
@@ -2617,9 +2617,9 @@ mdns_resp_rename_service(struct netif *netif, u8_t slot, const char *name)
|
||||
static err_t
|
||||
mdns_txt_add_charstr(struct mdns_txtdata *txtdata, const char *value, u8_t len)
|
||||
{
|
||||
if (1 + len + txtdata->length > MDNS_TXT_RDATA_SIZE) {
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("mdns_txt_add_charstr: adding string would exceed buffer (1+%d+%d > %d). Consider increasing MDNS_TXT_RDATA_SIZE.\n",
|
||||
len, txtdata->length, MDNS_TXT_RDATA_SIZE));
|
||||
if (1 + len + txtdata->length > MDNS_TXT_RDATA_MAXLEN) {
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("mdns_txt_add_charstr: adding string would exceed buffer (1+%d+%d > %d). Consider increasing MDNS_TXT_RDATA_MAXLEN.\n",
|
||||
len, txtdata->length, MDNS_TXT_RDATA_MAXLEN));
|
||||
return ERR_MEM;
|
||||
}
|
||||
txtdata->rdata[txtdata->length] = len;
|
||||
@@ -2634,7 +2634,7 @@ mdns_txt_add_charstr(struct mdns_txtdata *txtdata, const char *value, u8_t len)
|
||||
/**
|
||||
* @ingroup mdns
|
||||
* Call this function from inside the service_get_txt_fn_t callback to add text data.
|
||||
* Buffer for TXT data is MDNS_TXT_RDATA_SIZE (default 256) bytes, and each
|
||||
* Buffer for TXT data is MDNS_TXT_RDATA_MAXLEN (default 256) bytes, and each
|
||||
* field is prefixed with a length byte.
|
||||
* @param service The service provided to the get_txt callback
|
||||
* @param txt String to add to the TXT field.
|
||||
@@ -2647,6 +2647,8 @@ mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
LWIP_ASSERT("mdns_resp_add_service_txtitem: service != NULL", service);
|
||||
|
||||
LWIP_DEBUGF(MDNS_DEBUG, ("mDNS: adding txtitem: txt_len=%d, %02x %02x %02x %02x\n", txt_len, (int)txt[0], (int)txt[1], (int)txt[2], (int)txt[3])); /* DEBUG FIXME(dlitz) */
|
||||
|
||||
/* Use a mdns_domain struct to store txt chunks since it is the same encoding */
|
||||
return mdns_txt_add_charstr(&service->txtdata, txt, txt_len);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
#define DOMAIN_JUMP_SIZE 2
|
||||
#define DOMAIN_JUMP 0xc000
|
||||
|
||||
#define TOPDOMAIN_LOCAL "local"
|
||||
#define TOPDOMAIN_LOCAL "local2"
|
||||
|
||||
#define REVERSE_PTR_TOPDOMAIN "arpa"
|
||||
#define REVERSE_PTR_V4_DOMAIN "in-addr"
|
||||
|
||||
@@ -88,10 +88,10 @@
|
||||
#define MDNS_OUTPUT_PACKET_SIZE ((MDNS_MAX_SERVICES == 1) ? 512 : 1450)
|
||||
#endif
|
||||
|
||||
/** The maximum size of TXT RDATA allocated for each service.
|
||||
/** The maximum size of TXT RDATA allocated for each service record.
|
||||
*/
|
||||
#ifndef MDNS_TXT_RDATA_SIZE
|
||||
# define MDNS_TXT_RDATA_SIZE 256
|
||||
#ifndef MDNS_TXT_RDATA_MAXLEN
|
||||
# define MDNS_TXT_RDATA_MAXLEN 256
|
||||
#endif
|
||||
|
||||
/** MDNS_RESP_USENETIF_EXTCALLBACK==1: register an ext_callback on the netif
|
||||
|
||||
@@ -92,7 +92,7 @@ struct mdns_request {
|
||||
|
||||
/** TXT record data */
|
||||
struct mdns_txtdata {
|
||||
u8_t rdata[MDNS_TXT_RDATA_SIZE];
|
||||
u8_t rdata[MDNS_TXT_RDATA_MAXLEN];
|
||||
u16_t length;
|
||||
};
|
||||
|
||||
@@ -236,6 +236,12 @@ struct udp_pcb* get_mdns_pcb(void);
|
||||
|
||||
#endif /* LWIP_MDNS_RESPONDER */
|
||||
|
||||
char checker(int);
|
||||
char checkSizeOfInt[sizeof(struct mdns_service)]={checker(&checkSizeOfInt)};
|
||||
/*char checkSizeOfInt[sizeof(struct mdns_service_old)]={checker(&checkSizeOfInt)}; */
|
||||
char checkSizeOfInt[sizeof(struct mdns_domain)]={checker(&checkSizeOfInt)};
|
||||
char checkSizeOfInt[sizeof(struct mdns_txtdata)]={checker(&checkSizeOfInt)};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/apps/mdns.h"
|
||||
#include "lwip/apps/mdns_domain.h"
|
||||
#include "lwip/apps/mdns_out.h"
|
||||
#include "lwip/apps/mdns_priv.h"
|
||||
|
||||
START_TEST(readname_basic)
|
||||
@@ -877,155 +876,6 @@ START_TEST(compress_long_match)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
#define TXT_STRING_1 "path=/"
|
||||
#define TXT_LENGTH_1 6
|
||||
#define TXT_LENSTR_1 "\006"
|
||||
|
||||
#define TXT_STRING_2 ""
|
||||
#define TXT_LENGTH_2 0
|
||||
#define TXT_LENSTR_2 "\000"
|
||||
|
||||
#define TXT_STRING_3 "This sentence is sixty-three bytes long, including punctuation."
|
||||
#define TXT_LENGTH_3 63
|
||||
#define TXT_LENSTR_3 "\077"
|
||||
|
||||
#define TXT_STRING_4 "This tests whether mdns_resp_add_service_txtitem can properly handle strings longer than 63 characters."
|
||||
#define TXT_LENGTH_4 103
|
||||
#define TXT_LENSTR_4 "\147"
|
||||
|
||||
START_TEST(txt_short_item)
|
||||
{
|
||||
const char *expected_txtdata = TXT_LENSTR_1 TXT_STRING_1;
|
||||
const size_t expected_txtdata_length = 1 + TXT_LENGTH_1;
|
||||
|
||||
struct mdns_service service;
|
||||
err_t res;
|
||||
memset(&service, 0, sizeof(struct mdns_service));
|
||||
|
||||
mdns_prepare_txtdata(&service);
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_1, TXT_LENGTH_1);
|
||||
fail_unless(res == ERR_OK);
|
||||
|
||||
fail_unless(service.txtdata.length == expected_txtdata_length);
|
||||
fail_if(memcmp(service.txtdata.rdata, expected_txtdata, expected_txtdata_length));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(txt_empty_item)
|
||||
{
|
||||
const char *expected_txtdata = TXT_LENSTR_2 TXT_STRING_2;
|
||||
const size_t expected_txtdata_length = 1 + TXT_LENGTH_2;
|
||||
|
||||
struct mdns_service service;
|
||||
err_t res;
|
||||
memset(&service, 0, sizeof(struct mdns_service));
|
||||
|
||||
mdns_prepare_txtdata(&service);
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_2, TXT_LENGTH_2);
|
||||
fail_unless(res == ERR_OK);
|
||||
|
||||
fail_unless(service.txtdata.length == expected_txtdata_length);
|
||||
fail_if(memcmp(service.txtdata.rdata, expected_txtdata, expected_txtdata_length));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(txt_long_item)
|
||||
{
|
||||
const char *expected_txtdata = TXT_LENSTR_4 TXT_STRING_4;
|
||||
const size_t expected_txtdata_length = 1 + TXT_LENGTH_4;
|
||||
|
||||
struct mdns_service service;
|
||||
err_t res;
|
||||
memset(&service, 0, sizeof(struct mdns_service));
|
||||
|
||||
mdns_prepare_txtdata(&service);
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_4, TXT_LENGTH_4);
|
||||
fail_unless(res == ERR_OK);
|
||||
|
||||
fail_unless(service.txtdata.length == expected_txtdata_length);
|
||||
fail_if(memcmp(service.txtdata.rdata, expected_txtdata, expected_txtdata_length));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(txt_multiple_items)
|
||||
{
|
||||
const char *expected_txtdata = (
|
||||
TXT_LENSTR_1
|
||||
TXT_STRING_1
|
||||
TXT_LENSTR_2
|
||||
TXT_STRING_2
|
||||
TXT_LENSTR_3
|
||||
TXT_STRING_3
|
||||
TXT_LENSTR_4
|
||||
TXT_STRING_4
|
||||
);
|
||||
const size_t expected_txtdata_length = (
|
||||
1 + TXT_LENGTH_1
|
||||
+ 1 + TXT_LENGTH_2
|
||||
+ 1 + TXT_LENGTH_3
|
||||
+ 1 + TXT_LENGTH_4
|
||||
);
|
||||
|
||||
struct mdns_service service;
|
||||
err_t res;
|
||||
memset(&service, 0, sizeof(struct mdns_service));
|
||||
|
||||
mdns_prepare_txtdata(&service);
|
||||
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_1, TXT_LENGTH_1);
|
||||
fail_unless(res == ERR_OK); /* TXT_STRING_1 */
|
||||
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_2, TXT_LENGTH_2);
|
||||
fail_unless(res == ERR_OK); /* TXT_STRING_1 */
|
||||
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_3, TXT_LENGTH_3);
|
||||
fail_unless(res == ERR_OK); /* TXT_STRING_3 */
|
||||
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_4, TXT_LENGTH_4);
|
||||
fail_unless(res == ERR_OK); /* TXT_STRING_4 */
|
||||
|
||||
fail_unless(service.txtdata.length == expected_txtdata_length);
|
||||
fail_if(memcmp(service.txtdata.rdata, expected_txtdata, expected_txtdata_length));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(txt_buffer_full)
|
||||
{
|
||||
const char *expected_txtdata = (
|
||||
TXT_LENSTR_3 TXT_STRING_3
|
||||
TXT_LENSTR_3 TXT_STRING_3
|
||||
TXT_LENSTR_3 TXT_STRING_3
|
||||
TXT_LENSTR_3 TXT_STRING_3
|
||||
);
|
||||
const size_t expected_txtdata_length = 256;
|
||||
|
||||
struct mdns_service service;
|
||||
err_t res;
|
||||
int i;
|
||||
memset(&service, 0, sizeof(struct mdns_service));
|
||||
|
||||
mdns_prepare_txtdata(&service);
|
||||
|
||||
/* add a 64-byte string 4 times = 256 bytes */
|
||||
for (i = 0; i < 4; i++) {
|
||||
res = mdns_resp_add_service_txtitem(&service, TXT_STRING_3, TXT_LENGTH_3);
|
||||
ck_assert_msg(res == ERR_OK,
|
||||
"adding text item failed with error %d (i=%d, txtdata.length=%d)",
|
||||
res, i, service.txtdata.length);
|
||||
}
|
||||
|
||||
/* Try to add a few more strings while the buffer is full. This should fail. */
|
||||
res = mdns_resp_add_service_txtitem(&service, "", 0);
|
||||
fail_unless(res != ERR_OK); /* empty string */
|
||||
|
||||
res = mdns_resp_add_service_txtitem(&service, "path=/", 6);
|
||||
fail_unless(res != ERR_OK); /* short string */
|
||||
|
||||
fail_unless(service.txtdata.length == expected_txtdata_length);
|
||||
fail_if(memcmp(service.txtdata.rdata, expected_txtdata, expected_txtdata_length));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite* mdns_suite(void)
|
||||
{
|
||||
testfunc tests[] = {
|
||||
@@ -1061,12 +911,6 @@ Suite* mdns_suite(void)
|
||||
TESTFUNC(compress_2nd_label_short),
|
||||
TESTFUNC(compress_jump_to_jump),
|
||||
TESTFUNC(compress_long_match),
|
||||
|
||||
TESTFUNC(txt_short_item),
|
||||
TESTFUNC(txt_empty_item),
|
||||
TESTFUNC(txt_long_item),
|
||||
TESTFUNC(txt_multiple_items),
|
||||
TESTFUNC(txt_buffer_full),
|
||||
};
|
||||
return create_suite("MDNS", tests, sizeof(tests)/sizeof(testfunc), NULL, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user