clientthread.h
来自「著名的SecureBlackBox控件完整源码」· C头文件 代码 · 共 123 行
H
123 行
//---------------------------------------------------------------------------
#ifndef ClientThreadH
#define ClientThreadH
//---------------------------------------------------------------------------
#include <winsock2.h>
#include <Classes.hpp>
#include <IdTCPClient.hpp>
#include <IdTCPServer.hpp>
#include <SBSSHClient.hpp>
#include <SBSSHCommon.hpp>
#include <SBSSHKeyStorage.hpp>
//#include <Windows.hpp>
//#include <SyncObjs.hpp>
#include <SBSharedResource.hpp>
#include <SBUtils.hpp>
//#include <SysUtils.hpp>
//---------------------------------------------------------------------------
class TConnection;
typedef void __fastcall (__closure *TLogEvent)(System::TObject* Sender, const AnsiString Log, bool Error);
typedef void __fastcall (__closure *TConnectionEvent)(System::TObject* Sender, TConnection* Conn);
class TClientThread : public TThread
{
private:
// Class members
bool FError;
TCriticalSection* FCS;
TCriticalSection* FGuiCS;
TList* FChannels;
AnsiString FLogString;
bool FLogError;
TConnection* FConn;
bool FNoGUI;
// SSH connection TCP client
TIdTCPClient* FTCPClient;
// Listening socket
TIdTCPServer* FTCPServer;
// SSH stuff
TElSSHClient* FSSHClient;
TElLocalPortForwardSSHTunnel* FTunnel;
TElSSHTunnelList* FTunnelList;
// Events
TLogEvent FOnLog;
TConnectionEvent FOnChange;
TConnectionEvent FOnConnectionAdd;
TConnectionEvent FOnConnectionRemove;
// Event handlers
void __fastcall TunnelOpen(TObject* Sender, TElSSHTunnelConnection* TunnelConnection);
void __fastcall TunnelClose(TObject* Sender, TElSSHTunnelConnection* TunnelConnection);
void __fastcall TunnelError(TObject* Sender, int Error, void* Data);
void __fastcall TunnelConnData(TObject* Sender, void* Buffer, int Size);
void __fastcall SSHClientKeyValidate(TObject* Sender, TElSSHKey* ServerKey, bool &Validate);
void __fastcall SSHClientAuthSuccess(TObject* Sender);
void __fastcall SSHClientAuthFailed(TObject* Sender, int AuthenticationType);
void __fastcall SSHClientSend(TObject* Sender, void* Buffer, int Size);
void __fastcall SSHClientReceive(TObject* Sender, void* Buffer, int MaxSize, int &Written);
void __fastcall SSHClientOpen(TObject* Sender);
void __fastcall SSHClientClose(TObject* Sender);
void __fastcall SSHClientError(TObject* Sender, int ErrorCode);
void __fastcall TCPServerConnect(TIdPeerThread* AThread);
void __fastcall TCPServerExecute(TIdPeerThread* AThread);
void __fastcall TCPServerThreadTerminate(TObject* Sender);
// auxiliary routines
void Log(const AnsiString S, bool Error);
void DoConnectionAdd(TConnection* Conn);
void DoConnectionRemove(TConnection* Conn);
void DoConnectionChange(TConnection* Conn);
void __fastcall TriggerLog(void);
void __fastcall TriggerConnectionChange(void);
void __fastcall TriggerConnectionAdd(void);
void __fastcall TriggerConnectionRemove(void);
public:
TClientThread(const AnsiString AHost, int APort, const AnsiString Username, AnsiString Password,
int AForwardPort, const AnsiString ADestHost, int ADestPort, bool NoGUI = false);
__fastcall ~TClientThread();
virtual void __fastcall Execute(void);
__property TLogEvent OnLog = {read = FOnLog, write = FOnLog};
__property TConnectionEvent OnConnectionAdd = {read = FOnConnectionAdd, write = FOnConnectionAdd};
__property TConnectionEvent OnConnectionRemove = {read = FOnConnectionRemove, write = FOnConnectionRemove};
__property TConnectionEvent OnConnectionChange = {read = FOnChange, write = FOnChange};
};
typedef enum {icsActive, icsClosing, icsClosed} TInConnectionState;
typedef enum {ocsEstablishing, ocsActive, ocsClosing, ocsClosed} TOutConnectionState;
class TConnection
{
friend class TClientThread;
private:
TIdPeerThread* FThread;
TElSSHTunnelConnection* FChannel;
char* FChannelBuffer; // : ByteArray;
char* FSocketBuffer; // : ByteArray;
int FChannelBufferSize;
int FSocketBufferSize;
TElSharedResource* FSharedResource;
TInConnectionState FInState;
TOutConnectionState FOutState;
AnsiString FRemoteHost;
int FRemotePort;
int FSent;
int FReceived;
protected:
int ReadFromSocketBuffer(void* Buffer, int MaxSize);
int ReadFromChannelBuffer(void* Buffer, int MaxSize);
void WriteToSocketBuffer(void* Buffer, int Size);
void WriteToChannelBuffer(void* Buffer, int Size);
public:
TConnection();
~TConnection();
__property AnsiString RemoteHost = {read = FRemoteHost};
__property int RemotePort = {read = FRemotePort};
__property int Sent = {read = FSent};
__property int Received = {read = FReceived};
__property TInConnectionState InState = {read = FInState};
__property TOutConnectionState OutState = {read = FOutState};
};
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?