summaryrefslogtreecommitdiff
path: root/include/json_html_serializer.hpp
AgeCommit message (Collapse)AuthorFilesLines
2025-01-20Use SPDX identifiersEd Tanous1-0/+2
SPDX identifiers are simpler, and reduce the amount of cruft we have in code files. They are recommended by linux foundation, and therefore we should do as they allow. This patchset does not intend to modify any intent on any existing copyrights or licenses, only to standardize their inclusion. [1] https://www.linuxfoundation.org/blog/blog/copyright-notices-in-open-source-software-projects Change-Id: I935c7c0156caa78fc368c929cebd0f068031e830 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2023-06-14Add missing pragma onceEd Tanous1-0/+2
This header didn't include a pragma once. Fix it. Tested: Code compiles Change-Id: I8bd4f9d870ec9b7dc1687e8de1c8a61d93140c7e Signed-off-by: Ed Tanous <edtanous@google.com>
2023-06-05Break out serializer into its own cpp fileEd Tanous1-621/+5
This commit is entirely just moving code, such that not all compile units need to pull in the full html serializer. Tested: Unit tests pass. Pretty good coverage. Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ifaebe9534c0693dc678fd994517563b89aca0cc5
2023-05-19Fix integer display in HTMLJason M. Bills1-1/+1
When displaying an integer in HTML, the number of characters is off by 1 causing the numbers to display without the last digit. This is because the pointer into numberbuffer gets initially advanced by the number of characters which ends up being one too many. For example, the buffer pointer is pointing at numberbuffer[0]. If we display a 4 digit number, we advance by 4, so it ends up pointing at numberbuffer[4] for the last digit. In the end, we return only the number of characters which is numberbuffer[0-3] cutting off the last digit. This changes the pointer to advance by one less than the number of digits, so the buffer fills from numberbuffer[3] and returns all 4 digits. Tested: Read redfish/v1/SessionService and confirmed that the "SessionTimeout" value displays the full value of 1800. Change-Id: Iaa974d7a41352fd9a15024ccf04c5926a4efe7a2 Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
2023-05-12log-services: fix clang-tidy warningsPatrick Williams1-5/+3
A number of similar warnings about unsafe pointer arithmetic. ``` ../redfish-core/lib/log_services.hpp:269:39: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage] indexStr.data(), indexStr.data() + indexStr.size(), index); ``` Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: Icc4a0d2f418c76d6987ef2318b0098d30d116389
2023-05-11json-html-serializer: fix clang-tidy warningPatrick Williams1-25/+26
``` ../include/json_html_serializer.hpp:426:42: error: 'end' declared with a const-qualified typedef; results in the type being 'char *const' instead of 'const char *' [misc-misplaced-const,-warnings-as-errors] const std::array<char, 64>::iterator end = ^ /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/array:106:44: note: typedef declared here typedef value_type* iterator; ../include/json_html_serializer.hpp:165:60: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage] std::snprintf(stringBuffer.data() + bytes, 7, ../include/json_html_serializer.hpp:327:11: error: 'bufferPtr' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage] auto* bufferPtr = begin(numberbuffer); ../include/json_html_serializer.hpp:393:11: error: 'begin' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage] char* begin = numberbuffer.data(); ../include/json_html_serializer.hpp:425:56: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage] std::remove(numberbuffer.begin(), numberbuffer.begin() + len, ','); ``` Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: If6aaf038c939ad76da73e68e746a56b0905b2804
2022-03-12Enable readability checksEd Tanous1-2/+7
clang-tidy readability checks are overall a good thing, and help us to write consistent and readable code, even if it doesn't change the result. All changes done by the robot. Tested: Code compiles, inspection only (changes made by robot) Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iee4a0c74a11eef9f158f0044eae675ebc518b549
2022-02-15Enable readability-uppercase-literal-suffixEd Tanous1-3/+3
We only had a few violations of this; Fix them and enable the check. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I159e774fd0169a91a092218ec8dc896ba9edebf4
2022-01-12enable cppcoreguidelines-pro-type-vararg checksEd Tanous1-4/+7
We only use varargs in some code we borrowed from nlohmann, so ignore that, and enable the check. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iab1305784e7532e2ee10c617fb59b75aba142ce6
2022-01-12Enable checks for pointer arithmeticEd Tanous1-0/+3
Quite a few places we've disobeyed this rule, so simply ignore them for now to avoid new issues popping up. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I3e518a8e8742279afb3ad1a9dad54006ed109fb1
2022-01-12Enable init checkerEd Tanous1-2/+2
clang-tidy added cppcoreguidelines-init-variables as a check, which is something we already enforce to some extent, but getting CI to enforce it will help reviews move faster. Tested: Code compiles. Noop changes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7e10950de617b1d3262265572b1703f2e60b69d0
2021-09-23Make code format the sameEd Tanous1-3/+2
The only difference between a clang-format-11 formatter and a clang-format-12 formatter seems to be this line, which seems to confuse people. https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/46932 already got pushed trying to "fix" this, only to be rejected by CI. It appears that the extra parens on the method name seems to confuse clang-format, which makes little sense. This is code we inherited from nlohmann and changed to support the html formatter, so while nlohmann might have had good reasons for it (weird compiler support maybe) we don't need it, so this patchset removes the parens and reformats. Tested: Code compiles. No functional changes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ide31e0be057d4b97da69203890ca6720e79887e5
2021-09-11fix clang formattingEd Tanous1-2/+3
Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie2a2583054ff4de3d00e52765059fed79fa7fb0c
2020-09-29Fix naming conventionsEd Tanous1-16/+16
Lots of code has been checked in that doesn't match the naming conventions. Lets fix that. Tested: Code compiles. Variable/function renames only. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I6bd107811d0b724f1fad990016113cdf035b604b
2020-09-28Fix the buildEd Tanous1-0/+5
In between the json patch being written, and the json patch being merged, nlohmann library added binary types: https://nlohmann.github.io/json/features/binary_values/ Which is non standard, but used for things like cbor. Add a switch to handle them. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I8599847a063a14c5f489e8347c2c440347d2544d
2020-09-24Improve JSON->HTML conversionEd Tanous1-0/+614
The existing JSON to html conversion is quite unfortunate, as it runs several very expensive regular expressions on an output to properly invoke the correct behavior, and to escape things like links. This patchset adjusts the behavior to directly dump the tree to HTML, skipping the json step entirely. Most of the code was pulled from the nlohmann::serializer class. Small side node: This also resolves the CSP issue with the inline CSS classes that are currently embedded in the json UI. Note, in terms of user facing behavior, this finally fixes the CSS issue, so the div is now centered as designed. Previously it was left justified. Tested: Ran several redfish schemas and compared to old ones. Output appears the same in the window, and content security policy warnings are gone. Verified several links works as expected, and verified the behavior of all base types, as well as empty arrays and empty objects. All appear to work correctly. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: Id9bf6dc33acb1603f009de4cd322e81d83f334be