| | | 1 | | namespace Renci.SshNet.Messages.Connection |
| | | 2 | | { |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents "env" type channel request information. |
| | | 5 | | /// </summary> |
| | | 6 | | internal sealed class EnvironmentVariableRequestInfo : RequestInfo |
| | | 7 | | { |
| | | 8 | | private byte[] _variableName; |
| | | 9 | | private byte[] _variableValue; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Channel request name. |
| | | 13 | | /// </summary> |
| | | 14 | | public const string Name = "env"; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets the name of the request. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <value> |
| | | 20 | | /// The name of the request. |
| | | 21 | | /// </value> |
| | | 22 | | public override string RequestName |
| | | 23 | | { |
| | 0 | 24 | | get { return Name; } |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets the name of the variable. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <value> |
| | | 31 | | /// The name of the variable. |
| | | 32 | | /// </value> |
| | | 33 | | public string VariableName |
| | | 34 | | { |
| | 0 | 35 | | get { return Utf8.GetString(_variableName, 0, _variableName.Length); } |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Gets the value of the variable. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <value> |
| | | 42 | | /// The variable value. |
| | | 43 | | /// </value> |
| | | 44 | | public string VariableValue |
| | | 45 | | { |
| | 0 | 46 | | get { return Utf8.GetString(_variableValue, 0, _variableValue.Length); } |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the size of the message in bytes. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <value> |
| | | 53 | | /// The size of the messages in bytes. |
| | | 54 | | /// </value> |
| | | 55 | | protected override int BufferCapacity |
| | | 56 | | { |
| | | 57 | | get |
| | 0 | 58 | | { |
| | 0 | 59 | | var capacity = base.BufferCapacity; |
| | 0 | 60 | | capacity += 4; // VariableName length |
| | 0 | 61 | | capacity += _variableName.Length; // VariableName |
| | 0 | 62 | | capacity += 4; // VariableValue length |
| | 0 | 63 | | capacity += _variableValue.Length; // VariableValue |
| | 0 | 64 | | return capacity; |
| | 0 | 65 | | } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Initializes a new instance of the <see cref="EnvironmentVariableRequestInfo"/> class. |
| | | 70 | | /// </summary> |
| | 2804 | 71 | | public EnvironmentVariableRequestInfo() |
| | 2804 | 72 | | { |
| | 2804 | 73 | | WantReply = true; |
| | 2804 | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Initializes a new instance of the <see cref="EnvironmentVariableRequestInfo"/> class. |
| | | 78 | | /// </summary> |
| | | 79 | | /// <param name="variableName">Name of the variable.</param> |
| | | 80 | | /// <param name="variableValue">The variable value.</param> |
| | | 81 | | public EnvironmentVariableRequestInfo(string variableName, string variableValue) |
| | 0 | 82 | | : this() |
| | 0 | 83 | | { |
| | 0 | 84 | | _variableName = Utf8.GetBytes(variableName); |
| | 0 | 85 | | _variableValue = Utf8.GetBytes(variableValue); |
| | 0 | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Called when type specific data need to be loaded. |
| | | 90 | | /// </summary> |
| | | 91 | | protected override void LoadData() |
| | 0 | 92 | | { |
| | 0 | 93 | | base.LoadData(); |
| | | 94 | | |
| | 0 | 95 | | _variableName = ReadBinary(); |
| | 0 | 96 | | _variableValue = ReadBinary(); |
| | 0 | 97 | | } |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// Called when type specific data need to be saved. |
| | | 101 | | /// </summary> |
| | | 102 | | protected override void SaveData() |
| | 0 | 103 | | { |
| | 0 | 104 | | base.SaveData(); |
| | | 105 | | |
| | 0 | 106 | | WriteBinaryString(_variableName); |
| | 0 | 107 | | WriteBinaryString(_variableValue); |
| | 0 | 108 | | } |
| | | 109 | | } |
| | | 110 | | } |