namespace Renci.SshNet.Messages.Connection
{
///
/// Represents SSH_MSG_CHANNEL_REQUEST message.
///
[Message("SSH_MSG_CHANNEL_REQUEST", 98)]
public class ChannelRequestMessage : ChannelMessage
{
private string _requestName;
private byte[] _requestNameBytes;
///
/// Gets the name of the request.
///
///
/// The name of the request.
///
public string RequestName
{
get
{
return _requestName;
}
private set
{
_requestName = value;
_requestNameBytes = Ascii.GetBytes(value);
}
}
///
/// Gets channel request data.
///
public byte[] RequestData { get; private set; }
///
/// Gets the size of the message in bytes.
///
///
/// The size of the messages in bytes.
///
protected override int BufferCapacity
{
get
{
var capacity = base.BufferCapacity;
capacity += 4; // RequestName length
capacity += _requestNameBytes.Length; // RequestName
capacity += RequestData.Length; // RequestData
return capacity;
}
}
///
/// Initializes a new instance of the class.
///
public ChannelRequestMessage()
{
// Required for dynamically loading request type when it comes from the server
}
///
/// Initializes a new instance of the class.
///
/// The local channel number.
/// The info.
public ChannelRequestMessage(uint localChannelNumber, RequestInfo info)
: base(localChannelNumber)
{
RequestName = info.RequestName;
RequestData = info.GetBytes();
}
///
/// Called when type specific data need to be loaded.
///
protected override void LoadData()
{
base.LoadData();
_requestNameBytes = ReadBinary();
_requestName = Ascii.GetString(_requestNameBytes, 0, _requestNameBytes.Length);
RequestData = ReadBytes();
}
///
/// Called when type specific data need to be saved.
///
protected override void SaveData()
{
base.SaveData();
WriteBinaryString(_requestNameBytes);
Write(RequestData);
}
internal override void Process(Session session)
{
session.OnChannelRequestReceived(this);
}
}
}