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/transport/nricestunaddr.cpp | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 dom/media/webrtc/transport/nricestunaddr.cpp (limited to 'dom/media/webrtc/transport/nricestunaddr.cpp') diff --git a/dom/media/webrtc/transport/nricestunaddr.cpp b/dom/media/webrtc/transport/nricestunaddr.cpp new file mode 100644 index 0000000000..d1e8d3ac52 --- /dev/null +++ b/dom/media/webrtc/transport/nricestunaddr.cpp @@ -0,0 +1,93 @@ +/* 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 "logging.h" + +// nICEr includes +extern "C" { +#include "nr_api.h" +#include "local_addr.h" +} + +// Local includes +#include "nricestunaddr.h" + +namespace mozilla { + +MOZ_MTLOG_MODULE("mtransport") + +NrIceStunAddr::NrIceStunAddr() : localAddr_(new nr_local_addr) { + memset(localAddr_, 0, sizeof(nr_local_addr)); +} + +NrIceStunAddr::NrIceStunAddr(const nr_local_addr* addr) + : localAddr_(new nr_local_addr) { + nr_local_addr_copy(localAddr_, const_cast(addr)); +} + +NrIceStunAddr::NrIceStunAddr(const NrIceStunAddr& rhs) + : localAddr_(new nr_local_addr) { + nr_local_addr_copy(localAddr_, const_cast(rhs.localAddr_)); +} + +NrIceStunAddr::~NrIceStunAddr() { delete localAddr_; } + +size_t NrIceStunAddr::SerializationBufferSize() const { + return sizeof(nr_local_addr); +} + +nsresult NrIceStunAddr::Serialize(char* buffer, size_t buffer_size) const { + if (buffer_size != sizeof(nr_local_addr)) { + MOZ_MTLOG(ML_ERROR, + "Failed trying to serialize NrIceStunAddr, " + "input buffer length (" + << buffer_size << ") does not match required length (" + << sizeof(nr_local_addr) << ")"); + MOZ_ASSERT(false, "Failed to serialize NrIceStunAddr, bad buffer size"); + return NS_ERROR_FAILURE; + } + + nr_local_addr* toAddr = (nr_local_addr*)buffer; + if (nr_local_addr_copy(toAddr, localAddr_)) { + MOZ_MTLOG(ML_ERROR, + "Failed trying to serialize NrIceStunAddr, " + "could not copy nr_local_addr."); + MOZ_ASSERT(false, + "Failed to serialize NrIceStunAddr, nr_local_addr_copy failed"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult NrIceStunAddr::Deserialize(const char* buffer, size_t buffer_size) { + if (buffer_size != sizeof(nr_local_addr)) { + MOZ_MTLOG(ML_ERROR, + "Failed trying to deserialize NrIceStunAddr, " + "input buffer length (" + << buffer_size << ") does not match required length (" + << sizeof(nr_local_addr) << ")"); + MOZ_ASSERT(false, "Failed to deserialize NrIceStunAddr, bad buffer size"); + return NS_ERROR_FAILURE; + } + + nr_local_addr* from_addr = + const_cast((const nr_local_addr*)buffer); + + // At this point, from_addr->addr.addr is invalid (null), but will + // be fixed by nr_local_addr_copy. + if (nr_local_addr_copy(localAddr_, from_addr)) { + MOZ_MTLOG(ML_ERROR, + "Failed trying to deserialize NrIceStunAddr, " + "could not copy nr_local_addr."); + MOZ_ASSERT( + false, + "Failed to deserialize NrIceStunAddr, nr_local_addr_copy failed"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +} // namespace mozilla -- cgit v1.2.3