| 54 |
function CgiDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime): Boolean; |
function CgiDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime): Boolean; |
| 55 |
function DatDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime; RangeStart: Integer; AdjustLen: Integer): Boolean; |
function DatDownload(ItemType: TGikoDownloadType; URL: string; Modified: TDateTime; RangeStart: Integer; AdjustLen: Integer): Boolean; |
| 56 |
function DeleteStatusLine(Content: string): string; |
function DeleteStatusLine(Content: string): string; |
| 57 |
|
procedure InitHttpClient(client: TIdHttp); |
| 58 |
|
procedure ClearHttpClient(client: TIdHttp); |
| 59 |
protected |
protected |
| 60 |
procedure Execute; override; |
procedure Execute; override; |
| 61 |
public |
public |
| 120 |
|
|
| 121 |
destructor TDownloadThread.Destroy; |
destructor TDownloadThread.Destroy; |
| 122 |
begin |
begin |
| 123 |
FIndy.Request.CustomHeaders.Clear; |
ClearHttpClient(FIndy); |
|
FIndy.Request.RawHeaders.Clear; |
|
|
FIndy.Request.Clear; |
|
|
FIndy.Response.CustomHeaders.Clear; |
|
|
FIndy.Response.RawHeaders.Clear; |
|
|
FIndy.Response.Clear; |
|
|
FIndy.ProxyParams.Clear; |
|
| 124 |
FIndy.Free; |
FIndy.Free; |
| 125 |
inherited; |
inherited; |
| 126 |
end; |
end; |
| 142 |
[Day, Copy(StrMonth, 1 + 3 * (Month - 1), 3), |
[Day, Copy(StrMonth, 1 + 3 * (Month - 1), 3), |
| 143 |
Year, Hour, Min, Sec]); |
Year, Hour, Min, Sec]); |
| 144 |
end; |
end; |
| 145 |
|
// ****************************************************************** |
| 146 |
|
// HTTPClientの初期化 |
| 147 |
|
// ****************************************************************** |
| 148 |
|
procedure TDownloadThread.InitHttpClient(client: TIdHttp); |
| 149 |
|
begin |
| 150 |
|
ClearHttpClient(client); |
| 151 |
|
client.Disconnect; |
| 152 |
|
client.Request.UserAgent := GikoSys.GetUserAgent; |
| 153 |
|
client.RecvBufferSize := Gikosys.Setting.RecvBufferSize; |
| 154 |
|
client.ProxyParams.BasicAuthentication := False; |
| 155 |
|
client.ReadTimeout := GikoSys.Setting.ReadTimeOut; |
| 156 |
|
{$IFDEF DEBUG} |
| 157 |
|
Writeln('------------------------------------------------------------'); |
| 158 |
|
{$ENDIF} |
| 159 |
|
//FIndy.AllowCookies := False; |
| 160 |
|
if GikoSys.Setting.ReadProxy then begin |
| 161 |
|
if GikoSys.Setting.ProxyProtocol then |
| 162 |
|
client.ProtocolVersion := pv1_1 |
| 163 |
|
else |
| 164 |
|
client.ProtocolVersion := pv1_0; |
| 165 |
|
client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; |
| 166 |
|
client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; |
| 167 |
|
client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; |
| 168 |
|
client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; |
| 169 |
|
if GikoSys.Setting.ReadProxyUserID <> '' then |
| 170 |
|
client.ProxyParams.BasicAuthentication := True; |
| 171 |
|
{$IFDEF DEBUG} |
| 172 |
|
Writeln('プロキシ設定あり'); |
| 173 |
|
Writeln('ホスト: ' + GikoSys.Setting.ReadProxyAddress); |
| 174 |
|
Writeln('ポート: ' + IntToStr(GikoSys.Setting.ReadProxyPort)); |
| 175 |
|
{$ENDIF} |
| 176 |
|
end else begin |
| 177 |
|
if GikoSys.Setting.Protocol then |
| 178 |
|
client.ProtocolVersion := pv1_1 |
| 179 |
|
else |
| 180 |
|
client.ProtocolVersion := pv1_0; |
| 181 |
|
client.ProxyParams.ProxyServer := ''; |
| 182 |
|
client.ProxyParams.ProxyPort := 80; |
| 183 |
|
client.ProxyParams.ProxyUsername := ''; |
| 184 |
|
client.ProxyParams.ProxyPassword := ''; |
| 185 |
|
{$IFDEF DEBUG} |
| 186 |
|
Writeln('プロキシ設定なし'); |
| 187 |
|
{$ENDIF} |
| 188 |
|
end; |
| 189 |
|
end; |
| 190 |
|
// ****************************************************************** |
| 191 |
|
// HTTPClientのリクエストとレスポンスのデータの消去 |
| 192 |
|
// ****************************************************************** |
| 193 |
|
procedure TDownloadThread.ClearHttpClient(client: TIdHttp); |
| 194 |
|
begin |
| 195 |
|
client.Request.CustomHeaders.Clear; |
| 196 |
|
client.Request.RawHeaders.Clear; |
| 197 |
|
client.Request.Clear; |
| 198 |
|
client.Response.CustomHeaders.Clear; |
| 199 |
|
client.Response.RawHeaders.Clear; |
| 200 |
|
client.Response.Clear; |
| 201 |
|
|
| 202 |
|
client.ProxyParams.Clear; |
| 203 |
|
end; |
| 204 |
procedure TDownloadThread.Execute; |
procedure TDownloadThread.Execute; |
| 205 |
var |
var |
| 206 |
ResStream: TMemoryStream; |
ResStream: TMemoryStream; |
| 244 |
begin |
begin |
| 245 |
FDownloadTitle := FItem.FThreadItem.Title; |
FDownloadTitle := FItem.FThreadItem.Title; |
| 246 |
if FItem.FThreadItem <> nil then begin |
if FItem.FThreadItem <> nil then begin |
| 247 |
if FItem.FThreadItem.ParentBoard.IsBoardPlugInAvailable then begin |
if FItem.FThreadItem.ParentBoard.IsBoardPlugInAvailable then begin |
| 248 |
boardPlugIn := FItem.FThreadItem.ParentBoard.BoardPlugIn; |
boardPlugIn := FItem.FThreadItem.ParentBoard.BoardPlugIn; |
| 249 |
Item.State := TGikoDownloadState( boardPlugIn.DownloadThread( DWORD( FItem.FThreadItem ) ) ); |
Item.State := TGikoDownloadState( boardPlugIn.DownloadThread( DWORD( FItem.FThreadItem ) ) ); |
| 250 |
end; |
end; |
| 251 |
//if FItem.FThreadItem.IsBoardPlugInAvailable then begin |
//if FItem.FThreadItem.IsBoardPlugInAvailable then begin |
| 252 |
// boardPlugIn := FItem.FThreadItem.BoardPlugIn; |
// boardPlugIn := FItem.FThreadItem.BoardPlugIn; |
| 253 |
// Item.State := TGikoDownloadState( boardPlugIn.DownloadThread( DWORD( FItem.FThreadItem ) ) ); |
// Item.State := TGikoDownloadState( boardPlugIn.DownloadThread( DWORD( FItem.FThreadItem ) ) ); |
| 254 |
//end; |
//end; |
| 271 |
Continue; |
Continue; |
| 272 |
end; |
end; |
| 273 |
|
|
|
//===== プラグインを使用しない場合 |
|
| 274 |
FAbort := False; |
FAbort := False; |
| 275 |
FIndy.Request.CustomHeaders.Clear; |
//===== プラグインを使用しない場合 |
| 276 |
FIndy.Response.Clear; |
InitHttpClient(FIndy); |
|
FIndy.Request.Clear; |
|
|
FIndy.ProxyParams.Clear; |
|
|
FIndy.Disconnect; |
|
|
FIndy.Request.UserAgent := GikoSys.GetUserAgent; |
|
|
FIndy.RecvBufferSize := Gikosys.Setting.RecvBufferSize; |
|
|
FIndy.ProxyParams.BasicAuthentication := False; |
|
|
FIndy.ReadTimeout := GikoSys.Setting.ReadTimeOut; |
|
|
{$IFDEF DEBUG} |
|
|
Writeln('------------------------------------------------------------'); |
|
|
{$ENDIF} |
|
|
//FIndy.AllowCookies := False; |
|
|
if GikoSys.Setting.ReadProxy then begin |
|
|
if GikoSys.Setting.ProxyProtocol then |
|
|
FIndy.ProtocolVersion := pv1_1 |
|
|
else |
|
|
FIndy.ProtocolVersion := pv1_0; |
|
|
FIndy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; |
|
|
FIndy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; |
|
|
FIndy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; |
|
|
FIndy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; |
|
|
if GikoSys.Setting.ReadProxyUserID <> '' then |
|
|
FIndy.ProxyParams.BasicAuthentication := True; |
|
|
{$IFDEF DEBUG} |
|
|
Writeln('プロキシ設定あり'); |
|
|
Writeln('ホスト: ' + GikoSys.Setting.ReadProxyAddress); |
|
|
Writeln('ポート: ' + IntToStr(GikoSys.Setting.ReadProxyPort)); |
|
|
{$ENDIF} |
|
|
end else begin |
|
|
if GikoSys.Setting.Protocol then |
|
|
FIndy.ProtocolVersion := pv1_1 |
|
|
else |
|
|
FIndy.ProtocolVersion := pv1_0; |
|
|
FIndy.ProxyParams.ProxyServer := ''; |
|
|
FIndy.ProxyParams.ProxyPort := 80; |
|
|
FIndy.ProxyParams.ProxyUsername := ''; |
|
|
FIndy.ProxyParams.ProxyPassword := ''; |
|
|
{$IFDEF DEBUG} |
|
|
Writeln('プロキシ設定なし'); |
|
|
{$ENDIF} |
|
|
end; |
|
|
|
|
| 277 |
adjustMargin := 0; |
adjustMargin := 0; |
| 278 |
if Item.DownType = gdtThread then begin |
if Item.DownType = gdtThread then begin |
| 279 |
if FileExists( Item.ThreadItem.GetThreadFileName ) then begin |
if FileExists( Item.ThreadItem.GetThreadFileName ) then begin |
| 607 |
else |
else |
| 608 |
Item.State := gdsError; |
Item.State := gdsError; |
| 609 |
end; |
end; |
|
{ |
|
|
//無いと思うけど。。。 |
|
|
if (Item.ResponseCode in [200, 206]) and (Item.Content = '') then |
|
|
Item.State := gdsError; |
|
|
Item.LastModified := FIndy.Response.LastModified; |
|
|
//差分取得で1バイト前からとってきたときはマイナスする |
|
|
Item.ContentLength := FIndy.Response.ContentLength + AdjustLen; |
|
|
try |
|
|
ResStream.Clear; |
|
|
FIndy.Get(URL, ResStream); |
|
|
Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding); |
|
|
if (Item.DownType = gdtThread) and (AdjustLen = -1) and (Item.Content[1] <> #10) then begin |
|
|
//差分取得かつ1バイト目がLFでない場合は「あぼーん」されているかもしれんので再取得 |
|
|
//ここでメッセージ表示イベント |
|
|
//event |
|
|
FMsg := '「あぼーん」を検出したので再取得を行います'; |
|
|
if Assigned(OnDownloadMsg) then |
|
|
Synchronize(FireDownloadMsg); |
|
|
FIndy.Request.ContentRangeStart := 0; |
|
|
FIndy.Request.ContentRangeEnd := 0; |
|
|
AdjustLen := 0; |
|
|
ResStream.Clear; |
|
|
FIndy.Get(URL, ResStream); |
|
|
Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding); |
|
|
end else if (Item.DownType = gdtThread) and (AdjustLen = -1) and (Item.Content[1] = #10) then begin |
|
|
//差分取得かつ1バイト目がLFの場合(正常取得)は頭のLFを削除 |
|
|
Item.Content := Copy(Item.Content, 2, Length(Item.Content)); |
|
|
end; |
|
|
except |
|
|
Item.State := gdsError; |
|
|
end; |
|
|
Item.ResponseCode := FIndy.ResponseCode; |
|
|
} |
|
|
{ |
|
|
try |
|
|
ResStream.Clear; |
|
|
FIndy.Get(URL, ResStream); |
|
|
Item.Content := GikoSys.GzipDecompress(ResStream, FIndy.Response.ContentEncoding); |
|
|
except |
|
|
Item.State := gdsError; |
|
|
end; |
|
|
|
|
|
CgiStatus := ParseCgiStatus(Item.Content); |
|
|
if CgiStatus.FStatus = gcsOK then begin |
|
|
if CgiStatus.FSize = 0 then |
|
|
Item.State := gdsNotModify |
|
|
else if Item.DownType = gdtBoard then |
|
|
Item.State := gdsComplete |
|
|
else |
|
|
Item.State := gdsDiffComplete; |
|
|
end else if CgiStatus.FStatus = gcsINCR then begin |
|
|
Item.State := gdsComplete; |
|
|
end else if CgiStatus.FStatus = gcsERR then begin |
|
|
Item.State := gdsError; |
|
|
Item.ErrText := CgiStatus.FErrText; |
|
|
end; |
|
|
Item.ContentLength := CgiStatus.FSize; |
|
|
} |
|
| 610 |
except |
except |
| 611 |
Item.State := gdsError; |
Item.State := gdsError; |
| 612 |
end; |
end; |
|
//Item.ResponseCode := FIndy.ResponseCode; |
|
| 613 |
if FAbort then |
if FAbort then |
| 614 |
Item.State := gdsAbort; |
Item.State := gdsAbort; |
| 615 |
finally |
finally |
| 618 |
ResStream.Free; |
ResStream.Free; |
| 619 |
end; |
end; |
| 620 |
|
|
| 621 |
FIndy.Request.CustomHeaders.Clear; |
ClearHttpClient(FIndy); |
|
FIndy.Request.RawHeaders.Clear; |
|
|
FIndy.Request.Clear; |
|
|
FIndy.Response.CustomHeaders.Clear; |
|
|
FIndy.Response.RawHeaders.Clear; |
|
|
FIndy.Response.Clear; |
|
|
FIndy.ProxyParams.Clear; |
|
| 622 |
|
|
| 623 |
if Terminated then Break; |
if Terminated then Break; |
| 624 |
Suspend; |
Suspend; |
| 710 |
begin |
begin |
| 711 |
ResponseCode := -1; |
ResponseCode := -1; |
| 712 |
if (ItemType = gdtThread) and (RangeStart > 0) then begin |
if (ItemType = gdtThread) and (RangeStart > 0) then begin |
|
// if (ItemType = gdtThread) and (Item.ThreadItem.Size > 0) then begin |
|
|
// FIndy.Request.ContentRangeStart := Item.ThreadItem.Size + AdjustLen; |
|
| 713 |
FIndy.Request.ContentRangeStart := RangeStart + AdjustLen; |
FIndy.Request.ContentRangeStart := RangeStart + AdjustLen; |
| 714 |
FIndy.Request.ContentRangeEnd := 0; |
FIndy.Request.ContentRangeEnd := 0; |
| 715 |
end else begin |
end else begin |
| 722 |
FIndy.Request.CustomHeaders.Add('Pragma: no-cache'); |
FIndy.Request.CustomHeaders.Add('Pragma: no-cache'); |
| 723 |
if (Modified <> 0) and (Modified <> ZERO_DATE) then begin |
if (Modified <> 0) and (Modified <> ZERO_DATE) then begin |
| 724 |
FIndy.Request.LastModified := modified - OffsetFromUTC; |
FIndy.Request.LastModified := modified - OffsetFromUTC; |
|
//FIndy.Request.CustomHeaders.Add('If-Modified-Since: ' + RFC1123_Date(modified - OffsetFromUTC) + ' GMT'); |
|
| 725 |
end; |
end; |
|
// FIndy.Request.AcceptEncoding := 'gzip'; |
|
| 726 |
if RangeStart = 0 then |
if RangeStart = 0 then |
| 727 |
FIndy.Request.AcceptEncoding := 'gzip' |
FIndy.Request.AcceptEncoding := 'gzip' |
| 728 |
else |
else |
| 1193 |
NewRes: Integer; |
NewRes: Integer; |
| 1194 |
finish : Boolean; |
finish : Boolean; |
| 1195 |
loopCnt : Integer; |
loopCnt : Integer; |
|
// KokoTxt : string; |
|
|
// KokoIdx : Integer; |
|
|
// NewTxt : string; |
|
|
// NewIdx : Integer; |
|
|
// LastTxt : string; |
|
| 1196 |
LastIdx : Integer; |
LastIdx : Integer; |
| 1197 |
begin |
begin |
| 1198 |
FileName := ThreadItem.GetThreadFileName; |
FileName := ThreadItem.GetThreadFileName; |