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