Commit Graph

21 Commits

Author SHA1 Message Date
Abtin Keshavarzian b3d3b5c3c7 [netdiag] require 'RD:' prefix for vendor name on reference devices (#12233)
When `OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` is active, this
change mandates that the vendor name string MUST begin with the "RD:"
prefix. This ensures that reference devices are clearly and
consistently identifiable through network diagnostic queries.

The enforcement is applied at two levels:

- A compile-time `static_assert` is added to validate the default
  `OPENTHREAD_CONFIG_NET_DIAG_VENDOR_NAME` at build time. This uses a
  new `constexpr` helper utility `CheckConstStringPrefix()`.

- A runtime check is added to `otThreadSetVendorName()`, which will
  now return `OT_ERROR_INVALID_ARGS` if an invalid name is provided
  on a reference device build.

All related test configurations (`scan-build`, `toranj`, `nexus`) and
CLI tests are updated to reflect this new requirement and validate
it.
2026-01-16 10:20:13 -08:00
Abtin Keshavarzian a57d927b0a [string] add ParseDigit(), ParseHexDigit(), and other helper functions (#10282)
This commit adds a set of helper functions to parse a given digit or
hex digit character to its numeric value, or to check if a given
character is a digit, uppercase, or lowercase letter.
2024-05-22 14:37:22 -07:00
Abtin Keshavarzian a69c2db333 [meshcop] simplify processing of Commissioner ID TLV (#9543)
This commit updates CommissionerIdTlv to be defined as `StringTlvInfo`
(a TLV with a UTF-8 string value with a specified maximum length). This
allows us to use `Tlv` helper methods to `Find` and `Append` this
TLV, simplifying the code.

This commit also adds a helper `StringCopy()` method that copies a
C string into a given target string buffer array if it fits in the array.
This method can also optionally perform an encoding check on the string,
such as a UTF-8 encoding check. This helper method is used to simplify
setting different strings, such as Commissioner ID, Provisioning URL,
Vendor Name, etc.
2023-10-18 16:11:49 -07:00
Abtin Keshavarzian a259d23e7f [string] add StringParseUint8() helper function (#9026)
This commit adds a helper function to parse a decimal number from a
given string as `uint8_t` and skip over the parsed characters. This
is used to simplify the methods parsing IPv6/IPv4 address or prefix
from a string.
2023-05-09 12:54:39 -07:00
Yakun Xu 0e667b8e03 [test] use cmake to run unit tests (#8724)
This commit migrates unit tests to cmake.
* build unit tests with cmake
* add missing tests in cmake
* use ctest
* add platform udp stubs for test platform
* skip some static_assert with gcc-4
2023-02-09 10:19:01 -08:00
Abtin Keshavarzian a4cba16c39 [common] add BinarySearch module and Stringfy (#7294)
This commit adds set of generic binary search related functions in
OpenThread core under `BinarySearch` module. The binary search module
replaces and enhances the existing `Lookup` table module (which was
limited to search based on strings and mainly used by CLI to map from
command string to a handler function).

This commit also adds a new class `Stringfy` in `string.hpp` to help
convert from a set of `uint16_t` values (e.g., a non-sequential
`enum`) to strings using binary search in a table. The new methods are
used for converting `Coap::Code` and `IpProto` enumerations to
corresponding strings.
2022-01-10 13:19:34 -08:00
Abtin Keshavarzian 07031e1651 [string] new functions for case-insensitive comparison (#7189)
This commit adds new string helper functions to convert between
lowercase and uppercase letters. It also adds new function
`StringStartsWith()` which determines whether the string starts with
a given prefix string and `StringMatch()` which compares and matches
two strings.

This commit also adds a new mechanism in all string helper functions
allowing the caller to specify the match mode to be used when
comparing strings: Either an exact match of characters, or a
case-insensitive match where uppercase and lowercase characters are
treated as equal.

This commit also updates `test_string` unit test to validate the new
functions and behaviors.
2021-11-23 16:31:18 -08:00
whd e2f0afab5d [network-name] implement additional validation rules (#6988)
According to SPEC-981, we need to verify 3 more things while setting a
network name:
- The name length >= 1.
- There are no UTF control characters in the name.
- There are no UTF NUL characters in the name. This is covered by the
  second rule.
2021-09-09 15:41:06 -07:00
Abtin Keshavarzian 57d072d352 [test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.

This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
2021-06-28 11:38:10 -07:00
Abtin Keshavarzian d47a3fa9ad [string] new StringFind()/StringEndsWith() for a sub-string (#6733)
This commit adds a new flavor of function `StringFind()` which finds
the first occurrence of a given sub-string within a string. It also
adds `StringEndsWith()` function that works with a sub-string. The
unit test `test_string` is also updated to cover the new behavior of
the newly added function.
2021-06-17 10:13:03 -07:00
Abtin Keshavarzian 5915483063 [string] change String<kSize> to inherit from StringWriter (#6658)
This commit changes the `String<kSize>` class to inherit from
`StringWriter` class. It helps simplify their use allowing
`StringWriter` methods to be directly called on an `String` instance
while ensuring the implementation is still shared among all template
variants of `String<kSize>` class. This change also ensures that
`String<kSize>` is always initialized and set to an empty string from
its constructor.
2021-05-21 12:08:26 -07:00
Abtin Keshavarzian f4001aa26d [log] fix uninitialized string use (#6584)
This commit fixes an issue with some of the log related methods where
`String` object may be used without being initialized (this was added
from commit b39f5b6dd and PR #6564).

This commit ensures that `String` variable definitions are always
immediately  followed by a `StringWriter()` definition which then
initializes the string buffer (sets it as empty).

This commit also updates `test_string` unit test.
2021-05-06 19:27:58 -07:00
Yakun Xu b39f5b6dd2 [string] introduce StringWriter class (#6564)
This commit moves methods of String out of the header file to save code
size.

Since most use cases of String writers ignores errors, this commit
changes the return of writers to the Writer object itself for chained
writes.
2021-05-05 21:52:59 -07:00
Abtin Keshavarzian 73126f7099 [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.
2020-12-08 12:20:19 -08:00
Moandor c7192ba798 [string] add UTF-8 validation (#5810) 2020-11-30 08:33:05 -08:00
Abtin Keshavarzian 612e10e664 [error] add missing IgnoreError (#4931) 2020-05-06 22:05:25 -07:00
Jonathan Hui 71a7e47c81 [utils] remove strnlen (#4483) 2020-01-22 13:39:25 -08:00
Abtin Keshavarzian f10c6c36fd [unit-test] remove (unnecessary) ENABLE_TEST_MAIN definition (#4367) 2019-12-11 09:16:48 -08:00
Abtin Keshavarzian e71bd6267e [test] fix PRETTY_FILES definition in unit test makefile (#3532)
The `test_string` source is also made "pretty".
2019-01-29 11:55:16 -08:00
Jonathan Hui 9d585edc46 [types] move types into specific headers (#2946) 2018-08-08 11:19:41 -07:00
Abtin Keshavarzian 4b918f85f0 [string] adding ot::String<size> class (#2764)
This commit adds a new template class `ot::String<size>` which
implements a fixed-length character string. This class is then used as
return value of `ToString()` methods from different classes. This
simplifies the `ToString()` implementation and its use. This commit
also adds a unit test for `String`.
2018-06-11 09:10:52 -07:00