sessiond: validate existence of field reference received from LTTng-UST
[lttng-tools.git] / src / bin / lttng-sessiond / field.hpp
index f353adafbcc7d04e04e056144d53bb3c269b1b73..dec5b103222008200b7adbcb8a019fa2ae3dbd3d 100644 (file)
@@ -8,13 +8,15 @@
 #ifndef LTTNG_FIELD_H
 #define LTTNG_FIELD_H
 
+#include <common/format.hpp>
+
+#include <vendor/optional.hpp>
+
 #include <memory>
 #include <string>
 #include <type_traits>
 #include <vector>
 
-#include <vendor/optional.hpp>
-
 namespace lttng {
 namespace sessiond {
 namespace trace {
@@ -27,6 +29,26 @@ enum class byte_order {
        LITTLE_ENDIAN_,
 };
 
+class field_location {
+public:
+       enum class root {
+               PACKET_HEADER,
+               PACKET_CONTEXT,
+               EVENT_RECORD_HEADER,
+               EVENT_RECORD_COMMON_CONTEXT,
+               EVENT_RECORD_SPECIFIC_CONTEXT,
+               EVENT_RECORD_PAYLOAD,
+       };
+
+       using elements = std::vector<std::string>;
+
+       field_location(root lookup_root, elements elements);
+       bool operator==(const field_location& other) const noexcept;
+
+       const root root_;
+       const elements elements_;
+};
+
 /*
  * Field, and the various field types, represents fields as exposed by the
  * LTTng tracers. These classes do not attempt to describe the complete spectrum of the CTF
@@ -277,11 +299,11 @@ class dynamic_length_array_type : public array_type {
 public:
        dynamic_length_array_type(unsigned int alignment,
                        type::cuptr element_type,
-                       std::string length_field_name);
+                       field_location length_field_location);
 
        virtual void accept(type_visitor& visitor) const override final;
 
-       const std::string length_field_name;
+       const field_location length_field_location;
 
 private:
        virtual bool _is_equal(const type& base_other) const noexcept override final;
@@ -309,11 +331,11 @@ private:
 
 class dynamic_length_blob_type : public type {
 public:
-       dynamic_length_blob_type(unsigned int alignment, std::string length_field_name);
+       dynamic_length_blob_type(unsigned int alignment, field_location length_field_location);
 
        virtual void accept(type_visitor& visitor) const override final;
 
-       const std::string length_field_name;
+       const field_location length_field_location;
 
 private:
        virtual bool _is_equal(const type& base_other) const noexcept override final;
@@ -355,10 +377,10 @@ class dynamic_length_string_type : public string_type {
 public:
        dynamic_length_string_type(unsigned int alignment,
                        enum encoding in_encoding,
-                       std::string length_field_name);
+                       field_location length_field_location);
        virtual void accept(type_visitor& visitor) const override final;
 
-       const std::string length_field_name;
+       const field_location length_field_location;
 
 private:
        virtual bool _is_equal(const type& base_other) const noexcept override final;
@@ -388,12 +410,15 @@ class variant_type : public type {
 public:
        using choices = std::vector<field::cuptr>;
 
-       variant_type(unsigned int alignment, std::string tag_name, choices in_choices);
+       variant_type(unsigned int alignment,
+                       field_location selector_field_location,
+                       choices in_choices);
 
        virtual void accept(type_visitor& visitor) const override final;
 
-       const std::string tag_name;
+       const field_location selector_field_location;
        const choices _choices;
+;
 
 private:
        virtual bool _is_equal(const type& base_other) const noexcept override final;
@@ -433,4 +458,48 @@ protected:
 } /* namespace sessiond */
 } /* namespace lttng */
 
+/*
+ * Due to a bug in g++ < 7.1, this specialization must be enclosed in the fmt namespace,
+ * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480.
+ */
+namespace fmt {
+template <>
+struct formatter<lttng::sessiond::trace::field_location> : formatter<std::string> {
+       template <typename FormatCtx>
+       typename FormatCtx::iterator format(
+                       const lttng::sessiond::trace::field_location& location, FormatCtx& ctx)
+       {
+               std::string location_str{"["};
+
+               switch (location.root_) {
+               case lttng::sessiond::trace::field_location::root::PACKET_HEADER:
+                       location_str += "\"packet-header\"";
+                       break;
+               case lttng::sessiond::trace::field_location::root::PACKET_CONTEXT:
+                       location_str += "\"packet-context\"";
+                       break;
+               case lttng::sessiond::trace::field_location::root::EVENT_RECORD_HEADER:
+                       location_str += "\"event-record-header\"";
+                       break;
+               case lttng::sessiond::trace::field_location::root::EVENT_RECORD_COMMON_CONTEXT:
+                       location_str += "\"event-record-common-context\"";
+                       break;
+               case lttng::sessiond::trace::field_location::root::EVENT_RECORD_SPECIFIC_CONTEXT:
+                       location_str += "\"event-record-specific-context\"";
+                       break;
+               case lttng::sessiond::trace::field_location::root::EVENT_RECORD_PAYLOAD:
+                       location_str += "\"event-record-payload\"";
+                       break;
+               }
+
+               for (const auto &name : location.elements_) {
+                       location_str += ", \"" + name + "\"";
+               }
+
+               location_str += "]";
+               return format_to(ctx.out(), location_str);
+       }
+};
+} /* namespace fmt */
+
 #endif /* LTTNG_FIELD_H */
This page took 0.025763 seconds and 4 git commands to generate.