From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/webrtc/sdp/SdpParser.h | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 dom/media/webrtc/sdp/SdpParser.h (limited to 'dom/media/webrtc/sdp/SdpParser.h') diff --git a/dom/media/webrtc/sdp/SdpParser.h b/dom/media/webrtc/sdp/SdpParser.h new file mode 100644 index 0000000000..4b23e93705 --- /dev/null +++ b/dom/media/webrtc/sdp/SdpParser.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef _SDPPARSER_H_ +#define _SDPPARSER_H_ + +#include +#include +#include "sdp/Sdp.h" +#include "sdp/SdpLog.h" + +#include "mozilla/Telemetry.h" + +namespace mozilla { + +class SdpParser { + public: + SdpParser() = default; + virtual ~SdpParser() = default; + + class Results { + public: + typedef std::pair Anomaly; + typedef std::vector AnomalyVec; + virtual ~Results() = default; + UniquePtr& Sdp() { return mSdp; } + AnomalyVec& Errors() { return mErrors; } + AnomalyVec& Warnings() { return mWarnings; } + virtual const std::string& ParserName() const = 0; + bool Ok() const { return mErrors.empty(); } + + protected: + UniquePtr mSdp; + AnomalyVec mErrors; + AnomalyVec mWarnings; + }; + + // The name of the parser implementation + virtual const std::string& Name() const = 0; + + /** + * This parses the provided text into an SDP object. + * This returns a nullptr-valued pointer if things go poorly. + */ + virtual UniquePtr Parse(const std::string& aText) = 0; + + class InternalResults : public Results { + public: + explicit InternalResults(const std::string& aParserName) + : mParserName(aParserName) {} + virtual ~InternalResults() = default; + + void SetSdp(UniquePtr&& aSdp) { mSdp = std::move(aSdp); } + + void AddParseError(size_t line, const std::string& message) { + MOZ_LOG(SdpLog, LogLevel::Error, + ("%s: parser error %s, at line %zu", mParserName.c_str(), + message.c_str(), line)); + mErrors.push_back(std::make_pair(line, message)); + } + + void AddParseWarning(size_t line, const std::string& message) { + MOZ_LOG(SdpLog, LogLevel::Warning, + ("%s: parser warning %s, at line %zu", mParserName.c_str(), + message.c_str(), line)); + mWarnings.push_back(std::make_pair(line, message)); + } + + const std::string& ParserName() const override { return mParserName; } + + private: + const std::string mParserName; + }; +}; + +} // namespace mozilla + +#endif -- cgit v1.2.3