Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/ExternalBoardPlugInMain.pas

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


Revision 1.3 - (show annotations) (download) (as text)
Thu Nov 20 10:59:07 2003 UTC (20 years, 5 months ago) by yoffy
Branch: MAIN
Changes since 1.2: +2 -1 lines
File MIME type: text/x-pascal
・InternalAbon が dat ファイルのパスを引数に取るようになった。

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

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