From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/media/webrtc/sdp/RsdparsaSdpParser.cpp | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 dom/media/webrtc/sdp/RsdparsaSdpParser.cpp (limited to 'dom/media/webrtc/sdp/RsdparsaSdpParser.cpp') diff --git a/dom/media/webrtc/sdp/RsdparsaSdpParser.cpp b/dom/media/webrtc/sdp/RsdparsaSdpParser.cpp new file mode 100644 index 0000000000..b955bcd46b --- /dev/null +++ b/dom/media/webrtc/sdp/RsdparsaSdpParser.cpp @@ -0,0 +1,73 @@ +/* -*- 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/. */ + +#include "nsError.h" + +#include "mozilla/UniquePtr.h" + +#include "sdp/Sdp.h" +#include "sdp/RsdparsaSdp.h" +#include "sdp/RsdparsaSdpParser.h" +#include "sdp/RsdparsaSdpInc.h" +#include "sdp/RsdparsaSdpGlue.h" + +namespace mozilla { + +const std::string& RsdparsaSdpParser::ParserName() { + static const std::string& WEBRTC_SDP_NAME = "WEBRTCSDP"; + return WEBRTC_SDP_NAME; +} + +UniquePtr RsdparsaSdpParser::Parse( + const std::string& aText) { + UniquePtr results( + new SdpParser::InternalResults(Name())); + RustSdpSession* result = nullptr; + RustSdpError* err = nullptr; + StringView sdpTextView{aText.c_str(), aText.length()}; + nsresult rv = parse_sdp(sdpTextView, false, &result, &err); + if (rv != NS_OK) { + size_t line = sdp_get_error_line_num(err); + char* cString = sdp_get_error_message(err); + if (cString) { + std::string errMsg(cString); + sdp_free_error_message(cString); + sdp_free_error(err); + results->AddParseError(line, errMsg); + } else { + results->AddParseError(line, "Unable to retreive parse error."); + } + return results; + } + + if (err) { + size_t line = sdp_get_error_line_num(err); + char* cString = sdp_get_error_message(err); + if (cString) { + std::string warningMsg(cString); + results->AddParseWarning(line, warningMsg); + sdp_free_error_message(cString); + sdp_free_error(err); + } else { + results->AddParseWarning(line, "Unable to retreive parse warning."); + } + } + + RsdparsaSessionHandle uniqueResult(result); + RustSdpOrigin rustOrigin = sdp_get_origin(uniqueResult.get()); + auto address = convertExplicitlyTypedAddress(&rustOrigin.addr); + SdpOrigin origin(convertStringView(rustOrigin.username), rustOrigin.sessionId, + rustOrigin.sessionVersion, address.first, address.second); + + results->SetSdp(MakeUnique(std::move(uniqueResult), origin)); + return results; +} + +bool RsdparsaSdpParser::IsNamed(const std::string& aName) { + return aName == ParserName(); +} + +} // namespace mozilla -- cgit v1.2.3