OSDN Git Service

Basic認証のProxy対応(手抜き版:SSPの処理と同じ)
authorC.Ponapalt <ponapalt@shillest.net>
Sat, 13 Nov 2004 10:21:29 +0000 (10:21 +0000)
committerC.Ponapalt <ponapalt@shillest.net>
Sat, 13 Nov 2004 10:21:29 +0000 (10:21 +0000)
sakurasuite/IdSLPP20.pas

index c218479..3c4989d 100644 (file)
@@ -10,7 +10,7 @@ interface
 
 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  IdTCPClient, IdGlobal, IdException;
+  IdTCPClient, IdCoderMIME, IdGlobal, IdException;
 
 const
   SLPP_PORT = 9871;
@@ -45,6 +45,8 @@ type
     FSLPPThread: TIdSLPP20ReadThread;
     FDebugMode: boolean;
     FProxyMode: boolean;
+    FProxyUser: String;
+    FProxyPass: String;
     FLUID: String;
     FOnSlppEvent: TIdSlppEvent;
     FOnConnect: TNotifyEvent;
@@ -56,6 +58,8 @@ type
     procedure SetLUID(const Value: String);
     procedure SetOnSlppEvent(const Value: TIdSlppEvent);
     procedure SetProxyMode(const Value: boolean);
+    procedure SetProxyUser(const Value: String);
+    procedure SetProxyPass(const Value: String);
     procedure SetOnConnect(const Value: TNotifyEvent);
     procedure SetOnDisconnect(const Value: TNotifyEvent);
     function GetLastReadTimeInterval: integer;
@@ -78,6 +82,8 @@ type
     property Port default SLPP_PORT;
     property DebugMode: boolean read FDebugMode write SetDebugMode;
     property ProxyMode: boolean read FProxyMode write SetProxyMode;
+    property ProxyUser: String read FProxyUser write SetProxyUser;
+    property ProxyPass: String read FProxyPass write SetProxyPass;
     property OnConnect: TNotifyEvent read FOnConnect write SetOnConnect;
     property OnConnectFailed: TNotifyEvent read FOnConnectFailed write SetOnConnectFailed;
     property OnDisconnect: TNotifyEvent read FOnDisconnect write SetOnDisconnect;
@@ -119,6 +125,8 @@ begin
   inherited Create(AOwner);
   Port := SLPP_PORT;
   Host := SLPP_HOST;
+  ProxyUser := '';
+  ProxyPass := '';
 end;
 
 destructor TIdSLPP20.Destroy;
@@ -207,6 +215,16 @@ begin
   FProxyMode := Value;
 end;
 
+procedure TIdSLPP20.SetProxyUser(const Value: String);
+begin
+  FProxyUser := Value;
+end;
+
+procedure TIdSLPP20.SetProxyPass(const Value: String);
+begin
+  FProxyPass := Value;
+end;
+
 { TIdSLPP20ReadThread }
 
 constructor TIdSLPP20ReadThread.Create(AClient: TIdSLPP20);
@@ -219,6 +237,8 @@ end;
 
 procedure TIdSLPP20ReadThread.Execute;
 var Line: String;
+    EncodedPassword,PlainPassword: String;
+    Base64Encoder: TIdEncoderMIME;
 begin
   try
     FClient.Connect(FClient.FTimeout);
@@ -230,12 +250,27 @@ begin
     Exit;
   end;
 
+  EncodedPassword := '';
+  if FClient.ProxyUser <> '' then begin
+    if FClient.ProxyPass <> '' then begin
+      PlainPassword := FClient.ProxyUser + ':' + FClient.ProxyPass;
+      Base64Encoder.Create(nil);
+      EncodedPassword := Base64Encoder.Encode(PlainPassword);
+      FreeAndNil(Base64Encoder);
+    end;
+  end;
+
   FRecvData := TStringList.Create;
   FReceivedLog := TStringList.Create;
   if FClient.ProxyMode then begin
     FClient.Writeln('POST http://bottle.mikage.to:9871/ HTTP/1.0');
     FClient.Writeln('Content-Length: ' + IntToStr(Length(FClient.LUID)));
     FClient.Writeln('Connection: close');
+
+    if EncodedPassword <> '' then begin
+      FClient.Writeln('Proxy-Authorization: Basic ' + EncodedPassword);
+    end;
+
     FClient.Writeln;
     FClient.Writeln(FClient.LUID);
   end else begin
@@ -279,6 +314,12 @@ function TIdSLPP20ReadThread.Parse: boolean;
 var
   command: String;
 begin
+  //\8dÅ\92á\8cÀ\83R\83}\83\93\83h\8ds+1\82Í\82È\82¢\82Æ\83_\83\81 - 2\88È\8fã
+  if FRecvData.Count <= 1 then begin
+    Result := false;
+    Exit;
+  end;
+
   command := FRecvData[0];
   FRecvData.Delete(0);
   FParam := FRecvData.Text;