diff --git a/src/Camera/VehicleCameraControl.cc b/src/Camera/VehicleCameraControl.cc index ede5743095ab..907a9efc94dd 100644 --- a/src/Camera/VehicleCameraControl.cc +++ b/src/Camera/VehicleCameraControl.cc @@ -1817,7 +1817,8 @@ void VehicleCameraControl::setCurrentStream(int stream) if (stream != _currentStream && stream >= 0 && stream < _streamLabels.count()) { QGCVideoStreamInfo* pInfo = currentStreamInstance(); if(pInfo) { - qCDebug(VehicleCameraControlLog) << "Stopping stream:" << pInfo->uri(); + qCDebug(VehicleCameraControlLog) + << "Stopping stream:" << QGCNetworkHelper::redactedUrlForLogging(pInfo->uri()); //-- Stop current stream _vehicle->sendMavCommand( _compID, // Target component @@ -1829,7 +1830,8 @@ void VehicleCameraControl::setCurrentStream(int stream) pInfo = currentStreamInstance(); if(pInfo) { //-- Start new stream - qCDebug(VehicleCameraControlLog) << "Starting stream:" << pInfo->uri(); + qCDebug(VehicleCameraControlLog) + << "Starting stream:" << QGCNetworkHelper::redactedUrlForLogging(pInfo->uri()); _vehicle->sendMavCommand( _compID, // Target component MAV_CMD_VIDEO_START_STREAMING, // Command id diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index ae43d03c6c1a..ffe9767c42c3 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -2,6 +2,7 @@ #include "VideoManager.h" #include "QGCLoggingCategory.h" +#include "QGCNetworkHelper.h" #include #include @@ -243,23 +244,31 @@ bool VideoSettings::streamConfigured(void) } //-- If UDP, check for URL if(vSource == videoSourceUDPH264 || vSource == videoSourceUDPH265) { - qCDebug(VideoSettingsLog) << "Testing configuration for UDP Stream:" << udpUrl()->rawValue().toString(); - return !udpUrl()->rawValue().toString().isEmpty(); + const QString url = udpUrl()->rawValue().toString(); + qCDebug(VideoSettingsLog) << "Testing configuration for UDP Stream:" + << QGCNetworkHelper::redactedUrlForLogging(url); + return !url.isEmpty(); } //-- If RTSP, check for URL if(vSource == videoSourceRTSP) { - qCDebug(VideoSettingsLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString(); - return !rtspUrl()->rawValue().toString().isEmpty(); + const QString url = rtspUrl()->rawValue().toString(); + qCDebug(VideoSettingsLog) << "Testing configuration for RTSP Stream:" + << QGCNetworkHelper::redactedUrlForLogging(url); + return !url.isEmpty(); } //-- If TCP, check for URL if(vSource == videoSourceTCP) { - qCDebug(VideoSettingsLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString(); - return !tcpUrl()->rawValue().toString().isEmpty(); + const QString url = tcpUrl()->rawValue().toString(); + qCDebug(VideoSettingsLog) << "Testing configuration for TCP Stream:" + << QGCNetworkHelper::redactedUrlForLogging(url); + return !url.isEmpty(); } //-- If MPEG-TS, check for URL if(vSource == videoSourceMPEGTS) { - qCDebug(VideoSettingsLog) << "Testing configuration for MPEG-TS Stream:" << udpUrl()->rawValue().toString(); - return !udpUrl()->rawValue().toString().isEmpty(); + const QString url = udpUrl()->rawValue().toString(); + qCDebug(VideoSettingsLog) << "Testing configuration for MPEG-TS Stream:" + << QGCNetworkHelper::redactedUrlForLogging(url); + return !url.isEmpty(); } //-- If Herelink Air unit, good to go if(vSource == videoSourceHerelinkAirUnit) { diff --git a/src/Utilities/Network/QGCNetworkHelper.cc b/src/Utilities/Network/QGCNetworkHelper.cc index 5545ee2cc389..84804189e547 100644 --- a/src/Utilities/Network/QGCNetworkHelper.cc +++ b/src/Utilities/Network/QGCNetworkHelper.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -342,6 +343,58 @@ QUrl urlWithoutQuery(const QUrl& url) return url.adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment); } +namespace { +bool isHostPortForLogging(const QString& value) +{ + static const QRegularExpression pattern(QStringLiteral(R"(^[^/@?#\s]+:\d{1,5}$)")); + return pattern.match(value).hasMatch(); +} +} // namespace + +QString redactedUrlForLogging(const QUrl& url) +{ + if (url.isEmpty()) { + return QStringLiteral(""); + } + if (!url.isValid()) { + if (url.scheme().isEmpty() && isHostPortForLogging(url.path())) { + return url.path(); + } + return QStringLiteral(""); + } + + QUrl redactedUrl = url.adjusted(QUrl::RemoveUserInfo); + if (redactedUrl.hasQuery()) { + const auto queryItems = QUrlQuery(redactedUrl).queryItems(QUrl::FullyDecoded); + QUrlQuery redactedQuery; + for (const auto& queryItem : queryItems) { + redactedQuery.addQueryItem(queryItem.first, QStringLiteral("REDACTED")); + } + if (queryItems.isEmpty()) { + redactedUrl.setQuery(QString()); + } else { + redactedUrl.setQuery(redactedQuery); + } + } + if (redactedUrl.hasFragment()) { + redactedUrl.setFragment(QStringLiteral("REDACTED")); + } + + return redactedUrl.toDisplayString(QUrl::FullyEncoded); +} + +QString redactedUrlForLogging(const QString& url) +{ + if (isHostPortForLogging(url)) { + return url; + } + const QUrl parsedUrl(url); + if (!url.isEmpty() && !parsedUrl.isValid()) { + return QStringLiteral("").arg(url.size()); + } + return redactedUrlForLogging(parsedUrl); +} + // ============================================================================ // Request Configuration // ============================================================================ diff --git a/src/Utilities/Network/QGCNetworkHelper.h b/src/Utilities/Network/QGCNetworkHelper.h index cb92f2d03a3d..e83571e20c74 100644 --- a/src/Utilities/Network/QGCNetworkHelper.h +++ b/src/Utilities/Network/QGCNetworkHelper.h @@ -139,6 +139,11 @@ QUrl buildUrl(const QString& baseUrl, const QList>& para /// Get URL without query string and fragment QUrl urlWithoutQuery(const QUrl& url); +/// Return a URL suitable for diagnostics. Stream identity is preserved while user info, +/// query values, and fragment content are redacted. +QString redactedUrlForLogging(const QUrl& url); +QString redactedUrlForLogging(const QString& url); + // ============================================================================ // Request Configuration // ============================================================================ diff --git a/src/VideoManager/VideoManager.cc b/src/VideoManager/VideoManager.cc index 72d47e207f7d..624923aae7b2 100644 --- a/src/VideoManager/VideoManager.cc +++ b/src/VideoManager/VideoManager.cc @@ -7,6 +7,7 @@ #include "QGCCameraManager.h" #include "QGCCorePlugin.h" #include "QGCLoggingCategory.h" +#include "QGCNetworkHelper.h" #include "QGCVideoStreamInfo.h" #include "SettingsManager.h" #include "SubtitleWriter.h" @@ -593,7 +594,8 @@ bool VideoManager::_updateAutoStream(VideoReceiver *receiver) return false; } - qCDebug(VideoManagerLog) << QString("Configure stream (%1):").arg(receiver->name()) << pInfo->uri(); + qCDebug(VideoManagerLog) << QString("Configure stream (%1):").arg(receiver->name()) + << QGCNetworkHelper::redactedUrlForLogging(pInfo->uri()); QString source, url; switch (pInfo->type()) { @@ -651,7 +653,7 @@ bool VideoManager::_updateVideoUri(VideoReceiver *receiver, const QString &uri) return false; } - qCDebug(VideoManagerLog) << "New Video URI" << uri; + qCDebug(VideoManagerLog) << "New Video URI" << QGCNetworkHelper::redactedUrlForLogging(uri); receiver->setUri(uri); @@ -899,13 +901,16 @@ void VideoManager::_initVideoReceiver(VideoReceiver *receiver, QQuickWindow *win }); (void) connect(receiver, &VideoReceiver::onStopComplete, this, [this, receiver](VideoReceiver::STATUS status) { - qCDebug(VideoManagerLog) << "Stop complete" << receiver->name() << receiver->uri() << ", status:" << status; + qCDebug(VideoManagerLog) << "Stop complete" << receiver->name() + << QGCNetworkHelper::redactedUrlForLogging(receiver->uri()) + << ", status:" << status; receiver->setStarted(false); if (status == VideoReceiver::STATUS_INVALID_URL) { qCDebug(VideoManagerLog) << "Invalid video URL. Not restarting"; } else { QTimer::singleShot(1000, receiver, [this, receiver]() { - qCDebug(VideoManagerLog) << "Restarting video receiver" << receiver->name() << receiver->uri(); + qCDebug(VideoManagerLog) << "Restarting video receiver" << receiver->name() + << QGCNetworkHelper::redactedUrlForLogging(receiver->uri()); _startReceiver(receiver); }); } diff --git a/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.cc b/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.cc index 6176704bfd69..c20378ece58a 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.cc @@ -82,7 +82,7 @@ QString writePipelineDot(GstElement* pipeline, const char* tag) QFile::remove(existing.takeFirst().absoluteFilePath()); } - gchar* data = gst_debug_bin_to_dot_data(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL); + gchar* data = gst_debug_bin_to_dot_data(GST_BIN(pipeline), kDiagnosticDotGraphDetails); if (!data) return {}; const QString fileName = QStringLiteral("%1-%2.dot") diff --git a/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.h b/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.h index 568884a98985..cdd28168c3b7 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.h +++ b/src/VideoManager/VideoReceiver/GStreamer/GStreamerHelpers.h @@ -9,6 +9,10 @@ #include "GStreamer.h" // VideoDecoderOptions namespace GStreamer { +/// Automatic field-report graphs omit element properties because source properties can contain credentials. +inline constexpr GstDebugGraphDetails kDiagnosticDotGraphDetails = static_cast( + GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS | GST_DEBUG_GRAPH_SHOW_STATES); + bool isValidRtspUri(const gchar* uri_str); /// Dump @p pipeline's graph as a rotating .dot under CacheLocation/qgc-pipeline-dot/ for field reports. diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc index 9a61cdacb3f1..281cb98afdb8 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc @@ -7,6 +7,7 @@ #include "GStreamerHelpers.h" #include "QGCLoggingCategory.h" +#include "QGCNetworkHelper.h" QGC_LOGGING_CATEGORY(GstSourceFactoryLog, "Video.GStreamer.GstSourceFactory") @@ -273,7 +274,7 @@ void linkPad(GstElement* element, GstPad* pad, gpointer data) GstElement* buildRtspSource(const QString& uri, const QUrl& sourceUrl, const Config& config, guint latencyMs) { if (!GStreamer::isValidRtspUri(uri.toUtf8().constData())) { - qCCritical(GstSourceFactoryLog) << "Invalid RTSP URI:" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); + qCWarning(GstSourceFactoryLog) << "Invalid RTSP URI:" << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); return nullptr; } @@ -313,12 +314,14 @@ GstElement* buildTcpSource(const QUrl& sourceUrl) { const int port = sourceUrl.port(); if (!validPort(port)) { - qCCritical(GstSourceFactoryLog) << "Invalid TCP port" << port << "in" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); + qCWarning(GstSourceFactoryLog) << "Invalid TCP port" << port << "in" + << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); return nullptr; } const QString host = sourceUrl.host(); if (host.isEmpty()) { - qCCritical(GstSourceFactoryLog) << "Missing host in TCP URI" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); + qCWarning(GstSourceFactoryLog) << "Missing host in TCP URI" + << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); return nullptr; } @@ -336,7 +339,8 @@ GstElement* buildUdpSource(const QUrl& sourceUrl, bool isUdpH264, bool isUdpH265 { const int port = sourceUrl.port(); if (!validPort(port)) { - qCCritical(GstSourceFactoryLog) << "Invalid UDP port" << port << "in" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); + qCWarning(GstSourceFactoryLog) << "Invalid UDP port" << port << "in" + << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); return nullptr; } @@ -505,7 +509,8 @@ GstElement* create(const QString& uri, const Config& config) const bool isTcpMPEGTS = (scheme == QLatin1String("tcp")); if (!isRtsp && !isUdpH264 && !isUdpH265 && !isUdpMPEGTS && !isTcpMPEGTS) { - qCWarning(GstSourceFactoryLog) << "Unsupported URI scheme:" << scheme << "in" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); + qCWarning(GstSourceFactoryLog) << "Unsupported URI scheme:" << scheme << "in" + << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); return nullptr; } diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc b/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc index 2b376b42e4ee..49ea210e418b 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc @@ -15,6 +15,7 @@ #include "GStreamerHelpers.h" #include "GstSourceFactory.h" #include "QGCLoggingCategory.h" +#include "QGCNetworkHelper.h" #include "QGCQVideoSinkController.h" #include @@ -77,6 +78,11 @@ GstVideoReceiver::~GstVideoReceiver() qCDebug(GstVideoReceiverLog) << this; } +QString GstVideoReceiver::_redactedUri() const +{ + return QGCNetworkHelper::redactedUrlForLogging(_uri); +} + void GstVideoReceiver::start(uint32_t timeout) { if (_needDispatch()) { @@ -85,7 +91,7 @@ void GstVideoReceiver::start(uint32_t timeout) } if (_pipeline) { - qCDebug(GstVideoReceiverLog) << "Already running!" << _uri; + qCDebug(GstVideoReceiverLog) << "Already running!" << _redactedUri(); emit onStartComplete(STATUS_INVALID_STATE); return; } @@ -99,7 +105,8 @@ void GstVideoReceiver::start(uint32_t timeout) _timeout = timeout; _buffer = lowLatency() ? -1 : 0; - qCDebug(GstVideoReceiverLog) << "Starting" << _uri << ", lowLatency" << lowLatency() << ", timeout" << _timeout; + qCDebug(GstVideoReceiverLog) << "Starting" << _redactedUri() << ", lowLatency" << lowLatency() + << ", timeout" << _timeout; // GST_DEBUG_BIN_TO_DOT_FILE is a no-op unless GST_DEBUG_DUMP_DOT_DIR is set; surface that // once per process so field debugging doesn't require re-reading the source. @@ -270,7 +277,7 @@ void GstVideoReceiver::start(uint32_t timeout) emit onStartComplete(STATUS_FAIL); } else { GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-started"); - qCDebug(GstVideoReceiverLog) << "Started" << _uri; + qCDebug(GstVideoReceiverLog) << "Started" << _redactedUri(); // _watchdogTimer lives on `this` (GUI thread); the emit runs synchronously on the // worker thread, so the timer start has to be queued separately or QObject warns. @@ -291,7 +298,7 @@ void GstVideoReceiver::stop() return; } - qCDebug(GstVideoReceiverLog) << "Stopping" << _uri; + qCDebug(GstVideoReceiverLog) << "Stopping" << _redactedUri(); // Bump the epoch synchronously (atomic — no GUI thread needed) so any in-flight reconnect lambda // is superseded before this stop() returns; cross-callsite QueuedConnection FIFO is not guaranteed. @@ -406,18 +413,18 @@ void GstVideoReceiver::stop() if (_streaming) { _streaming = false; - qCDebug(GstVideoReceiverLog) << "Streaming stopped" << _uri; + qCDebug(GstVideoReceiverLog) << "Streaming stopped" << _redactedUri(); emit streamingChanged(_streaming); } else { - qCDebug(GstVideoReceiverLog) << "Streaming did not start" << _uri; + qCDebug(GstVideoReceiverLog) << "Streaming did not start" << _redactedUri(); } } - qCDebug(GstVideoReceiverLog) << "Stopped" << _uri; + qCDebug(GstVideoReceiverLog) << "Stopped" << _redactedUri(); if (const HwBuffers::PathStats hwStats = HwBuffers::formatPathStats(true); hwStats.totalDelivered > 0) { qCInfo(GstVideoReceiverLog).noquote() - << "HW path stats" << _uri << hwStats.line + HwBuffers::takeExtraPathStats(); + << "HW path stats" << _redactedUri() << hwStats.line + HwBuffers::takeExtraPathStats(); } emit onStopComplete(STATUS_OK); @@ -426,7 +433,7 @@ void GstVideoReceiver::stop() void GstVideoReceiver::startDecoding(void *sink) { if (!sink) { - qCCritical(GstVideoReceiverLog) << "VideoSink is NULL" << _uri; + qCCritical(GstVideoReceiverLog) << "VideoSink is NULL" << _redactedUri(); return; } @@ -435,10 +442,10 @@ void GstVideoReceiver::startDecoding(void *sink) return; } - qCDebug(GstVideoReceiverLog) << "Starting decoding" << _uri; + qCDebug(GstVideoReceiverLog) << "Starting decoding" << _redactedUri(); if (!_widget) { - qCDebug(GstVideoReceiverLog) << "Video Widget is NULL" << _uri; + qCDebug(GstVideoReceiverLog) << "Video Widget is NULL" << _redactedUri(); emit onStartDecodingComplete(STATUS_FAIL); return; } @@ -448,7 +455,7 @@ void GstVideoReceiver::startDecoding(void *sink) } if (_videoSink || _decoding) { - qCDebug(GstVideoReceiverLog) << "Already decoding!" << _uri; + qCDebug(GstVideoReceiverLog) << "Already decoding!" << _redactedUri(); emit onStartDecodingComplete(STATUS_INVALID_STATE); return; } @@ -456,7 +463,7 @@ void GstVideoReceiver::startDecoding(void *sink) GstElement *videoSink = GST_ELEMENT(sink); GstPad *pad = gst_element_get_static_pad(videoSink, "sink"); if (!pad) { - qCCritical(GstVideoReceiverLog) << "Unable to find sink pad of video sink" << _uri; + qCCritical(GstVideoReceiverLog) << "Unable to find sink pad of video sink" << _redactedUri(); emit onStartDecodingComplete(STATUS_FAIL); return; } @@ -480,7 +487,7 @@ void GstVideoReceiver::startDecoding(void *sink) _ensureVideoSinkInPipeline(); if (!_addDecoder(_decoderValve)) { - qCCritical(GstVideoReceiverLog) << "_addDecoder() failed" << _uri; + qCCritical(GstVideoReceiverLog) << "_addDecoder() failed" << _redactedUri(); _shutdownDecodingBranch(); emit onStartDecodingComplete(STATUS_FAIL); return; @@ -490,7 +497,7 @@ void GstVideoReceiver::startDecoding(void *sink) "drop", FALSE, nullptr); - qCDebug(GstVideoReceiverLog) << "Decoding started" << _uri; + qCDebug(GstVideoReceiverLog) << "Decoding started" << _redactedUri(); emit onStartDecodingComplete(STATUS_OK); } @@ -502,14 +509,14 @@ void GstVideoReceiver::stopDecoding() return; } - qCDebug(GstVideoReceiverLog) << "Stopping decoding" << _uri; + qCDebug(GstVideoReceiverLog) << "Stopping decoding" << _redactedUri(); // Gate on _videoSink (set by startDecoding) instead of _decoding (which only flips on // first sink-buffer probe). Without this, stopDecoding() called between // onStartDecodingComplete(OK) and the first frame returns STATUS_INVALID_STATE and // leaves the decoder/sink branch live. if (!_pipeline || !_videoSink) { - qCDebug(GstVideoReceiverLog) << "Not decoding!" << _uri; + qCDebug(GstVideoReceiverLog) << "Not decoding!" << _redactedUri(); emit onStopDecodingComplete(STATUS_INVALID_STATE); return; } @@ -535,25 +542,25 @@ void GstVideoReceiver::startRecording(const QString &videoFile, FILE_FORMAT form return; } - qCDebug(GstVideoReceiverLog) << "Starting recording" << _uri; + qCDebug(GstVideoReceiverLog) << "Starting recording" << _redactedUri(); if (!_pipeline) { - qCDebug(GstVideoReceiverLog) << "Streaming is not active!" << _uri; + qCDebug(GstVideoReceiverLog) << "Streaming is not active!" << _redactedUri(); emit onStartRecordingComplete(STATUS_INVALID_STATE); return; } if (_recording) { - qCDebug(GstVideoReceiverLog) << "Already recording!" << _uri; + qCDebug(GstVideoReceiverLog) << "Already recording!" << _redactedUri(); emit onStartRecordingComplete(STATUS_INVALID_STATE); return; } - qCDebug(GstVideoReceiverLog) << "New video file:" << videoFile << _uri; + qCDebug(GstVideoReceiverLog) << "New video file:" << videoFile << _redactedUri(); _fileSink = _makeFileSink(videoFile, format); if (!_fileSink) { - qCCritical(GstVideoReceiverLog) << "_makeFileSink() failed" << _uri; + qCCritical(GstVideoReceiverLog) << "_makeFileSink() failed" << _redactedUri(); emit onStartRecordingComplete(STATUS_FAIL); return; } @@ -565,7 +572,7 @@ void GstVideoReceiver::startRecording(const QString &videoFile, FILE_FORMAT form gst_bin_add(GST_BIN(_pipeline), _fileSink); if (!gst_element_link(_recorderValve, _fileSink)) { - qCCritical(GstVideoReceiverLog) << "Failed to link valve and file sink" << _uri; + qCCritical(GstVideoReceiverLog) << "Failed to link valve and file sink" << _redactedUri(); emit onStartRecordingComplete(STATUS_FAIL); return; } @@ -579,7 +586,7 @@ void GstVideoReceiver::startRecording(const QString &videoFile, FILE_FORMAT form // This will ensure the first frame is a keyframe at t=0, and decoding can begin immediately on playback GstPad *probepad = gst_element_get_static_pad(_recorderValve, "src"); if (!probepad) { - qCCritical(GstVideoReceiverLog) << "gst_element_get_static_pad() failed" << _uri; + qCCritical(GstVideoReceiverLog) << "gst_element_get_static_pad() failed" << _redactedUri(); emit onStartRecordingComplete(STATUS_FAIL); return; } @@ -593,7 +600,7 @@ void GstVideoReceiver::startRecording(const QString &videoFile, FILE_FORMAT form _recordingOutput = videoFile; _recording = true; - qCDebug(GstVideoReceiverLog) << "Recording started" << _uri; + qCDebug(GstVideoReceiverLog) << "Recording started" << _redactedUri(); emit onStartRecordingComplete(STATUS_OK); emit recordingChanged(_recording); } @@ -605,10 +612,10 @@ void GstVideoReceiver::stopRecording() return; } - qCDebug(GstVideoReceiverLog) << "Stopping recording" << _uri; + qCDebug(GstVideoReceiverLog) << "Stopping recording" << _redactedUri(); if (!_pipeline || !_recording) { - qCDebug(GstVideoReceiverLog) << "Not recording!" << _uri; + qCDebug(GstVideoReceiverLog) << "Not recording!" << _redactedUri(); emit onStopRecordingComplete(STATUS_INVALID_STATE); return; } @@ -638,7 +645,7 @@ void GstVideoReceiver::takeScreenshot(const QString &imageFile) return; } - qCDebug(GstVideoReceiverLog) << "taking screenshot" << _uri; + qCDebug(GstVideoReceiverLog) << "taking screenshot" << _redactedUri(); // FIXME: record screenshot here emit onTakeScreenshotComplete(STATUS_NOT_IMPLEMENTED); @@ -661,7 +668,7 @@ void GstVideoReceiver::_watchdog() if (++_statsTickCounter >= 10) { _statsTickCounter = 0; if (const HwBuffers::PathStats hwStats = HwBuffers::formatPathStats(false); hwStats.totalDelivered > 0) { - qCDebug(GstVideoReceiverLog).noquote() << "HW path live" << _uri << hwStats.line; + qCDebug(GstVideoReceiverLog).noquote() << "HW path live" << _redactedUri() << hwStats.line; } } @@ -672,7 +679,7 @@ void GstVideoReceiver::_watchdog() qint64 elapsed = now - lastSourceFrameTime; if (elapsed > _timeout) { - qCDebug(GstVideoReceiverLog) << "Stream timeout, no frames for" << elapsed << _uri; + qCDebug(GstVideoReceiverLog) << "Stream timeout, no frames for" << elapsed << _redactedUri(); GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-watchdog-timeout"); emit timeout(); _scheduleReconnect("source watchdog"); @@ -688,7 +695,7 @@ void GstVideoReceiver::_watchdog() elapsed = now - lastVideoFrameTime; if (elapsed > (_timeout * 2)) { - qCDebug(GstVideoReceiverLog) << "Video decoder timeout, no frames for" << elapsed << _uri; + qCDebug(GstVideoReceiverLog) << "Video decoder timeout, no frames for" << elapsed << _redactedUri(); GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-watchdog-timeout"); emit timeout(); _scheduleReconnect("decoder watchdog"); @@ -729,7 +736,8 @@ void GstVideoReceiver::_scheduleReconnect(const char *reason) const quint64 epoch = _reconnectEpoch.load(std::memory_order_relaxed); const int attempts = next; qCInfo(GstVideoReceiverLog) << "Scheduling reconnect #" << attempts - << "in" << delaySec << "s after" << reason << uri; + << "in" << delaySec << "s after" << reason + << QGCNetworkHelper::redactedUrlForLogging(uri); QTimer::singleShot(delaySec * 1000, this, [this, epoch, attempts, reconnectTimeout, uri]() { if (epoch != _reconnectEpoch.load(std::memory_order_relaxed)) return; // superseded by stop() // _pipeline is mutated by the worker under _pipelineMutex; a bare deref here (GUI @@ -738,7 +746,8 @@ void GstVideoReceiver::_scheduleReconnect(const char *reason) const bool pipelineUp = (livePipeline != nullptr); if (livePipeline) gst_object_unref(livePipeline); if (uri.isEmpty() || pipelineUp) return; // pipeline already came back - qCInfo(GstVideoReceiverLog) << "Reconnecting (attempt" << attempts << ")" << uri; + qCInfo(GstVideoReceiverLog) << "Reconnecting (attempt" << attempts << ")" + << QGCNetworkHelper::redactedUrlForLogging(uri); start(reconnectTimeout); }); }, Qt::QueuedConnection); @@ -894,7 +903,7 @@ void GstVideoReceiver::_onNewSourcePad(GstPad *pad) if (!_streaming) { _streaming = true; - qCDebug(GstVideoReceiverLog) << "Streaming started" << _uri; + qCDebug(GstVideoReceiverLog) << "Streaming started" << _redactedUri(); emit streamingChanged(_streaming); } @@ -921,7 +930,7 @@ void GstVideoReceiver::_onNewSourcePad(GstPad *pad) "drop", FALSE, nullptr); - qCDebug(GstVideoReceiverLog) << "Decoding started" << _uri; + qCDebug(GstVideoReceiverLog) << "Decoding started" << _redactedUri(); } void GstVideoReceiver::_logDecodebin3SelectedCodec(GstElement *decodebin3) @@ -981,7 +990,7 @@ void GstVideoReceiver::_logDecodebin3SelectedCodec(GstElement *decodebin3) void GstVideoReceiver::_onNewDecoderPad(GstPad *pad) { - qCDebug(GstVideoReceiverLog) << "_onNewDecoderPad" << _uri; + qCDebug(GstVideoReceiverLog) << "_onNewDecoderPad" << _redactedUri(); GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-with-new-decoder-pad"); @@ -1087,7 +1096,8 @@ bool GstVideoReceiver::_addVideoSink(GstPad *pad) QSize videoSize; do { if (!_decoderValve) { - qCCritical(GstVideoReceiverLog) << "Unable to determine video size - _decoderValve is NULL" << _uri; + qCCritical(GstVideoReceiverLog) << "Unable to determine video size - _decoderValve is NULL" + << _redactedUri(); break; } @@ -1106,7 +1116,8 @@ bool GstVideoReceiver::_addVideoSink(GstPad *pad) const GstStructure *structure = gst_caps_get_structure(valveSrcPadCaps, 0); if (!structure) { - qCCritical(GstVideoReceiverLog) << "Unable to determine video size - structure is NULL" << _uri; + qCCritical(GstVideoReceiverLog) << "Unable to determine video size - structure is NULL" + << _redactedUri(); gst_clear_object(&valveSrcPad); break; } @@ -1152,10 +1163,10 @@ void GstVideoReceiver::_noteTeeFrame() } const quint64 sourceFrames = _sourceFrameCount.fetch_add(1, std::memory_order_relaxed) + 1; if (sourceFrames == 1) { - qCInfo(GstVideoReceiverLog).noquote() << "Source receiving frames (tee):" << _uri; + qCInfo(GstVideoReceiverLog).noquote() << "Source receiving frames (tee):" << _redactedUri(); } else if ((sourceFrames % 300) == 0) { qCDebug(GstVideoReceiverLog).noquote() - << "Source flow: teeFrames=" << sourceFrames << "decoding=" << _decoding << _uri; + << "Source flow: teeFrames=" << sourceFrames << "decoding=" << _decoding << _redactedUri(); } } @@ -1494,7 +1505,7 @@ gboolean GstVideoReceiver::_onBusMessage(GstBus * /* bus */, GstMessage *msg, gp gst_query_unref(q); const QString decName = pThis->decoderName(); qCDebug(GstVideoReceiverLog).noquote() - << "Pipeline PLAYING:" << pThis->_uri + << "Pipeline PLAYING:" << pThis->_redactedUri() << "decoder:" << (decName.isEmpty() ? QStringLiteral("(pending)") : decName) << "min-latency:" << (min / 1000000) << "ms" << "max-latency:" << (max / 1000000) << "ms"; diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.h b/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.h index 834b31a3bd3f..e4b17f6bf274 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.h +++ b/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.h @@ -85,6 +85,7 @@ private slots: void _handleEOS(); private: + QString _redactedUri() const; GstElement *_makeDecoder(); GstElement *_makeFileSink(const QString &videoFile, FILE_FORMAT format); diff --git a/src/VideoManager/VideoReceiver/GStreamer/README.md b/src/VideoManager/VideoReceiver/GStreamer/README.md index 5ffa3eacce36..f7be8459b617 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/README.md +++ b/src/VideoManager/VideoReceiver/GStreamer/README.md @@ -132,6 +132,8 @@ dot -Tpng /tmp/qgc-pipeline-dots/0.00.00.*-pipeline-started.dot -o pipeline.png When the env var is **unset**, QGC still writes a rotating snapshot (≤10 files) to `/qgc-pipeline-dot/-.dot` on `ERROR` and on watchdog timeout, so field-bug-report bundles include the topology automatically. The `GstVideoReceiver::dumpPipelineGraph(tag)` slot (callable from QML) writes a snapshot on demand for use from a debug menu. +QGC graph dumps include topology, caps, media types, and states. Element property values are omitted because source properties can contain stream credentials. + ### Latency tracer Per-element latency from source to sink: diff --git a/test/Utilities/Network/CMakeLists.txt b/test/Utilities/Network/CMakeLists.txt index af4c50eba070..ce0c1a5d072e 100644 --- a/test/Utilities/Network/CMakeLists.txt +++ b/test/Utilities/Network/CMakeLists.txt @@ -7,8 +7,11 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE QGCNetworkHelperTest.cc QGCNetworkHelperTest.h + QGCNetworkRedactionTest.cc + QGCNetworkRedactionTest.h ) target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_qgc_test(QGCNetworkHelperTest LABELS Unit Utilities Network) +add_qgc_test(QGCNetworkRedactionTest LABELS Unit Utilities) diff --git a/test/Utilities/Network/QGCNetworkRedactionTest.cc b/test/Utilities/Network/QGCNetworkRedactionTest.cc new file mode 100644 index 000000000000..2956fa0d28ef --- /dev/null +++ b/test/Utilities/Network/QGCNetworkRedactionTest.cc @@ -0,0 +1,71 @@ +#include "QGCNetworkRedactionTest.h" + +#include +#include + +#include "QGCNetworkHelper.h" + +void QGCNetworkRedactionTest::_testPreservesStreamIdentity() +{ + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("rtsp://camera.example:554/axis-media/media.amp")), + QStringLiteral("rtsp://camera.example:554/axis-media/media.amp")); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("udp://0.0.0.0:5600")), + QStringLiteral("udp://0.0.0.0:5600")); +} + +void QGCNetworkRedactionTest::_testRemovesUserInfo() +{ + const QString result = QGCNetworkHelper::redactedUrlForLogging( + QStringLiteral("https://pilot%40ops:secret%2Fvalue@example.com:8443/video%20feed")); + + QCOMPARE(result, QStringLiteral("https://example.com:8443/video%20feed")); + QVERIFY(!result.contains(QStringLiteral("pilot"))); + QVERIFY(!result.contains(QStringLiteral("secret"))); +} + +void QGCNetworkRedactionTest::_testRedactsQueryValues() +{ + const QString result = QGCNetworkHelper::redactedUrlForLogging( + QStringLiteral("https://example.com/video?token=abc123&mode=low-latency#session")); + const QUrl resultUrl(result); + const QUrlQuery resultQuery(resultUrl); + + QCOMPARE(resultUrl.path(), QStringLiteral("/video")); + QCOMPARE(resultQuery.queryItemValue(QStringLiteral("token")), QStringLiteral("REDACTED")); + QCOMPARE(resultQuery.queryItemValue(QStringLiteral("mode")), QStringLiteral("REDACTED")); + QCOMPARE(resultUrl.fragment(), QStringLiteral("REDACTED")); + QVERIFY(!result.contains(QStringLiteral("abc123"))); + QVERIFY(!result.contains(QStringLiteral("low-latency"))); + QVERIFY(!result.contains(QStringLiteral("session"))); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("https://example.com/video?")), + QStringLiteral("https://example.com/video")); +} + +void QGCNetworkRedactionTest::_testHandlesRelativeAndInvalidInput() +{ + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("5600")), QStringLiteral("5600")); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("camera.local:5600")), + QStringLiteral("camera.local:5600")); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("0.0.0.0:5600")), QStringLiteral("0.0.0.0:5600")); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("192.168.1.10:5600")), + QStringLiteral("192.168.1.10:5600")); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QString()), QStringLiteral("")); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(QStringLiteral("http://[invalid")), + QStringLiteral("")); +} + +void QGCNetworkRedactionTest::_testQUrlOverload() +{ + const QUrl sourceUrl(QStringLiteral("rtsp://pilot:secret@camera.example:8554/live?token=abc123")); + const QString result = QGCNetworkHelper::redactedUrlForLogging(sourceUrl); + const QUrl hostPortUrl(QStringLiteral("192.168.1.10:5600")); + + QCOMPARE(QUrl(result).path(), QStringLiteral("/live")); + QVERIFY(!result.contains(QStringLiteral("pilot"))); + QVERIFY(!result.contains(QStringLiteral("secret"))); + QVERIFY(!result.contains(QStringLiteral("abc123"))); + QVERIFY(!hostPortUrl.isValid()); + QCOMPARE(QGCNetworkHelper::redactedUrlForLogging(hostPortUrl), QStringLiteral("192.168.1.10:5600")); +} + +UT_REGISTER_TEST(QGCNetworkRedactionTest, TestLabel::Unit, TestLabel::Utilities) diff --git a/test/Utilities/Network/QGCNetworkRedactionTest.h b/test/Utilities/Network/QGCNetworkRedactionTest.h new file mode 100644 index 000000000000..bc33846a4af8 --- /dev/null +++ b/test/Utilities/Network/QGCNetworkRedactionTest.h @@ -0,0 +1,15 @@ +#pragma once + +#include "UnitTest.h" + +class QGCNetworkRedactionTest : public UnitTest +{ + Q_OBJECT + +private slots: + void _testPreservesStreamIdentity(); + void _testRemovesUserInfo(); + void _testRedactsQueryValues(); + void _testHandlesRelativeAndInvalidInput(); + void _testQUrlOverload(); +}; diff --git a/test/VideoManager/GStreamer/GStreamerTest.cc b/test/VideoManager/GStreamer/GStreamerTest.cc index 20a570c4215e..c38c5389d08b 100644 --- a/test/VideoManager/GStreamer/GStreamerTest.cc +++ b/test/VideoManager/GStreamer/GStreamerTest.cc @@ -431,6 +431,33 @@ void GStreamerTest::_testWritePipelineDotReturnsEmptyOnWriteFailure() QVERIFY2(path.isEmpty(), qPrintable(QStringLiteral("Expected empty path for failed dot write, got %1").arg(path))); } +void GStreamerTest::_testPipelineDotOmitsElementProperties() +{ + GstElement* pipeline = gst_pipeline_new("safe-dot-test"); + QVERIFY(pipeline); + const auto pipelineCleanup = qScopeGuard([&] { gst_object_unref(pipeline); }); + + GstElement* source = gst_element_factory_make("filesrc", "source"); + GstElement* sink = gst_element_factory_make("fakesink", "sink"); + QVERIFY(source); + QVERIFY(sink); + + constexpr auto kSecretLocation = "/tmp/qgc-dot-secret-token"; + g_object_set(source, "location", kSecretLocation, nullptr); + gst_bin_add_many(GST_BIN(pipeline), source, sink, nullptr); + QVERIFY(gst_element_link(source, sink)); + + gchar* dotData = gst_debug_bin_to_dot_data(GST_BIN(pipeline), GStreamer::kDiagnosticDotGraphDetails); + QVERIFY(dotData); + const QByteArray dot(dotData); + g_free(dotData); + + QVERIFY(dot.contains("source")); + QVERIFY(dot.contains("sink")); + QVERIFY(!dot.contains(kSecretLocation)); + QVERIFY(!dot.contains("qgc-dot-secret-token")); +} + void GStreamerTest::_testCompleteInit() { GStreamer::redirectGLibLogging(); @@ -517,6 +544,7 @@ QGC_GST_SKIP_TEST(_testConfigureDebugLoggingIsIdempotent) QGC_GST_SKIP_TEST(_testVerifyRequiredPlugins) QGC_GST_SKIP_TEST(_testEnvironmentSetup) QGC_GST_SKIP_TEST(_testWritePipelineDotReturnsEmptyOnWriteFailure) +QGC_GST_SKIP_TEST(_testPipelineDotOmitsElementProperties) QGC_GST_SKIP_TEST(_testCompleteInit) QGC_GST_SKIP_TEST(_testCreateVideoReceiver) QGC_GST_SKIP_TEST(_testBindDebugLevelFactRejectsNullContext) diff --git a/test/VideoManager/GStreamer/GStreamerTest.h b/test/VideoManager/GStreamer/GStreamerTest.h index f45f2c6cc76f..edc12eecbed7 100644 --- a/test/VideoManager/GStreamer/GStreamerTest.h +++ b/test/VideoManager/GStreamer/GStreamerTest.h @@ -22,6 +22,7 @@ private slots: void _testVerifyRequiredPlugins(); void _testEnvironmentSetup(); void _testWritePipelineDotReturnsEmptyOnWriteFailure(); + void _testPipelineDotOmitsElementProperties(); void _testCompleteInit(); void _testCreateVideoReceiver(); void _testBindDebugLevelFactRejectsNullContext(); diff --git a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc index 35895f2a9dba..81e5d777e05b 100644 --- a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc +++ b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc @@ -135,9 +135,9 @@ void GStreamerTest::_testSourceFactoryRtspExcludesStaticJitterBuffer() void GStreamerTest::_testSourceFactoryRejectsBadUri() { ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtCriticalMsg, - QRegularExpression(QStringLiteral("URI is not specified|Invalid UDP port"))); + QRegularExpression(QStringLiteral("URI is not specified"))); ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtWarningMsg, - QRegularExpression(QStringLiteral("Unsupported URI scheme"))); + QRegularExpression(QStringLiteral("Unsupported URI scheme|Invalid UDP port"))); GStreamer::SourceFactory::Config config; QVERIFY(!GStreamer::SourceFactory::create(QString(), config)); @@ -172,7 +172,7 @@ void GStreamerTest::_testSourceFactoryTcpMpegTs() void GStreamerTest::_testSourceFactoryRejectsBadTcpUri() { - ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtCriticalMsg, + ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtWarningMsg, QRegularExpression(QStringLiteral("Invalid TCP port|Missing host in TCP URI"))); GStreamer::SourceFactory::Config config;