diff options
author | Ed Tanous <ed@tanous.net> | 2024-03-07 04:36:33 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-03-21 02:29:38 +0300 |
commit | 78d4ec4f0ccc85d92280c8b542f3c516b9e72786 (patch) | |
tree | 2971527976a2b8e39d71593e735869dcc2404865 /redfish-core | |
parent | 2932dcb6139c6241bc7d56bf9cd495be4ddb3455 (diff) | |
download | bmcweb-78d4ec4f0ccc85d92280c8b542f3c516b9e72786.tar.xz |
Clean up event service to use readJson
Use multiple level direct read.
Tested: Visual only. Need help if anyone wants to test.
Change-Id: I8655e74d39edcbab43fcd2a8379b085e91ed00eb
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/lib/event_service.hpp | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp index 8bc8f9b1ae..aebc2824b0 100644 --- a/redfish-core/lib/event_service.hpp +++ b/redfish-core/lib/event_service.hpp @@ -285,8 +285,8 @@ inline void requestRoutesEventDestinationCollection(App& app) std::optional<std::vector<std::string>> msgIds; std::optional<std::vector<std::string>> regPrefixes; std::optional<std::vector<std::string>> resTypes; - std::optional<std::vector<nlohmann::json>> headers; - std::optional<std::vector<nlohmann::json>> mrdJsonArray; + std::optional<std::vector<nlohmann::json::object_t>> headers; + std::optional<std::vector<nlohmann::json::object_t>> mrdJsonArray; if (!json_util::readJsonPatch( req, asyncResp->res, "Destination", destUrl, "Context", context, @@ -467,32 +467,33 @@ inline void requestRoutesEventDestinationCollection(App& app) { size_t cumulativeLen = 0; - for (const nlohmann::json& headerChunk : *headers) + for (const nlohmann::json::object_t& headerChunk : *headers) { - std::string hdr{headerChunk.dump( - -1, ' ', true, nlohmann::json::error_handler_t::replace)}; - cumulativeLen += hdr.length(); - - // This value is selected to mirror http_connection.hpp - constexpr const uint16_t maxHeaderSizeED = 8096; - if (cumulativeLen > maxHeaderSizeED) - { - messages::arraySizeTooLong(asyncResp->res, "HttpHeaders", - maxHeaderSizeED); - return; - } - for (const auto& item : headerChunk.items()) + for (const auto& item : headerChunk) { const std::string* value = - item.value().get_ptr<const std::string*>(); + item.second.get_ptr<const std::string*>(); if (value == nullptr) { messages::propertyValueFormatError( - asyncResp->res, item.value(), - "HttpHeaders/" + item.key()); + asyncResp->res, item.second, + "HttpHeaders/" + item.first); + return; + } + // Adding a new json value is the size of the key, + + // the size of the value + 2 * 2 quotes for each, + + // the colon and space between. example: + // "key": "value" + cumulativeLen += item.first.size() + value->size() + 6; + // This value is selected to mirror http_connection.hpp + constexpr const uint16_t maxHeaderSizeED = 8096; + if (cumulativeLen > maxHeaderSizeED) + { + messages::arraySizeTooLong( + asyncResp->res, "HttpHeaders", maxHeaderSizeED); return; } - subValue->httpHeaders.set(item.key(), *value); + subValue->httpHeaders.set(item.first, *value); } } } @@ -596,12 +597,12 @@ inline void requestRoutesEventDestinationCollection(App& app) if (mrdJsonArray) { - for (nlohmann::json& mrdObj : *mrdJsonArray) + for (nlohmann::json::object_t& mrdObj : *mrdJsonArray) { std::string mrdUri; - if (!json_util::readJson(mrdObj, asyncResp->res, "@odata.id", - mrdUri)) + if (!json_util::readJsonObject(mrdObj, asyncResp->res, + "@odata.id", mrdUri)) { return; @@ -705,7 +706,7 @@ inline void requestRoutesEventDestination(App& app) std::optional<std::string> context; std::optional<std::string> retryPolicy; - std::optional<std::vector<nlohmann::json>> headers; + std::optional<std::vector<nlohmann::json::object_t>> headers; if (!json_util::readJsonPatch(req, asyncResp->res, "Context", context, "DeliveryRetryPolicy", retryPolicy, @@ -722,23 +723,23 @@ inline void requestRoutesEventDestination(App& app) if (headers) { boost::beast::http::fields fields; - for (const nlohmann::json& headerChunk : *headers) + for (const nlohmann::json::object_t& headerChunk : *headers) { - for (const auto& it : headerChunk.items()) + for (const auto& it : headerChunk) { const std::string* value = - it.value().get_ptr<const std::string*>(); + it.second.get_ptr<const std::string*>(); if (value == nullptr) { messages::propertyValueFormatError( - asyncResp->res, it.value(), - "HttpHeaders/" + it.key()); + asyncResp->res, it.second, + "HttpHeaders/" + it.first); return; } - fields.set(it.key(), *value); + fields.set(it.first, *value); } } - subValue->httpHeaders = fields; + subValue->httpHeaders = std::move(fields); } if (retryPolicy) |