Skip to content

Commit eb5d636

Browse files
authored
use newlib api in new mDNS, fix host using mDNS (esp8266#5545)
1 parent cac22e3 commit eb5d636

File tree

4 files changed

+51
-50
lines changed

4 files changed

+51
-50
lines changed

libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
203203
u8HostOrServiceReplies |= (pService->m_u8ReplyMask |= u8ReplyMaskForQuestion);
204204
DEBUG_EX_INFO(if (u8ReplyMaskForQuestion) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Service reply needed for (%s.%s.%s): %u (%s)\n"), (pService->m_pcName ?: m_pcHostname), pService->m_pcService, pService->m_pcProtocol, u8ReplyMaskForQuestion, IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str()); } );
205205
/*if ((u8ReplyMaskForQuestion) &&
206-
(0 == os_strcmp("hap", pService->m_pcService))) {
206+
(0 == strcmp("hap", pService->m_pcService))) {
207207
DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Service reply needed for (%s.%s.%s): %u (%s)\n"), (pService->m_pcName ?: m_pcHostname), pService->m_pcService, pService->m_pcProtocol, u8ReplyMaskForQuestion, IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str());
208208
}*/
209209

@@ -386,7 +386,7 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
386386
if ((u8ServiceMatchMask) && // The RR in the known answer matches an RR we are planning to send, AND
387387
((MDNS_SERVICE_TTL / 2) <= pKnownRRAnswer->m_u32TTL)) { // The TTL of the known answer is longer than half of the new service TTL (4500s)
388388

389-
/*if ((0 == os_strcmp("hap", pService->m_pcService))) {
389+
/*if ((0 == strcmp("hap", pService->m_pcService))) {
390390
DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Known answer for (%s.%s.%s): %u (%s) %u\n"), (pService->m_pcName ?: m_pcHostname), pService->m_pcService, pService->m_pcProtocol, pKnownRRAnswer->answerType(), IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str(), pKnownRRAnswer->m_u32TTL);
391391
}*/
392392

@@ -484,7 +484,7 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
484484
u8ReplyNeeded |= pService->m_u8ReplyMask;
485485

486486
if ((u8ReplyNeeded) &&
487-
(0 == os_strcmp("hap", pService->m_pcService))) {
487+
(0 == strcmp("hap", pService->m_pcService))) {
488488
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Sending service reply for (%s.%s.%s): %u (%s)\n"), (pService->m_pcName ?: m_pcHostname), pService->m_pcService, pService->m_pcProtocol, u8ReplyNeeded, IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str()););
489489
}
490490
}

libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ namespace MDNSImplementation {
102102
const char* pFoundDivider = strrstr(p_rpcDomain, pcDivider);
103103
if (pFoundDivider) { // maybe already extended
104104
char* pEnd = 0;
105-
unsigned long ulIndex = strtoul((pFoundDivider + os_strlen(pcDivider)), &pEnd, 10);
105+
unsigned long ulIndex = strtoul((pFoundDivider + strlen(pcDivider)), &pEnd, 10);
106106
if ((ulIndex) &&
107-
((pEnd - p_rpcDomain) == os_strlen(p_rpcDomain)) &&
107+
((pEnd - p_rpcDomain) == (ptrdiff_t)strlen(p_rpcDomain)) &&
108108
(!*pEnd)) { // Valid (old) index found
109109

110110
char acIndexBuffer[16];
111111
sprintf(acIndexBuffer, "%lu", (++ulIndex));
112-
size_t stLength = ((pFoundDivider - p_rpcDomain + os_strlen(pcDivider)) + os_strlen(acIndexBuffer) + 1);
112+
size_t stLength = ((pFoundDivider - p_rpcDomain + strlen(pcDivider)) + strlen(acIndexBuffer) + 1);
113113
char* pNewHostname = new char[stLength];
114114
if (pNewHostname) {
115-
memcpy(pNewHostname, p_rpcDomain, (pFoundDivider - p_rpcDomain + os_strlen(pcDivider)));
116-
pNewHostname[pFoundDivider - p_rpcDomain + os_strlen(pcDivider)] = 0;
117-
os_strcat(pNewHostname, acIndexBuffer);
115+
memcpy(pNewHostname, p_rpcDomain, (pFoundDivider - p_rpcDomain + strlen(pcDivider)));
116+
pNewHostname[pFoundDivider - p_rpcDomain + strlen(pcDivider)] = 0;
117+
strcat(pNewHostname, acIndexBuffer);
118118

119119
delete[] p_rpcDomain;
120120
p_rpcDomain = pNewHostname;
@@ -131,7 +131,7 @@ namespace MDNSImplementation {
131131
}
132132

133133
if (!pFoundDivider) { // not yet extended (or failed to increment extension) -> start indexing
134-
size_t stLength = os_strlen(p_rpcDomain) + (os_strlen(pcDivider) + 1 + 1); // Name + Divider + '2' + '\0'
134+
size_t stLength = strlen(p_rpcDomain) + (strlen(pcDivider) + 1 + 1); // Name + Divider + '2' + '\0'
135135
char* pNewHostname = new char[stLength];
136136
if (pNewHostname) {
137137
sprintf(pNewHostname, "%s%s2", p_rpcDomain, pcDivider);
@@ -150,10 +150,10 @@ namespace MDNSImplementation {
150150
// No given host domain, use base or default
151151
const char* cpcDefaultName = (p_pcDefaultDomain ?: "esp8266");
152152

153-
size_t stLength = os_strlen(cpcDefaultName) + 1; // '\0'
153+
size_t stLength = strlen(cpcDefaultName) + 1; // '\0'
154154
p_rpcDomain = new char[stLength];
155155
if (p_rpcDomain) {
156-
os_strncpy(p_rpcDomain, cpcDefaultName, stLength);
156+
strncpy(p_rpcDomain, cpcDefaultName, stLength);
157157
bResult = true;
158158
}
159159
else {
@@ -364,7 +364,7 @@ bool MDNSResponder::_setHostname(const char* p_pcHostname) {
364364

365365
size_t stLength = 0;
366366
if ((p_pcHostname) &&
367-
(MDNS_DOMAIN_LABEL_MAXLENGTH >= (stLength = os_strlen(p_pcHostname)))) { // char max size for a single label
367+
(MDNS_DOMAIN_LABEL_MAXLENGTH >= (stLength = strlen(p_pcHostname)))) { // char max size for a single label
368368
// Copy in hostname characters as lowercase
369369
if ((bResult = (0 != (m_pcHostname = new char[stLength + 1])))) {
370370
#ifdef MDNS_FORCE_LOWERCASE_HOSTNAME
@@ -374,7 +374,7 @@ bool MDNSResponder::_setHostname(const char* p_pcHostname) {
374374
}
375375
m_pcHostname[i] = 0;
376376
#else
377-
os_strncpy(m_pcHostname, p_pcHostname, (stLength + 1));
377+
strncpy(m_pcHostname, p_pcHostname, (stLength + 1));
378378
#endif
379379
}
380380
}
@@ -408,11 +408,11 @@ MDNSResponder::stcMDNSService* MDNSResponder::_allocService(const char* p_pcName
408408

409409
stcMDNSService* pService = 0;
410410
if (((!p_pcName) ||
411-
(MDNS_DOMAIN_LABEL_MAXLENGTH >= os_strlen(p_pcName))) &&
411+
(MDNS_DOMAIN_LABEL_MAXLENGTH >= strlen(p_pcName))) &&
412412
(p_pcService) &&
413-
(MDNS_SERVICE_NAME_LENGTH >= os_strlen(p_pcService)) &&
413+
(MDNS_SERVICE_NAME_LENGTH >= strlen(p_pcService)) &&
414414
(p_pcProtocol) &&
415-
(MDNS_SERVICE_PROTOCOL_LENGTH >= os_strlen(p_pcProtocol)) &&
415+
(MDNS_SERVICE_PROTOCOL_LENGTH >= strlen(p_pcProtocol)) &&
416416
(p_u16Port) &&
417417
(0 != (pService = new stcMDNSService)) &&
418418
(pService->setName(p_pcName ?: m_pcHostname)) &&
@@ -528,23 +528,23 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_allocServiceTxt(MDNSResponder:
528528
(p_pcKey) &&
529529
(MDNS_SERVICE_TXT_MAXLENGTH > (p_pService->m_Txts.length() +
530530
1 + // Length byte
531-
(p_pcKey ? os_strlen(p_pcKey) : 0) +
531+
(p_pcKey ? strlen(p_pcKey) : 0) +
532532
1 + // '='
533-
(p_pcValue ? os_strlen(p_pcValue) : 0)))) {
533+
(p_pcValue ? strlen(p_pcValue) : 0)))) {
534534

535535
pTxt = new stcMDNSServiceTxt;
536536
if (pTxt) {
537-
size_t stLength = (p_pcKey ? os_strlen(p_pcKey) : 0);
537+
size_t stLength = (p_pcKey ? strlen(p_pcKey) : 0);
538538
pTxt->m_pcKey = new char[stLength + 1];
539539
if (pTxt->m_pcKey) {
540-
os_strncpy(pTxt->m_pcKey, p_pcKey, stLength); pTxt->m_pcKey[stLength] = 0;
540+
strncpy(pTxt->m_pcKey, p_pcKey, stLength); pTxt->m_pcKey[stLength] = 0;
541541
}
542542

543543
if (p_pcValue) {
544-
stLength = (p_pcValue ? os_strlen(p_pcValue) : 0);
544+
stLength = (p_pcValue ? strlen(p_pcValue) : 0);
545545
pTxt->m_pcValue = new char[stLength + 1];
546546
if (pTxt->m_pcValue) {
547-
os_strncpy(pTxt->m_pcValue, p_pcValue, stLength); pTxt->m_pcValue[stLength] = 0;
547+
strncpy(pTxt->m_pcValue, p_pcValue, stLength); pTxt->m_pcValue[stLength] = 0;
548548
}
549549
}
550550
pTxt->m_bTemp = p_bTemp;
@@ -578,8 +578,8 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_updateServiceTxt(MDNSResponder
578578
if ((p_pService) &&
579579
(p_pTxt) &&
580580
(MDNS_SERVICE_TXT_MAXLENGTH > (p_pService->m_Txts.length() -
581-
(p_pTxt->m_pcValue ? os_strlen(p_pTxt->m_pcValue) : 0) +
582-
(p_pcValue ? os_strlen(p_pcValue) : 0)))) {
581+
(p_pTxt->m_pcValue ? strlen(p_pTxt->m_pcValue) : 0) +
582+
(p_pcValue ? strlen(p_pcValue) : 0)))) {
583583
p_pTxt->update(p_pcValue);
584584
p_pTxt->m_bTemp = p_bTemp;
585585
}
@@ -615,7 +615,7 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_addServiceTxt(MDNSResponder::s
615615

616616
if ((p_pService) &&
617617
(p_pcKey) &&
618-
(os_strlen(p_pcKey))) {
618+
(strlen(p_pcKey))) {
619619

620620
stcMDNSServiceTxt* pTxt = p_pService->m_Txts.find(p_pcKey);
621621
if (pTxt) {

libraries/ESP8266mDNS/src/LEAmDNS_Structs.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setKey(const char* p_pcKey,
126126
releaseKey();
127127
if (p_stLength) {
128128
if (allocKey(p_stLength)) {
129-
os_strncpy(m_pcKey, p_pcKey, p_stLength);
129+
strncpy(m_pcKey, p_pcKey, p_stLength);
130130
m_pcKey[p_stLength] = 0;
131131
bResult = true;
132132
}
@@ -139,7 +139,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setKey(const char* p_pcKey,
139139
*/
140140
bool MDNSResponder::stcMDNSServiceTxt::setKey(const char* p_pcKey) {
141141

142-
return setKey(p_pcKey, (p_pcKey ? os_strlen(p_pcKey) : 0));
142+
return setKey(p_pcKey, (p_pcKey ? strlen(p_pcKey) : 0));
143143
}
144144

145145
/*
@@ -177,7 +177,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setValue(const char* p_pcValue,
177177
releaseValue();
178178
if (p_stLength) {
179179
if (allocValue(p_stLength)) {
180-
os_strncpy(m_pcValue, p_pcValue, p_stLength);
180+
strncpy(m_pcValue, p_pcValue, p_stLength);
181181
m_pcValue[p_stLength] = 0;
182182
bResult = true;
183183
}
@@ -193,7 +193,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setValue(const char* p_pcValue,
193193
*/
194194
bool MDNSResponder::stcMDNSServiceTxt::setValue(const char* p_pcValue) {
195195

196-
return setValue(p_pcValue, (p_pcValue ? os_strlen(p_pcValue) : 0));
196+
return setValue(p_pcValue, (p_pcValue ? strlen(p_pcValue) : 0));
197197
}
198198

199199
/*
@@ -237,9 +237,9 @@ size_t MDNSResponder::stcMDNSServiceTxt::length(void) const {
237237

238238
size_t stLength = 0;
239239
if (m_pcKey) {
240-
stLength += os_strlen(m_pcKey); // Key
240+
stLength += strlen(m_pcKey); // Key
241241
stLength += 1; // '='
242-
stLength += (m_pcValue ? os_strlen(m_pcValue) : 0); // Value
242+
stLength += (m_pcValue ? strlen(m_pcValue) : 0); // Value
243243
}
244244
return stLength;
245245
}
@@ -461,15 +461,15 @@ bool MDNSResponder::stcMDNSServiceTxts::c_str(char* p_pcBuffer) {
461461
*p_pcBuffer = 0;
462462
for (stcMDNSServiceTxt* pTxt=m_pTxts; ((bResult) && (pTxt)); pTxt = pTxt->m_pNext) {
463463
size_t stLength;
464-
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? os_strlen(pTxt->m_pcKey) : 0))))) {
464+
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? strlen(pTxt->m_pcKey) : 0))))) {
465465
if (pTxt != m_pTxts) {
466466
*p_pcBuffer++ = ';';
467467
}
468-
os_strncpy(p_pcBuffer, pTxt->m_pcKey, stLength); p_pcBuffer[stLength] = 0;
468+
strncpy(p_pcBuffer, pTxt->m_pcKey, stLength); p_pcBuffer[stLength] = 0;
469469
p_pcBuffer += stLength;
470470
*p_pcBuffer++ = '=';
471-
if ((stLength = (pTxt->m_pcValue ? os_strlen(pTxt->m_pcValue) : 0))) {
472-
os_strncpy(p_pcBuffer, pTxt->m_pcValue, stLength); p_pcBuffer[stLength] = 0;
471+
if ((stLength = (pTxt->m_pcValue ? strlen(pTxt->m_pcValue) : 0))) {
472+
strncpy(p_pcBuffer, pTxt->m_pcValue, stLength); p_pcBuffer[stLength] = 0;
473473
p_pcBuffer += stLength;
474474
}
475475
}
@@ -503,12 +503,12 @@ bool MDNSResponder::stcMDNSServiceTxts::buffer(char* p_pcBuffer) {
503503
for (stcMDNSServiceTxt* pTxt=m_pTxts; ((bResult) && (pTxt)); pTxt = pTxt->m_pNext) {
504504
*(unsigned char*)p_pcBuffer++ = pTxt->length();
505505
size_t stLength;
506-
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? os_strlen(pTxt->m_pcKey) : 0))))) {
507-
os_memcpy(p_pcBuffer, pTxt->m_pcKey, stLength);
506+
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? strlen(pTxt->m_pcKey) : 0))))) {
507+
memcpy(p_pcBuffer, pTxt->m_pcKey, stLength);
508508
p_pcBuffer += stLength;
509509
*p_pcBuffer++ = '=';
510-
if ((stLength = (pTxt->m_pcValue ? os_strlen(pTxt->m_pcValue) : 0))) {
511-
os_memcpy(p_pcBuffer, pTxt->m_pcValue, stLength);
510+
if ((stLength = (pTxt->m_pcValue ? strlen(pTxt->m_pcValue) : 0))) {
511+
memcpy(p_pcBuffer, pTxt->m_pcValue, stLength);
512512
p_pcBuffer += stLength;
513513
}
514514
}
@@ -532,7 +532,7 @@ bool MDNSResponder::stcMDNSServiceTxts::compare(const MDNSResponder::stcMDNSServ
532532
bResult = ((pOtherTxt) &&
533533
(pTxt->m_pcValue) &&
534534
(pOtherTxt->m_pcValue) &&
535-
(os_strlen(pTxt->m_pcValue) == os_strlen(pOtherTxt->m_pcValue)) &&
535+
(strlen(pTxt->m_pcValue) == strlen(pOtherTxt->m_pcValue)) &&
536536
(0 == strcmp(pTxt->m_pcValue, pOtherTxt->m_pcValue)));
537537
}
538538
// Compare B->A
@@ -541,7 +541,7 @@ bool MDNSResponder::stcMDNSServiceTxts::compare(const MDNSResponder::stcMDNSServ
541541
bResult = ((pTxt) &&
542542
(pOtherTxt->m_pcValue) &&
543543
(pTxt->m_pcValue) &&
544-
(os_strlen(pOtherTxt->m_pcValue) == os_strlen(pTxt->m_pcValue)) &&
544+
(strlen(pOtherTxt->m_pcValue) == strlen(pTxt->m_pcValue)) &&
545545
(0 == strcmp(pOtherTxt->m_pcValue, pTxt->m_pcValue)));
546546
}
547547
}
@@ -660,7 +660,7 @@ bool MDNSResponder::stcMDNS_RRDomain::addLabel(const char* p_pcLabel,
660660
bool bResult = false;
661661

662662
size_t stLength = (p_pcLabel
663-
? (os_strlen(p_pcLabel) + (p_bPrependUnderline ? 1 : 0))
663+
? (strlen(p_pcLabel) + (p_bPrependUnderline ? 1 : 0))
664664
: 0);
665665
if ((MDNS_DOMAIN_LABEL_MAXLENGTH >= stLength) &&
666666
(MDNS_DOMAIN_MAXLENGTH >= (m_u16NameLength + (1 + stLength)))) {
@@ -673,7 +673,7 @@ bool MDNSResponder::stcMDNS_RRDomain::addLabel(const char* p_pcLabel,
673673
m_acName[m_u16NameLength++] = '_';
674674
--stLength;
675675
}
676-
os_strncpy(&(m_acName[m_u16NameLength]), p_pcLabel, stLength); m_acName[m_u16NameLength + stLength] = 0;
676+
strncpy(&(m_acName[m_u16NameLength]), p_pcLabel, stLength); m_acName[m_u16NameLength + stLength] = 0;
677677
m_u16NameLength += stLength;
678678
}
679679
bResult = true;
@@ -1235,10 +1235,10 @@ bool MDNSResponder::stcMDNSService::setName(const char* p_pcName) {
12351235
bool bResult = false;
12361236

12371237
releaseName();
1238-
size_t stLength = (p_pcName ? os_strlen(p_pcName) : 0);
1238+
size_t stLength = (p_pcName ? strlen(p_pcName) : 0);
12391239
if (stLength) {
12401240
if ((bResult = (0 != (m_pcName = new char[stLength + 1])))) {
1241-
os_strncpy(m_pcName, p_pcName, stLength);
1241+
strncpy(m_pcName, p_pcName, stLength);
12421242
m_pcName[stLength] = 0;
12431243
}
12441244
}
@@ -1268,10 +1268,10 @@ bool MDNSResponder::stcMDNSService::setService(const char* p_pcService) {
12681268
bool bResult = false;
12691269

12701270
releaseService();
1271-
size_t stLength = (p_pcService ? os_strlen(p_pcService) : 0);
1271+
size_t stLength = (p_pcService ? strlen(p_pcService) : 0);
12721272
if (stLength) {
12731273
if ((bResult = (0 != (m_pcService = new char[stLength + 1])))) {
1274-
os_strncpy(m_pcService, p_pcService, stLength);
1274+
strncpy(m_pcService, p_pcService, stLength);
12751275
m_pcService[stLength] = 0;
12761276
}
12771277
}
@@ -1301,10 +1301,10 @@ bool MDNSResponder::stcMDNSService::setProtocol(const char* p_pcProtocol) {
13011301
bool bResult = false;
13021302

13031303
releaseProtocol();
1304-
size_t stLength = (p_pcProtocol ? os_strlen(p_pcProtocol) : 0);
1304+
size_t stLength = (p_pcProtocol ? strlen(p_pcProtocol) : 0);
13051305
if (stLength) {
13061306
if ((bResult = (0 != (m_pcProtocol = new char[stLength + 1])))) {
1307-
os_strncpy(m_pcProtocol, p_pcProtocol, stLength);
1307+
strncpy(m_pcProtocol, p_pcProtocol, stLength);
13081308
m_pcProtocol[stLength] = 0;
13091309
}
13101310
}

tests/host/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ ARDUINO_LIBS := \
237237
ESP8266mDNS/src/LEAmDNS_Helpers.cpp \
238238
ESP8266mDNS/src/LEAmDNS_Structs.cpp \
239239
ESP8266mDNS/src/LEAmDNS_Transfer.cpp \
240+
ESP8266mDNS/src/ESP8266mDNS.cpp \
240241
ArduinoOTA/ArduinoOTA.cpp \
241242
DNSServer/src/DNSServer.cpp \
242243
ESP8266AVRISP/src/ESP8266AVRISP.cpp \

0 commit comments

Comments
 (0)