1 unit ExternalBoardPlugInMain;
6 Windows, Classes, SysUtils, Menus,
7 IdHTTP, IdComponent, IdGlobal, IdException,
12 //
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\90¬
\8c÷
\82µ
\82½
\82©
\82Ç
\82¤
\82©
13 TDownloadState = (dsWait, dsWork, dsComplete, dsDiffComplete, dsNotModify, dsAbort, dsError);
15 //
\8ew
\92è
\82µ
\82½ URL
\82ð
\82±
\82Ì
\83v
\83\89\83O
\83C
\83\93\82Å
\8eó
\82¯
\95t
\82¯
\82é
\82©
\82Ç
\82¤
\82©
16 TAcceptType = (atNoAccept, atBBS, atBoard, atThread);
18 //
\83\81\83j
\83\85\81[
\83n
\83\93\83h
\83\89
19 TMenuHandler = procedure(
20 inHandle : HMENU //
\83\81\83j
\83\85\81[
\83n
\83\93\83h
\83\8b
23 // *************************************************************************
24 //
\83v
\83\89\83O
\83C
\83\93\82ª(
\90³
\82µ
\82)
\83\8d\81[
\83h
\82³
\82ê
\82½
25 // *************************************************************************
27 inInstance : DWORD //
\83v
\83\89\83O
\83C
\83\93\82Ì
\83C
\83\93\83X
\83^
\83\93\83X
30 // *************************************************************************
31 //
\83v
\83\89\83O
\83C
\83\93\82Ì
\83o
\81[
\83W
\83\87\83\93
32 // *************************************************************************
33 TOnVersionInfo = procedure(
34 var outAgent : PChar; //
\83o
\81[
\83W
\83\87\83\93\82ð
\88ê
\90Ø
\8aÜ
\82Ü
\82È
\82¢
\8f\83\90\88\82È
\96¼
\8fÌ
35 var outMajor : DWORD; //
\83\81\83W
\83\83\81[
\83o
\81[
\83W
\83\87\83\93
36 var outMinor : DWORD; //
\83}
\83C
\83i
\81[
\83o
\81[
\83W
\83\87\83\93
37 var outRelease : PChar; //
\83\8a\83\8a\81[
\83X
\92i
\8aK
\96¼
38 var outRevision : DWORD //
\83\8a\83r
\83W
\83\87\83\93\83i
\83\93\83o
\81[
41 // *************************************************************************
42 //
\8ew
\92è
\82µ
\82½ URL
\82ð
\82±
\82Ì
\83v
\83\89\83O
\83C
\83\93\82Å
\8eó
\82¯
\95t
\82¯
\82é
\82©
\82Ç
\82¤
\82©
43 // *************************************************************************
44 TOnAcceptURL = function(
45 inURL : PChar //
\94»
\92f
\82ð
\8bÂ
\82¢
\82Å
\82¢
\82é URL
46 ): TAcceptType; stdcall; // URL
\82Ì
\8eí
\97Þ
48 // *************************************************************************
49 //
\83\81\83j
\83\85\81[
\83n
\83\93\83h
\83\89
50 // *************************************************************************
51 TOnPlugInMenu = procedure(
52 inInstance : DWORD //
\83\81\83j
\83\85\81[
\83n
\83\93\83h
\83\8b
55 // *************************************************************************
56 //
\83X
\83\8c\88ê
\97\97\82Ì URL
\82©
\82ç
\83X
\83\8c\83b
\83h
\82Ì URL
\82ð
\93±
\82«
\8fo
\82·
57 // *************************************************************************
58 TOnListURL2ThreadURL = function(
59 inListURL : PChar; //
\83X
\83\8c\88ê
\97\97\82ð
\8e¦
\82µ
\82½ URL
60 inFileName : PChar //
\83X
\83\8c\83b
\83h
\83t
\83@
\83C
\83\8b\96¼
61 ) : PChar; stdcall; //
\83X
\83\8c\83b
\83h
\82Ì URL
63 function CreateResultString(
67 procedure DisposeResultString(
73 uses ExternalBoardManager, ExternalThreadItem, GikoSystem, BoardGroup, Giko;
75 // *************************************************************************
76 //
\96ß
\82è
\92l
\82ª PChar
\82Å
\82 \82é API
\82Ì
\83\81\83\82\83\8a\82ð
\8am
\95Û
\82·
\82é
77 // *************************************************************************
78 function CreateResultString(
85 tmp := PChar( resultStr );
86 GetMem( Result, Length( tmp ) + 1 );
87 Move( tmp^, Result^, Length( tmp ) + 1 );
91 // *************************************************************************
92 //
\96ß
\82è
\92l
\82ª PChar
\82Å
\82 \82é API
\82Ì
\83\81\83\82\83\8a\82ð
\8aJ
\95ú
\82·
\82é
93 // *************************************************************************
94 procedure DisposeResultString(
103 // *************************************************************************
104 //
\83v
\83\8d\83O
\83\89\83\80\96{
\91Ì
\82Ì
\83o
\81[
\83W
\83\87\83\93\82ð
\8eæ
\93¾
\82·
\82é
105 // *************************************************************************
106 procedure VersionInfo(
107 var outAgent : PChar; //
\83o
\81[
\83W
\83\87\83\93\82ð
\88ê
\90Ø
\8aÜ
\82Ü
\82È
\82¢
\8f\83\90\88\82È
\96¼
\8fÌ
108 var outMajor : DWORD; //
\83\81\83W
\83\83\81[
\83o
\81[
\83W
\83\87\83\93
109 var outMinor : DWORD; //
\83}
\83C
\83i
\81[
\83o
\81[
\83W
\83\87\83\93
110 var outRelease : PChar; //
\83\8a\83\8a\81[
\83X
\92i
\8aK
\96¼
111 var outRevision : DWORD //
\83\8a\83r
\83W
\83\87\83\93\83i
\83\93\83o
\81[
116 Writeln('ExternalBoardManager.VersionInfo');
118 outAgent := CreateResultString( PChar( APP_NAME ) );
121 outRelease := CreateResultString( PChar( BETA_VERSION_NAME_E ) );
122 outRevision := BETA_VERSION;
126 // *************************************************************************
127 //
\83\81\83b
\83Z
\81[
\83W
\82ð
\95\
\8e¦
\82·
\82é
128 // *************************************************************************
129 procedure InternalPrint(
130 inMessage : PChar //
\83\81\83b
\83Z
\81[
\83W
134 GikoForm.AddMessageList( inMessage, nil, gmiWhat );
138 // *************************************************************************
139 //
\83f
\83o
\83b
\83O
\83\81\83b
\83Z
\81[
\83W
\82ð
\95\
\8e¦
\82·
\82é
140 // *************************************************************************
141 procedure InternalDebugPrint(
142 inMessage : PChar //
\83\81\83b
\83Z
\81[
\83W
147 Writeln( inMessage );
152 // *************************************************************************
153 //
\83\
\83P
\83b
\83g
\82ð
\8f\89\8aú
\89»
\82·
\82é(
\8eG
\97p
\8aÖ
\90\94)
154 // *************************************************************************
155 procedure InitializeSocket(
160 if inSocket <> nil then begin
161 //
\83C
\83x
\83\93\83g
\82Ì
\90Ý
\92è
162 if Assigned( OnWork ) then
163 inSocket.OnWork := OnWork;
164 if Assigned( OnWorkBegin ) then
165 inSocket.OnWorkBegin := OnWorkBegin;
166 if Assigned( OnWorkEnd ) then
167 inSocket.OnWorkEnd := OnWorkEnd;
169 //
\92Ê
\90M
\82É
\8aÖ
\82·
\82é
\90Ý
\92è
170 inSocket.Request.CustomHeaders.Clear;
171 inSocket.Response.Clear;
172 inSocket.Request.Clear;
174 inSocket.Request.UserAgent := GikoSys.GetUserAgent;
175 inSocket.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
176 inSocket.ProxyParams.BasicAuthentication := False;
178 Writeln('------------------------------------------------------------');
180 //inSocket.AllowCookies := False;
181 if GikoSys.Setting.ReadProxy then begin
182 if GikoSys.Setting.ProxyProtocol then
183 inSocket.ProtocolVersion := pv1_1
185 inSocket.ProtocolVersion := pv1_0;
186 inSocket.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
187 inSocket.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
188 inSocket.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
189 inSocket.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
190 if GikoSys.Setting.ReadProxyUserID <> '' then
191 inSocket.ProxyParams.BasicAuthentication := True;
193 Writeln('
\83v
\83\8d\83L
\83V
\90Ý
\92è
\82 \82è');
194 Writeln('
\83z
\83X
\83g: ' + GikoSys.Setting.ReadProxyAddress);
195 Writeln('
\83|
\81[
\83g: ' + IntToStr( GikoSys.Setting.ReadProxyPort ));
198 if GikoSys.Setting.Protocol then
199 inSocket.ProtocolVersion := pv1_1
201 inSocket.ProtocolVersion := pv1_0;
202 inSocket.ProxyParams.ProxyServer := '';
203 inSocket.ProxyParams.ProxyPort := 80;
204 inSocket.ProxyParams.ProxyUsername := '';
205 inSocket.ProxyParams.ProxyPassword := '';
207 Writeln('
\83v
\83\8d\83L
\83V
\90Ý
\92è
\82È
\82µ');
214 // *************************************************************************
215 //
\8ew
\92è
\82µ
\82½ URL
\82ð
\83_
\83E
\83\93\83\8d\81[
\83h
\82µ
\82Ä
\95Ô
\82·
216 // *************************************************************************
217 function InternalDownload(
218 inURL : PChar; //
\83_
\83E
\83\93\83\8d\81[
\83h
\82·
\82é URL
219 var ioModified : Double; //
\8dÅ
\8cã
\82É
\8eæ
\93¾
\82µ
\82½
\93ú
\8e\9e
220 var outResultData : PChar; //
\83_
\83E
\83\93\83\8d\81[
\83h
\82³
\82ê
\82½
\95¶
\8e\9a\97ñ
221 inRangeStart : DWORD; //
\8aJ
\8en
\88Ê
\92u
222 inRangeEnd : DWORD //
\8fI
\97¹
\88Ê
\92u
223 ) : Longint; stdcall; //
\83\8c\83X
\83|
\83\93\83X
\83R
\81[
\83h
225 httpSocket : TIdHTTP;
226 resStream : TMemoryStream;
231 Writeln('ExternalBoardManager.InternalDownload');
235 httpSocket := TIdHTTP.Create( nil );
237 InitializeSocket( httpSocket );
239 httpSocket.Request.ContentRangeStart := inRangeStart;
240 httpSocket.Request.ContentRangeEnd := inRangeEnd;
241 if (ioModified <> 0) and (ioModified <> ZERO_DATE) then
242 httpSocket.Request.LastModified := ioModified - OffsetFromUTC;
243 if inRangeStart = 0 then
244 httpSocket.Request.AcceptEncoding := 'gzip'
246 httpSocket.Request.AcceptEncoding := '';
247 httpSocket.Request.Accept := 'text/html';
249 resStream := TMemoryStream.Create;
255 Writeln('URL: ' + inURL);
257 httpSocket.Get( inURL, resStream );
259 Writeln('
\8eæ
\93¾
\82Å
\97á
\8aO
\82È
\82µ');
262 content := GikoSys.GzipDecompress( resStream, httpSocket.Response.ContentEncoding );
263 ioModified := httpSocket.Response.LastModified;
265 Result := httpSocket.ResponseCode;
266 if (Length( content ) = 0) and (Result = 206) then
269 outResultData := CreateResultString( content );
271 on E: EIdSocketError do begin
272 ioModified := ZERO_DATE;
273 outResultData := nil;
275 on E: EIdConnectException do begin
276 ioModified := ZERO_DATE;
277 outResultData := nil;
278 //Item.ErrText := E.Message;
280 on E: Exception do begin
282 Writeln('
\8eæ
\93¾
\82Å
\97á
\8aO
\82 \82è');
283 Writeln('E.Message: ' + E.Message);
285 ioModified := ZERO_DATE;
286 outResultData := nil;
287 Result := httpSocket.ResponseCode;
288 //Item.ErrText := E.Message;
301 // *************************************************************************
302 //
\8ew
\92è
\82µ
\82½ URL
\82Ö
\83f
\81[
\83^
\82ð
\91\97\90M
\82·
\82é
303 // *************************************************************************
304 function InternalPost(
305 inURL : PChar; //
\91\97\90M
\82·
\82é URL
306 inSource : PChar; //
\91\97\90M
\82·
\82é
\93à
\97e
307 var outResultData : PChar //
\95Ô
\82Á
\82Ä
\82«
\82½
\95¶
\8e\9a\97ñ
308 ) : Longint; stdcall; //
\83\8c\83X
\83|
\83\93\83X
\83R
\81[
\83h
310 httpSocket : TIdHTTP;
312 resStream : TStringStream;
313 sourceStream : TStringStream;
317 Writeln('ExternalBoardManager.InternalPost');
321 httpSocket := TIdHTTP.Create( nil );
323 InitializeSocket( httpSocket );
325 httpSocket.Request.CustomHeaders.Add('Pragma: no-cache');
326 httpSocket.Request.AcceptLanguage := 'ja';
327 httpSocket.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
328 httpSocket.Request.ContentType := 'application/x-www-form-urlencoded';
330 resStream := TStringStream.Create( content );
331 sourceStream := TStringStream.Create( string( inSource ) );
335 Writeln('URL: ' + inURL);
336 Writeln('Source: ' + inSource);
338 httpSocket.Post( string( inURL ), sourceStream, resStream );
340 Writeln('
\8eæ
\93¾
\82Å
\97á
\8aO
\82È
\82µ');
343 Result := httpSocket.ResponseCode;
345 outResultData := CreateResultString( resStream.DataString );
347 on E: EIdSocketError do begin
348 outResultData := nil;
350 on E: EIdConnectException do begin
351 outResultData := nil;
353 on E: Exception do begin
355 Writeln('
\8eæ
\93¾
\82Å
\97á
\8aO
\82 \82è');
356 Writeln('E.Message: ' + E.Message);
358 outResultData := CreateResultString( resStream.DataString );
359 Result := httpSocket.ResponseCode;
372 // *************************************************************************
373 //
\82Q
\82¿
\82á
\82ñ
\82Ë
\82é
\82Ì dat
\8c`
\8e®
\82ð
\83\8d\81[
\83J
\83\8b\82 \82Ú
\81`
\82ñ
\82É
\92Ê
\82·
374 // *************************************************************************
376 function InternalAbon(
377 inDatText : PChar; //
\96¼
\91O<>
\83\81\81[
\83\8b<>
\93ú
\95tID<>
\96{
\95¶<>[
\89ü
\8ds]
\82Å
\8d\
\90¬
\82³
\82ê
\82½
\83e
\83L
\83X
\83g
378 inDatPath : PChar // dat
\83t
\83@
\83C
\83\8b\82Ì
\83t
\83\8b\83p
\83X
380 ) : PChar; stdcall; //
\82 \82Ú
\81`
\82ñ
\8dÏ
\82Ý
\82Ì dat
\8c`
\8e®
\83e
\83L
\83X
\83g
382 datList : TStringList;
386 datList := TStringList.Create;
388 datList.Text := string( inDatText );
389 FileName := string( inDatPath );
390 GikoSys.FAbon.IndividualAbon( datList, ChangeFileExt(FileName,'.NG'));
391 GikoSys.FAbon.Execute( datList );
392 GikoSys.FSelectResFilter.Execute( datList );
394 Result := CreateResultString( datList.Text );
401 // *************************************************************************
402 //
\82Q
\82¿
\82á
\82ñ
\82Ë
\82é
\82Ì dat
\8c`
\8e®
\82ð
\83\8d\81[
\83J
\83\8b\82 \82Ú
\81`
\82ñ
\82É
\92Ê
\82·
403 //
\82½
\82¾
\82µ
\81A
\82P
\83\8c\83X
\82¸
\82Â
404 // *************************************************************************
406 function InternalAbonForOne(
407 inDatText : PChar; //
\96¼
\91O<>
\83\81\81[
\83\8b<>
\93ú
\95tID<>
\96{
\95¶<>[
\89ü
\8ds]
\82Å
\8d\
\90¬
\82³
\82ê
\82½
\83e
\83L
\83X
\83g
408 inDatPath : PChar; // dat
\83t
\83@
\83C
\83\8b\82Ì
\83t
\83\8b\83p
\83X
409 inNo : Integer //
\97v
\8b\81\82³
\82ê
\82½
\83\8c\83X
\94Ô
\8d\86
410 ) : PChar; stdcall; //
\82 \82Ú
\81`
\82ñ
\8dÏ
\82Ý
\82Ì dat
\8c`
\8e®
\83e
\83L
\83X
\83g
416 datString := string( inDatText );
417 FileName := string( inDatPath );
418 GikoSys.FAbon.IndividualAbon( datString, ChangeFileExt(FileName,'.NG'), inNo);
419 GikoSys.FAbon.Execute( datString , inNo);
420 GikoSys.FSelectResFilter.Execute( datString , inNo );
422 Result := CreateResultString( datString );
426 // *************************************************************************
427 //
\82Q
\82¿
\82á
\82ñ
\82Ë
\82é
\82Ì dat
\8c`
\8e® 1
\8ds
\82ð HTML
\82É
\95Ï
\8a·
\82·
\82é
428 // *************************************************************************
429 function InternalDat2HTML(
430 inDatRes : PChar; //
\96¼
\91O<>
\83\81\81[
\83\8b<>
\93ú
\95tID<>
\96{
\95¶<>
\82Å
\8d\
\90¬
\82³
\82ê
\82½
\83e
\83L
\83X
\83g
431 inResNo : DWORD; //
\83\8c\83X
\94Ô
\8d\86
432 inIsNew : Boolean //
\90V
\92\85\83\8c\83X
\82È
\82ç True
433 ) : PChar; stdcall; //
\90®
\8c`
\82³
\82ê
\82½ HTML
436 threadItem : TThreadItem;
439 //
\83_
\83~
\81[
\82Ì
\83N
\83\89\83X
440 board := TBoard.Create( nil, 'about://dummy/' );
441 threadItem := TThreadItem.Create( nil, 'about://dummy/test/read.cgi/dummy/' );
444 board.Add( threadItem );
446 Result := ThreadItemDat2HTML( DWORD( threadItem ), inDatRes, inResNo, inIsNew );
456 // *************************************************************************
457 //
\83v
\83\89\83O
\83C
\83\93\83\81\83j
\83\85\81[
\82É
\8d\80\96Ú
\82ð
\92Ç
\89Á
458 // *************************************************************************
459 function AddPlugInMenu(
460 inInstance : DWORD; //
\83v
\83\89\83O
\83C
\83\93\82Ì
\83C
\83\93\83X
\83^
\83\93\83X
461 inCaption : PChar //
\83\81\83j
\83\85\81[
\82É
\95\
\8e¦
\82·
\82é
\95¶
\8e\9a\97ñ
462 ) : HMENU; stdcall; //
\83\81\83j
\83\85\81[
\83n
\83\93\83h
\83\8b\81A
\92Ç
\89Á
\82É
\8e¸
\94s
\82µ
\82½
\8fê
\8d\87\82Í NULL
468 newItem := TMenuItem.Create( nil );
469 newItem.Caption := inCaption;
470 newItem.Tag := inInstance;
471 newItem.OnClick := GikoForm.OnPlugInMenuItem;
472 GikoForm.PlugInMenu.Add( newItem );
474 Result := newItem.Handle;
481 // *************************************************************************
482 //
\83v
\83\89\83O
\83C
\83\93\83\81\83j
\83\85\81[
\82©
\82ç
\8d\80\96Ú
\82ð
\8dí
\8f\9c
483 // *************************************************************************
484 procedure RemovePlugInMenu(
485 inHandle : HMENU //
\83\81\83j
\83\85\81[
\83n
\83\93\83h
\83\8b
491 for i := GikoForm.PlugInMenu.Count - 1 downto 0 do begin
492 if GikoForm.PlugInMenu.Items[ i ].Handle = inHandle then begin
493 GikoForm.PlugInMenu.items[i].Free;
494 //GikoForm.PlugInMenu.Delete( i );