001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.connection;
027:
028: import com.sshtools.j2ssh.io.ByteArrayReader;
029: import com.sshtools.j2ssh.io.ByteArrayWriter;
030: import com.sshtools.j2ssh.transport.InvalidMessageException;
031: import com.sshtools.j2ssh.transport.SshMessage;
032:
033: import java.io.IOException;
034:
035: /**
036: *
037: *
038: * @author $author$
039: * @version $Revision: 1.20 $
040: */
041: public class SshMsgChannelOpenConfirmation extends SshMessage {
042: /** */
043: protected final static int SSH_MSG_CHANNEL_OPEN_CONFIRMATION = 91;
044: private byte[] channelData;
045: private long initialWindowSize;
046: private long maximumPacketSize;
047: private long recipientChannel;
048: private long senderChannel;
049:
050: /**
051: * Creates a new SshMsgChannelOpenConfirmation object.
052: *
053: * @param recipientChannel
054: * @param senderChannel
055: * @param initialWindowSize
056: * @param maximumPacketSize
057: * @param channelData
058: */
059: public SshMsgChannelOpenConfirmation(long recipientChannel,
060: long senderChannel, long initialWindowSize,
061: long maximumPacketSize, byte[] channelData) {
062: super (SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
063: this .recipientChannel = recipientChannel;
064: this .senderChannel = senderChannel;
065: this .initialWindowSize = initialWindowSize;
066: this .maximumPacketSize = maximumPacketSize;
067: this .channelData = channelData;
068: }
069:
070: /**
071: * Creates a new SshMsgChannelOpenConfirmation object.
072: */
073: public SshMsgChannelOpenConfirmation() {
074: super (SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
075: }
076:
077: /**
078: *
079: *
080: * @return
081: */
082: public byte[] getChannelData() {
083: return channelData;
084: }
085:
086: /**
087: *
088: *
089: * @return
090: */
091: public long getInitialWindowSize() {
092: return initialWindowSize;
093: }
094:
095: /**
096: *
097: *
098: * @return
099: */
100: public long getMaximumPacketSize() {
101: return maximumPacketSize;
102: }
103:
104: /**
105: *
106: *
107: * @return
108: */
109: public String getMessageName() {
110: return "SSH_MSG_CHANNEL_OPEN_CONFIRMATION";
111: }
112:
113: /**
114: *
115: *
116: * @return
117: */
118: public long getRecipientChannel() {
119: return recipientChannel;
120: }
121:
122: /**
123: *
124: *
125: * @return
126: */
127: public long getSenderChannel() {
128: return senderChannel;
129: }
130:
131: /**
132: *
133: *
134: * @param baw
135: *
136: * @throws InvalidMessageException
137: */
138: protected void constructByteArray(ByteArrayWriter baw)
139: throws InvalidMessageException {
140: try {
141: baw.writeInt(recipientChannel);
142: baw.writeInt(senderChannel);
143: baw.writeInt(initialWindowSize);
144: baw.writeInt(maximumPacketSize);
145:
146: if (channelData != null) {
147: baw.write(channelData);
148: }
149: } catch (IOException ioe) {
150: throw new InvalidMessageException("Invalid message data");
151: }
152: }
153:
154: /**
155: *
156: *
157: * @param bar
158: *
159: * @throws InvalidMessageException
160: */
161: protected void constructMessage(ByteArrayReader bar)
162: throws InvalidMessageException {
163: try {
164: recipientChannel = bar.readInt();
165: senderChannel = bar.readInt();
166: initialWindowSize = bar.readInt();
167: maximumPacketSize = bar.readInt();
168:
169: if (bar.available() > 0) {
170: channelData = new byte[bar.available()];
171: bar.read(channelData);
172: }
173: } catch (IOException ioe) {
174: throw new InvalidMessageException("Invalid message data");
175: }
176: }
177: }
|