diff options
author | George Liu <liuxiwei@inspur.com> | 2021-09-30 15:24:46 +0300 |
---|---|---|
committer | George Liu <liuxiwei@inspur.com> | 2021-10-21 06:31:51 +0300 |
commit | 287ece64bf9a8ee0c42f77cefce559054b488ae7 (patch) | |
tree | c411eeb8c8ba97d173ea6afabcc6872ccc6692bf /redfish-core/include | |
parent | d8e3c29a3b8626ed8072be4547a2bbcf7321c757 (diff) | |
download | bmcweb-287ece64bf9a8ee0c42f77cefce559054b488ae7.tar.xz |
Remove NTPServers duplicate values and null values
When saving the set NTPServers values from webUI, NTPServer may contain
duplicate values and null values and update them to D-Bus.
Now, need to parse and verify the value of the ntpServers attribute,and
remove duplicate values and null values.
Tested:save NTP and check it via D-Bus
without this patch:
NTPServers property as 3 "" "10.164.29.2" "10.164.29.2"
with this patch:
NTPServers property as 2 "" "10.164.29.2"
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I52291e4608efd635b179f3934c3d3e805afd2209
Diffstat (limited to 'redfish-core/include')
-rw-r--r-- | redfish-core/include/utils/stl_utils.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/redfish-core/include/utils/stl_utils.hpp b/redfish-core/include/utils/stl_utils.hpp new file mode 100644 index 0000000000..04d02cbada --- /dev/null +++ b/redfish-core/include/utils/stl_utils.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include <algorithm> +#include <string> + +namespace redfish +{ + +namespace stl_utils +{ + +template <typename ForwardIterator> +ForwardIterator firstDuplicate(ForwardIterator first, ForwardIterator last) +{ + auto newLast = first; + + for (auto current = first; current != last; ++current) + { + if (std::find(first, newLast, *current) == newLast) + { + if (newLast != current) + { + *newLast = *current; + } + ++newLast; + } + } + + return newLast; +} + +template <typename T> +void removeDuplicate(T& t) +{ + t.erase(firstDuplicate(t.begin(), t.end()), t.end()); +} + +} // namespace stl_utils +} // namespace redfish |