This is an automated email from the ASF dual-hosted git repository. jbonofre pushed a commit to branch karaf-4.3.x in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/karaf-4.3.x by this push: new 93b5dc8a7e [KARAF-7607]: careful JLine/SSHD translation 93b5dc8a7e is described below commit 93b5dc8a7e56104390a1cf319295a11db993bfff Author: Robert Varga <robert.va...@pantheon.tech> AuthorDate: Thu Nov 10 04:00:22 2022 +0100 [KARAF-7607]: careful JLine/SSHD translation (cherry picked from commit 0acc109093f46bf88f85b44308e549802262046a) --- .../main/java/org/apache/karaf/client/Main.java | 40 +++++++++++--------- .../java/org/apache/karaf/shell/ssh/SshAction.java | 43 +++++++++++++--------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java index f92b104ef0..9d3a11c999 100644 --- a/client/src/main/java/org/apache/karaf/client/Main.java +++ b/client/src/main/java/org/apache/karaf/client/Main.java @@ -39,7 +39,6 @@ import org.apache.sshd.agent.SshAgent; import org.apache.sshd.agent.local.AgentImpl; import org.apache.sshd.agent.local.LocalAgentFactory; import org.apache.sshd.client.ClientBuilder; -import org.apache.sshd.client.ClientFactoryManager; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.auth.keyboard.UserInteraction; import org.apache.sshd.client.channel.ChannelExec; @@ -221,22 +220,22 @@ public class Main { try { Map<PtyMode, Integer> modes = new HashMap<>(); // Control chars - modes.put(PtyMode.VINTR, attributes.getControlChar(ControlChar.VINTR)); - modes.put(PtyMode.VQUIT, attributes.getControlChar(ControlChar.VQUIT)); - modes.put(PtyMode.VERASE, attributes.getControlChar(ControlChar.VERASE)); - modes.put(PtyMode.VKILL, attributes.getControlChar(ControlChar.VKILL)); - modes.put(PtyMode.VEOF, attributes.getControlChar(ControlChar.VEOF)); - modes.put(PtyMode.VEOL, attributes.getControlChar(ControlChar.VEOL)); - modes.put(PtyMode.VEOL2, attributes.getControlChar(ControlChar.VEOL2)); - modes.put(PtyMode.VSTART, attributes.getControlChar(ControlChar.VSTART)); - modes.put(PtyMode.VSTOP, attributes.getControlChar(ControlChar.VSTOP)); - modes.put(PtyMode.VSUSP, attributes.getControlChar(ControlChar.VSUSP)); - modes.put(PtyMode.VDSUSP, attributes.getControlChar(ControlChar.VDSUSP)); - modes.put(PtyMode.VREPRINT, attributes.getControlChar(ControlChar.VREPRINT)); - modes.put(PtyMode.VWERASE, attributes.getControlChar(ControlChar.VWERASE)); - modes.put(PtyMode.VLNEXT, attributes.getControlChar(ControlChar.VLNEXT)); - modes.put(PtyMode.VSTATUS, attributes.getControlChar(ControlChar.VSTATUS)); - modes.put(PtyMode.VDISCARD, attributes.getControlChar(ControlChar.VDISCARD)); + addMode(modes, PtyMode.VINTR, attributes, ControlChar.VINTR); + addMode(modes, PtyMode.VQUIT, attributes, ControlChar.VQUIT); + addMode(modes, PtyMode.VERASE, attributes, ControlChar.VERASE); + addMode(modes, PtyMode.VKILL, attributes, ControlChar.VKILL); + addMode(modes, PtyMode.VEOF, attributes, ControlChar.VEOF); + addMode(modes, PtyMode.VEOL, attributes, ControlChar.VEOL); + addMode(modes, PtyMode.VEOL2, attributes, ControlChar.VEOL2); + addMode(modes, PtyMode.VSTART, attributes, ControlChar.VSTART); + addMode(modes, PtyMode.VSTOP, attributes, ControlChar.VSTOP); + addMode(modes, PtyMode.VSUSP, attributes, ControlChar.VSUSP); + addMode(modes, PtyMode.VDSUSP, attributes, ControlChar.VDSUSP); + addMode(modes, PtyMode.VREPRINT, attributes, ControlChar.VREPRINT); + addMode(modes, PtyMode.VWERASE, attributes, ControlChar.VWERASE); + addMode(modes, PtyMode.VLNEXT, attributes, ControlChar.VLNEXT); + addMode(modes, PtyMode.VSTATUS, attributes, ControlChar.VSTATUS); + addMode(modes, PtyMode.VDISCARD, attributes, ControlChar.VDISCARD); // Input flags modes.put(PtyMode.IGNPAR, getFlag(attributes, InputFlag.IGNPAR)); modes.put(PtyMode.PARMRK, getFlag(attributes, InputFlag.PARMRK)); @@ -338,6 +337,13 @@ public class Main { } } + private static void addMode(Map<PtyMode, Integer> modes, PtyMode mode, Attributes attributes, ControlChar ctrl) { + final int value = attributes.getControlChar(ctrl); + if (value != -1) { + modes.put(mode, value); + } + } + private static int getFlag(Attributes attributes, InputFlag flag) { return attributes.getInputFlag(flag) ? 1 : 0; } diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java index b0d7b04022..bbd4a6c3a3 100644 --- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java +++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshAction.java @@ -37,13 +37,13 @@ import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.karaf.shell.api.console.Session; import org.apache.karaf.shell.api.console.Terminal; import org.apache.sshd.agent.SshAgent; -import org.apache.sshd.client.channel.ClientChannelEvent; -import org.apache.sshd.client.keyverifier.ServerKeyVerifier; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.auth.keyboard.UserInteraction; import org.apache.sshd.client.channel.ChannelShell; import org.apache.sshd.client.channel.ClientChannel; +import org.apache.sshd.client.channel.ClientChannelEvent; import org.apache.sshd.client.future.ConnectFuture; +import org.apache.sshd.client.keyverifier.ServerKeyVerifier; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.channel.PtyMode; import org.apache.sshd.common.keyprovider.FileKeyPairProvider; @@ -193,22 +193,22 @@ public class SshAction implements Action { try { Map<PtyMode, Integer> modes = new HashMap<>(); // Control chars - modes.put(PtyMode.VINTR, attributes.getControlChar(ControlChar.VINTR)); - modes.put(PtyMode.VQUIT, attributes.getControlChar(ControlChar.VQUIT)); - modes.put(PtyMode.VERASE, attributes.getControlChar(ControlChar.VERASE)); - modes.put(PtyMode.VKILL, attributes.getControlChar(ControlChar.VKILL)); - modes.put(PtyMode.VEOF, attributes.getControlChar(ControlChar.VEOF)); - modes.put(PtyMode.VEOL, attributes.getControlChar(ControlChar.VEOL)); - modes.put(PtyMode.VEOL2, attributes.getControlChar(ControlChar.VEOL2)); - modes.put(PtyMode.VSTART, attributes.getControlChar(ControlChar.VSTART)); - modes.put(PtyMode.VSTOP, attributes.getControlChar(ControlChar.VSTOP)); - modes.put(PtyMode.VSUSP, attributes.getControlChar(ControlChar.VSUSP)); - modes.put(PtyMode.VDSUSP, attributes.getControlChar(ControlChar.VDSUSP)); - modes.put(PtyMode.VREPRINT, attributes.getControlChar(ControlChar.VREPRINT)); - modes.put(PtyMode.VWERASE, attributes.getControlChar(ControlChar.VWERASE)); - modes.put(PtyMode.VLNEXT, attributes.getControlChar(ControlChar.VLNEXT)); - modes.put(PtyMode.VSTATUS, attributes.getControlChar(ControlChar.VSTATUS)); - modes.put(PtyMode.VDISCARD, attributes.getControlChar(ControlChar.VDISCARD)); + addMode(modes, PtyMode.VINTR, attributes, ControlChar.VINTR); + addMode(modes, PtyMode.VQUIT, attributes, ControlChar.VQUIT); + addMode(modes, PtyMode.VERASE, attributes, ControlChar.VERASE); + addMode(modes, PtyMode.VKILL, attributes, ControlChar.VKILL); + addMode(modes, PtyMode.VEOF, attributes, ControlChar.VEOF); + addMode(modes, PtyMode.VEOL, attributes, ControlChar.VEOL); + addMode(modes, PtyMode.VEOL2, attributes, ControlChar.VEOL2); + addMode(modes, PtyMode.VSTART, attributes, ControlChar.VSTART); + addMode(modes, PtyMode.VSTOP, attributes, ControlChar.VSTOP); + addMode(modes, PtyMode.VSUSP, attributes, ControlChar.VSUSP); + addMode(modes, PtyMode.VDSUSP, attributes, ControlChar.VDSUSP); + addMode(modes, PtyMode.VREPRINT, attributes, ControlChar.VREPRINT); + addMode(modes, PtyMode.VWERASE, attributes, ControlChar.VWERASE); + addMode(modes, PtyMode.VLNEXT, attributes, ControlChar.VLNEXT); + addMode(modes, PtyMode.VSTATUS, attributes, ControlChar.VSTATUS); + addMode(modes, PtyMode.VDISCARD, attributes, ControlChar.VDISCARD); // Input flags modes.put(PtyMode.IGNPAR, getFlag(attributes, InputFlag.IGNPAR)); modes.put(PtyMode.PARMRK, getFlag(attributes, InputFlag.PARMRK)); @@ -308,6 +308,13 @@ public class SshAction implements Action { return null; } + private static void addMode(Map<PtyMode, Integer> modes, PtyMode mode, Attributes attributes, ControlChar ctrl) { + final int value = attributes.getControlChar(ctrl); + if (value != -1) { + modes.put(mode, value); + } + } + private static int getFlag(Attributes attributes, InputFlag flag) { return attributes.getInputFlag(flag) ? 1 : 0; }