Add length limit for user-defined values

Previously, the only limit for most user-defined values like id or name
was the one enforced by dbus, which was fairly big. In order to save
space used by persistent data, new meson options were added, with length
limit for those fields.

This directly impacts following dbus interfaces:
- TriggerManager.AddTrigger:
  - Id
  - Name
  - Reports
  - Thresholds (only name of discrete threshold)
- Trigger.Name
- Trigger.Reports
- Trigger.Thresholds (only name of discrete threshold)
- ReportManager.AddReport(FutureVersion):
  - Id
  - Name
  - MetricParameters (metricId)
- Report.Name
- Report.ReadingParameters (metricId)

For Id fields we support 'prefixes', which also are limited, but those
limit are separate. So if limit for prefix is set to 5 and limit for
id/name is set to 5, following Ids are fine:
- 12345/12345
- 12345
and following are not:
- 123456/1234
- 1/123456

Testing done:
- UTs are passing.
- new limits are reflected when calling mentioned dbus interfaces.

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I29291a1cc56a344d92fb65491c9186fdb90a8529
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index 738dd6d..1677bb3 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -3,7 +3,8 @@
 #include "report.hpp"
 #include "types/report_types.hpp"
 #include "utils/conversion.hpp"
-#include "utils/generate_id.hpp"
+#include "utils/dbus_path_utils.hpp"
+#include "utils/make_id_name.hpp"
 #include "utils/transform.hpp"
 
 #include <phosphor-logging/log.hpp>
@@ -46,10 +47,6 @@
                 "MaxReports", size_t{}, sdbusplus::vtable::property_::const_,
                 [](const auto&) { return maxReports; });
             dbusIface.register_property_r(
-                "MaxReportIdLength", size_t{},
-                sdbusplus::vtable::property_::const_,
-                [](const auto&) { return maxReportIdLength; });
-            dbusIface.register_property_r(
                 "MinInterval", uint64_t{}, sdbusplus::vtable::property_::const_,
                 [](const auto&) -> uint64_t { return minInterval.count(); });
             dbusIface.register_property_r(
@@ -133,12 +130,31 @@
         reports.end());
 }
 
+void ReportManager::verifyMetricParameters(
+    const std::vector<LabeledMetricParameters>& readingParams)
+{
+    namespace ts = utils::tstring;
+
+    for (auto readingParam : readingParams)
+    {
+        if (readingParam.at_label<ts::Id>().length() >
+            utils::constants::maxIdNameLength)
+        {
+            throw sdbusplus::exception::SdBusError(
+                static_cast<int>(std::errc::invalid_argument),
+                "MetricId too long");
+        }
+    }
+}
+
 void ReportManager::verifyAddReport(
     const std::string& reportId, const std::string& reportName,
     const ReportingType reportingType, Milliseconds interval,
     const ReportUpdates reportUpdates, const uint64_t appendLimit,
     const std::vector<LabeledMetricParameters>& readingParams)
 {
+    namespace ts = utils::tstring;
+
     if (reports.size() >= maxReports)
     {
         throw sdbusplus::exception::SdBusError(
@@ -178,10 +194,10 @@
             "Too many reading parameters");
     }
 
+    verifyMetricParameters(readingParams);
+
     try
     {
-        namespace ts = utils::tstring;
-
         for (const LabeledMetricParameters& item : readingParams)
         {
             utils::toOperationType(
@@ -221,8 +237,8 @@
     const auto existingReportIds = utils::transform(
         reports, [](const auto& report) { return report->getId(); });
 
-    auto [id, name] = utils::generateId(reportId, reportName, reportNameDefault,
-                                        existingReportIds, maxReportIdLength);
+    auto [id, name] = utils::makeIdName(reportId, reportName, reportNameDefault,
+                                        existingReportIds);
 
     verifyAddReport(id, name, reportingType, interval, reportUpdates,
                     appendLimit, labeledMetricParams);