Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : Re: TIdTCPServer - CommandHandlers again...

www.cryer.info
Managed Newsgroup Archive

Re: TIdTCPServer - CommandHandlers again...

Subject:Re: TIdTCPServer - CommandHandlers again...
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Mon, 12 Nov 2007 14:19:20

"Jamie Dale" <jamie.dale@yahoo.com> wrote in message
news:4738c737$1@newsgroups.borland.com...

> Now the problem I just realised I have is that I have no way of
> decrypting the command before the commandhandler takes over!
>
> If I use OnBeforeCommandHandler then the command is a const value.

You must still be using Indy 9, because that value was changed to a 'var' in
Indy 10 so that it can be modified before being processed.

> I could decrypt it here (using LockBox components) but the
> Command itself would still remain encrypted as I cannot pass
> the decrypted value back.

In Indy 9, you will have to set the server's CommandHandlersEnabled property
to False and then use the OnExecute event to mimic what the server does
internally to invoke the parsing.  For example:

    procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
    var
        I, L: integer;
        LLine: string;
    begin
        L := CommandHandlers.Count-1;
        LLine := AThread.Connection.ReadLn;
        if LLine <> '' then
        begin
            // OnBeforeCommandHandler
            // modify LLine as needed here...
            try
                I := 0;
                while I <= L do
                begin
                    with IdTCPServer1.CommandHandlers.Items[I] do
                    begin
                        if Enabled and Check(LLine, AThread) then
                        begin
                            Break;
                        end;
                    end;
                    Inc(I);
                end;
                if I > L then
                begin

                    // OnNoCommandHandler
                    // send an error reply back...
                end;
            finally
                // OnAfterCommandHandler
                // do any post-processing here...
            end;
        end;
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive