diff options
author | Ed Tanous <edtanous@google.com> | 2021-09-14 03:00:19 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-09-22 20:31:26 +0300 |
commit | c0bd5e4b37f65ce29a392594d1ef240c64c99734 (patch) | |
tree | c63ad3326fd6bb871b4031ddf067151ce444fda1 /redfish-core/lib | |
parent | 58e42b189dedd843f721b3a1c943f95ede0b2ca7 (diff) | |
download | bmcweb-c0bd5e4b37f65ce29a392594d1ef240c64c99734.tar.xz |
Move log service file parsing to use from_chars
std::from_chars seems to be what most other bmcweb code has moved to,
and allows removal of exceptions usage.
Tested:
Ran redfishtool -S Always -A Session -u root -p 0penBmc -r 192.168.7.2 raw GET "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/1632252609998258"
And observed that the uri component got parsed properly.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Icd4808196eeae0f8a19a208a065b5f2f4f0b050c
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/log_services.hpp | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 6ddd6d6f91..3b9069f179 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -332,44 +332,18 @@ inline static bool tsStr.remove_suffix(tsStr.size() - underscorePos); std::string_view indexStr(entryID); indexStr.remove_prefix(underscorePos + 1); - std::size_t pos; - try - { - index = std::stoul(std::string(indexStr), &pos); - } - catch (std::invalid_argument&) - { - messages::resourceMissingAtURI(asyncResp->res, entryID); - return false; - } - catch (std::out_of_range&) - { - messages::resourceMissingAtURI(asyncResp->res, entryID); - return false; - } - if (pos != indexStr.size()) + auto [ptr, ec] = std::from_chars( + indexStr.data(), indexStr.data() + indexStr.size(), index); + if (ec != std::errc()) { messages::resourceMissingAtURI(asyncResp->res, entryID); return false; } } // Timestamp has no index - std::size_t pos; - try - { - timestamp = std::stoull(std::string(tsStr), &pos); - } - catch (std::invalid_argument&) - { - messages::resourceMissingAtURI(asyncResp->res, entryID); - return false; - } - catch (std::out_of_range&) - { - messages::resourceMissingAtURI(asyncResp->res, entryID); - return false; - } - if (pos != tsStr.size()) + auto [ptr, ec] = + std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp); + if (ec != std::errc()) { messages::resourceMissingAtURI(asyncResp->res, entryID); return false; |