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 SshMsgChannelRequest extends SshMessage {
042: /** */
043: protected final static int SSH_MSG_CHANNEL_REQUEST = 98;
044: private String requestType;
045: private byte[] channelData;
046: private boolean wantReply;
047: private long recipientChannel;
048:
049: /**
050: * Creates a new SshMsgChannelRequest object.
051: *
052: * @param recipientChannel
053: * @param requestType
054: * @param wantReply
055: * @param channelData
056: */
057: public SshMsgChannelRequest(long recipientChannel,
058: String requestType, boolean wantReply, byte[] channelData) {
059: super (SSH_MSG_CHANNEL_REQUEST);
060: this .recipientChannel = recipientChannel;
061: this .requestType = requestType;
062: this .wantReply = wantReply;
063: this .channelData = channelData;
064: }
065:
066: /**
067: * Creates a new SshMsgChannelRequest object.
068: */
069: public SshMsgChannelRequest() {
070: super (SSH_MSG_CHANNEL_REQUEST);
071: }
072:
073: /**
074: *
075: *
076: * @return
077: */
078: public byte[] getChannelData() {
079: return channelData;
080: }
081:
082: /**
083: *
084: *
085: * @return
086: */
087: public String getMessageName() {
088: return "SSH_MSG_CHANNEL_REQUEST";
089: }
090:
091: /**
092: *
093: *
094: * @return
095: */
096: public long getRecipientChannel() {
097: return recipientChannel;
098: }
099:
100: /**
101: *
102: *
103: * @return
104: */
105: public String getRequestType() {
106: return requestType;
107: }
108:
109: /**
110: *
111: *
112: * @return
113: */
114: public boolean getWantReply() {
115: return wantReply;
116: }
117:
118: /**
119: *
120: *
121: * @param baw
122: *
123: * @throws InvalidMessageException
124: */
125: protected void constructByteArray(ByteArrayWriter baw)
126: throws InvalidMessageException {
127: try {
128: baw.writeInt(recipientChannel);
129: baw.writeString(requestType);
130: baw.write((wantReply ? 1 : 0));
131:
132: if (channelData != null) {
133: baw.write(channelData);
134: }
135: } catch (IOException ioe) {
136: throw new InvalidMessageException("Invalid message data");
137: }
138: }
139:
140: /**
141: *
142: *
143: * @param bar
144: *
145: * @throws InvalidMessageException
146: */
147: protected void constructMessage(ByteArrayReader bar)
148: throws InvalidMessageException {
149: try {
150: recipientChannel = bar.readInt();
151: requestType = bar.readString();
152: wantReply = ((bar.read() == 0) ? false : true);
153:
154: if (bar.available() > 0) {
155: channelData = new byte[bar.available()];
156: bar.read(channelData);
157: }
158: } catch (IOException ioe) {
159: throw new InvalidMessageException("Invalid message data");
160: }
161: }
162: }
|