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 SshMsgChannelOpen extends SshMessage {
042: /** */
043: protected final static int SSH_MSG_CHANNEL_OPEN = 90;
044: private String channelType;
045: private byte[] channelData;
046: private long initialWindowSize;
047: private long maximumPacketSize;
048: private long senderChannelId;
049:
050: /**
051: * Creates a new SshMsgChannelOpen object.
052: *
053: * @param channelType
054: * @param senderChannelId
055: * @param initialWindowSize
056: * @param maximumPacketSize
057: * @param channelData
058: */
059: public SshMsgChannelOpen(String channelType, long senderChannelId,
060: long initialWindowSize, long maximumPacketSize,
061: byte[] channelData) {
062: super (SSH_MSG_CHANNEL_OPEN);
063: this .channelType = channelType;
064: this .senderChannelId = senderChannelId;
065: this .initialWindowSize = initialWindowSize;
066: this .maximumPacketSize = maximumPacketSize;
067: this .channelData = channelData;
068: }
069:
070: /**
071: * Creates a new SshMsgChannelOpen object.
072: */
073: public SshMsgChannelOpen() {
074: super (SSH_MSG_CHANNEL_OPEN);
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 String getChannelType() {
092: return channelType;
093: }
094:
095: /**
096: *
097: *
098: * @return
099: */
100: public long getInitialWindowSize() {
101: return initialWindowSize;
102: }
103:
104: /**
105: *
106: *
107: * @return
108: */
109: public long getMaximumPacketSize() {
110: return maximumPacketSize;
111: }
112:
113: /**
114: *
115: *
116: * @return
117: */
118: public String getMessageName() {
119: return "SSH_MSG_CHANNEL_OPEN";
120: }
121:
122: /**
123: *
124: *
125: * @return
126: */
127: public long getSenderChannelId() {
128: return senderChannelId;
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.writeString(channelType);
142: baw.writeInt(senderChannelId);
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(
151: "Could not write message data");
152: }
153: }
154:
155: /**
156: *
157: *
158: * @param bar
159: *
160: * @throws InvalidMessageException
161: */
162: protected void constructMessage(ByteArrayReader bar)
163: throws InvalidMessageException {
164: try {
165: channelType = bar.readString();
166: senderChannelId = bar.readInt();
167: initialWindowSize = bar.readInt();
168: maximumPacketSize = bar.readInt();
169:
170: if (bar.available() > 0) {
171: channelData = new byte[bar.available()];
172: bar.read(channelData);
173: }
174: } catch (IOException ioe) {
175: throw new InvalidMessageException("Invalid message data");
176: }
177: }
178: }
|