From b0cc2f58b0550298dde3acd45b9da6933b2523f8 Mon Sep 17 00:00:00 2001 From: Rich Logan Date: Tue, 22 Jul 2025 10:46:39 +0100 Subject: [PATCH] Example validation --- src/CMakeLists.txt | 1 + src/moqt_validate.cpp | 152 ++++++++++++++++++ .../MessageSpec_Header_Structs_tmpl.jinja2 | 2 + .../MessageSpec_Source_Structs_tmple.jinja2 | 6 + 4 files changed, 161 insertions(+) create mode 100644 src/moqt_validate.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d17e7394..a7717032b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ target_sources (quicr PRIVATE ctrl_message_types.cpp ${ctrl_messages_SOURCE} messages.cpp + moqt_validate.cpp publish_fetch_handler.cpp publish_track_handler.cpp fetch_track_handler.cpp diff --git a/src/moqt_validate.cpp b/src/moqt_validate.cpp new file mode 100644 index 000000000..4c040ec4b --- /dev/null +++ b/src/moqt_validate.cpp @@ -0,0 +1,152 @@ +#include + +namespace quicr::messages { + bool SubscribeUpdate::Validate() const + { + return true; + } + + bool Subscribe::Validate() const + { + return true; + } + + bool SubscribeOk::Validate() const + { + return true; + } + + bool SubscribeError::Validate() const + { + return true; + } + + bool Announce::Validate() const + { + return true; + } + + bool AnnounceOk::Validate() const + { + return true; + } + + bool AnnounceError::Validate() const + { + return true; + } + + bool Unannounce::Validate() const + { + return true; + } + + bool Unsubscribe::Validate() const + { + return true; + } + + bool SubscribeDone::Validate() const + { + return true; + } + + bool AnnounceCancel::Validate() const + { + return true; + } + + bool TrackStatusRequest::Validate() const + { + return true; + } + + bool TrackStatus::Validate() const + { + return true; + } + + bool Goaway::Validate() const + { + return true; + } + + bool SubscribeAnnounces::Validate() const + { + return true; + } + + bool SubscribeAnnouncesOk::Validate() const + { + return true; + } + + bool SubscribeAnnouncesError::Validate() const + { + return true; + } + + bool UnsubscribeAnnounces::Validate() const + { + return true; + } + + bool MaxRequestId::Validate() const + { + return true; + } + + bool Fetch::Validate() const + { + return true; + } + bool FetchCancel::Validate() const + { + return true; + } + + bool FetchOk::Validate() const + { + return true; + } + + bool FetchError::Validate() const + { + return true; + } + + bool RequestsBlocked::Validate() const + { + return true; + } + + bool Publish::Validate() const + { + return true; + } + + bool PublishOk::Validate() const + { + return true; + } + + bool PublishError::Validate() const + { + return true; + } + + bool ClientSetup::Validate() const + { + return true; + } + + bool ServerSetup::Validate() const + { + return true; + } + + bool NewGroupRequest::Validate() const + { + return true; + } +} diff --git a/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Header_Structs_tmpl.jinja2 b/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Header_Structs_tmpl.jinja2 index 2f7039265..d852ef8ce 100644 --- a/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Header_Structs_tmpl.jinja2 +++ b/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Header_Structs_tmpl.jinja2 @@ -63,6 +63,8 @@ {% endif %} public: + virtual bool Validate() const; + {% for field in message.fields %} {% if field.spec_name not in field_discards %} {% if field.is_optional %} diff --git a/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Source_Structs_tmple.jinja2 b/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Source_Structs_tmple.jinja2 index aa4cf7eb6..ff88ea890 100644 --- a/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Source_Structs_tmple.jinja2 +++ b/tools/draft_parser/moqt_parser/templates/cpp/MessageSpec_Source_Structs_tmple.jinja2 @@ -44,6 +44,9 @@ {% endif %} {% endif %} {% endfor %} + if (!msg.Validate()) { + throw ProtocolViolationException("Invalid message"); + } return buffer; } @@ -52,6 +55,9 @@ */ Bytes& operator<<(Bytes& buffer, const {{message.name}}& msg) { + if (!msg.Validate()) { + throw std::invalid_argument("Invalid message"); + } Bytes payload; // fill out payload {% for field in message.fields %}