procedure TIdTrivialFTP.CheckOptionAck(
const OptionPacket: TIdBytes; Reading: Boolean);
var
LOptName, LOptValue:
String;
LOffset, Idx, OptionIdx: Integer;
LRequestedBlkSize: Integer;
begin
LOffset := 2;
// skip packet opcode
try
while LOffset < Length(OptionPacket)
do
begin
Idx := ByteIndex(0, OptionPacket, LOffset);
if Idx = -1
then begin
raise EIdTFTPOptionNegotiationFailed.Create('
');
end;
LOptName := BytesToString(OptionPacket, LOffset, Idx-LOffset, IndyASCIIEncoding);
LOffset := Idx+1;
OptionIdx := PosInStrArray(LOptName, [sBlockSize, sTransferSize], False);
if OptionIdx = -1
then begin
raise EIdTFTPOptionNegotiationFailed.CreateFmt(RSTFTPUnsupportedOption, [LOptName]);
end;
Idx := ByteIndex(0, OptionPacket, LOffset);
if Idx = -1
then begin
raise EIdTFTPOptionNegotiationFailed.Create('
');
end;
LOptValue := BytesToString(OptionPacket, LOffset, Idx-LOffset, IndyASCIIEncoding);
LOffset := Idx+1;
case OptionIdx
of
0:
begin
LRequestedBlkSize := IndyStrToInt(LOptValue);
if (LRequestedBlkSize < 8)
or (LRequestedBlkSize > 65464)
then begin
raise EIdTFTPOptionNegotiationFailed.CreateFmt(RSTFTPUnsupportedOptionValue, [LOptValue, LOptName]);
end;
BufferSize := 4 + LRequestedBlkSize;
end;
1:
begin
if Reading
then
begin
// TODO
{
if (IndyStrToInt(LOptValue) is not available) then begin
raise raise EIdTFTPAllocationExceeded.Create('');
end;
}
end;
end;
end;
end;
except
on E:
Exception do begin
SendError(Self, FPeerIP, FPeerPort, E);
raise;
end;
end;
end;