MDNSResponder: Add method to get TXT key values. (#5135)
This commit is contained in:
		
							parent
							
								
									76f0a80fe7
								
							
						
					
					
						commit
						1b2f34b0d6
					
				| @ -245,6 +245,16 @@ mdns_result_t * MDNSResponder::_getResult(int idx){ | |||||||
|     return result; |     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) { | String MDNSResponder::hostname(int idx) { | ||||||
|     mdns_result_t * result = _getResult(idx); |     mdns_result_t * result = _getResult(idx); | ||||||
|     if(!result){ |     if(!result){ | ||||||
| @ -333,13 +343,17 @@ String MDNSResponder::txt(int idx, const char * key) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String MDNSResponder::txt(int idx, int txtIdx) { | String MDNSResponder::txt(int idx, int txtIdx) { | ||||||
|     mdns_result_t * result = _getResult(idx); |     mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx); | ||||||
|     if(!result){ |     return !resultTxt | ||||||
|         log_e("Result %d not found", idx); |         ? "" | ||||||
|         return ""; |         : 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; | MDNSResponder MDNS; | ||||||
|  | |||||||
| @ -111,11 +111,13 @@ public: | |||||||
|   bool hasTxt(int idx, const char * key); |   bool hasTxt(int idx, const char * key); | ||||||
|   String txt(int idx, const char * key); |   String txt(int idx, const char * key); | ||||||
|   String txt(int idx, int txtIdx); |   String txt(int idx, int txtIdx); | ||||||
|  |   String txtKey(int idx, int txtIdx); | ||||||
|    |    | ||||||
| private: | private: | ||||||
|   String _hostname; |   String _hostname; | ||||||
|   mdns_result_t * results; |   mdns_result_t * results; | ||||||
|   mdns_result_t * _getResult(int idx); |   mdns_result_t * _getResult(int idx); | ||||||
|  |   mdns_txt_item_t * _getResultTxt(int idx, int txtIdx); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern MDNSResponder MDNS; | extern MDNSResponder MDNS; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user