Skip to content

Commit 1b2f34b

Browse files
authored
MDNSResponder: Add method to get TXT key values. (#5135)
1 parent 76f0a80 commit 1b2f34b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

libraries/ESPmDNS/src/ESPmDNS.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ mdns_result_t * MDNSResponder::_getResult(int idx){
245245
return result;
246246
}
247247

248+
mdns_txt_item_t * MDNSResponder::_getResultTxt(int idx, int txtIdx){
249+
mdns_result_t * result = _getResult(idx);
250+
if(!result){
251+
log_e("Result %d not found", idx);
252+
return NULL;
253+
}
254+
if (txtIdx >= result->txt_count) return NULL;
255+
return &result->txt[txtIdx];
256+
}
257+
248258
String MDNSResponder::hostname(int idx) {
249259
mdns_result_t * result = _getResult(idx);
250260
if(!result){
@@ -333,13 +343,17 @@ String MDNSResponder::txt(int idx, const char * key) {
333343
}
334344

335345
String MDNSResponder::txt(int idx, int txtIdx) {
336-
mdns_result_t * result = _getResult(idx);
337-
if(!result){
338-
log_e("Result %d not found", idx);
339-
return "";
340-
}
341-
if (txtIdx >= result->txt_count) return "";
342-
return result->txt[txtIdx].value;
346+
mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx);
347+
return !resultTxt
348+
? ""
349+
: resultTxt->value;
350+
}
351+
352+
String MDNSResponder::txtKey(int idx, int txtIdx) {
353+
mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx);
354+
return !resultTxt
355+
? ""
356+
: resultTxt->key;
343357
}
344358

345359
MDNSResponder MDNS;

libraries/ESPmDNS/src/ESPmDNS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ class MDNSResponder {
111111
bool hasTxt(int idx, const char * key);
112112
String txt(int idx, const char * key);
113113
String txt(int idx, int txtIdx);
114+
String txtKey(int idx, int txtIdx);
114115

115116
private:
116117
String _hostname;
117118
mdns_result_t * results;
118119
mdns_result_t * _getResult(int idx);
120+
mdns_txt_item_t * _getResultTxt(int idx, int txtIdx);
119121
};
120122

121123
extern MDNSResponder MDNS;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy