MDNSResponder: Add method to get TXT key values. (#5135)

This commit is contained in:
Alexey D. Filimonov 2021-05-18 13:51:43 +03:00 committed by GitHub
parent 76f0a80fe7
commit 1b2f34b0d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View File

@ -245,6 +245,16 @@ mdns_result_t * MDNSResponder::_getResult(int idx){
return result;
}
mdns_txt_item_t * MDNSResponder::_getResultTxt(int idx, int txtIdx){
mdns_result_t * result = _getResult(idx);
if(!result){
log_e("Result %d not found", idx);
return NULL;
}
if (txtIdx >= result->txt_count) return NULL;
return &result->txt[txtIdx];
}
String MDNSResponder::hostname(int idx) {
mdns_result_t * result = _getResult(idx);
if(!result){
@ -333,13 +343,17 @@ String MDNSResponder::txt(int idx, const char * key) {
}
String MDNSResponder::txt(int idx, int txtIdx) {
mdns_result_t * result = _getResult(idx);
if(!result){
log_e("Result %d not found", idx);
return "";
mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx);
return !resultTxt
? ""
: resultTxt->value;
}
if (txtIdx >= result->txt_count) return "";
return result->txt[txtIdx].value;
String MDNSResponder::txtKey(int idx, int txtIdx) {
mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx);
return !resultTxt
? ""
: resultTxt->key;
}
MDNSResponder MDNS;

View File

@ -111,11 +111,13 @@ public:
bool hasTxt(int idx, const char * key);
String txt(int idx, const char * key);
String txt(int idx, int txtIdx);
String txtKey(int idx, int txtIdx);
private:
String _hostname;
mdns_result_t * results;
mdns_result_t * _getResult(int idx);
mdns_txt_item_t * _getResultTxt(int idx, int txtIdx);
};
extern MDNSResponder MDNS;