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