Einzelnen Beitrag anzeigen

schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#1

Overload einer Funktion der TIdTrivialFTP Komponente

  Alt 8. Sep 2011, 12:33
Hi,

ich habe eine Frage zu Overload/Override.

Ich habe die Funktion in der unit IdTrivialFTP:
Delphi-Quellcode:
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;
Nun habe ich eine Hardware hier, die aber einen anderen Offset hat.
So funktioniert es mit LOffset = 4:
Delphi-Quellcode:
procedure TIdTrivialFTP.CheckOptionAck(const OptionPacket: TIdBytes; Reading: Boolean);
var
  LOptName, LOptValue: String;
  LOffset, Idx, OptionIdx: Integer;
  LRequestedBlkSize: Integer;
begin
  LOffset := 2; // skip packet opcode

  LOffset := LOffset + 2; // skip packet opcode PicoMOD3

  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;
Keine Ahnung warum da ein anderer Offset ist, aber mit 2 geht es nicht. Die Optionen starten erst ab Offset 4.

Kann ich das irgendwie in meine eigene Unit einbauen damit die IdTrivalFTP Unit unangetastet bleibt?
Delphi 2010, Update 4 & 5
  Mit Zitat antworten Zitat