| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Renci.SshNet.Messages.Connection |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Used to open "x11" channel type. |
| | | 7 | | /// </summary> |
| | | 8 | | internal sealed class X11ChannelOpenInfo : ChannelOpenInfo |
| | | 9 | | { |
| | | 10 | | private byte[] _originatorAddress; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Specifies channel open type. |
| | | 14 | | /// </summary> |
| | | 15 | | public const string Name = "x11"; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets the type of the channel to open. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <value> |
| | | 21 | | /// The type of the channel to open. |
| | | 22 | | /// </value> |
| | | 23 | | public override string ChannelType |
| | | 24 | | { |
| | 36 | 25 | | get { return Name; } |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the originator address. |
| | | 30 | | /// </summary> |
| | | 31 | | public string OriginatorAddress |
| | | 32 | | { |
| | 18 | 33 | | get { return Utf8.GetString(_originatorAddress, 0, _originatorAddress.Length); } |
| | 9 | 34 | | private set { _originatorAddress = Utf8.GetBytes(value); } |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the originator port. |
| | | 39 | | /// </summary> |
| | 15 | 40 | | public uint OriginatorPort { get; private set; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets the size of the message in bytes. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <value> |
| | | 46 | | /// The size of the messages in bytes. |
| | | 47 | | /// </value> |
| | | 48 | | protected override int BufferCapacity |
| | | 49 | | { |
| | | 50 | | get |
| | 3 | 51 | | { |
| | 3 | 52 | | var capacity = base.BufferCapacity; |
| | 3 | 53 | | capacity += 4; // OriginatorAddress length |
| | 3 | 54 | | capacity += _originatorAddress.Length; // OriginatorAddress |
| | 3 | 55 | | capacity += 4; // OriginatorPort |
| | 3 | 56 | | return capacity; |
| | 3 | 57 | | } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Initializes a new instance of the <see cref="X11ChannelOpenInfo"/> class from the |
| | | 62 | | /// specified data. |
| | | 63 | | /// </summary> |
| | | 64 | | /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langword="null"/>.</exception> |
| | 3 | 65 | | public X11ChannelOpenInfo(byte[] data) |
| | 3 | 66 | | { |
| | 3 | 67 | | Load(data); |
| | 3 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Initializes a new instance of the <see cref="X11ChannelOpenInfo"/> class with the |
| | | 72 | | /// specified originator address and port. |
| | | 73 | | /// </summary> |
| | | 74 | | /// <param name="originatorAddress">The originator address.</param> |
| | | 75 | | /// <param name="originatorPort">The originator port.</param> |
| | 3 | 76 | | public X11ChannelOpenInfo(string originatorAddress, uint originatorPort) |
| | 3 | 77 | | { |
| | 3 | 78 | | OriginatorAddress = originatorAddress; |
| | 3 | 79 | | OriginatorPort = originatorPort; |
| | 3 | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Called when type specific data need to be loaded. |
| | | 84 | | /// </summary> |
| | | 85 | | protected override void LoadData() |
| | 3 | 86 | | { |
| | 3 | 87 | | base.LoadData(); |
| | | 88 | | |
| | 3 | 89 | | _originatorAddress = ReadBinary(); |
| | 3 | 90 | | OriginatorPort = ReadUInt32(); |
| | 3 | 91 | | } |
| | | 92 | | |
| | | 93 | | /// <summary> |
| | | 94 | | /// Called when type specific data need to be saved. |
| | | 95 | | /// </summary> |
| | | 96 | | protected override void SaveData() |
| | 3 | 97 | | { |
| | 3 | 98 | | base.SaveData(); |
| | | 99 | | |
| | 3 | 100 | | WriteBinaryString(_originatorAddress); |
| | 3 | 101 | | Write(OriginatorPort); |
| | 3 | 102 | | } |
| | | 103 | | } |
| | | 104 | | } |