| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- namespace Renci.SshNet.Messages.Connection
- {
- /// <summary>
- /// Represents SSH_MSG_GLOBAL_REQUEST message.
- /// </summary>
- [Message("SSH_MSG_GLOBAL_REQUEST", 80)]
- public class GlobalRequestMessage : Message
- {
- /// <summary>
- /// Gets the name of the request.
- /// </summary>
- /// <value>
- /// The name of the request.
- /// </value>
- public GlobalRequestName RequestName { get; private set; }
- /// <summary>
- /// Gets a value indicating whether message reply should be sent..
- /// </summary>
- /// <value>
- /// <c>true</c> if message reply should be sent; otherwise, <c>false</c>.
- /// </value>
- public bool WantReply { get; private set; }
- /// <summary>
- /// Gets the address to bind to.
- /// </summary>
- public string AddressToBind { get; private set; }
- // TODO: Extract AddressToBind property to be in different class and GlobalREquestMessage to be a base class fo it.
- /// <summary>
- /// Gets port number to bind to.
- /// </summary>
- public UInt32 PortToBind { get; private set; }
- /// <summary>
- /// Initializes a new instance of the <see cref="GlobalRequestMessage"/> class.
- /// </summary>
- public GlobalRequestMessage()
- {
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="GlobalRequestMessage"/> class.
- /// </summary>
- /// <param name="requestName">Name of the request.</param>
- /// <param name="wantReply">if set to <c>true</c> [want reply].</param>
- public GlobalRequestMessage(GlobalRequestName requestName, bool wantReply)
- {
- this.RequestName = requestName;
- this.WantReply = wantReply;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="GlobalRequestMessage"/> class.
- /// </summary>
- /// <param name="requestName">Name of the request.</param>
- /// <param name="wantReply">if set to <c>true</c> [want reply].</param>
- /// <param name="addressToBind">The address to bind.</param>
- /// <param name="portToBind">The port to bind.</param>
- public GlobalRequestMessage(GlobalRequestName requestName, bool wantReply, string addressToBind, uint portToBind)
- : this(requestName, wantReply)
- {
- this.AddressToBind = addressToBind;
- this.PortToBind = portToBind;
- }
- /// <summary>
- /// Called when type specific data need to be loaded.
- /// </summary>
- protected override void LoadData()
- {
- var requestName = this.ReadAsciiString();
- switch (requestName)
- {
- case "tcpip-forward":
- this.RequestName = GlobalRequestName.TcpIpForward;
- break;
- case "cancel-tcpip-forward":
- this.RequestName = GlobalRequestName.CancelTcpIpForward;
- break;
- default:
- break;
- }
- this.WantReply = this.ReadBoolean();
- this.AddressToBind = this.ReadString();
- this.PortToBind = this.ReadUInt32();
- }
- /// <summary>
- /// Called when type specific data need to be saved.
- /// </summary>
- protected override void SaveData()
- {
- switch (this.RequestName)
- {
- case GlobalRequestName.TcpIpForward:
- this.WriteAscii("tcpip-forward");
- break;
- case GlobalRequestName.CancelTcpIpForward:
- this.WriteAscii("cancel-tcpip-forward");
- break;
- default:
- break;
- }
- this.Write(this.WantReply);
- switch (this.RequestName)
- {
- case GlobalRequestName.TcpIpForward:
- case GlobalRequestName.CancelTcpIpForward:
- this.Write(this.AddressToBind);
- this.Write(this.PortToBind);
- break;
- default:
- break;
- }
- }
- }
- }
|