| 1 |
unit ExternalBoardPlugInMain; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Windows, Classes, SysUtils, |
| 7 |
IdHTTP, IdComponent, IdGlobal, IdException, |
| 8 |
AbonUnit; |
| 9 |
|
| 10 |
type |
| 11 |
|
| 12 |
// ?????潟???若???????????????????? |
| 13 |
TDownloadState = (dsWait, dsWork, dsComplete, dsDiffComplete, dsNotModify, dsAbort, dsError); |
| 14 |
|
| 15 |
// ??絎????? URL ???????????違?ゃ?潟?у???篁????????????? |
| 16 |
TAcceptType = (atNoAccept, atBBS, atBoard, atThread); |
| 17 |
|
| 18 |
// ************************************************************************* |
| 19 |
// ?????違?ゃ?潟?????若?吾?с??/span> |
| 20 |
// ************************************************************************* |
| 21 |
TOnVersionInfo = procedure( |
| 22 |
var outAgent : PChar; // ???若?吾?с?潟??筝??????障????膣?膕?????腱?/span> |
| 23 |
var outMajor : DWORD; // ?<?吾?c?若???若?吾?с??/span> |
| 24 |
var outMinor : DWORD; // ???ゃ???若???若?吾?с??/span> |
| 25 |
var outRelease : PChar; // ?????若?号????? |
| 26 |
var outRevision : DWORD // ?????吾?с?潟???潟????/span> |
| 27 |
); stdcall; |
| 28 |
|
| 29 |
// ************************************************************************* |
| 30 |
// ??絎????? URL ???????????違?ゃ?潟?у???篁????????????? |
| 31 |
// ************************************************************************* |
| 32 |
TOnAcceptURL = function( |
| 33 |
inURL : PChar // ?ゆ????篁違???с???? URL |
| 34 |
): TAcceptType; stdcall; // URL ??┏蕁? |
| 35 |
|
| 36 |
// ************************************************************************* |
| 37 |
// ?鴻???荀с? URL ?????鴻??????? URL ??絨????冴?? |
| 38 |
// ************************************************************************* |
| 39 |
TOnListURL2ThreadURL = function( |
| 40 |
inListURL : PChar; // ?鴻???荀с??腓冴???? URL |
| 41 |
inFileName : PChar // ?鴻?????????<?ゃ???? |
| 42 |
) : PChar; stdcall; // ?鴻??????? URL |
| 43 |
|
| 44 |
function CreateResultString( |
| 45 |
resultStr : string |
| 46 |
) : PChar; stdcall; |
| 47 |
|
| 48 |
procedure DisposeResultString( |
| 49 |
resultStr : PChar |
| 50 |
); stdcall; |
| 51 |
|
| 52 |
implementation |
| 53 |
|
| 54 |
uses ExternalBoardManager, ExternalThreadItem, GikoSystem, BoardGroup, Giko; |
| 55 |
|
| 56 |
// ************************************************************************* |
| 57 |
// ?祉???ゃ?? PChar ?с???? API ???<?≪????腆坂????? |
| 58 |
// ************************************************************************* |
| 59 |
function CreateResultString( |
| 60 |
resultStr : string |
| 61 |
) : PChar; stdcall; |
| 62 |
var |
| 63 |
tmp : PChar; |
| 64 |
begin |
| 65 |
|
| 66 |
tmp := PChar( resultStr ); |
| 67 |
GetMem( Result, Length( tmp ) + 1 ); |
| 68 |
Move( tmp^, Result^, Length( tmp ) + 1 ); |
| 69 |
|
| 70 |
end; |
| 71 |
|
| 72 |
// ************************************************************************* |
| 73 |
// ?祉???ゃ?? PChar ?с???? API ???<?≪???????障???? |
| 74 |
// ************************************************************************* |
| 75 |
procedure DisposeResultString( |
| 76 |
resultStr : PChar |
| 77 |
); stdcall; |
| 78 |
begin |
| 79 |
|
| 80 |
FreeMem( resultStr ); |
| 81 |
|
| 82 |
end; |
| 83 |
|
| 84 |
// ************************************************************************* |
| 85 |
// ?????違????????????若?吾?с?潟????緇????? |
| 86 |
// ************************************************************************* |
| 87 |
procedure VersionInfo( |
| 88 |
var outAgent : PChar; // ???若?吾?с?潟??筝??????障????膣?膕?????腱?/span> |
| 89 |
var outMajor : DWORD; // ?<?吾?c?若???若?吾?с??/span> |
| 90 |
var outMinor : DWORD; // ???ゃ???若???若?吾?с??/span> |
| 91 |
var outRelease : PChar; // ?????若?号????? |
| 92 |
var outRevision : DWORD // ?????吾?с?潟???潟????/span> |
| 93 |
); stdcall; |
| 94 |
begin |
| 95 |
|
| 96 |
{$IFDEF DEBUG} |
| 97 |
Writeln('ExternalBoardManager.VersionInfo'); |
| 98 |
{$ENDIF} |
| 99 |
outAgent := CreateResultString( PChar( APP_NAME ) ); |
| 100 |
outMajor := 1; |
| 101 |
outMinor := 0; |
| 102 |
outRelease := CreateResultString( PChar( BETA_VERSION_NAME_E ) ); |
| 103 |
outRevision := BETA_VERSION; |
| 104 |
|
| 105 |
end; |
| 106 |
|
| 107 |
// ************************************************************************* |
| 108 |
// ?<???祉?若?吾??茵?ず???? |
| 109 |
// ************************************************************************* |
| 110 |
procedure InternalPrint( |
| 111 |
inMessage : PChar // ?<???祉?若??/span> |
| 112 |
); stdcall; |
| 113 |
begin |
| 114 |
|
| 115 |
GikoForm.AddMessageList( inMessage, nil, gmiWhat ); |
| 116 |
|
| 117 |
end; |
| 118 |
|
| 119 |
// ************************************************************************* |
| 120 |
// ???????違?<???祉?若?吾??茵?ず???? |
| 121 |
// ************************************************************************* |
| 122 |
procedure InternalDebugPrint( |
| 123 |
inMessage : PChar // ?<???祉?若??/span> |
| 124 |
); stdcall; |
| 125 |
begin |
| 126 |
|
| 127 |
{$IFDEF DEBUG} |
| 128 |
Writeln( inMessage ); |
| 129 |
{$ENDIF} |
| 130 |
|
| 131 |
end; |
| 132 |
|
| 133 |
// ************************************************************************* |
| 134 |
// ?純?宴????????????????(?????∽?? |
| 135 |
// ************************************************************************* |
| 136 |
procedure InitializeSocket( |
| 137 |
inSocket : TIdHTTP |
| 138 |
); |
| 139 |
begin |
| 140 |
|
| 141 |
if inSocket <> nil then begin |
| 142 |
// ?ゃ???潟????┃絎? |
| 143 |
if Assigned( OnWork ) then |
| 144 |
inSocket.OnWork := OnWork; |
| 145 |
if Assigned( OnWorkBegin ) then |
| 146 |
inSocket.OnWorkBegin := OnWorkBegin; |
| 147 |
if Assigned( OnWorkEnd ) then |
| 148 |
inSocket.OnWorkEnd := OnWorkEnd; |
| 149 |
|
| 150 |
// ??篆<???≪????荐?? |
| 151 |
inSocket.Request.CustomHeaders.Clear; |
| 152 |
inSocket.Response.Clear; |
| 153 |
inSocket.Request.Clear; |
| 154 |
|
| 155 |
inSocket.Request.UserAgent := GikoSys.GetUserAgent; |
| 156 |
inSocket.RecvBufferSize := Gikosys.Setting.RecvBufferSize; |
| 157 |
inSocket.ProxyParams.BasicAuthentication := False; |
| 158 |
{$IFDEF DEBUG} |
| 159 |
Writeln('------------------------------------------------------------'); |
| 160 |
{$ENDIF} |
| 161 |
//inSocket.AllowCookies := False; |
| 162 |
if GikoSys.Setting.ReadProxy then begin |
| 163 |
if GikoSys.Setting.ProxyProtocol then |
| 164 |
inSocket.ProtocolVersion := pv1_1 |
| 165 |
else |
| 166 |
inSocket.ProtocolVersion := pv1_0; |
| 167 |
inSocket.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; |
| 168 |
inSocket.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; |
| 169 |
inSocket.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; |
| 170 |
inSocket.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; |
| 171 |
if GikoSys.Setting.ReadProxyUserID <> '' then |
| 172 |
inSocket.ProxyParams.BasicAuthentication := True; |
| 173 |
{$IFDEF DEBUG} |
| 174 |
Writeln('???????決┃絎?????'); |
| 175 |
Writeln('???鴻??: ' + GikoSys.Setting.ReadProxyAddress); |
| 176 |
Writeln('???若??: ' + IntToStr( GikoSys.Setting.ReadProxyPort )); |
| 177 |
{$ENDIF} |
| 178 |
end else begin |
| 179 |
if GikoSys.Setting.Protocol then |
| 180 |
inSocket.ProtocolVersion := pv1_1 |
| 181 |
else |
| 182 |
inSocket.ProtocolVersion := pv1_0; |
| 183 |
inSocket.ProxyParams.ProxyServer := ''; |
| 184 |
inSocket.ProxyParams.ProxyPort := 80; |
| 185 |
inSocket.ProxyParams.ProxyUsername := ''; |
| 186 |
inSocket.ProxyParams.ProxyPassword := ''; |
| 187 |
{$IFDEF DEBUG} |
| 188 |
Writeln('???????決┃絎?????'); |
| 189 |
{$ENDIF} |
| 190 |
end; |
| 191 |
end; |
| 192 |
|
| 193 |
end; |
| 194 |
|
| 195 |
// ************************************************************************* |
| 196 |
// ??絎????? URL ???????潟???若????????? |
| 197 |
// ************************************************************************* |
| 198 |
function InternalDownload( |
| 199 |
inURL : PChar; // ?????潟???若?????? URL |
| 200 |
var ioModified : Double; // ??緇??????????ユ?? |
| 201 |
var outResultData : PChar; // ?????潟???若??????????絖??? |
| 202 |
inRangeStart : DWORD; // ??紮?篏?臀?/span> |
| 203 |
inRangeEnd : DWORD // 腟?篋?篏?臀?/span> |
| 204 |
) : Longint; stdcall; // ???鴻???潟?鴻?潟?若?? |
| 205 |
var |
| 206 |
httpSocket : TIdHTTP; |
| 207 |
resStream : TMemoryStream; |
| 208 |
content : string; |
| 209 |
begin |
| 210 |
|
| 211 |
{$IFDEF DEBUG} |
| 212 |
Writeln('ExternalBoardManager.InternalDownload'); |
| 213 |
{$ENDIF} |
| 214 |
Result := -1; |
| 215 |
|
| 216 |
httpSocket := TIdHTTP.Create( nil ); |
| 217 |
try |
| 218 |
InitializeSocket( httpSocket ); |
| 219 |
|
| 220 |
httpSocket.Request.ContentRangeStart := inRangeStart; |
| 221 |
httpSocket.Request.ContentRangeEnd := inRangeEnd; |
| 222 |
if (ioModified <> 0) and (ioModified <> ZERO_DATE) then |
| 223 |
httpSocket.Request.LastModified := ioModified - OffsetFromUTC; |
| 224 |
if inRangeStart = 0 then |
| 225 |
httpSocket.Request.AcceptEncoding := 'gzip' |
| 226 |
else |
| 227 |
httpSocket.Request.AcceptEncoding := ''; |
| 228 |
httpSocket.Request.Accept := 'text/html'; |
| 229 |
|
| 230 |
resStream := TMemoryStream.Create; |
| 231 |
try |
| 232 |
try |
| 233 |
resStream.Clear; |
| 234 |
|
| 235 |
{$IFDEF DEBUG} |
| 236 |
Writeln('URL: ' + inURL); |
| 237 |
{$ENDIF} |
| 238 |
httpSocket.Get( inURL, resStream ); |
| 239 |
{$IFDEF DEBUG} |
| 240 |
Writeln('??緇??т?紊?????'); |
| 241 |
{$ENDIF} |
| 242 |
|
| 243 |
content := GikoSys.GzipDecompress( resStream, httpSocket.Response.ContentEncoding ); |
| 244 |
ioModified := httpSocket.Response.LastModified; |
| 245 |
|
| 246 |
Result := httpSocket.ResponseCode; |
| 247 |
if (Length( content ) = 0) and (Result = 206) then |
| 248 |
Result := 304; |
| 249 |
|
| 250 |
outResultData := CreateResultString( content ); |
| 251 |
except |
| 252 |
on E: EIdSocketError do begin |
| 253 |
ioModified := ZERO_DATE; |
| 254 |
outResultData := nil; |
| 255 |
end; |
| 256 |
on E: EIdConnectException do begin |
| 257 |
ioModified := ZERO_DATE; |
| 258 |
outResultData := nil; |
| 259 |
//Item.ErrText := E.Message; |
| 260 |
end; |
| 261 |
on E: Exception do begin |
| 262 |
{$IFDEF DEBUG} |
| 263 |
Writeln('??緇??т?紊?????'); |
| 264 |
Writeln('E.Message: ' + E.Message); |
| 265 |
{$ENDIF} |
| 266 |
ioModified := ZERO_DATE; |
| 267 |
outResultData := nil; |
| 268 |
Result := httpSocket.ResponseCode; |
| 269 |
//Item.ErrText := E.Message; |
| 270 |
end; |
| 271 |
end; |
| 272 |
finally |
| 273 |
resStream.Free; |
| 274 |
end; |
| 275 |
|
| 276 |
finally |
| 277 |
httpSocket.Free; |
| 278 |
end; |
| 279 |
|
| 280 |
end; |
| 281 |
|
| 282 |
// ************************************************************************* |
| 283 |
// ??絎????? URL ?吾???若?帥????篆<???? |
| 284 |
// ************************************************************************* |
| 285 |
function InternalPost( |
| 286 |
inURL : PChar; // ??篆<???? URL |
| 287 |
inSource : PChar; // ??篆<??????絎?/span> |
| 288 |
var outResultData : PChar // 菴??c????????絖??? |
| 289 |
) : Longint; stdcall; // ???鴻???潟?鴻?潟?若?? |
| 290 |
var |
| 291 |
httpSocket : TIdHTTP; |
| 292 |
content : string; |
| 293 |
resStream : TStringStream; |
| 294 |
sourceStream : TStringStream; |
| 295 |
begin |
| 296 |
|
| 297 |
{$IFDEF DEBUG} |
| 298 |
Writeln('ExternalBoardManager.InternalPost'); |
| 299 |
{$ENDIF} |
| 300 |
Result := -1; |
| 301 |
|
| 302 |
httpSocket := TIdHTTP.Create( nil ); |
| 303 |
try |
| 304 |
InitializeSocket( httpSocket ); |
| 305 |
|
| 306 |
httpSocket.Request.CustomHeaders.Add('Pragma: no-cache'); |
| 307 |
httpSocket.Request.AcceptLanguage := 'ja'; |
| 308 |
httpSocket.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*'; |
| 309 |
httpSocket.Request.ContentType := 'application/x-www-form-urlencoded'; |
| 310 |
|
| 311 |
resStream := TStringStream.Create( content ); |
| 312 |
sourceStream := TStringStream.Create( string( inSource ) ); |
| 313 |
try |
| 314 |
try |
| 315 |
{$IFDEF DEBUG} |
| 316 |
Writeln('URL: ' + inURL); |
| 317 |
Writeln('Source: ' + inSource); |
| 318 |
{$ENDIF} |
| 319 |
httpSocket.Post( string( inURL ), sourceStream, resStream ); |
| 320 |
{$IFDEF DEBUG} |
| 321 |
Writeln('??緇??т?紊?????'); |
| 322 |
{$ENDIF} |
| 323 |
|
| 324 |
Result := httpSocket.ResponseCode; |
| 325 |
|
| 326 |
outResultData := CreateResultString( resStream.DataString ); |
| 327 |
except |
| 328 |
on E: EIdSocketError do begin |
| 329 |
outResultData := nil; |
| 330 |
end; |
| 331 |
on E: EIdConnectException do begin |
| 332 |
outResultData := nil; |
| 333 |
end; |
| 334 |
on E: Exception do begin |
| 335 |
{$IFDEF DEBUG} |
| 336 |
Writeln('??緇??т?紊?????'); |
| 337 |
Writeln('E.Message: ' + E.Message); |
| 338 |
{$ENDIF} |
| 339 |
outResultData := CreateResultString( resStream.DataString ); |
| 340 |
Result := httpSocket.ResponseCode; |
| 341 |
end; |
| 342 |
end; |
| 343 |
finally |
| 344 |
resStream.Free; |
| 345 |
sourceStream.Free; |
| 346 |
end; |
| 347 |
finally |
| 348 |
httpSocket.Free; |
| 349 |
end; |
| 350 |
|
| 351 |
end; |
| 352 |
|
| 353 |
// ************************************************************************* |
| 354 |
// 鐚??<????????? dat 綵√??????若???????若?????????? |
| 355 |
// ************************************************************************* |
| 356 |
|
| 357 |
function InternalAbon( |
| 358 |
inDatText : PChar; // ????<>?<?若??lt;>?ヤ?ID<>????<>[?壕?] ?ф??????????????鴻?? |
| 359 |
inDatPath : PChar // dat ???<?ゃ????????????/span> |
| 360 |
|
| 361 |
) : PChar; stdcall; // ???若????羝??帥? dat 綵√??????鴻?? |
| 362 |
var |
| 363 |
datList : TStringList; |
| 364 |
FileName : String; |
| 365 |
begin |
| 366 |
|
| 367 |
datList := TStringList.Create; |
| 368 |
datList.Text := string( inDatText ); |
| 369 |
FileName := string( inDatPath ); |
| 370 |
GikoSys.FAbon.IndividualAbon( datList, ChangeFileExt(FileName,'.NG')); |
| 371 |
GikoSys.FAbon.Execute( datList ); |
| 372 |
GikoSys.FSelectResFilter.Execute( datList ); |
| 373 |
|
| 374 |
Result := CreateResultString( datList.Text ); |
| 375 |
|
| 376 |
end; |
| 377 |
// ************************************************************************* |
| 378 |
// 鐚??<????????? dat 綵√??????若???????若?????????? |
| 379 |
// ????????鐚????鴻????/span> |
| 380 |
// ************************************************************************* |
| 381 |
|
| 382 |
function InternalAbonForOne( |
| 383 |
inDatText : PChar; // ????<>?<?若??lt;>?ヤ?ID<>????<>[?壕?] ?ф??????????????鴻?? |
| 384 |
inDatPath : PChar; // dat ???<?ゃ????????????/span> |
| 385 |
inNo : Integer // 荀?羆??????????合???/span> |
| 386 |
) : PChar; stdcall; // ???若????羝??帥? dat 綵√??????鴻?? |
| 387 |
var |
| 388 |
datString : String; |
| 389 |
FileName : String; |
| 390 |
begin |
| 391 |
|
| 392 |
datString := string( inDatText ); |
| 393 |
FileName := string( inDatPath ); |
| 394 |
GikoSys.FAbon.IndividualAbon( datString, ChangeFileExt(FileName,'.NG'), inNo); |
| 395 |
GikoSys.FAbon.Execute( datString , inNo); |
| 396 |
GikoSys.FSelectResFilter.Execute( datString , inNo ); |
| 397 |
|
| 398 |
Result := CreateResultString( datString ); |
| 399 |
|
| 400 |
end; |
| 401 |
|
| 402 |
// ************************************************************************* |
| 403 |
// 鐚??<????????? dat 綵√? 1 茵??? HTML ????????? |
| 404 |
// ************************************************************************* |
| 405 |
function InternalDat2HTML( |
| 406 |
inDatRes : PChar; // ????<>?<?若??lt;>?ヤ?ID<>????<> ?ф??????????????鴻?? |
| 407 |
inResNo : DWORD; // ???合???/span> |
| 408 |
inIsNew : Boolean // ?亥?????鴻???? True |
| 409 |
) : PChar; stdcall; // ?翫就?????? HTML |
| 410 |
var |
| 411 |
board : TBoard; |
| 412 |
threadItem : TThreadItem; |
| 413 |
begin |
| 414 |
|
| 415 |
// ?????若????????/span> |
| 416 |
board := TBoard.Create( nil, 'about://dummy/' ); |
| 417 |
threadItem := TThreadItem.Create( nil, 'about://dummy/test/read.cgi/dummy/' ); |
| 418 |
try |
| 419 |
try |
| 420 |
board.Add( threadItem ); |
| 421 |
|
| 422 |
Result := ThreadItemDat2HTML( DWORD( threadItem ), inDatRes, inResNo, inIsNew ); |
| 423 |
except |
| 424 |
Result := nil; |
| 425 |
end; |
| 426 |
finally |
| 427 |
board.Free; |
| 428 |
end; |
| 429 |
|
| 430 |
end; |
| 431 |
|
| 432 |
exports |
| 433 |
CreateResultString, |
| 434 |
DisposeResultString, |
| 435 |
VersionInfo, |
| 436 |
InternalPrint, |
| 437 |
InternalDebugPrint, |
| 438 |
InternalDownload, |
| 439 |
InternalPost, |
| 440 |
InternalAbon, |
| 441 |
InternalAbonForOne, |
| 442 |
InternalDat2HTML; |
| 443 |
|
| 444 |
end. |