www.pudn.com > netcode58.zip > DblPxyTcp.pas, change:2004-01-06,size:2478b


unit DblPxyTcp; 
 
interface 
 
uses SysUtils, Classes, blckSock, synsock; 
 
type 
  TDblProxyTcpSocket = class(TTCPBlockSocket) 
  public 
    constructor Create; 
    procedure Connect(IP, Port: string); override; 
    procedure Listen; override; 
  end; 
 
implementation 
 
constructor TDblProxyTcpSocket.Create; 
begin 
  inherited Create; 
end; 
 
procedure TDblProxyTcpSocket.Connect(IP, Port: string); 
var x: integer; 
    b: boolean; 
begin 
  x := 0; 
  if FSocksIP <> '' then x := x + 1; 
  if FHTTPTunnelIP <> '' then x := x + 2; 
  case x of 
    1: SocksDoConnect(IP, Port); 
    2: HTTPTunnelDoConnect(IP, Port); 
    3: begin 
         HTTPTunnelDoConnect(FSocksIP, FSocksPort); 
         if FLastError = 0 then 
         begin 
           b := SocksOpen; 
           if b then b := SocksRequest(1, IP, Port); 
           if b then b := SocksResponse; 
           if not b and (FLastError = 0) then FLastError := WSASYSNOTREADY; 
           FSocksLocalIP := FSocksResponseIP; 
           FSocksLocalPort := FSocksResponsePort; 
           FSocksRemoteIP := IP; 
           FSocksRemotePort := Port; 
         end; 
         ExceptCheck; 
         DoStatus(HR_Connect, IP + ':' + Port); 
       end; 
    else 
      inherited Connect(IP, Port); 
  end; 
  if FSslEnabled then 
    if FLastError = 0 then 
      SSLDoConnect 
    else 
    begin 
      x := FLastError; 
      SSLEnabled := False; 
      FLastError := x; 
    end; 
end; 
 
procedure TDblProxyTcpSocket.Listen; 
var 
  b: Boolean; 
  Sip, SPort, SC: string; 
begin 
  if FSocksIP = '' then 
  begin 
    SockCheck(synsock.Listen(FSocket, SOMAXCONN)); 
    GetSins; 
  end 
  else 
  begin 
    Sip := GetLocalSinIP; 
    if Sip = cAnyHost then Sip := LocalName; 
    SPort := IntToStr(GetLocalSinPort); 
    if FHTTPTunnelIP = '' then 
    begin 
      SC := FSocksIP; 
      FSocksIP := ''; 
      inherited Connect(SC, FSocksPort); 
      FSocksIp := SC; 
    end 
    else HTTPTunnelDoConnect(FSocksIP, FSocksPort); 
    b := SocksOpen; 
    if b then 
      b := SocksRequest(2, Sip, SPort); 
    if b then 
      b := SocksResponse; 
    if not b and (FLastError = 0) then 
      FLastError := WSANO_RECOVERY; 
    FSocksLocalIP := FSocksResponseIP; 
    if FSocksLocalIP = cAnyHost then 
      FSocksLocalIP := FSocksIP; 
    FSocksLocalPort := FSocksResponsePort; 
    FSocksRemoteIP := ''; 
    FSocksRemotePort := ''; 
  end; 
  ExceptCheck; 
  DoStatus(HR_Listen, ''); 
end; 
 
end.