From 1279c63819307b6ed5aa7bbc5b686cbb3766e02a Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Fri, 9 Oct 2020 11:59:58 -0700 Subject: [PATCH] From orbit, nuke the Telnet connection and all supporting infra. (#7840) This is not going to be our plan of record for Universal going forward. This updates the Universal configuration to 1) match non-universal and 2) switch to local applications (cherry picked from commit d33ca7e8eb431f42913d0f617e6354cc93ab7a4e) --- NOTICE.md | 30 -- .../LegacyProfileGeneratorNamespaces.h | 1 - src/cascadia/TerminalApp/TelnetGenerator.h | 19 - .../TerminalApp/TerminalAppLib.vcxproj | 1 - .../TerminalAppLib.vcxproj.filters | 3 - src/cascadia/TerminalApp/TerminalPage.cpp | 7 - .../TerminalApp/defaults-universal.json | 143 ++++++-- .../TerminalConnection/AzureConnection.cpp | 4 - .../TerminalConnection/ConptyConnection.cpp | 4 - .../TerminalConnection/EchoConnection.cpp | 4 - .../Resources/en-US/Resources.resw | 3 - .../TerminalConnection/TelnetConnection.cpp | 333 ------------------ .../TerminalConnection/TelnetConnection.h | 72 ---- .../TerminalConnection/TelnetConnection.idl | 14 - .../TerminalConnection.vcxproj | 9 - .../TerminalConnection.vcxproj.filters | 3 - .../TerminalConnection/packages.config | 3 +- src/cascadia/TerminalConnection/pch.h | 2 - src/inc/LibraryIncludes.h | 2 - src/inc/til/bitmap.h | 2 +- src/inc/til/color.h | 2 +- 21 files changed, 116 insertions(+), 545 deletions(-) delete mode 100644 src/cascadia/TerminalApp/TelnetGenerator.h delete mode 100644 src/cascadia/TerminalConnection/TelnetConnection.cpp delete mode 100644 src/cascadia/TerminalConnection/TelnetConnection.h delete mode 100644 src/cascadia/TerminalConnection/TelnetConnection.idl diff --git a/NOTICE.md b/NOTICE.md index f5b54b42688..e3c984a1fd1 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -48,36 +48,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` -## telnetpp - -**Source**: https://github.com/KazDragon/telnetpp - -### License - -``` -The MIT License (MIT) - -Copyright (c) 2015-2017 Matthew Chaplain a.k.a KazDragon - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` - ## chromium/base/numerics **Source**: https://github.com/chromium/chromium/tree/master/base/numerics diff --git a/src/cascadia/TerminalApp/LegacyProfileGeneratorNamespaces.h b/src/cascadia/TerminalApp/LegacyProfileGeneratorNamespaces.h index cf15c2b69b0..30d0f636aed 100644 --- a/src/cascadia/TerminalApp/LegacyProfileGeneratorNamespaces.h +++ b/src/cascadia/TerminalApp/LegacyProfileGeneratorNamespaces.h @@ -18,5 +18,4 @@ Author(s): static constexpr std::wstring_view WslGeneratorNamespace{ L"Windows.Terminal.Wsl" }; static constexpr std::wstring_view AzureGeneratorNamespace{ L"Windows.Terminal.Azure" }; -static constexpr std::wstring_view TelnetGeneratorNamespace{ L"Windows.Terminal.Telnet" }; static constexpr std::wstring_view PowershellCoreGeneratorNamespace{ L"Windows.Terminal.PowershellCore" }; diff --git a/src/cascadia/TerminalApp/TelnetGenerator.h b/src/cascadia/TerminalApp/TelnetGenerator.h deleted file mode 100644 index c7356b65fd9..00000000000 --- a/src/cascadia/TerminalApp/TelnetGenerator.h +++ /dev/null @@ -1,19 +0,0 @@ -/*++ -Copyright (c) Microsoft Corporation -Licensed under the MIT license. - -Module Name: -- TelnetGenerator - -Abstract: -- Information needed to detect a Telnet connection type. - -Author(s): -- Michael Niksa - 2019-12-05 - ---*/ - -#pragma once - -// {311153fb-d3f0-4ac6-b920-038de7cf5289} -static constexpr winrt::guid TelnetConnectionType = { 0x311153fb, 0xd3f0, 0x4ac6, { 0xb9, 0x20, 0x03, 0x8d, 0xe7, 0xcf, 0x52, 0x89 } }; diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index 9a799688d8f..de4c69d8bc6 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -129,7 +129,6 @@ - TerminalSettings.idl diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters index e8949cbdfe6..035e9b93725 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters @@ -117,9 +117,6 @@ - - profileGeneration - settings diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index a449b709c46..ec4e0a9b5d4 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -16,7 +16,6 @@ #include "KeyChordSerialization.h" #include "AzureCloudShellGenerator.h" // For AzureConnectionType -#include "TelnetGenerator.h" // For TelnetConnectionType #include "TabRowControl.h" #include "ColorHelper.h" #include "DebugTapConnection.h" @@ -792,12 +791,6 @@ namespace winrt::TerminalApp::implementation winrt::guid()); } - else if (hasConnectionType && - connectionType == TelnetConnectionType) - { - connection = TerminalConnection::TelnetConnection(settings.Commandline()); - } - else { std::wstring guidWString = Utils::GuidToString(profileGuid); diff --git a/src/cascadia/TerminalApp/defaults-universal.json b/src/cascadia/TerminalApp/defaults-universal.json index a580c30ff5d..8ecc53a1bc3 100644 --- a/src/cascadia/TerminalApp/defaults-universal.json +++ b/src/cascadia/TerminalApp/defaults-universal.json @@ -1,15 +1,16 @@ // THIS IS AN AUTO-GENERATED FILE! Changes to this file will be ignored. { - "defaultProfile": "{550ce7b8-d500-50ad-8a1a-c400c3262db3}", + "defaultProfile": "{70bfecf4-bcbb-443b-a8fa-d7ac4f7ad201}", // Launch Settings "initialCols": 120, "initialRows": 30, "launchMode": "default", + "alwaysOnTop": false, // Selection "copyOnSelect": false, - "copyFormatting": false, + "copyFormatting": true, "wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502", // Tab UI @@ -17,30 +18,56 @@ "showTabsInTitlebar": true, "showTerminalTitleInTitlebar": true, "tabWidthMode": "equal", + "useTabSwitcher": true, // Miscellaneous "confirmCloseAllTabs": true, + "startOnUserLogin": false, "theme": "system", "snapToGridOnResize": true, "profiles": [ { - "guid": "{550ce7b8-d500-50ad-8a1a-c400c3262db3}", - "name": "Telnet Loopback", - "commandline": "ms-telnet-loop://127.0.0.1:23", - "connectionType" : "{311153fb-d3f0-4ac6-b920-038de7cf5289}", + "guid": "{70bfecf4-bcbb-443b-a8fa-d7ac4f7ad201}", + "name": "PowerShell", + "commandline": "pwsh.exe", + "icon": "ms-appx:///ProfileIcons/pwsh.png", + "colorScheme": "Campbell", + "antialiasingMode": "grayscale", + "closeOnExit": "graceful", + "cursorShape": "bar", + "fontFace": "Cascadia Mono", + "fontSize": 12, "hidden": false, - "startingDirectory": "%USERPROFILE%", + "historySize": 9001, + "padding": "8, 8, 8, 8", + "snapOnInput": true, + "altGrAliasing": true, + "startingDirectory": "%SystemRoot%", + "useAcrylic": false, + "backgroundImage": "ms-appx:///internal-background.png", + "backgroundImageAlignment": "bottomRight", + "backgroundImageOpacity": 0.4, + "backgroundImageStretchMode": "none" + }, + { + "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", + "name": "Command Prompt", + "commandline": "%SystemRoot%\\System32\\cmd.exe", + "icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png", + "colorScheme": "Campbell", + "antialiasingMode": "grayscale", "closeOnExit": "graceful", - "colorScheme": "Vintage", - "cursorColor": "#FFFFFF", "cursorShape": "bar", "fontFace": "Cascadia Mono", - "icon": "ms-appx:///ProfileIcons/{550ce7b8-d500-50ad-8a1a-c400c3262db3}.png", + "fontSize": 12, + "hidden": false, + "historySize": 9001, "padding": "8, 8, 8, 8", "snapOnInput": true, "altGrAliasing": true, + "startingDirectory": "%SystemRoot%", "useAcrylic": false, "backgroundImage": "ms-appx:///internal-background.png", "backgroundImageAlignment": "bottomRight", @@ -51,25 +78,26 @@ "schemes": [ { - "name": "Vintage", - "foreground": "#C0C0C0", - "background": "#000000", - "black": "#000000", - "red": "#800000", - "green": "#008000", - "yellow": "#808000", - "blue": "#000080", - "purple": "#800080", - "cyan": "#008080", - "white": "#C0C0C0", - "brightBlack": "#808080", - "brightRed": "#FF0000", - "brightGreen": "#00FF00", - "brightYellow": "#FFFF00", - "brightBlue": "#0000FF", - "brightPurple": "#FF00FF", - "brightCyan": "#00FFFF", - "brightWhite": "#FFFFFF" + "name": "Campbell", + "foreground": "#CCCCCC", + "background": "#0C0C0C", + "cursorColor": "#FFFFFF", + "black": "#0C0C0C", + "red": "#C50F1F", + "green": "#13A10E", + "yellow": "#C19C00", + "blue": "#0037DA", + "purple": "#881798", + "cyan": "#3A96DD", + "white": "#CCCCCC", + "brightBlack": "#767676", + "brightRed": "#E74856", + "brightGreen": "#16C60C", + "brightYellow": "#F9F1A5", + "brightBlue": "#3B78FF", + "brightPurple": "#B4009E", + "brightCyan": "#61D6D6", + "brightWhite": "#F2F2F2" } ], "actions": @@ -78,14 +106,21 @@ { "command": "closeWindow", "keys": "alt+f4" }, { "command": "toggleFullscreen", "keys": "alt+enter" }, { "command": "toggleFullscreen", "keys": "f11" }, + { "command": "toggleFocusMode" }, + { "command": "toggleAlwaysOnTop" }, { "command": "openNewTabDropdown", "keys": "ctrl+shift+space" }, { "command": "openSettings", "keys": "ctrl+," }, + { "command": { "action": "openSettings", "target": "defaultsFile" }, "keys": "ctrl+alt+," }, { "command": "find", "keys": "ctrl+shift+f" }, + { "command": "toggleRetroEffect" }, + { "command": "openTabColorPicker" }, { "command": "commandPalette", "keys":"ctrl+shift+p" }, // Tab Management // "command": "closeTab" is unbound by default. // The closeTab command closes a tab without confirmation, even if it has multiple panes. + { "command": "closeOtherTabs" }, + { "command": "closeTabsAfter" }, { "command": "newTab", "keys": "ctrl+shift+t" }, { "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+shift+1" }, { "command": { "action": "newTab", "index": 1 }, "keys": "ctrl+shift+2" }, @@ -121,6 +156,7 @@ { "command": { "action": "moveFocus", "direction": "left" }, "keys": "alt+left" }, { "command": { "action": "moveFocus", "direction": "right" }, "keys": "alt+right" }, { "command": { "action": "moveFocus", "direction": "up" }, "keys": "alt+up" }, + { "command": "togglePaneZoom" }, // Clipboard Integration { "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+shift+c" }, @@ -137,6 +173,53 @@ // Visual Adjustments { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+=" }, { "command": { "action": "adjustFontSize", "delta": -1 }, "keys": "ctrl+-" }, - { "command": "resetFontSize", "keys": "ctrl+0" } + { "command": "resetFontSize", "keys": "ctrl+0" }, + + // Other commands + { + // Select color scheme... + "name": { "key": "SetColorSchemeParentCommandName" }, + "commands": [ + { + "iterateOn": "schemes", + "name": "${scheme.name}", + "command": { "action": "setColorScheme", "colorScheme": "${scheme.name}" } + } + ] + }, + { + // New tab... + "name": { "key": "NewTabParentCommandName" }, + "commands": [ + { + "iterateOn": "profiles", + "icon": "${profile.icon}", + "name": "${profile.name}", + "command": { "action": "newTab", "profile": "${profile.name}" } + } + ] + }, + { + // Split pane... + "name": { "key": "SplitPaneParentCommandName" }, + "commands": [ + { + "iterateOn": "profiles", + "icon": "${profile.icon}", + "name": "${profile.name}...", + "commands": [ + { + "command": { "action": "splitPane", "profile": "${profile.name}", "split": "auto" } + }, + { + "command": { "action": "splitPane", "profile": "${profile.name}", "split": "vertical" } + }, + { + "command": { "action": "splitPane", "profile": "${profile.name}", "split": "horizontal" } + } + ] + } + ] + } ] } diff --git a/src/cascadia/TerminalConnection/AzureConnection.cpp b/src/cascadia/TerminalConnection/AzureConnection.cpp index ae7b3a5601e..eb31dceba58 100644 --- a/src/cascadia/TerminalConnection/AzureConnection.cpp +++ b/src/cascadia/TerminalConnection/AzureConnection.cpp @@ -3,10 +3,6 @@ #include "pch.h" -// We have to define GSL here, not PCH -// because TelnetConnection has a conflicting GSL implementation. -#include - #include "AzureConnection.h" #include "AzureClientID.h" #include diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp index 676d1f905fc..b05dd74425d 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.cpp +++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp @@ -3,10 +3,6 @@ #include "pch.h" -// We have to define GSL here, not PCH -// because TelnetConnection has a conflicting GSL implementation. -#include - #include "ConptyConnection.h" #include diff --git a/src/cascadia/TerminalConnection/EchoConnection.cpp b/src/cascadia/TerminalConnection/EchoConnection.cpp index d3922144b82..2fd34cd9764 100644 --- a/src/cascadia/TerminalConnection/EchoConnection.cpp +++ b/src/cascadia/TerminalConnection/EchoConnection.cpp @@ -5,10 +5,6 @@ #include "EchoConnection.h" #include -// We have to define GSL here, not PCH -// because TelnetConnection has a conflicting GSL implementation. -#include - #include "EchoConnection.g.cpp" namespace winrt::Microsoft::Terminal::TerminalConnection::implementation diff --git a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw index 8632aa4294a..b0abd44a0cb 100644 --- a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw @@ -212,7 +212,4 @@ The first argument {0...} is the hexadecimal error code. The second argument {1} is the user-specified path to a program. If this string is broken to multiple lines, it will not be displayed properly. - - Could not connect to telnet server. - diff --git a/src/cascadia/TerminalConnection/TelnetConnection.cpp b/src/cascadia/TerminalConnection/TelnetConnection.cpp deleted file mode 100644 index d7753349588..00000000000 --- a/src/cascadia/TerminalConnection/TelnetConnection.cpp +++ /dev/null @@ -1,333 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#include "pch.h" -#include "TelnetConnection.h" -#include - -#include "TelnetConnection.g.cpp" - -#include "../../types/inc/Utils.hpp" - -using namespace ::Microsoft::Console; - -constexpr std::wstring_view telnetScheme = L"telnet"; -constexpr std::wstring_view msTelnetLoopbackScheme = L"ms-telnet-loop"; - -namespace winrt::Microsoft::Terminal::TerminalConnection::implementation -{ - TelnetConnection::TelnetConnection(const hstring& uri) : - _reader{ nullptr }, - _writer{ nullptr }, - _uri{ uri }, - _receiveBuffer{} - { - _session.install(_nawsServer); - _nawsServer.activate([](auto&&) {}); - } - - // Method description: - // - ascribes to the ITerminalConnection interface - // - creates the output thread - void TelnetConnection::Start() - try - { - // Create our own output handling thread - // Each connection needs to make sure to drain the output from its backing host. - _hOutputThread.reset(CreateThread( - nullptr, - 0, - [](LPVOID lpParameter) { - auto pInstance = static_cast(lpParameter); - if (pInstance) - { - return pInstance->_outputThread(); - } - return gsl::narrow_cast(ERROR_BAD_ARGUMENTS); - }, - this, - 0, - nullptr)); - - THROW_LAST_ERROR_IF_NULL(_hOutputThread); - - _transitionToState(ConnectionState::Connecting); - - // Set initial window title. - _TerminalOutputHandlers(L"\x1b]0;Telnet\x7"); - } - catch (...) - { - LOG_CAUGHT_EXCEPTION(); - _transitionToState(ConnectionState::Failed); - } - - // Method description: - // - ascribes to the ITerminalConnection interface - // - handles the different possible inputs in the different states - // Arguments: - // the user's input - void TelnetConnection::WriteInput(hstring const& data) - { - if (!_isStateOneOf(ConnectionState::Connected, ConnectionState::Connecting)) - { - return; - } - - auto str = winrt::to_string(data); - if (str.size() == 1 && str.at(0) == L'\r') - { - str = "\r\n"; - } - -#pragma warning(suppress : 26490) // Using something that isn't reinterpret_cast to forward stream bytes is more clumsy than just using it. - telnetpp::bytes bytes(reinterpret_cast(str.data()), str.size()); - _session.send(bytes, [=](telnetpp::bytes data) { - _socketSend(data); - }); - } - - // Method description: - // - ascribes to the ITerminalConnection interface - // - resizes the terminal - // Arguments: - // - the new rows/cols values - void TelnetConnection::Resize(uint32_t rows, uint32_t columns) - { - if (_prevResize.has_value() && _prevResize.value().first == rows && _prevResize.value().second == columns) - { - return; - } - - _prevResize.emplace(std::pair{ rows, columns }); - - _nawsServer.set_window_size(gsl::narrow(columns), - gsl::narrow(rows), - [=](telnetpp::subnegotiation sub) { - _session.send(sub, - [=](telnetpp::bytes data) { - _socketBufferedSend(data); - }); - _socketFlushBuffer(); - }); - } - - // Method description: - // - ascribes to the ITerminalConnection interface - // - closes the socket connection and the output thread - void TelnetConnection::Close() - try - { - if (_transitionToState(ConnectionState::Closing)) - { - _socket.Close(); - if (_hOutputThread) - { - // Tear down our output thread - WaitForSingleObject(_hOutputThread.get(), INFINITE); - _hOutputThread.reset(); - } - - _transitionToState(ConnectionState::Closed); - } - } - catch (...) - { - LOG_CAUGHT_EXCEPTION(); - _transitionToState(ConnectionState::Failed); - } - - // Method description: - // - this is the output thread, where we initiate the connection to the remote host - // and establish a socket connection - // Return value: - // - return status - DWORD TelnetConnection::_outputThread() - try - { - while (true) - { - if (_isStateOneOf(ConnectionState::Failed)) - { - _TerminalOutputHandlers(RS_(L"TelnetInternetOrServerIssue") + L"\r\n"); - return E_FAIL; - } - else if (_isStateAtOrBeyond(ConnectionState::Closing)) - { - return S_FALSE; - } - else if (_isStateOneOf(ConnectionState::Connecting)) - { - try - { - const auto uri = Windows::Foundation::Uri(_uri); - const auto host = Windows::Networking::HostName(uri.Host()); - - bool autoLogin = false; - // If we specified the special ms loopback scheme, then set autologin and proceed below. - if (msTelnetLoopbackScheme == uri.SchemeName()) - { - autoLogin = true; - } - // Otherwise, make sure we said telnet://, anything else is not supported here. - else if (telnetScheme != uri.SchemeName()) - { - THROW_HR(E_INVALIDARG); - } - - _socket.ConnectAsync(host, winrt::to_hstring(uri.Port())).get(); - _writer = Windows::Storage::Streams::DataWriter(_socket.OutputStream()); - _reader = Windows::Storage::Streams::DataReader(_socket.InputStream()); - _reader.InputStreamOptions(Windows::Storage::Streams::InputStreamOptions::Partial); // returns when 1 or more bytes ready. - _transitionToState(ConnectionState::Connected); - - if (autoLogin) - { - // Send newline to bypass User Name prompt. - const auto newline = winrt::to_hstring("\r\n"); - WriteInput(newline); - - // Wait for login. - Sleep(1000); - - // Send "cls" enter to clear the thing and just look like a prompt. - const auto clearScreen = winrt::to_hstring("cls\r\n"); - WriteInput(clearScreen); - } - } - catch (...) - { - LOG_CAUGHT_EXCEPTION(); - _transitionToState(ConnectionState::Failed); - } - } - else if (_isStateOneOf(ConnectionState::Connected)) - { - // Read from socket - const auto amountReceived = _socketReceive(_receiveBuffer); - - _session.receive( - telnetpp::bytes{ _receiveBuffer.data(), amountReceived }, - [=](telnetpp::bytes data, - std::function const& send) { - _applicationReceive(data, send); - }, - [=](telnetpp::bytes data) { - _socketSend(data); - }); - } - } - } - catch (...) - { - // If the exception was thrown while we were already supposed to be closing, fine. We're closed. - // This is because the socket got mad things were being torn down. - if (_isStateAtOrBeyond(ConnectionState::Closing)) - { - _transitionToState(ConnectionState::Closed); - return S_OK; - } - else - { - LOG_CAUGHT_EXCEPTION(); - _transitionToState(ConnectionState::Failed); - return E_FAIL; - } - } - - // Routine Description: - // - Call to buffer up bytes to send to the remote device. - // - You must flush before they'll go out. - // Arguments: - // - data - View of bytes to be sent - // Return Value: - // - - void TelnetConnection::_socketBufferedSend(telnetpp::bytes data) - { - // winrt::array_view should take data/size but it doesn't. - // We contacted the WinRT owners and they said, more or less, that it's not worth fixing - // with std::span on the horizon instead of this. So we're suppressing the warning - // and hoping for a std::span future that will eliminate winrt::array_view -#pragma warning(push) -#pragma warning(disable : 26481) - const uint8_t* first = data.data(); - const uint8_t* last = data.data() + data.size(); -#pragma warning(pop) - - const winrt::array_view arrayView(first, last); - _writer.WriteBytes(arrayView); - } - - // Routine Description: - // - Flushes any buffered bytes to the underlying socket - // Arguments: - // - - // Return Value: - // - - fire_and_forget TelnetConnection::_socketFlushBuffer() - { - co_await _writer.StoreAsync(); - } - - // Routine Description: - // - Used to send bytes into the socket to the remote device - // Arguments: - // - data - View of bytes to be sent - // Return Value: - // - - void TelnetConnection::_socketSend(telnetpp::bytes data) - { - _socketBufferedSend(data); - _socketFlushBuffer(); - } - - // Routine Description: - // - Reads bytes from the socket into the given array. - // Arguments: - // - buffer - The array of bytes to use for storage - // Return Value: - // - The number of bytes actually read (less than or equal to input array size) - size_t TelnetConnection::_socketReceive(gsl::span buffer) - { - const auto bytesLoaded = _reader.LoadAsync(gsl::narrow(buffer.size())).get(); - - // winrt::array_view, despite having a pointer and size constructor - // hides it as protected. - // So we have to get first/last (even though cppcorechecks will be - // mad at us for it) to use a public array_view constructor. - // The WinRT team isn't fixing this because std::span is coming - // soon and that will do it. -#pragma warning(push) -#pragma warning(disable : 26481) - const auto first = buffer.data(); - const auto last = first + bytesLoaded; -#pragma warning(pop) - - const winrt::array_view arrayView(first, last); - _reader.ReadBytes(arrayView); - return bytesLoaded; - } - - // Routine Description: - // - Called by telnetpp framework when application data is received on the channel - // In contrast, telnet metadata payload is consumed by telnetpp and not forwarded to us. - // Arguments: - // - data - The relevant application-level payload received - // - send - A function where we can send a reply to given data immediately - // in reaction to the received message. - // Return Value: - // - - void TelnetConnection::_applicationReceive(telnetpp::bytes data, - std::function const& /*send*/) - { - // Convert telnetpp bytes to standard string_view -#pragma warning(suppress : 26490) // Using something that isn't reinterpret_cast to forward stream bytes is more clumsy than just using it. - const auto stringView = std::string_view{ reinterpret_cast(data.data()), gsl::narrow(data.size()) }; - - // Convert to hstring - const auto hstr = winrt::to_hstring(stringView); - - // Pass the output to our registered event handlers - _TerminalOutputHandlers(hstr); - } -} diff --git a/src/cascadia/TerminalConnection/TelnetConnection.h b/src/cascadia/TerminalConnection/TelnetConnection.h deleted file mode 100644 index ca632c4366f..00000000000 --- a/src/cascadia/TerminalConnection/TelnetConnection.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#pragma once - -#include "TelnetConnection.g.h" - -#include -#include - -#pragma warning(push) -#pragma warning(disable : 4100) -#pragma warning(disable : 4251) -#include -#include -#include -#pragma warning(pop) - -#include "winrt/Windows.Networking.Sockets.h" -#include "winrt/Windows.Storage.Streams.h" - -#include "../cascadia/inc/cppwinrt_utils.h" -#include "ConnectionStateHolder.h" - -namespace winrt::Microsoft::Terminal::TerminalConnection::implementation -{ - struct TelnetConnection : TelnetConnectionT, ConnectionStateHolder - { - TelnetConnection(const hstring& uri); - - void Start(); - void WriteInput(hstring const& data); - void Resize(uint32_t rows, uint32_t columns); - void Close(); - - WINRT_CALLBACK(TerminalOutput, TerminalOutputHandler); - - private: - hstring _uri; - - void _applicationReceive(telnetpp::bytes data, - std::function const& send); - - void _socketBufferedSend(telnetpp::bytes data); - fire_and_forget _socketFlushBuffer(); - void _socketSend(telnetpp::bytes data); - size_t _socketReceive(gsl::span buffer); - - telnetpp::session _session; - // NAWS = Negotiation About Window Size - telnetpp::options::naws::server _nawsServer; - Windows::Networking::Sockets::StreamSocket _socket; - Windows::Storage::Streams::DataWriter _writer; - Windows::Storage::Streams::DataReader _reader; - - std::optional> _prevResize; - - static constexpr size_t _receiveBufferSize = 1024; - std::array _receiveBuffer; - - wil::unique_handle _hOutputThread; - - DWORD _outputThread(); - }; -} - -namespace winrt::Microsoft::Terminal::TerminalConnection::factory_implementation -{ - struct TelnetConnection : TelnetConnectionT - { - }; -} diff --git a/src/cascadia/TerminalConnection/TelnetConnection.idl b/src/cascadia/TerminalConnection/TelnetConnection.idl deleted file mode 100644 index ac250b39ca6..00000000000 --- a/src/cascadia/TerminalConnection/TelnetConnection.idl +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import "ITerminalConnection.idl"; - -namespace Microsoft.Terminal.TerminalConnection -{ - [default_interface] - runtimeclass TelnetConnection : ITerminalConnection - { - TelnetConnection(String uri); - }; - -} diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj index 9c3713ea0b2..3cc6689e191 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj @@ -28,9 +28,6 @@ EchoConnection.idl - - TelnetConnection.idl - @@ -47,16 +44,12 @@ ConptyConnection.idl - - TelnetConnection.idl - - @@ -88,14 +81,12 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - $(OpenConsoleCommonOutDir)\conptylib.lib;%(AdditionalDependencies) - diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters index 13132925970..91e6af3f51c 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters @@ -18,21 +18,18 @@ - - - diff --git a/src/cascadia/TerminalConnection/packages.config b/src/cascadia/TerminalConnection/packages.config index dc021f9134d..208b7812ed1 100644 --- a/src/cascadia/TerminalConnection/packages.config +++ b/src/cascadia/TerminalConnection/packages.config @@ -2,5 +2,4 @@ - - \ No newline at end of file + diff --git a/src/cascadia/TerminalConnection/pch.h b/src/cascadia/TerminalConnection/pch.h index 1550c51ca4e..9a0c20e2ef9 100644 --- a/src/cascadia/TerminalConnection/pch.h +++ b/src/cascadia/TerminalConnection/pch.h @@ -10,8 +10,6 @@ // Needs to be defined or we get redeclaration errors #define WIN32_LEAN_AND_MEAN -#define BLOCK_GSL - // Manually include til after we include Windows.Foundation to give it winrt superpowers #define BLOCK_TIL #include diff --git a/src/inc/LibraryIncludes.h b/src/inc/LibraryIncludes.h index 4f7721b89d3..e2837dc2c5b 100644 --- a/src/inc/LibraryIncludes.h +++ b/src/inc/LibraryIncludes.h @@ -61,11 +61,9 @@ // GSL // Block GSL Multi Span include because it both has C++17 deprecated iterators // and uses the C-namespaced "max" which conflicts with Windows definitions. -#ifndef BLOCK_GSL #define GSL_MULTI_SPAN_H #include #include -#endif // CppCoreCheck #include diff --git a/src/inc/til/bitmap.h b/src/inc/til/bitmap.h index 028123cc455..f992fe765b6 100644 --- a/src/inc/til/bitmap.h +++ b/src/inc/til/bitmap.h @@ -405,7 +405,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" const auto bitShift = delta_y * _sz.width(); #pragma warning(push) - // we can't depend on GSL here (some libraries use BLOCK_GSL), so we use static_cast for explicit narrowing + // we can't depend on GSL here, so we use static_cast for explicit narrowing #pragma warning(disable : 26472) const auto newBits = static_cast(std::abs(bitShift)); #pragma warning(pop) diff --git a/src/inc/til/color.h b/src/inc/til/color.h index 0ab76f66123..b39682b7f11 100644 --- a/src/inc/til/color.h +++ b/src/inc/til/color.h @@ -8,7 +8,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" // color is a universal integral 8bpp RGBA (0-255) color type implicitly convertible to/from // a number of other color types. #pragma warning(push) - // we can't depend on GSL here (some libraries use BLOCK_GSL), so we use static_cast for explicit narrowing + // we can't depend on GSL here, so we use static_cast for explicit narrowing #pragma warning(disable : 26472) struct color {