Home | History | Annotate | Download | only in packets
      1 /*
      2  * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
      3  * Please refer to the LICENSE.txt for licensing details.
      4  */
      5 package ch.ethz.ssh2.packets;
      6 
      7 import java.io.IOException;
      8 
      9 /**
     10  * PacketChannelOpenFailure.
     11  *
     12  * @author Christian Plattner
     13  * @version 2.50, 03/15/10
     14  */
     15 public class PacketChannelOpenFailure
     16 {
     17 	byte[] payload;
     18 
     19 	public int recipientChannelID;
     20 	public int reasonCode;
     21 	public String description;
     22 	public String languageTag;
     23 
     24 	public PacketChannelOpenFailure(int recipientChannelID, int reasonCode, String description,
     25 			String languageTag)
     26 	{
     27 		this.recipientChannelID = recipientChannelID;
     28 		this.reasonCode = reasonCode;
     29 		this.description = description;
     30 		this.languageTag = languageTag;
     31 	}
     32 
     33 	public PacketChannelOpenFailure(byte payload[], int off, int len) throws IOException
     34 	{
     35 		this.payload = new byte[len];
     36 		System.arraycopy(payload, off, this.payload, 0, len);
     37 
     38 		TypesReader tr = new TypesReader(payload, off, len);
     39 
     40 		int packet_type = tr.readByte();
     41 
     42 		if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_FAILURE)
     43 			throw new IOException(
     44 					"This is not a SSH_MSG_CHANNEL_OPEN_FAILURE! ("
     45 							+ packet_type + ")");
     46 
     47 		recipientChannelID = tr.readUINT32();
     48 		reasonCode = tr.readUINT32();
     49 		description = tr.readString();
     50 		languageTag = tr.readString();
     51 
     52 		if (tr.remain() != 0)
     53 			throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN_FAILURE packet!");
     54 	}
     55 
     56 	public byte[] getPayload()
     57 	{
     58 		if (payload == null)
     59 		{
     60 			TypesWriter tw = new TypesWriter();
     61 			tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_FAILURE);
     62 			tw.writeUINT32(recipientChannelID);
     63 			tw.writeUINT32(reasonCode);
     64 			tw.writeString(description);
     65 			tw.writeString(languageTag);
     66 			payload = tw.getBytes();
     67 		}
     68 		return payload;
     69 	}
     70 }
     71