#ifndef OverbyteIcsProxySslServer1H
#define OverbyteIcsProxySslServer1H

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>

#include "OverbyteIcsWSocket.hpp"
#include "OverbyteIcsWSocketS.hpp"
#include "OverbyteIcsWndControl.hpp"
#include "OverbyteIcsProxy.hpp"
#include "OverbyteIcsSslX509Certs.hpp"
#include "OverbyteIcsSslBase.hpp"
#include "OverbyteIcsTypes.hpp"

const unsigned WM_STARTUP = WM_USER + 711;

class TProxySslServerForm : public TForm
{
__published:
    TPanel *ToolsPanel;
    TMemo *DisplayMemo;
    TButton *StartButton;
    TButton *StopButton;
    TIcsHttpProxy *IcsHttpProxy1;
    TTimer *Timer1;
    TButton *RecheckCertsButton;
    TSslX509Certs *IcsSslX509Certs;
    void __fastcall FormShow(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall StartButtonClick(TObject *Sender);
    void __fastcall StopButtonClick(TObject *Sender);
    void __fastcall IcsHttpProxy1ProxyProg(TObject *Sender, TLogOption LogOption, const String Msg);
    void __fastcall IcsHttpProxy1SetTarget(TObject *Sender, TProxyClient *ProxyClient);
    void __fastcall Timer1Timer(TObject *Sender);
    void __fastcall RecheckCertsButtonClick(TObject *Sender);
    void __fastcall IcsHttpProxy1HttpWellKnown(TObject *Sender, THttpProxyClient *ProxyClient, String &Arg);
    void __fastcall IcsHttpProxy1HttpReqBody(TObject *Sender, THttpProxyClient *ProxyClient, String &Arg);
    void __fastcall IcsHttpProxy1HttpRespBody(TObject *Sender, THttpProxyClient *ProxyClient, String &Arg);
    void __fastcall IcsSslX509CertsCertProg(TObject *Sender, TLogOption LogOption, const String Msg);
    void __fastcall IcsSslX509CertsNewCert(TObject *Sender);
    void __fastcall IcsSslX509CertsOAuthAuthUrl(TObject *Sender, const String URL);
    void __fastcall IcsHttpProxy1ConfReqBody(TObject *Sender, THttpProxyClient *ProxyClient, bool &Process);
    void __fastcall IcsHttpProxy1ConfRespBody(TObject *Sender, THttpProxyClient *ProxyClient, bool &Process);
    void __fastcall IcsHttpProxy1SrvSslHandshakeDone(TObject *Sender, System::Word ErrCode, TX509Base *PeerCert, bool &Disconnect);
    void __fastcall IcsSslX509CertsChallgRefresh(TObject *Sender);
    void __fastcall IcsHttpProxy1SrcConnect(TObject *Sender, TWSocketClient *Client, System::Word Error);
    void __fastcall IcsHttpProxy1ProxyForward(TObject *Sender, THttpProxyClient *ProxyClient, const String TarPort, bool &Allowed);
    void __fastcall IcsHttpProxy1HttpPxyAuth(TObject *Sender, THttpProxyClient *ProxyClient, String &Arg);

private:
    String FIniFileName;
    bool FInitialized;
    String FWinLinesBuff;
    int FWinDispCur;
    int FLogDate;
    __int64 FCertCheckTrigger;

protected:
    void __fastcall WMStartup(TMessage &Msg);

    BEGIN_MESSAGE_MAP
        VCL_MESSAGE_HANDLER(WM_STARTUP, TMessage, WMStartup)
    END_MESSAGE_MAP(TForm)

public:
    __fastcall TProxySslServerForm(TComponent *Owner);
    void Display(const String &Msg);
    void ReportHosts();
};

extern PACKAGE TProxySslServerForm *ProxySslServerForm;

#endif
