aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/main')
-rw-r--r--lib/src/main/java/com/trilead/ssh2/Session.java11
-rw-r--r--lib/src/main/java/com/trilead/ssh2/channel/ChannelManager.java30
-rw-r--r--lib/src/main/java/com/trilead/ssh2/packets/PacketSessionPtyResize.java40
3 files changed, 81 insertions, 0 deletions
diff --git a/lib/src/main/java/com/trilead/ssh2/Session.java b/lib/src/main/java/com/trilead/ssh2/Session.java
index 4784537..c41d837 100644
--- a/lib/src/main/java/com/trilead/ssh2/Session.java
+++ b/lib/src/main/java/com/trilead/ssh2/Session.java
@@ -129,6 +129,17 @@ public class Session
cm.requestPTY(cn, term, term_width_characters, term_height_characters, term_width_pixels, term_height_pixels,
terminal_modes);
}
+
+ public void resizePTY(int width, int height) throws IOException {
+ synchronized (this)
+ {
+ /* The following is just a nicer error, we would catch it anyway later in the channel code */
+ if (flag_closed)
+ throw new IOException("This session is closed.");
+ }
+
+ cm.resizePTY(cn, width, height);
+ }
/**
* Request X11 forwarding for the current session.
diff --git a/lib/src/main/java/com/trilead/ssh2/channel/ChannelManager.java b/lib/src/main/java/com/trilead/ssh2/channel/ChannelManager.java
index ebd7585..74906d3 100644
--- a/lib/src/main/java/com/trilead/ssh2/channel/ChannelManager.java
+++ b/lib/src/main/java/com/trilead/ssh2/channel/ChannelManager.java
@@ -17,6 +17,7 @@ import com.trilead.ssh2.packets.PacketOpenDirectTCPIPChannel;
import com.trilead.ssh2.packets.PacketOpenSessionChannel;
import com.trilead.ssh2.packets.PacketSessionExecCommand;
import com.trilead.ssh2.packets.PacketSessionPtyRequest;
+import com.trilead.ssh2.packets.PacketSessionPtyResize;
import com.trilead.ssh2.packets.PacketSessionStartShell;
import com.trilead.ssh2.packets.PacketSessionSubsystemRequest;
import com.trilead.ssh2.packets.PacketSessionX11Request;
@@ -675,6 +676,35 @@ public class ChannelManager implements MessageHandler
throw (IOException) new IOException("PTY request failed").initCause(e);
}
}
+
+
+ public void resizePTY(Channel c, int width, int height) throws IOException {
+ PacketSessionPtyResize spr;
+
+ synchronized (c) {
+ if (c.state != Channel.STATE_OPEN)
+ throw new IOException("Cannot request PTY on this channel ("
+ + c.getReasonClosed() + ")");
+
+ spr = new PacketSessionPtyResize(c.remoteID, true, width, height);
+ c.successCounter = c.failedCounter = 0;
+ }
+
+ synchronized (c.channelSendLock) {
+ if (c.closeMessageSent)
+ throw new IOException("Cannot request PTY on this channel ("
+ + c.getReasonClosed() + ")");
+ tm.sendMessage(spr.getPayload());
+ }
+
+ try {
+ waitForChannelSuccessOrFailure(c);
+ } catch (IOException e) {
+ throw (IOException) new IOException("PTY request failed")
+ .initCause(e);
+ }
+ }
+
public void requestX11(Channel c, boolean singleConnection, String x11AuthenticationProtocol,
String x11AuthenticationCookie, int x11ScreenNumber) throws IOException
diff --git a/lib/src/main/java/com/trilead/ssh2/packets/PacketSessionPtyResize.java b/lib/src/main/java/com/trilead/ssh2/packets/PacketSessionPtyResize.java
new file mode 100644
index 0000000..20d35cd
--- /dev/null
+++ b/lib/src/main/java/com/trilead/ssh2/packets/PacketSessionPtyResize.java
@@ -0,0 +1,40 @@
+package com.trilead.ssh2.packets;
+
+public class PacketSessionPtyResize {
+ byte[] payload;
+
+ public int recipientChannelID;
+ public boolean wantReply;
+ public String term;
+ public int width;
+ public int height;
+
+ public PacketSessionPtyResize(int recipientChannelID, boolean wantReply, int width, int height) {
+ this.recipientChannelID = recipientChannelID;
+ this.wantReply = wantReply;
+ this.term = term;
+ this.width = width;
+ this.height = height;
+ }
+
+ public byte[] getPayload()
+ {
+ if (payload == null)
+ {
+ TypesWriter tw = new TypesWriter();
+ tw.writeByte(Packets.SSH_MSG_CHANNEL_REQUEST);
+ tw.writeUINT32(recipientChannelID);
+ tw.writeString("window-change");
+ tw.writeBoolean(wantReply);
+ tw.writeUINT32(width);
+ tw.writeUINT32(height);
+ tw.writeUINT32(0);
+ tw.writeUINT32(0);
+
+ payload = tw.getBytes();
+ }
+ return payload;
+ }
+}
+
+