Mercurial > 510Connectbot
comparison app/src/main/java/ch/ethz/ssh2/packets/PacketDisconnect.java @ 438:d29cce60f393
migrate from Eclipse to Android Studio
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 03 Dec 2015 11:23:55 -0800 |
parents | src/ch/ethz/ssh2/packets/PacketDisconnect.java@071eccdff8ea |
children |
comparison
equal
deleted
inserted
replaced
437:208b31032318 | 438:d29cce60f393 |
---|---|
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 import ch.ethz.ssh2.PacketFormatException; | |
10 import ch.ethz.ssh2.PacketTypeException; | |
11 | |
12 /** | |
13 * @author Christian Plattner | |
14 * @version $Id: PacketDisconnect.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $ | |
15 */ | |
16 public final class PacketDisconnect { | |
17 | |
18 public enum Reason { | |
19 SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT, | |
20 SSH_DISCONNECT_PROTOCOL_ERROR, | |
21 SSH_DISCONNECT_KEY_EXCHANGE_FAILED, | |
22 SSH_DISCONNECT_RESERVED, | |
23 SSH_DISCONNECT_MAC_ERROR, | |
24 SSH_DISCONNECT_COMPRESSION_ERROR, | |
25 SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, | |
26 SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, | |
27 SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE, | |
28 SSH_DISCONNECT_CONNECTION_LOST, | |
29 SSH_DISCONNECT_BY_APPLICATION, | |
30 SSH_DISCONNECT_TOO_MANY_CONNECTIONS, | |
31 SSH_DISCONNECT_AUTH_CANCELLED_BY_USER, | |
32 SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, | |
33 SSH_DISCONNECT_ILLEGAL_USER_NAME | |
34 } | |
35 | |
36 private final byte[] payload; | |
37 | |
38 private final Reason reason; | |
39 | |
40 private final String message; | |
41 | |
42 public PacketDisconnect(byte payload[]) throws IOException { | |
43 this.payload = payload; | |
44 TypesReader tr = new TypesReader(payload); | |
45 int packet_type = tr.readByte(); | |
46 | |
47 if (packet_type != Packets.SSH_MSG_DISCONNECT) { | |
48 throw new PacketTypeException(packet_type); | |
49 } | |
50 | |
51 reason = PacketDisconnect.Reason.values()[tr.readUINT32()]; | |
52 message = tr.readString(); | |
53 String lang = tr.readString(); | |
54 | |
55 if (tr.remain() != 0) { | |
56 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type))); | |
57 } | |
58 } | |
59 | |
60 public PacketDisconnect(Reason reason, String desc) { | |
61 this.reason = reason; | |
62 this.message = desc; | |
63 TypesWriter tw = new TypesWriter(); | |
64 tw.writeByte(Packets.SSH_MSG_DISCONNECT); | |
65 tw.writeUINT32(reason.ordinal()); | |
66 tw.writeString(desc); | |
67 tw.writeString(""); | |
68 payload = tw.getBytes(); | |
69 } | |
70 | |
71 public Reason getReason() { | |
72 return reason; | |
73 } | |
74 | |
75 public String getMessage() { | |
76 return message; | |
77 } | |
78 | |
79 public byte[] getPayload() { | |
80 return payload; | |
81 } | |
82 } |