tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SdpParser.h (2376B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef _SDPPARSER_H_
      8 #define _SDPPARSER_H_
      9 
     10 #include <string>
     11 #include <vector>
     12 
     13 #include "sdp/Sdp.h"
     14 #include "sdp/SdpLog.h"
     15 
     16 namespace mozilla {
     17 
     18 class SdpParser {
     19 public:
     20  SdpParser() = default;
     21  virtual ~SdpParser() = default;
     22 
     23  class Results {
     24   public:
     25    typedef std::pair<size_t, std::string> Anomaly;
     26    typedef std::vector<Anomaly> AnomalyVec;
     27    virtual ~Results() = default;
     28    UniquePtr<mozilla::Sdp>& Sdp() { return mSdp; }
     29    AnomalyVec& Errors() { return mErrors; }
     30    AnomalyVec& Warnings() { return mWarnings; }
     31    virtual const std::string& ParserName() const = 0;
     32    bool Ok() const { return mErrors.empty(); }
     33 
     34   protected:
     35    UniquePtr<mozilla::Sdp> mSdp;
     36    AnomalyVec mErrors;
     37    AnomalyVec mWarnings;
     38  };
     39 
     40  // The name of the parser implementation
     41  virtual const std::string& Name() const = 0;
     42 
     43  /**
     44   * This parses the provided text into an SDP object.
     45   * This returns a nullptr-valued pointer if things go poorly.
     46   */
     47  virtual UniquePtr<SdpParser::Results> Parse(const std::string& aText) = 0;
     48 
     49  class InternalResults : public Results {
     50   public:
     51    explicit InternalResults(const std::string& aParserName)
     52        : mParserName(aParserName) {}
     53    virtual ~InternalResults() = default;
     54 
     55    void SetSdp(UniquePtr<mozilla::Sdp>&& aSdp) { mSdp = std::move(aSdp); }
     56 
     57    void AddParseError(size_t line, const std::string& message) {
     58      MOZ_LOG(SdpLog, LogLevel::Error,
     59              ("%s: parser error %s, at line %zu", mParserName.c_str(),
     60               message.c_str(), line));
     61      mErrors.push_back(std::make_pair(line, message));
     62    }
     63 
     64    void AddParseWarning(size_t line, const std::string& message) {
     65      MOZ_LOG(SdpLog, LogLevel::Warning,
     66              ("%s: parser warning %s, at line %zu", mParserName.c_str(),
     67               message.c_str(), line));
     68      mWarnings.push_back(std::make_pair(line, message));
     69    }
     70 
     71    const std::string& ParserName() const override { return mParserName; }
     72 
     73   private:
     74    const std::string mParserName;
     75  };
     76 };
     77 
     78 }  // namespace mozilla
     79 
     80 #endif