blob: a1b5709b45d0e8acb2bf8b53c3b5b89c63fe612b [file] [log] [blame]
Szymon Dompke1cdd7e42022-06-08 14:43:13 +02001#pragma once
2
3#include <sdbusplus/message.hpp>
4
5#include <algorithm>
6#include <ranges>
7#include <string_view>
8
9namespace utils
10{
11
12namespace constants
13{
14constexpr std::string_view triggerDirStr =
15 "/xyz/openbmc_project/Telemetry/Triggers/";
16constexpr std::string_view reportDirStr =
17 "/xyz/openbmc_project/Telemetry/Reports/";
18
19constexpr std::string_view allowedCharactersInPath =
20 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_/";
21constexpr size_t maxPrefixesInId = 1;
22
23const sdbusplus::message::object_path triggerDirPath =
24 sdbusplus::message::object_path(std::string(triggerDirStr));
25const sdbusplus::message::object_path reportDirPath =
26 sdbusplus::message::object_path(std::string(reportDirStr));
27} // namespace constants
28
29inline bool isValidDbusPath(const std::string& path)
30{
31 return (path.find_first_not_of(constants::allowedCharactersInPath) ==
32 std::string::npos) &&
33 !path.ends_with('/');
34}
35
36sdbusplus::message::object_path pathAppend(sdbusplus::message::object_path path,
37 const std::string& appended);
38
39std::string reportPathToId(const sdbusplus::message::object_path& path);
40
41} // namespace utils