Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/ExternalBoardPlugInMain.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10.2.1 - (hide annotations) (download) (as text)
Mon Apr 19 22:46:48 2004 UTC (20 years ago) by yoffy
Branch: stable
Changes since 1.10: +0 -0 lines
File MIME type: text/x-pascal
・ハ゛タ 47 相当にマージ。

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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26