| | | 1 | | namespace Renci.SshNet.Messages.Connection |
| | | 2 | | { |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents "exit-signal" type channel request information. |
| | | 5 | | /// </summary> |
| | | 6 | | internal sealed class ExitSignalRequestInfo : RequestInfo |
| | | 7 | | { |
| | | 8 | | private byte[] _signalName; |
| | | 9 | | private byte[] _errorMessage; |
| | | 10 | | private byte[] _language; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Channel request name. |
| | | 14 | | /// </summary> |
| | | 15 | | public const string Name = "exit-signal"; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets the name of the request. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <value> |
| | | 21 | | /// The name of the request. |
| | | 22 | | /// </value> |
| | | 23 | | public override string RequestName |
| | | 24 | | { |
| | 0 | 25 | | get { return Name; } |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the name of the signal. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <value> |
| | | 32 | | /// The name of the signal. |
| | | 33 | | /// </value> |
| | | 34 | | public string SignalName |
| | | 35 | | { |
| | 0 | 36 | | get { return Ascii.GetString(_signalName, 0, _signalName.Length); } |
| | 0 | 37 | | private set { _signalName = Ascii.GetBytes(value); } |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets a value indicating whether core is dumped. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <value> |
| | | 44 | | /// <see langword="true"/> if core is dumped; otherwise, <see langword="false"/>. |
| | | 45 | | /// </value> |
| | 5 | 46 | | public bool CoreDumped { get; private set; } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets the error message. |
| | | 50 | | /// </summary> |
| | | 51 | | public string ErrorMessage |
| | | 52 | | { |
| | 0 | 53 | | get { return Utf8.GetString(_errorMessage, 0, _errorMessage.Length); } |
| | 0 | 54 | | private set { _errorMessage = Utf8.GetBytes(value); } |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets message language. |
| | | 59 | | /// </summary> |
| | | 60 | | public string Language |
| | | 61 | | { |
| | 0 | 62 | | get { return Utf8.GetString(_language, 0, _language.Length); } |
| | 0 | 63 | | private set { _language = Utf8.GetBytes(value); } |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | protected override int BufferCapacity |
| | | 67 | | { |
| | | 68 | | get |
| | 0 | 69 | | { |
| | 0 | 70 | | var capacity = base.BufferCapacity; |
| | 0 | 71 | | capacity += 4; // SignalName length |
| | 0 | 72 | | capacity += _signalName.Length; // SignalName |
| | 0 | 73 | | capacity += 1; // CoreDumped |
| | 0 | 74 | | capacity += 4; // ErrorMessage length |
| | 0 | 75 | | capacity += _errorMessage.Length; // ErrorMessage |
| | 0 | 76 | | capacity += 4; // Language length |
| | 0 | 77 | | capacity += _language.Length; // Language |
| | 0 | 78 | | return capacity; |
| | 0 | 79 | | } |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Initializes a new instance of the <see cref="ExitSignalRequestInfo"/> class. |
| | | 84 | | /// </summary> |
| | 2804 | 85 | | public ExitSignalRequestInfo() |
| | 2804 | 86 | | { |
| | 2804 | 87 | | WantReply = false; |
| | 2804 | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Initializes a new instance of the <see cref="ExitSignalRequestInfo"/> class. |
| | | 92 | | /// </summary> |
| | | 93 | | /// <param name="signalName">Name of the signal.</param> |
| | | 94 | | /// <param name="coreDumped">if set to <see langword="true"/> then core is dumped.</param> |
| | | 95 | | /// <param name="errorMessage">The error message.</param> |
| | | 96 | | /// <param name="language">The language.</param> |
| | | 97 | | public ExitSignalRequestInfo(string signalName, bool coreDumped, string errorMessage, string language) |
| | 0 | 98 | | : this() |
| | 0 | 99 | | { |
| | 0 | 100 | | SignalName = signalName; |
| | 0 | 101 | | CoreDumped = coreDumped; |
| | 0 | 102 | | ErrorMessage = errorMessage; |
| | 0 | 103 | | Language = language; |
| | 0 | 104 | | } |
| | | 105 | | |
| | | 106 | | /// <summary> |
| | | 107 | | /// Called when type specific data need to be loaded. |
| | | 108 | | /// </summary> |
| | | 109 | | protected override void LoadData() |
| | 5 | 110 | | { |
| | 5 | 111 | | base.LoadData(); |
| | | 112 | | |
| | 5 | 113 | | _signalName = ReadBinary(); |
| | 5 | 114 | | CoreDumped = ReadBoolean(); |
| | 5 | 115 | | _errorMessage = ReadBinary(); |
| | 5 | 116 | | _language = ReadBinary(); |
| | 5 | 117 | | } |
| | | 118 | | |
| | | 119 | | /// <summary> |
| | | 120 | | /// Called when type specific data need to be saved. |
| | | 121 | | /// </summary> |
| | | 122 | | protected override void SaveData() |
| | 0 | 123 | | { |
| | 0 | 124 | | base.SaveData(); |
| | | 125 | | |
| | 0 | 126 | | WriteBinaryString(_signalName); |
| | 0 | 127 | | Write(CoreDumped); |
| | 0 | 128 | | Write(_errorMessage); |
| | 0 | 129 | | Write(_language); |
| | 0 | 130 | | } |
| | | 131 | | } |
| | | 132 | | } |