1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-15 00:02:49 +03:00

Functional update, host and service probes (#5653)

* Functional update, host and service probes

* Fix ServiceMonitor.ino warnings

* Adding MDNSServiceQueryCallback functional
ServiceMonitor.ino needs some updates for web page but works on Serial output.

* DynamicServices Functional

* Fix ServiceMonitor to match latest MDNSServiceInfo

* Fix unused variable in LEAdns.h

* mDNS_Clock.ino fix

* example restyle

* Add keyValues and answerInfo

* Waring and formattin fix

* Change     struct MDNSServiceInfo   {  MDNSServiceInfo(MDNSResponder ...
to     struct MDNSServiceInfo { MDNSServiceInfo(MDNSResponder&

* Make AnswerType user friendly

* Update ServiceInfo example

* Code cleanup

* AnswerType update, Astyle update servicemonitor

* Update clock example to webserver

* Second typedef for probe callbacks
Change String -> const char* at multiple locations

* Optimizations

* Update callbacks to void

* esp32 compatibility

* std::map to const char*

* Fix emplace_back call

* Change Dynamic callback to void(...)

* Add WiFi events reset() in close()
This commit is contained in:
hreintke
2019-02-05 04:40:45 +01:00
committed by Develo
parent 848fbf5b4a
commit 82789d201c
7 changed files with 402 additions and 359 deletions

View File

@ -58,7 +58,6 @@ MDNSResponder::MDNSResponder(void)
m_pcHostname(0),
m_pServiceQueries(0),
m_fnServiceTxtCallback(0),
m_pServiceTxtCallbackUserdata(0),
#ifdef ENABLE_ESP_MDNS_RESPONDER_PASSIV_MODE
m_bPassivModeEnabled(true) {
#else
@ -138,7 +137,10 @@ bool MDNSResponder::begin(const char* p_pcHostname,
*/
bool MDNSResponder::close(void) {
_announce(false, true);
m_GotIPHandler.reset(); // reset WiFi event callbacks.
m_DisconnectedHandler.reset();
_announce(false, true);
_resetProbeStatus(false); // Stop probing
_releaseServiceQueries();
@ -148,6 +150,18 @@ bool MDNSResponder::close(void) {
return true;
}
/*
* MDNSResponder::end
*
* Ends the MDNS responder.
* for compatibility with esp32
*
*/
bool MDNSResponder::end(void) {
return close();
}
/*
* MDNSResponder::setHostname
*
@ -464,11 +478,9 @@ bool MDNSResponder::addServiceTxt(String p_strService,
* service TXT items are needed.
*
*/
bool MDNSResponder::setDynamicServiceTxtCallback(MDNSResponder::MDNSDynamicServiceTxtCallbackFn p_fnCallback,
void* p_pUserdata) {
bool MDNSResponder::setDynamicServiceTxtCallback(MDNSResponder::MDNSDynamicServiceTxtCallbackFunc p_fnCallback) {
m_fnServiceTxtCallback = p_fnCallback;
m_pServiceTxtCallbackUserdata = p_pUserdata;
return true;
}
@ -481,15 +493,13 @@ bool MDNSResponder::setDynamicServiceTxtCallback(MDNSResponder::MDNSDynamicServi
*
*/
bool MDNSResponder::setDynamicServiceTxtCallback(MDNSResponder::hMDNSService p_hService,
MDNSResponder::MDNSDynamicServiceTxtCallbackFn p_fnCallback,
void* p_pUserdata) {
MDNSResponder::MDNSDynamicServiceTxtCallbackFunc p_fnCallback) {
bool bResult = false;
stcMDNSService* pService = _findService(p_hService);
if (pService) {
pService->m_fnTxtCallback = p_fnCallback;
pService->m_pTxtCallbackUserdata = p_pUserdata;
bResult = true;
}
@ -766,8 +776,7 @@ uint16_t MDNSResponder::port(const uint32_t p_u32AnswerIndex) {
*/
MDNSResponder::hMDNSServiceQuery MDNSResponder::installServiceQuery(const char* p_pcService,
const char* p_pcProtocol,
MDNSResponder::MDNSServiceQueryCallbackFn p_fnCallback,
void* p_pUserdata) {
MDNSResponder::MDNSServiceQueryCallbackFunc p_fnCallback) {
hMDNSServiceQuery hResult = 0;
stcMDNSServiceQuery* pServiceQuery = 0;
@ -780,7 +789,6 @@ MDNSResponder::hMDNSServiceQuery MDNSResponder::installServiceQuery(const char*
(_buildDomainForService(p_pcService, p_pcProtocol, pServiceQuery->m_ServiceTypeDomain))) {
pServiceQuery->m_fnCallback = p_fnCallback;
pServiceQuery->m_pUserdata = p_pUserdata;
pServiceQuery->m_bLegacyQuery = false;
if (_sendMDNSServiceQuery(*pServiceQuery)) {
@ -822,6 +830,15 @@ uint32_t MDNSResponder::answerCount(const MDNSResponder::hMDNSServiceQuery p_hSe
return (pServiceQuery ? pServiceQuery->answerCount() : 0);
}
std::vector<MDNSResponder::MDNSServiceInfo> MDNSResponder::answerInfo (const MDNSResponder::hMDNSServiceQuery p_hServiceQuery) {
std::vector<MDNSResponder::MDNSServiceInfo> tempVector;
for (uint32_t i=0;i<answerCount(p_hServiceQuery);i++)
{
tempVector.emplace_back(*this,p_hServiceQuery,i);
}
return tempVector;
}
/*
* MDNSResponder::answerServiceDomain
*
@ -1011,7 +1028,7 @@ const char* MDNSResponder::answerTxts(const MDNSResponder::hMDNSServiceQuery p_h
if ((pSQAnswer) &&
(pSQAnswer->m_Txts.m_pTxts) &&
(!pSQAnswer->m_pcTxts)) {
pSQAnswer->m_pcTxts = pSQAnswer->allocTxts(pSQAnswer->m_Txts.c_strLength());
if (pSQAnswer->m_pcTxts) {
pSQAnswer->m_Txts.c_str(pSQAnswer->m_pcTxts);
@ -1020,7 +1037,6 @@ const char* MDNSResponder::answerTxts(const MDNSResponder::hMDNSServiceQuery p_h
return (pSQAnswer ? pSQAnswer->m_pcTxts : 0);
}
/*
* PROBING
*/
@ -1035,15 +1051,18 @@ const char* MDNSResponder::answerTxts(const MDNSResponder::hMDNSServiceQuery p_h
* When succeeded, the host or service domain will be announced by the MDNS responder.
*
*/
bool MDNSResponder::setProbeResultCallback(MDNSResponder::MDNSProbeResultCallbackFn p_fnCallback,
void* p_pUserdata) {
m_HostProbeInformation.m_fnProbeResultCallback = p_fnCallback;
m_HostProbeInformation.m_pProbeResultCallbackUserdata = p_pUserdata;
bool MDNSResponder::setHostProbeResultCallback(MDNSResponder::MDNSHostProbeFn p_fnCallback) {
m_HostProbeInformation.m_fnHostProbeResultCallback = p_fnCallback;
return true;
}
bool MDNSResponder::setHostProbeResultCallback(MDNSHostProbeFn1 pfn) {
using namespace std::placeholders;
return setHostProbeResultCallback(std::bind(pfn, *this, _1, _2));
}
/*
* MDNSResponder::setServiceProbeResultCallback
*
@ -1054,20 +1073,25 @@ bool MDNSResponder::setProbeResultCallback(MDNSResponder::MDNSProbeResultCallbac
*
*/
bool MDNSResponder::setServiceProbeResultCallback(const MDNSResponder::hMDNSService p_hService,
MDNSResponder::MDNSProbeResultCallbackFn p_fnCallback,
void* p_pUserdata) {
MDNSResponder::MDNSServiceProbeFn p_fnCallback) {
bool bResult = false;
stcMDNSService* pService = _findService(p_hService);
if (pService) {
pService->m_ProbeInformation.m_fnProbeResultCallback = p_fnCallback;
pService->m_ProbeInformation.m_pProbeResultCallbackUserdata = p_pUserdata;
pService->m_ProbeInformation.m_fnServiceProbeResultCallback = p_fnCallback;
bResult = true;
}
return bResult;
}
bool MDNSResponder::setServiceProbeResultCallback(const MDNSResponder::hMDNSService p_hService,
MDNSResponder::MDNSServiceProbeFn1 p_fnCallback) {
using namespace std::placeholders;
return setServiceProbeResultCallback(p_hService, std::bind(p_fnCallback, *this, _1, _2, _3));
}
/*
* MISC

View File

@ -109,6 +109,8 @@
#include "include/UdpContext.h"
#include <limits>
#include <PolledTimeout.h>
#include <map>
#include "ESP8266WiFi.h"
@ -186,7 +188,8 @@ public:
}
// Finish MDNS processing
bool close(void);
// for esp32 compatability
bool end(void);
// Change hostname (probing is restarted)
bool setHostname(const char* p_pcHostname);
// for compatibility...
@ -223,6 +226,8 @@ public:
//Warning: this has the side effect of changing the hostname.
//TODO: implement instancename different from hostname
void setInstanceName(const char* p_pcHostname) {setHostname(p_pcHostname);}
// for esp32 compatibilty
void setInstanceName(const String& s_pcHostname) {setInstanceName(s_pcHostname.c_str());}
/**
* hMDNSTxt (opaque handle to access the TXT items)
@ -275,19 +280,16 @@ public:
* MDNSDynamicServiceTxtCallbackFn
* Callback function for dynamic MDNS TXT items
*/
typedef bool (*MDNSDynamicServiceTxtCallbackFn)(MDNSResponder* p_pMDNSResponder,
const hMDNSService p_hService,
void* p_pUserdata);
typedef std::function<void(const hMDNSService p_hService)> MDNSDynamicServiceTxtCallbackFunc;
// Set a global callback for dynamic MDNS TXT items. The callback function is called
// every time, a TXT item is needed for one of the installed services.
bool setDynamicServiceTxtCallback(MDNSDynamicServiceTxtCallbackFn p_fnCallback,
void* p_pUserdata);
bool setDynamicServiceTxtCallback(MDNSDynamicServiceTxtCallbackFunc p_fnCallback);
// Set a service specific callback for dynamic MDNS TXT items. The callback function
// is called every time, a TXT item is needed for the given service.
bool setDynamicServiceTxtCallback(const hMDNSService p_hService,
MDNSDynamicServiceTxtCallbackFn p_fnCallback,
void* p_pUserdata);
MDNSDynamicServiceTxtCallbackFunc p_fnCallback);
// Add a (dynamic) MDNS TXT item ('key' = 'value') to the service
// Dynamic TXT items are removed right after one-time use. So they need to be added
@ -355,16 +357,28 @@ public:
#endif
} enuServiceQueryAnswerType;
enum class AnswerType : uint32_t {
Unknown = 0,
ServiceDomain = ServiceQueryAnswerType_ServiceDomain,
HostDomainAndPort = ServiceQueryAnswerType_HostDomainAndPort,
Txt = ServiceQueryAnswerType_Txts,
#ifdef MDNS_IP4_SUPPORT
IP4Address = ServiceQueryAnswerType_IP4Address,
#endif
#ifdef MDNS_IP6_SUPPORT
IP6Address = ServiceQueryAnswerType_IP6Address,
#endif
};
/**
* MDNSServiceQueryCallbackFn
* Callback function for received answers for dynamic service queries
*/
typedef bool (*MDNSServiceQueryCallbackFn)(MDNSResponder* p_pMDNSResponder,
const hMDNSServiceQuery p_hServiceQuery, // dynamic service query handle
uint32_t p_u32AnswerIndex, // index of the updated answer
uint32_t p_u32ServiceQueryAnswerMask, // flag for the updated answer item
bool p_bSetContent, // true: Answer component set, false: component deleted
void* p_pUserdata); // pUserdata set via 'installServiceQuery'
struct MDNSServiceInfo; // forward declaration
typedef std::function<void(const MDNSServiceInfo& mdnsServiceInfo,
AnswerType answerType , // flag for the updated answer item
bool p_bSetContent // true: Answer component set, false: component deleted
)> MDNSServiceQueryCallbackFunc;
// Install a dynamic service query. For every received answer (part) the given callback
// function is called. The query will be updated every time, the TTL for an answer
@ -379,12 +393,13 @@ public:
// - hasAnswerTxts/answerTxts
hMDNSServiceQuery installServiceQuery(const char* p_pcService,
const char* p_pcProtocol,
MDNSServiceQueryCallbackFn p_fnCallback,
void* p_pUserdata);
MDNSServiceQueryCallbackFunc p_fnCallback);
// Remove a dynamic service query
bool removeServiceQuery(hMDNSServiceQuery p_hServiceQuery);
uint32_t answerCount(const hMDNSServiceQuery p_hServiceQuery);
std::vector<MDNSResponder::MDNSServiceInfo> answerInfo (const MDNSResponder::hMDNSServiceQuery p_hServiceQuery);
const char* answerServiceDomain(const hMDNSServiceQuery p_hServiceQuery,
const uint32_t p_u32AnswerIndex);
bool hasAnswerHostDomain(const hMDNSServiceQuery p_hServiceQuery,
@ -418,28 +433,40 @@ public:
// Get the TXT items as a ';'-separated string
const char* answerTxts(const hMDNSServiceQuery p_hServiceQuery,
const uint32_t p_u32AnswerIndex);
/**
* MDNSProbeResultCallbackFn
* Callback function for (host and service domain) probe results
*/
typedef bool (*MDNSProbeResultCallbackFn)(MDNSResponder* p_pMDNSResponder,
const char* p_pcDomainName,
const hMDNSService p_hMDNSService, // 0 for host domain
bool p_bProbeResult,
void* p_pUserdata);
*/
typedef std::function<void(const char* p_pcDomainName,
bool p_bProbeResult)> MDNSHostProbeFn;
typedef std::function<void(MDNSResponder& resp,
const char* p_pcDomainName,
bool p_bProbeResult)> MDNSHostProbeFn1;
typedef std::function<void(const char* p_pcServiceName,
const hMDNSService p_hMDNSService,
bool p_bProbeResult)> MDNSServiceProbeFn;
typedef std::function<void(MDNSResponder& resp,
const char* p_pcServiceName,
const hMDNSService p_hMDNSService,
bool p_bProbeResult)> MDNSServiceProbeFn1;
// Set a global callback function for host and service probe results
// The callback function is called, when the probeing for the host domain
// The callback function is called, when the probing for the host domain
// (or a service domain, which hasn't got a service specific callback)
// Succeededs or fails.
// Succeeds or fails.
// In case of failure, the failed domain name should be changed.
bool setProbeResultCallback(MDNSProbeResultCallbackFn p_fnCallback,
void* p_pUserdata);
// Set a service specific probe result callcack
bool setServiceProbeResultCallback(const hMDNSService p_hService,
MDNSProbeResultCallbackFn p_fnCallback,
void* p_pUserdata);
bool setHostProbeResultCallback(MDNSHostProbeFn p_fnCallback);
bool setHostProbeResultCallback(MDNSHostProbeFn1 p_fnCallback);
// Set a service specific probe result callback
bool setServiceProbeResultCallback(const MDNSResponder::hMDNSService p_hService,
MDNSServiceProbeFn p_fnCallback);
bool setServiceProbeResultCallback(const MDNSResponder::hMDNSService p_hService,
MDNSServiceProbeFn1 p_fnCallback);
// Application should call this whenever AP is configured/disabled
bool notifyAPChange(void);
@ -462,6 +489,98 @@ public:
protected:
/** STRUCTS **/
/**
* MDNSServiceInfo, used in application callbacks
*/
public:
struct MDNSServiceInfo
{
MDNSServiceInfo(MDNSResponder& p_pM,MDNSResponder::hMDNSServiceQuery p_hS,uint32_t p_u32A)
: p_pMDNSResponder(p_pM),
p_hServiceQuery(p_hS),
p_u32AnswerIndex(p_u32A)
{};
struct CompareKey
{
bool operator()(char const *a, char const *b) const
{
return strcmp(a, b) < 0;
}
};
using KeyValueMap = std::map<const char*, const char*, CompareKey>;
protected:
MDNSResponder& p_pMDNSResponder;
MDNSResponder::hMDNSServiceQuery p_hServiceQuery;
uint32_t p_u32AnswerIndex;
KeyValueMap keyValueMap;
public:
const char* serviceDomain(){
return p_pMDNSResponder.answerServiceDomain(p_hServiceQuery, p_u32AnswerIndex);
};
bool hostDomainAvailable()
{
return (p_pMDNSResponder.hasAnswerHostDomain(p_hServiceQuery, p_u32AnswerIndex));
}
const char* hostDomain(){
return (hostDomainAvailable()) ?
p_pMDNSResponder.answerHostDomain(p_hServiceQuery, p_u32AnswerIndex) : nullptr;
};
bool hostPortAvailable()
{
return (p_pMDNSResponder.hasAnswerPort(p_hServiceQuery, p_u32AnswerIndex));
}
uint16_t hostPort(){
return (hostPortAvailable()) ?
p_pMDNSResponder.answerPort(p_hServiceQuery, p_u32AnswerIndex) : 0;
};
bool IP4AddressAvailable()
{
return (p_pMDNSResponder.hasAnswerIP4Address(p_hServiceQuery,p_u32AnswerIndex ));
}
std::vector<IPAddress> IP4Adresses(){
std::vector<IPAddress> internalIP;
if (IP4AddressAvailable()) {
uint16_t cntIP4Adress = p_pMDNSResponder.answerIP4AddressCount(p_hServiceQuery, p_u32AnswerIndex);
for (uint32_t u2 = 0; u2 < cntIP4Adress; ++u2) {
internalIP.emplace_back(p_pMDNSResponder.answerIP4Address(p_hServiceQuery, p_u32AnswerIndex, u2));
}
}
return internalIP;
};
bool txtAvailable()
{
return (p_pMDNSResponder.hasAnswerTxts(p_hServiceQuery, p_u32AnswerIndex));
}
const char* strKeyValue (){
return (txtAvailable()) ?
p_pMDNSResponder.answerTxts(p_hServiceQuery, p_u32AnswerIndex) : nullptr;
};
const KeyValueMap& keyValues()
{
if (txtAvailable() && keyValueMap.size() == 0)
{
for (auto kv = p_pMDNSResponder._answerKeyValue(p_hServiceQuery, p_u32AnswerIndex);kv != nullptr;kv = kv->m_pNext) {
keyValueMap.emplace(std::pair<const char*,const char*>(kv->m_pcKey,kv->m_pcValue));
}
}
return keyValueMap;
}
const char* value(const char* key)
{
char* result = nullptr;
for (stcMDNSServiceTxt* pTxt=p_pMDNSResponder._answerKeyValue(p_hServiceQuery, p_u32AnswerIndex); pTxt; pTxt=pTxt->m_pNext) {
if ((key) &&
(0 == strcmp(pTxt->m_pcKey, key))) {
result = pTxt->m_pcValue;
break;
}
}
return result;
}
};
protected:
/**
* stcMDNSServiceTxt
*/
@ -792,8 +911,8 @@ protected:
//clsMDNSTimeFlag m_TimeFlag; // Used for probes and announcements
bool m_bConflict;
bool m_bTiebreakNeeded;
MDNSProbeResultCallbackFn m_fnProbeResultCallback;
void* m_pProbeResultCallbackUserdata;
MDNSHostProbeFn m_fnHostProbeResultCallback;
MDNSServiceProbeFn m_fnServiceProbeResultCallback;
stcProbeInformation(void);
@ -813,8 +932,7 @@ protected:
uint16_t m_u16Port;
uint8_t m_u8ReplyMask;
stcMDNSServiceTxts m_Txts;
MDNSDynamicServiceTxtCallbackFn m_fnTxtCallback;
void* m_pTxtCallbackUserdata;
MDNSDynamicServiceTxtCallbackFunc m_fnTxtCallback;
stcProbeInformation m_ProbeInformation;
stcMDNSService(const char* p_pcName = 0,
@ -957,8 +1075,7 @@ protected:
stcMDNSServiceQuery* m_pNext;
stcMDNS_RRDomain m_ServiceTypeDomain; // eg. _http._tcp.local
MDNSServiceQueryCallbackFn m_fnCallback;
void* m_pUserdata;
MDNSServiceQueryCallbackFunc m_fnCallback;
bool m_bLegacyQuery;
uint8_t m_u8SentCount;
esp8266::polledTimeout::oneShot m_ResendTimeout;
@ -1035,8 +1152,7 @@ protected:
stcMDNSServiceQuery* m_pServiceQueries;
WiFiEventHandler m_DisconnectedHandler;
WiFiEventHandler m_GotIPHandler;
MDNSDynamicServiceTxtCallbackFn m_fnServiceTxtCallback;
void* m_pServiceTxtCallbackUserdata;
MDNSDynamicServiceTxtCallbackFunc m_fnServiceTxtCallback;
bool m_bPassivModeEnabled;
stcProbeInformation m_HostProbeInformation;
@ -1271,6 +1387,9 @@ protected:
const char* p_pcValue,
bool p_bTemp);
stcMDNSServiceTxt* _answerKeyValue(const hMDNSServiceQuery p_hServiceQuery,
const uint32_t p_u32AnswerIndex);
bool _collectServiceTxts(stcMDNSService& p_rService);
bool _releaseTempServiceTxts(stcMDNSService& p_rService);
const stcMDNSServiceTxt* _serviceTxts(const char* p_pcName,

View File

@ -776,10 +776,10 @@ bool MDNSResponder::_processPTRAnswer(const MDNSResponder::stcMDNS_RRAnswerPTR*
pSQAnswer->releaseServiceDomain();
bResult = pServiceQuery->addAnswer(pSQAnswer);
p_rbFoundNewKeyAnswer = true;
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_ServiceDomain, true, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this,(hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo, static_cast<AnswerType>(ServiceQueryAnswerType_ServiceDomain), true);
}
}
}
@ -823,7 +823,8 @@ bool MDNSResponder::_processSRVAnswer(const MDNSResponder::stcMDNS_RRAnswerSRV*
p_rbFoundNewKeyAnswer = true;
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_HostDomainAndPort, true, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo, static_cast<AnswerType>(ServiceQueryAnswerType_HostDomainAndPort), true);
}
}
}
@ -870,7 +871,8 @@ bool MDNSResponder::_processTXTAnswer(const MDNSResponder::stcMDNS_RRAnswerTXT*
pSQAnswer->releaseTxts();
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_Txts, true, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo , static_cast<AnswerType>(ServiceQueryAnswerType_Txts), true);
}
}
}
@ -933,9 +935,9 @@ bool MDNSResponder::_processTXTAnswer(const MDNSResponder::stcMDNS_RRAnswerTXT*
(pSQAnswer->addIP4Address(pIP4Address))) {
pSQAnswer->m_u32ContentFlags |= ServiceQueryAnswerType_IP4Address;
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_IP4Address, true, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo (*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo, static_cast<AnswerType>(ServiceQueryAnswerType_IP4Address), true);
}
}
else {
@ -1060,9 +1062,8 @@ bool MDNSResponder::_updateProbeStatus(void) {
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _updateProbeStatus: Done host probing.\n")););
m_HostProbeInformation.m_ProbingStatus = ProbingStatus_Done;
m_HostProbeInformation.m_Timeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());
if (m_HostProbeInformation.m_fnProbeResultCallback) {
m_HostProbeInformation.m_fnProbeResultCallback(this, m_pcHostname, 0, true, m_HostProbeInformation.m_pProbeResultCallbackUserdata);
if (m_HostProbeInformation.m_fnHostProbeResultCallback) {
m_HostProbeInformation.m_fnHostProbeResultCallback(m_pcHostname, true);
}
// Prepare to announce host
@ -1110,21 +1111,9 @@ bool MDNSResponder::_updateProbeStatus(void) {
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _updateProbeStatus: Done service probing %s.%s.%s\n\n"), (pService->m_pcName ?: m_pcHostname), pService->m_pcService, pService->m_pcProtocol););
pService->m_ProbeInformation.m_ProbingStatus = ProbingStatus_Done;
pService->m_ProbeInformation.m_Timeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());
MDNSProbeResultCallbackFn fnProbeResultCallback = 0;
void* pProbeResultCallbackUserdata = 0;
if (pService->m_ProbeInformation.m_fnProbeResultCallback) {
fnProbeResultCallback = pService->m_ProbeInformation.m_fnProbeResultCallback;
pProbeResultCallbackUserdata = pService->m_ProbeInformation.m_pProbeResultCallbackUserdata;
if (pService->m_ProbeInformation.m_fnServiceProbeResultCallback) {
pService->m_ProbeInformation.m_fnServiceProbeResultCallback(pService->m_pcName, pService, true);
}
else {
fnProbeResultCallback = m_HostProbeInformation.m_fnProbeResultCallback;
pProbeResultCallbackUserdata = m_HostProbeInformation.m_pProbeResultCallbackUserdata;
}
if (fnProbeResultCallback) {
fnProbeResultCallback(this, (pService->m_pcName ?: m_pcHostname), pService, true, pProbeResultCallbackUserdata);
}
// Prepare to announce service
pService->m_ProbeInformation.m_u8SentCount = 0;
pService->m_ProbeInformation.m_Timeout.reset(MDNS_ANNOUNCE_DELAY);
@ -1287,10 +1276,9 @@ bool MDNSResponder::_cancelProbingForHost(void) {
bool bResult = false;
m_HostProbeInformation.clear(false);
// Send host notification
if (m_HostProbeInformation.m_fnProbeResultCallback) {
m_HostProbeInformation.m_fnProbeResultCallback(this, m_pcHostname, 0, false, m_HostProbeInformation.m_pProbeResultCallbackUserdata);
if (m_HostProbeInformation.m_fnHostProbeResultCallback) {
m_HostProbeInformation.m_fnHostProbeResultCallback(m_pcHostname, false);
bResult = true;
}
@ -1309,21 +1297,10 @@ bool MDNSResponder::_cancelProbingForService(stcMDNSService& p_rService) {
bool bResult = false;
p_rService.m_ProbeInformation.clear(false);
// Send notification
MDNSProbeResultCallbackFn fnProbeResultCallback = 0;
void* pProbeResultCallbackUserdata = 0;
if (p_rService.m_ProbeInformation.m_fnProbeResultCallback) {
fnProbeResultCallback = p_rService.m_ProbeInformation.m_fnProbeResultCallback;
pProbeResultCallbackUserdata = p_rService.m_ProbeInformation.m_pProbeResultCallbackUserdata;
}
else {
fnProbeResultCallback = m_HostProbeInformation.m_fnProbeResultCallback;
pProbeResultCallbackUserdata = m_HostProbeInformation.m_pProbeResultCallbackUserdata;
}
if (fnProbeResultCallback) {
fnProbeResultCallback(this, (p_rService.m_pcName ?: m_pcHostname), &p_rService, false, pProbeResultCallbackUserdata);
bResult = true;
if (p_rService.m_ProbeInformation.m_fnServiceProbeResultCallback) {
p_rService.m_ProbeInformation.m_fnServiceProbeResultCallback(p_rService.m_pcName,&p_rService,false);
bResult = true;
}
return bResult;
}
@ -1506,7 +1483,8 @@ bool MDNSResponder::_checkServiceQueryCache(void) {
else {
// Timed out! -> Delete
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_ServiceDomain, false, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo, static_cast<AnswerType>(ServiceQueryAnswerType_ServiceDomain), false);
}
DEBUG_EX_INFO(
DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _checkServiceQueryCache: Will remove PTR answer for "));
@ -1563,9 +1541,9 @@ bool MDNSResponder::_checkServiceQueryCache(void) {
// Remove content flags for deleted answer parts
pSQAnswer->m_u32ContentFlags &= ~u32ContentFlags;
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), u32ContentFlags, false, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo,static_cast<AnswerType>(u32ContentFlags), false);
}
}
} // HostDomainAndPort flagged
@ -1601,7 +1579,8 @@ bool MDNSResponder::_checkServiceQueryCache(void) {
pSQAnswer->m_u32ContentFlags &= ~ServiceQueryAnswerType_Txts;
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_Txts, false, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo, static_cast<AnswerType>(ServiceQueryAnswerType_Txts), false);
}
}
} // TXTs flagged
@ -1648,7 +1627,8 @@ bool MDNSResponder::_checkServiceQueryCache(void) {
}
// Notify client
if (pServiceQuery->m_fnCallback) {
pServiceQuery->m_fnCallback(this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer), ServiceQueryAnswerType_IP4Address, false, pServiceQuery->m_pUserdata);
MDNSServiceInfo serviceInfo(*this, (hMDNSServiceQuery)pServiceQuery, pServiceQuery->indexOfAnswer(pSQAnswer));
pServiceQuery->m_fnCallback(serviceInfo, static_cast<AnswerType>(ServiceQueryAnswerType_IP4Address), false);
}
}
} // IP4 flagged

View File

@ -629,20 +629,27 @@ MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_addServiceTxt(MDNSResponder::s
return pResult;
}
MDNSResponder::stcMDNSServiceTxt* MDNSResponder::_answerKeyValue(const hMDNSServiceQuery p_hServiceQuery,
const uint32_t p_u32AnswerIndex) {
stcMDNSServiceQuery* pServiceQuery = _findServiceQuery(p_hServiceQuery);
stcMDNSServiceQuery::stcAnswer* pSQAnswer = (pServiceQuery ? pServiceQuery->answerAtIndex(p_u32AnswerIndex) : 0);
// Fill m_pcTxts (if not already done)
return (pSQAnswer) ? pSQAnswer->m_Txts.m_pTxts : 0;
}
/*
* MDNSResponder::_collectServiceTxts
*/
bool MDNSResponder::_collectServiceTxts(MDNSResponder::stcMDNSService& p_rService) {
bool bResult = (m_fnServiceTxtCallback
? m_fnServiceTxtCallback(this, (hMDNSService)&p_rService, m_pServiceTxtCallbackUserdata)
: true);
if ((bResult) &&
(p_rService.m_fnTxtCallback)) {
bResult = p_rService.m_fnTxtCallback(this, (hMDNSService)&p_rService, p_rService.m_pTxtCallbackUserdata);
// Call Dynamic service callbacks
if (m_fnServiceTxtCallback) {
m_fnServiceTxtCallback((hMDNSService)&p_rService);
}
return bResult;
if (p_rService.m_fnTxtCallback) {
p_rService.m_fnTxtCallback((hMDNSService)&p_rService);
}
return true;
}
/*

View File

@ -1162,8 +1162,8 @@ MDNSResponder::stcProbeInformation::stcProbeInformation(void)
m_Timeout(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max()),
m_bConflict(false),
m_bTiebreakNeeded(false),
m_fnProbeResultCallback(0),
m_pProbeResultCallbackUserdata(0) {
m_fnHostProbeResultCallback(0),
m_fnServiceProbeResultCallback(0) {
}
/*
@ -1177,8 +1177,8 @@ bool MDNSResponder::stcProbeInformation::clear(bool p_bClearUserdata /*= false*/
m_bConflict = false;
m_bTiebreakNeeded = false;
if (p_bClearUserdata) {
m_fnProbeResultCallback = 0;
m_pProbeResultCallbackUserdata = 0;
m_fnHostProbeResultCallback = 0;
m_fnServiceProbeResultCallback = 0;
}
return true;
}
@ -1207,8 +1207,7 @@ MDNSResponder::stcMDNSService::stcMDNSService(const char* p_pcName /*= 0*/,
m_pcProtocol(0),
m_u16Port(0),
m_u8ReplyMask(0),
m_fnTxtCallback(0),
m_pTxtCallbackUserdata(0) {
m_fnTxtCallback(0) {
setName(p_pcName);
setService(p_pcService);
@ -1921,7 +1920,6 @@ MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcIP6Address* MDNSResponder::stc
MDNSResponder::stcMDNSServiceQuery::stcMDNSServiceQuery(void)
: m_pNext(0),
m_fnCallback(0),
m_pUserdata(0),
m_bLegacyQuery(false),
m_u8SentCount(0),
m_ResendTimeout(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max()),
@ -1945,7 +1943,6 @@ MDNSResponder::stcMDNSServiceQuery::~stcMDNSServiceQuery(void) {
bool MDNSResponder::stcMDNSServiceQuery::clear(void) {
m_fnCallback = 0;
m_pUserdata = 0;
m_bLegacyQuery = false;
m_u8SentCount = 0;
m_ResendTimeout.reset(std::numeric_limits<esp8266::polledTimeout::oneShot::timeType>::max());