[dns-header] add common TXT record entry parsing API (#6157)

This commit adds a new public `ot` API for parsing an encoded DNS TXT
record data into `TxtEntry` key/value pairs. It also updates the TXT
data iterator model used for going through all TXT entries. The new
iterator definition provides a small buffer to store the key string.
This helps simplify the definition of `otDnsTxtEntry` to use
null-terminated C string for the key. The new parsing APIs are used in
CLI module.

This commit also fixes an issue with `TxtEntry::AppendEntries()` using
incorrect value for the key length.

Finally, this commit adds a test covering the behavior of all
`TxtEntry` related methods (encoding and parsing TXT data) in the unit
test `test_dns`.
This commit is contained in:
Abtin Keshavarzian
2021-02-19 16:17:35 -08:00
committed by GitHub
parent 196aa39c38
commit 14ef4e4082
19 changed files with 553 additions and 199 deletions
+2 -2
View File
@@ -106,7 +106,7 @@ class TestDnssd(thread_cert.TestCase):
'weight': 1,
'host': 'host1.default.service.arpa.',
'address': client1_addrs,
'txt_data': b'\x00',
'txt_data': '',
'srv_ttl': lambda x: x > 0,
'txt_ttl': lambda x: x > 0,
'aaaa_ttl': lambda x: x > 0,
@@ -118,7 +118,7 @@ class TestDnssd(thread_cert.TestCase):
'weight': 2,
'host': 'host2.default.service.arpa.',
'address': client2_addrs,
'txt_data': b'\x00',
'txt_data': '',
'srv_ttl': lambda x: x > 0,
'txt_ttl': lambda x: x > 0,
'aaaa_ttl': lambda x: x > 0,