Skip to content

use newlib api in new mDNS, fix host using mDNS #5545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
u8HostOrServiceReplies |= (pService->m_u8ReplyMask |= u8ReplyMaskForQuestion);
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()); } );
/*if ((u8ReplyMaskForQuestion) &&
(0 == os_strcmp("hap", pService->m_pcService))) {
(0 == strcmp("hap", pService->m_pcService))) {
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());
}*/

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

/*if ((0 == os_strcmp("hap", pService->m_pcService))) {
/*if ((0 == strcmp("hap", pService->m_pcService))) {
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);
}*/

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

if ((u8ReplyNeeded) &&
(0 == os_strcmp("hap", pService->m_pcService))) {
(0 == strcmp("hap", pService->m_pcService))) {
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()););
}
}
46 changes: 23 additions & 23 deletions libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp
Original file line number Diff line number Diff line change
@@ -102,19 +102,19 @@ namespace MDNSImplementation {
const char* pFoundDivider = strrstr(p_rpcDomain, pcDivider);
if (pFoundDivider) { // maybe already extended
char* pEnd = 0;
unsigned long ulIndex = strtoul((pFoundDivider + os_strlen(pcDivider)), &pEnd, 10);
unsigned long ulIndex = strtoul((pFoundDivider + strlen(pcDivider)), &pEnd, 10);
if ((ulIndex) &&
((pEnd - p_rpcDomain) == os_strlen(p_rpcDomain)) &&
((pEnd - p_rpcDomain) == (ptrdiff_t)strlen(p_rpcDomain)) &&
(!*pEnd)) { // Valid (old) index found

char acIndexBuffer[16];
sprintf(acIndexBuffer, "%lu", (++ulIndex));
size_t stLength = ((pFoundDivider - p_rpcDomain + os_strlen(pcDivider)) + os_strlen(acIndexBuffer) + 1);
size_t stLength = ((pFoundDivider - p_rpcDomain + strlen(pcDivider)) + strlen(acIndexBuffer) + 1);
char* pNewHostname = new char[stLength];
if (pNewHostname) {
memcpy(pNewHostname, p_rpcDomain, (pFoundDivider - p_rpcDomain + os_strlen(pcDivider)));
pNewHostname[pFoundDivider - p_rpcDomain + os_strlen(pcDivider)] = 0;
os_strcat(pNewHostname, acIndexBuffer);
memcpy(pNewHostname, p_rpcDomain, (pFoundDivider - p_rpcDomain + strlen(pcDivider)));
pNewHostname[pFoundDivider - p_rpcDomain + strlen(pcDivider)] = 0;
strcat(pNewHostname, acIndexBuffer);

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

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

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

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

stcMDNSService* pService = 0;
if (((!p_pcName) ||
(MDNS_DOMAIN_LABEL_MAXLENGTH >= os_strlen(p_pcName))) &&
(MDNS_DOMAIN_LABEL_MAXLENGTH >= strlen(p_pcName))) &&
(p_pcService) &&
(MDNS_SERVICE_NAME_LENGTH >= os_strlen(p_pcService)) &&
(MDNS_SERVICE_NAME_LENGTH >= strlen(p_pcService)) &&
(p_pcProtocol) &&
(MDNS_SERVICE_PROTOCOL_LENGTH >= os_strlen(p_pcProtocol)) &&
(MDNS_SERVICE_PROTOCOL_LENGTH >= strlen(p_pcProtocol)) &&
(p_u16Port) &&
(0 != (pService = new stcMDNSService)) &&
(pService->setName(p_pcName ?: m_pcHostname)) &&
@@ -528,23 +528,23 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_allocServiceTxt(MDNSResponder:
(p_pcKey) &&
(MDNS_SERVICE_TXT_MAXLENGTH > (p_pService->m_Txts.length() +
1 + // Length byte
(p_pcKey ? os_strlen(p_pcKey) : 0) +
(p_pcKey ? strlen(p_pcKey) : 0) +
1 + // '='
(p_pcValue ? os_strlen(p_pcValue) : 0)))) {
(p_pcValue ? strlen(p_pcValue) : 0)))) {

pTxt = new stcMDNSServiceTxt;
if (pTxt) {
size_t stLength = (p_pcKey ? os_strlen(p_pcKey) : 0);
size_t stLength = (p_pcKey ? strlen(p_pcKey) : 0);
pTxt->m_pcKey = new char[stLength + 1];
if (pTxt->m_pcKey) {
os_strncpy(pTxt->m_pcKey, p_pcKey, stLength); pTxt->m_pcKey[stLength] = 0;
strncpy(pTxt->m_pcKey, p_pcKey, stLength); pTxt->m_pcKey[stLength] = 0;
}

if (p_pcValue) {
stLength = (p_pcValue ? os_strlen(p_pcValue) : 0);
stLength = (p_pcValue ? strlen(p_pcValue) : 0);
pTxt->m_pcValue = new char[stLength + 1];
if (pTxt->m_pcValue) {
os_strncpy(pTxt->m_pcValue, p_pcValue, stLength); pTxt->m_pcValue[stLength] = 0;
strncpy(pTxt->m_pcValue, p_pcValue, stLength); pTxt->m_pcValue[stLength] = 0;
}
}
pTxt->m_bTemp = p_bTemp;
@@ -578,8 +578,8 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_updateServiceTxt(MDNSResponder
if ((p_pService) &&
(p_pTxt) &&
(MDNS_SERVICE_TXT_MAXLENGTH > (p_pService->m_Txts.length() -
(p_pTxt->m_pcValue ? os_strlen(p_pTxt->m_pcValue) : 0) +
(p_pcValue ? os_strlen(p_pcValue) : 0)))) {
(p_pTxt->m_pcValue ? strlen(p_pTxt->m_pcValue) : 0) +
(p_pcValue ? strlen(p_pcValue) : 0)))) {
p_pTxt->update(p_pcValue);
p_pTxt->m_bTemp = p_bTemp;
}
@@ -615,7 +615,7 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_addServiceTxt(MDNSResponder::s

if ((p_pService) &&
(p_pcKey) &&
(os_strlen(p_pcKey))) {
(strlen(p_pcKey))) {

stcMDNSServiceTxt* pTxt = p_pService->m_Txts.find(p_pcKey);
if (pTxt) {
48 changes: 24 additions & 24 deletions libraries/ESP8266mDNS/src/LEAmDNS_Structs.cpp
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setKey(const char* p_pcKey,
releaseKey();
if (p_stLength) {
if (allocKey(p_stLength)) {
os_strncpy(m_pcKey, p_pcKey, p_stLength);
strncpy(m_pcKey, p_pcKey, p_stLength);
m_pcKey[p_stLength] = 0;
bResult = true;
}
@@ -139,7 +139,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setKey(const char* p_pcKey,
*/
bool MDNSResponder::stcMDNSServiceTxt::setKey(const char* p_pcKey) {

return setKey(p_pcKey, (p_pcKey ? os_strlen(p_pcKey) : 0));
return setKey(p_pcKey, (p_pcKey ? strlen(p_pcKey) : 0));
}

/*
@@ -177,7 +177,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setValue(const char* p_pcValue,
releaseValue();
if (p_stLength) {
if (allocValue(p_stLength)) {
os_strncpy(m_pcValue, p_pcValue, p_stLength);
strncpy(m_pcValue, p_pcValue, p_stLength);
m_pcValue[p_stLength] = 0;
bResult = true;
}
@@ -193,7 +193,7 @@ bool MDNSResponder::stcMDNSServiceTxt::setValue(const char* p_pcValue,
*/
bool MDNSResponder::stcMDNSServiceTxt::setValue(const char* p_pcValue) {

return setValue(p_pcValue, (p_pcValue ? os_strlen(p_pcValue) : 0));
return setValue(p_pcValue, (p_pcValue ? strlen(p_pcValue) : 0));
}

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

size_t stLength = 0;
if (m_pcKey) {
stLength += os_strlen(m_pcKey); // Key
stLength += strlen(m_pcKey); // Key
stLength += 1; // '='
stLength += (m_pcValue ? os_strlen(m_pcValue) : 0); // Value
stLength += (m_pcValue ? strlen(m_pcValue) : 0); // Value
}
return stLength;
}
@@ -461,15 +461,15 @@ bool MDNSResponder::stcMDNSServiceTxts::c_str(char* p_pcBuffer) {
*p_pcBuffer = 0;
for (stcMDNSServiceTxt* pTxt=m_pTxts; ((bResult) && (pTxt)); pTxt = pTxt->m_pNext) {
size_t stLength;
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? os_strlen(pTxt->m_pcKey) : 0))))) {
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? strlen(pTxt->m_pcKey) : 0))))) {
if (pTxt != m_pTxts) {
*p_pcBuffer++ = ';';
}
os_strncpy(p_pcBuffer, pTxt->m_pcKey, stLength); p_pcBuffer[stLength] = 0;
strncpy(p_pcBuffer, pTxt->m_pcKey, stLength); p_pcBuffer[stLength] = 0;
p_pcBuffer += stLength;
*p_pcBuffer++ = '=';
if ((stLength = (pTxt->m_pcValue ? os_strlen(pTxt->m_pcValue) : 0))) {
os_strncpy(p_pcBuffer, pTxt->m_pcValue, stLength); p_pcBuffer[stLength] = 0;
if ((stLength = (pTxt->m_pcValue ? strlen(pTxt->m_pcValue) : 0))) {
strncpy(p_pcBuffer, pTxt->m_pcValue, stLength); p_pcBuffer[stLength] = 0;
p_pcBuffer += stLength;
}
}
@@ -503,12 +503,12 @@ bool MDNSResponder::stcMDNSServiceTxts::buffer(char* p_pcBuffer) {
for (stcMDNSServiceTxt* pTxt=m_pTxts; ((bResult) && (pTxt)); pTxt = pTxt->m_pNext) {
*(unsigned char*)p_pcBuffer++ = pTxt->length();
size_t stLength;
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? os_strlen(pTxt->m_pcKey) : 0))))) {
os_memcpy(p_pcBuffer, pTxt->m_pcKey, stLength);
if ((bResult = (0 != (stLength = (pTxt->m_pcKey ? strlen(pTxt->m_pcKey) : 0))))) {
memcpy(p_pcBuffer, pTxt->m_pcKey, stLength);
p_pcBuffer += stLength;
*p_pcBuffer++ = '=';
if ((stLength = (pTxt->m_pcValue ? os_strlen(pTxt->m_pcValue) : 0))) {
os_memcpy(p_pcBuffer, pTxt->m_pcValue, stLength);
if ((stLength = (pTxt->m_pcValue ? strlen(pTxt->m_pcValue) : 0))) {
memcpy(p_pcBuffer, pTxt->m_pcValue, stLength);
p_pcBuffer += stLength;
}
}
@@ -532,7 +532,7 @@ bool MDNSResponder::stcMDNSServiceTxts::compare(const MDNSResponder::stcMDNSServ
bResult = ((pOtherTxt) &&
(pTxt->m_pcValue) &&
(pOtherTxt->m_pcValue) &&
(os_strlen(pTxt->m_pcValue) == os_strlen(pOtherTxt->m_pcValue)) &&
(strlen(pTxt->m_pcValue) == strlen(pOtherTxt->m_pcValue)) &&
(0 == strcmp(pTxt->m_pcValue, pOtherTxt->m_pcValue)));
}
// Compare B->A
@@ -541,7 +541,7 @@ bool MDNSResponder::stcMDNSServiceTxts::compare(const MDNSResponder::stcMDNSServ
bResult = ((pTxt) &&
(pOtherTxt->m_pcValue) &&
(pTxt->m_pcValue) &&
(os_strlen(pOtherTxt->m_pcValue) == os_strlen(pTxt->m_pcValue)) &&
(strlen(pOtherTxt->m_pcValue) == strlen(pTxt->m_pcValue)) &&
(0 == strcmp(pOtherTxt->m_pcValue, pTxt->m_pcValue)));
}
}
@@ -660,7 +660,7 @@ bool MDNSResponder::stcMDNS_RRDomain::addLabel(const char* p_pcLabel,
bool bResult = false;

size_t stLength = (p_pcLabel
? (os_strlen(p_pcLabel) + (p_bPrependUnderline ? 1 : 0))
? (strlen(p_pcLabel) + (p_bPrependUnderline ? 1 : 0))
: 0);
if ((MDNS_DOMAIN_LABEL_MAXLENGTH >= stLength) &&
(MDNS_DOMAIN_MAXLENGTH >= (m_u16NameLength + (1 + stLength)))) {
@@ -673,7 +673,7 @@ bool MDNSResponder::stcMDNS_RRDomain::addLabel(const char* p_pcLabel,
m_acName[m_u16NameLength++] = '_';
--stLength;
}
os_strncpy(&(m_acName[m_u16NameLength]), p_pcLabel, stLength); m_acName[m_u16NameLength + stLength] = 0;
strncpy(&(m_acName[m_u16NameLength]), p_pcLabel, stLength); m_acName[m_u16NameLength + stLength] = 0;
m_u16NameLength += stLength;
}
bResult = true;
@@ -1235,10 +1235,10 @@ bool MDNSResponder::stcMDNSService::setName(const char* p_pcName) {
bool bResult = false;

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

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

releaseProtocol();
size_t stLength = (p_pcProtocol ? os_strlen(p_pcProtocol) : 0);
size_t stLength = (p_pcProtocol ? strlen(p_pcProtocol) : 0);
if (stLength) {
if ((bResult = (0 != (m_pcProtocol = new char[stLength + 1])))) {
os_strncpy(m_pcProtocol, p_pcProtocol, stLength);
strncpy(m_pcProtocol, p_pcProtocol, stLength);
m_pcProtocol[stLength] = 0;
}
}
1 change: 1 addition & 0 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
@@ -237,6 +237,7 @@ ARDUINO_LIBS := \
ESP8266mDNS/src/LEAmDNS_Helpers.cpp \
ESP8266mDNS/src/LEAmDNS_Structs.cpp \
ESP8266mDNS/src/LEAmDNS_Transfer.cpp \
ESP8266mDNS/src/ESP8266mDNS.cpp \
ArduinoOTA/ArduinoOTA.cpp \
DNSServer/src/DNSServer.cpp \
ESP8266AVRISP/src/ESP8266AVRISP.cpp \