ConnectionIntercept stream question

Giganews Newsgroups
Subject: ConnectionIntercept stream question
Posted by:  Jack Mays (jackmays…@SPAMsupplant.net)
Date: Sun, 14 Dec 2003

Hello all,

I'm workin with the IdTCPServer and intercepts so that i can decrypt/encrypt
data before the data hit the command handler.  What i was told is that i
have to re-write the AStream at the end of the intercept so that it is
passed to the command handler, or out the socket.

The problem is i can't seem to erase what's in AStream so that i can rewite
it with the decrypted data.. below is an example of some things i've tried..
If anyone could help me figure this out it would be great..  you'll see by
the comments, i got desperate to find a solution.. I"m not that strong with
streams either, so this may be something completely simple that i'm just
overlooking..

// ------------------------------------------------------

procedure TCustomPeerThread.InterceptReceive(ASender:
TIdConnectionIntercept;
  AStream: TStream);
var
  Client : TClientInfo;
  Data: TStringStream;
  Data2: TStringStream;
  encString, decString: String;

  text: string; // temp use for debugging.
begin

  // Get the client data for this client intercept
  Client := Pointer(Self.Data);
  Data := TStringStream.Create('');
  Data2 := TStringStream.Create('');
  Data.CopyFrom(AStream, 0);

  encString := Trim(Data.DataString); // must trim

    decString := DecryptData(encString, Client.SymKey, Client.SymKeyType,
      Client.SymKeyBitSize, Client.RSAProcessed, Client.FirstReceived);

  // Resetting the position on both streams, when doing the writestring, it
  // will overwrite the currect contents, if you dont reset the position it
  // will concantionate them together.
  Data.Position := 0;
  //Data2.Position := 0;
  AStream.Position := 0;

  // Putting the decrypted data into the temp stringstream.
  Data.writestring(decString);

  Text := Data.DataString;

  // Write the decrypted stringstream to the intercept so it will be
  // passed to the command handlers.

  //Astream.Create;
  //AStream := Data;
  // AStream.Size := Length(Text);

  // Data2.Write(Text[1], Length(Text));

  AStream := (Data as TStream);

    //AStream.WriteBuffer(decString[1], Length(decString));

  //AStream.CopyFrom(Data, 0); // 0 means start at pos 0 and read all
  Data2.CopyFrom(Astream, 0);
  //Data.CopyFrom(AStream, 0);
    Text := Data2.DataString;
  //ShowMessage(IntToStr(DataSize));
  //ShowMessage(Text);

  FreeAndNil(Data);
  FreeAndNil(Data2);

end;//EO InterceptReceive

Replies