From 12ab035aad66f090d355445d83766259ca4e6ca8 Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 3 Mar 2019 11:20:43 -0800 Subject: [PATCH] Fix receive side of LabVIEW USB streams (#1621) LabView only accepts %20 instead of + for parameters, only sends '\n' at the boundaries, and includes the -- when sending the initial boundary. This solves those parts. This is not fully enough to fix shuffleboard and others, as the NT format for paths is not the correct path. --- cscore/src/main/native/cpp/HttpCameraImpl.cpp | 14 +++++++++++--- wpiutil/src/main/native/include/wpi/HttpUtil.inl | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cscore/src/main/native/cpp/HttpCameraImpl.cpp b/cscore/src/main/native/cpp/HttpCameraImpl.cpp index f15fc5fcf8..296c3422c0 100644 --- a/cscore/src/main/native/cpp/HttpCameraImpl.cpp +++ b/cscore/src/main/native/cpp/HttpCameraImpl.cpp @@ -189,6 +189,9 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect( std::tie(key, value) = keyvalue.split('='); if (key.trim() == "boundary") { value = value.trim().trim('"'); // value may be quoted + if (value.startswith("--")) { + value = value.substr(2); + } boundary.append(value.begin(), value.end()); } } @@ -219,11 +222,16 @@ void HttpCameraImpl::DeviceStream(wpi::raw_istream& is, if (!FindMultipartBoundary(is, boundary, nullptr)) break; // Read the next two characters after the boundary (normally \r\n) + // Handle just \n for LabVIEW however char eol[2]; - is.read(eol, 2); + is.read(eol, 1); if (!m_active || is.has_error()) break; - // End-of-stream is indicated with trailing -- - if (eol[0] == '-' && eol[1] == '-') break; + if (eol[0] != '\n') { + is.read(eol + 1, 1); + if (!m_active || is.has_error()) break; + // End-of-stream is indicated with trailing -- + if (eol[0] == '-' && eol[1] == '-') break; + } if (!DeviceStreamFrame(is, imageBuf)) ++numErrors; diff --git a/wpiutil/src/main/native/include/wpi/HttpUtil.inl b/wpiutil/src/main/native/include/wpi/HttpUtil.inl index cfeb9b36c0..ce118b0a38 100644 --- a/wpiutil/src/main/native/include/wpi/HttpUtil.inl +++ b/wpiutil/src/main/native/include/wpi/HttpUtil.inl @@ -36,9 +36,9 @@ void HttpRequest::SetPath(StringRef path_, const T& params) { pathOs << '&'; } SmallString<64> escapeBuf; - pathOs << EscapeURI(GetFirst(param), escapeBuf); + pathOs << EscapeURI(GetFirst(param), escapeBuf, false); if (!GetSecond(param).empty()) { - pathOs << '=' << EscapeURI(GetSecond(param), escapeBuf); + pathOs << '=' << EscapeURI(GetSecond(param), escapeBuf, false); } } }