| | | 1 | | using System; |
| | | 2 | | using Renci.SshNet.Common; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Messages.Transport |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents SSH_MSG_SERVICE_REQUEST message. |
| | | 8 | | /// </summary> |
| | | 9 | | [Message("SSH_MSG_SERVICE_REQUEST", 5)] |
| | | 10 | | public class ServiceRequestMessage : Message |
| | | 11 | | { |
| | | 12 | | private readonly byte[] _serviceName; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets the name of the service. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <value> |
| | | 18 | | /// The name of the service. |
| | | 19 | | /// </value> |
| | | 20 | | public ServiceName ServiceName |
| | | 21 | | { |
| | 0 | 22 | | get { return _serviceName.ToServiceName(); } |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets the size of the message in bytes. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <value> |
| | | 29 | | /// The size of the messages in bytes. |
| | | 30 | | /// </value> |
| | | 31 | | protected override int BufferCapacity |
| | | 32 | | { |
| | | 33 | | get |
| | 1813 | 34 | | { |
| | 1813 | 35 | | var capacity = base.BufferCapacity; |
| | 1813 | 36 | | capacity += 4; // ServiceName length |
| | 1813 | 37 | | capacity += _serviceName.Length; // ServiceName |
| | 1813 | 38 | | return capacity; |
| | 1813 | 39 | | } |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Initializes a new instance of the <see cref="ServiceRequestMessage"/> class. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="serviceName">Name of the service.</param> |
| | 1813 | 46 | | public ServiceRequestMessage(ServiceName serviceName) |
| | 1813 | 47 | | { |
| | 1813 | 48 | | _serviceName = serviceName.ToArray(); |
| | 1813 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Called when type specific data need to be loaded. |
| | | 53 | | /// </summary> |
| | | 54 | | protected override void LoadData() |
| | 0 | 55 | | { |
| | 0 | 56 | | throw new InvalidOperationException("Load data is not supported."); |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Called when type specific data need to be saved. |
| | | 61 | | /// </summary> |
| | | 62 | | protected override void SaveData() |
| | 1813 | 63 | | { |
| | 1813 | 64 | | WriteBinaryString(_serviceName); |
| | 1813 | 65 | | } |
| | | 66 | | |
| | | 67 | | internal override void Process(Session session) |
| | 0 | 68 | | { |
| | 0 | 69 | | session.OnServiceRequestReceived(this); |
| | 0 | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |