mirror of
https://github.com/espressif/openthread.git
synced 2026-08-07 03:07:47 +00:00
[dns] add helper methods to append/parse DNS names (#5922)
This commit adds `Dns::Name` type which provides a set of helper methods to encode/decode DNS names. `AppendName()` method encodes and appends a full name (e.g., "test.example.com") to a message. Other helper methods enable appending labels (or groups of labels) and/or constructing a compressed name (using pointer labels). `ParseName()` method parses and skips over a full name in a message. `ReadLabel()` method reads labels one by one and works independently of whether the encoded name is compressed or not. `ReadName()` method read an entire name from message. The new methods are used in `Dns::Client`. This commit also add a unit test `test-dns` covering the behavior of the newly added helper methods. Finally, this commit adds few helper methods in `ResourceRecords` to get the size and check the type of a DNS record.
This commit is contained in:
@@ -154,6 +154,27 @@ void TestUtf8(void)
|
||||
printf(" -- PASS\n");
|
||||
}
|
||||
|
||||
void TestStringFind(void)
|
||||
{
|
||||
char emptyString[1] = {'\0'};
|
||||
char testString[] = "foo.bar\\.";
|
||||
|
||||
printf("\nTest 6: StringFind() function\n");
|
||||
|
||||
VerifyOrQuit(StringFind(testString, 'f') == testString, "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(testString, 'o') == &testString[1], "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(testString, '.') == &testString[3], "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(testString, 'r') == &testString[6], "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(testString, '\\') == &testString[7], "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(testString, 'x') == nullptr, "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(testString, ',') == nullptr, "StringFind() failed");
|
||||
|
||||
VerifyOrQuit(StringFind(emptyString, 'f') == nullptr, "StringFind() failed");
|
||||
VerifyOrQuit(StringFind(emptyString, '.') == nullptr, "StringFind() failed");
|
||||
|
||||
printf(" -- PASS\n");
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
@@ -161,6 +182,7 @@ int main(void)
|
||||
ot::TestString();
|
||||
ot::TestStringLength();
|
||||
ot::TestUtf8();
|
||||
ot::TestStringFind();
|
||||
printf("\nAll tests passed.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user