| 60 |
inFileName : PChar // スレッドファイル名 |
inFileName : PChar // スレッドファイル名 |
| 61 |
) : PChar; stdcall; // スレッドの URL |
) : PChar; stdcall; // スレッドの URL |
| 62 |
|
|
| 63 |
|
|
| 64 |
function CreateResultString( |
function CreateResultString( |
| 65 |
resultStr : string |
resultStr : string |
| 66 |
) : PChar; stdcall; |
) : PChar; stdcall; |
| 69 |
resultStr : PChar |
resultStr : PChar |
| 70 |
); stdcall; |
); stdcall; |
| 71 |
|
|
| 72 |
|
var |
| 73 |
|
socket : TIdHTTP; |
| 74 |
|
|
| 75 |
implementation |
implementation |
| 76 |
|
|
| 77 |
uses ExternalBoardManager, ExternalThreadItem, GikoSystem, BoardGroup, Giko; |
uses ExternalBoardManager, ExternalThreadItem, GikoSystem, BoardGroup, Giko; |
| 226 |
inRangeEnd : DWORD // 終了位置 |
inRangeEnd : DWORD // 終了位置 |
| 227 |
) : Longint; stdcall; // レスポンスコード |
) : Longint; stdcall; // レスポンスコード |
| 228 |
var |
var |
| 229 |
httpSocket : TIdHTTP; |
// httpSocket : TIdHTTP; |
| 230 |
resStream : TMemoryStream; |
resStream : TMemoryStream; |
| 231 |
content : string; |
content : string; |
| 232 |
|
|
| 233 |
begin |
begin |
| 234 |
|
|
| 235 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 236 |
Writeln('ExternalBoardManager.InternalDownload'); |
Writeln('ExternalBoardManager.InternalDownload'); |
| 237 |
{$ENDIF} |
{$ENDIF} |
| 238 |
Result := -1; |
// Result := -1; |
| 239 |
|
|
| 240 |
httpSocket := TIdHTTP.Create( nil ); |
socket := TIdHTTP.Create( nil ); |
| 241 |
try |
try |
| 242 |
InitializeSocket( httpSocket ); |
InitializeSocket( socket ); |
| 243 |
|
|
| 244 |
httpSocket.Request.ContentRangeStart := inRangeStart; |
socket.Request.ContentRangeStart := inRangeStart; |
| 245 |
httpSocket.Request.ContentRangeEnd := inRangeEnd; |
socket.Request.ContentRangeEnd := inRangeEnd; |
| 246 |
if (ioModified <> 0) and (ioModified <> ZERO_DATE) then |
if (ioModified <> 0) and (ioModified <> ZERO_DATE) then |
| 247 |
httpSocket.Request.LastModified := ioModified - OffsetFromUTC; |
socket.Request.LastModified := ioModified - OffsetFromUTC; |
| 248 |
if inRangeStart = 0 then |
if inRangeStart = 0 then |
| 249 |
httpSocket.Request.AcceptEncoding := 'gzip' |
socket.Request.AcceptEncoding := 'gzip' |
| 250 |
else |
else |
| 251 |
httpSocket.Request.AcceptEncoding := ''; |
socket.Request.AcceptEncoding := ''; |
| 252 |
httpSocket.Request.Accept := 'text/html'; |
socket.Request.Accept := 'text/html'; |
| 253 |
|
|
| 254 |
resStream := TMemoryStream.Create; |
resStream := TMemoryStream.Create; |
| 255 |
try |
try |
| 256 |
try |
try |
| 257 |
resStream.Clear; |
resStream.Clear; |
|
|
|
| 258 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 259 |
Writeln('URL: ' + inURL); |
Writeln('URL: ' + inURL); |
| 260 |
{$ENDIF} |
{$ENDIF} |
| 261 |
httpSocket.Get( inURL, resStream ); |
socket.Get( inURL, resStream ); |
| 262 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 263 |
Writeln('取得で例外なし'); |
Writeln('取得で例外なし'); |
| 264 |
{$ENDIF} |
{$ENDIF} |
| 265 |
|
|
| 266 |
content := GikoSys.GzipDecompress( resStream, httpSocket.Response.ContentEncoding ); |
content := GikoSys.GzipDecompress( resStream, socket.Response.ContentEncoding ); |
| 267 |
ioModified := httpSocket.Response.LastModified; |
|
| 268 |
|
ioModified := socket.Response.LastModified; |
| 269 |
|
|
| 270 |
Result := httpSocket.ResponseCode; |
Result := socket.ResponseCode; |
| 271 |
if (Length( content ) = 0) and (Result = 206) then |
if (Length( content ) = 0) and (Result = 206) then |
| 272 |
Result := 304; |
Result := 304; |
| 273 |
|
|
| 276 |
on E: EIdSocketError do begin |
on E: EIdSocketError do begin |
| 277 |
ioModified := ZERO_DATE; |
ioModified := ZERO_DATE; |
| 278 |
outResultData := nil; |
outResultData := nil; |
| 279 |
|
Result := socket.ResponseCode; |
| 280 |
end; |
end; |
| 281 |
on E: EIdConnectException do begin |
on E: EIdConnectException do begin |
| 282 |
ioModified := ZERO_DATE; |
ioModified := ZERO_DATE; |
| 283 |
outResultData := nil; |
outResultData := nil; |
| 284 |
|
Result := socket.ResponseCode; |
| 285 |
//Item.ErrText := E.Message; |
//Item.ErrText := E.Message; |
| 286 |
end; |
end; |
| 287 |
|
//中断されたときココに入る |
| 288 |
|
on E: EIdClosedSocket do begin |
| 289 |
|
ioModified := ZERO_DATE; |
| 290 |
|
outResultData := nil; |
| 291 |
|
Result := 408; //既に一部DL成功しているとレスポンスコードが200のままに |
| 292 |
|
//なってしまうので、明示的にエラーコードを返す |
| 293 |
|
end; |
| 294 |
on E: Exception do begin |
on E: Exception do begin |
| 295 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 296 |
Writeln('取得で例外あり'); |
Writeln('取得で例外あり'); |
| 298 |
{$ENDIF} |
{$ENDIF} |
| 299 |
ioModified := ZERO_DATE; |
ioModified := ZERO_DATE; |
| 300 |
outResultData := nil; |
outResultData := nil; |
| 301 |
Result := httpSocket.ResponseCode; |
Result := socket.ResponseCode; |
| 302 |
//Item.ErrText := E.Message; |
//Item.ErrText := E.Message; |
| 303 |
end; |
end; |
| 304 |
end; |
end; |
| 307 |
end; |
end; |
| 308 |
|
|
| 309 |
finally |
finally |
| 310 |
httpSocket.Free; |
socket.Free; |
| 311 |
|
socket := nil; |
| 312 |
end; |
end; |
| 313 |
|
|
| 314 |
end; |
end; |
| 326 |
content : string; |
content : string; |
| 327 |
resStream : TStringStream; |
resStream : TStringStream; |
| 328 |
sourceStream : TStringStream; |
sourceStream : TStringStream; |
| 329 |
|
tmpURL, Protocol, Host, Path, Document, Port, Bookmark : string; |
| 330 |
begin |
begin |
| 331 |
|
|
| 332 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 337 |
httpSocket := TIdHTTP.Create( nil ); |
httpSocket := TIdHTTP.Create( nil ); |
| 338 |
try |
try |
| 339 |
InitializeSocket( httpSocket ); |
InitializeSocket( httpSocket ); |
| 340 |
|
tmpURL := string(inURL); |
| 341 |
|
GikoSys.ParseURI(tmpURL, Protocol,Host, Path, Document, Port, Bookmark); |
| 342 |
httpSocket.Request.CustomHeaders.Add('Pragma: no-cache'); |
httpSocket.Request.CustomHeaders.Add('Pragma: no-cache'); |
| 343 |
httpSocket.Request.AcceptLanguage := 'ja'; |
httpSocket.Request.AcceptLanguage := 'ja'; |
| 344 |
httpSocket.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*'; |
httpSocket.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*'; |
| 345 |
httpSocket.Request.ContentType := 'application/x-www-form-urlencoded'; |
httpSocket.Request.ContentType := 'application/x-www-form-urlencoded'; |
| 346 |
|
httpSocket.Request.Referer := Protocol + '://' + Host; |
| 347 |
resStream := TStringStream.Create( content ); |
resStream := TStringStream.Create( content ); |
| 348 |
sourceStream := TStringStream.Create( string( inSource ) ); |
sourceStream := TStringStream.Create( string( inSource ) ); |
| 349 |
try |
try |