| | | 1 | | namespace Renci.SshNet.Messages.Transport |
| | | 2 | | { |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents SSH_MSG_DISCONNECT message. |
| | | 5 | | /// </summary> |
| | | 6 | | [Message("SSH_MSG_DISCONNECT", 1)] |
| | | 7 | | public class DisconnectMessage : Message, IKeyExchangedAllowed |
| | | 8 | | { |
| | | 9 | | private byte[] _description; |
| | | 10 | | private byte[] _language; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets disconnect reason code. |
| | | 14 | | /// </summary> |
| | 4111 | 15 | | public DisconnectReason ReasonCode { get; private set; } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets disconnect description. |
| | | 19 | | /// </summary> |
| | | 20 | | public string Description |
| | | 21 | | { |
| | 1197 | 22 | | get { return Utf8.GetString(_description, 0, _description.Length); } |
| | 5001 | 23 | | private set { _description = Utf8.GetBytes(value); } |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets message language. |
| | | 28 | | /// </summary> |
| | | 29 | | public string Language |
| | | 30 | | { |
| | 18 | 31 | | get { return Utf8.GetString(_language, 0, _language.Length); } |
| | 5001 | 32 | | private set { _language = Utf8.GetBytes(value); } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets the size of the message in bytes. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <value> |
| | | 39 | | /// The size of the messages in bytes. |
| | | 40 | | /// </value> |
| | | 41 | | protected override int BufferCapacity |
| | | 42 | | { |
| | | 43 | | get |
| | 1667 | 44 | | { |
| | 1667 | 45 | | var capacity = base.BufferCapacity; |
| | 1667 | 46 | | capacity += 4; // ReasonCode |
| | 1667 | 47 | | capacity += 4; // Description length |
| | 1667 | 48 | | capacity += _description.Length; // Description |
| | 1667 | 49 | | capacity += 4; // Language length |
| | 1667 | 50 | | capacity += _language.Length; // Language |
| | 1667 | 51 | | return capacity; |
| | 1667 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Initializes a new instance of the <see cref="DisconnectMessage"/> class. |
| | | 57 | | /// </summary> |
| | 189 | 58 | | public DisconnectMessage() |
| | 189 | 59 | | { |
| | 189 | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <summary> |
| | | 63 | | /// Initializes a new instance of the <see cref="DisconnectMessage"/> class. |
| | | 64 | | /// </summary> |
| | | 65 | | /// <param name="reasonCode">The reason code.</param> |
| | | 66 | | /// <param name="message">The message.</param> |
| | 1667 | 67 | | public DisconnectMessage(DisconnectReason reasonCode, string message) |
| | 1667 | 68 | | { |
| | 1667 | 69 | | ReasonCode = reasonCode; |
| | 1667 | 70 | | Description = message; |
| | 1667 | 71 | | Language = "en"; |
| | 1667 | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Called when type specific data need to be loaded. |
| | | 76 | | /// </summary> |
| | | 77 | | protected override void LoadData() |
| | 189 | 78 | | { |
| | 189 | 79 | | ReasonCode = (DisconnectReason) ReadUInt32(); |
| | 189 | 80 | | _description = ReadBinary(); |
| | 189 | 81 | | _language = ReadBinary(); |
| | 189 | 82 | | } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Called when type specific data need to be saved. |
| | | 86 | | /// </summary> |
| | | 87 | | protected override void SaveData() |
| | 1667 | 88 | | { |
| | 1667 | 89 | | Write((uint) ReasonCode); |
| | 1667 | 90 | | WriteBinaryString(_description); |
| | 1667 | 91 | | WriteBinaryString(_language); |
| | 1667 | 92 | | } |
| | | 93 | | |
| | | 94 | | internal override void Process(Session session) |
| | 189 | 95 | | { |
| | 189 | 96 | | session.OnDisconnectReceived(this); |
| | 189 | 97 | | } |
| | | 98 | | } |
| | | 99 | | } |