OSDN Git Service

1.60.0.783をマージ
[gikonavigoeson/gikonavi.git] / res / ExternalBoardPlugIn / MachiBBSPlugIn.dpr
1 library MachiBBSPlugIn;
2
3 {
4         MachiBBSBoardPlugIn
5         \82Ü\82¿BBS\8f\88\97\9d\83\86\83j\83b\83g
6 }
7
8 uses
9         Windows, SysUtils, Classes, Math, DateUtils,
10         IdURI,
11         PlugInMain in 'PlugInMain.pas',
12         ThreadItem in 'ThreadItem.pas',
13         BoardItem in 'BoardItem.pas',
14         FilePath in 'FilePath.pas',
15     MojuUtils in '..\..\MojuUtils.pas';
16
17 {$R *.res}
18
19 type
20         // =========================================================================
21         // TMachiBBSThreadItem
22         // =========================================================================
23         TMachiBBSThreadItem = class(TThreadItem)
24         private
25                 FIsTemporary    : Boolean;
26                 FDat                                    : TStringList;
27                 //FFilePath             : String;
28         public
29                 constructor     Create( inInstance : DWORD );
30                 destructor      Destroy; override;
31
32         private
33                 function        Download : TDownloadState;
34                 function        Write( inName : string; inMail : string; inMessage : string ) : TDownloadState;
35                 function        GetRes( inNo : Integer ) : string;
36                 function        GetDat( inNo : Integer ) : string;
37                 function        GetHeader( inOptionalHeader : string ) : string;
38                 function        GetFooter( inOptionalFooter : string ) : string;
39                 function        GetBoardURL : string;
40
41                 procedure       To2chDat( ioHTML : TStringList; inStartNo : Integer = 1 );
42                 procedure       LoadDat;
43                 procedure       FreeDat;
44                 function        ReadURL : string;
45                 //property      FilePath : string read FFilePath;
46         end;
47
48         // =========================================================================
49         // TMachiBBSBoardItem
50         // =========================================================================
51         TMachiBBSBoardItem = class(TBoardItem)
52         private
53                 FIsTemporary    : Boolean;
54                 FDat                                    : TStringList;
55
56         public
57                 constructor     Create( inInstance : DWORD );
58                 destructor      Destroy; override;
59
60         private
61                 function        Download : TDownloadState;
62                 function        CreateThread( inSubject : string; inName : string; inMail : string; inMessage : string ) : TDownloadState;
63                 function        ToThreadURL( inFileName : string ) : string;
64                 procedure       EnumThread( inCallBack : TBoardItemEnumThreadCallBack );
65
66                 function        SubjectURL : string;
67         end;
68
69         // =========================================================================
70         // \83T\83u\83W\83F\83N\83g\83\8c\83R\81[\83h
71         // =========================================================================
72         TSubjectRec = record
73                 FFileName: string;
74                 FTitle: string;
75                 FCount: Integer;
76         end;
77
78 const
79         LOG_DIR                                         = 'MachiBBS\';
80         SUBJECT_NAME                    = 'subject.txt';
81
82         PLUGIN_NAME                             = 'MachiBBSPlugIn';
83         MAJOR_VERSION                   = 1;
84         MINOR_VERSION                   = 0;
85         RELEASE_VERSION         = 'beta';
86         REVISION_VERSION        = 20;
87
88 // =========================================================================
89 // \8eG\97p\8aÖ\90\94
90 // =========================================================================
91
92 // *************************************************************************
93 // \83e\83\93\83|\83\89\83\8a\82È\83p\83X\82Ì\8eæ\93¾
94 // *************************************************************************
95 function TemporaryFile : string;
96 var
97         tempPath : array [0..MAX_PATH] of       char;
98 begin
99
100         GetTempPath( SizeOf(tempPath), tempPath );
101         repeat
102                 Result := tempPath + IntToStr( Random( $7fffffff ) );
103         until not FileExists( Result );
104
105 end;
106
107 // *************************************************************************
108 // \82Ü\82¿BBS\97p\83\8d\83O\83t\83H\83\8b\83_\8eæ\93¾
109 // *************************************************************************
110 function MyLogFolder : string;
111 var
112         folder : PChar;
113 begin
114
115         folder := LogFolder;
116         if Length( folder ) = 0 then
117                 Result := ''
118         else
119                 Result := folder + LOG_DIR;
120     DisposeResultString(folder);
121
122 end;
123
124 (*************************************************************************
125  *\83f\83B\83\8c\83N\83g\83\8a\82ª\91\8dÝ\82·\82é\82©\83`\83F\83b\83N
126  *************************************************************************)
127 function DirectoryExistsEx(const Name: string): Boolean;
128 var
129         Code: Integer;
130 begin
131         Code := GetFileAttributes(PChar(Name));
132         Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0);
133 end;
134
135 (*************************************************************************
136  *\83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\95¡\90\94\8aK\91w\91Î\89\9e\81j
137  *************************************************************************)
138 function ForceDirectoriesEx(Dir: string): Boolean;
139 begin
140         Result := True;
141         if Length(Dir) = 0 then
142                 raise Exception.Create('\83t\83H\83\8b\83_\82ª\8dì\90¬\8fo\97\88\82Ü\82¹\82ñ');
143         Dir := ExcludeTrailingPathDelimiter(Dir);
144         if (Length(Dir) < 3) or DirectoryExistsEx(Dir)
145                 or (ExtractFilePath(Dir) = Dir) then Exit; // avoid 'xyz:\' problem.
146         Result := ForceDirectoriesEx(ExtractFilePath(Dir)) and CreateDir(Dir);
147 end;
148
149 // \82Æ\82è\82 \82¦\82¸\82Ì\91ã\97p\95i\82È\82Ì\82Å chrWhite \82ð\8dl\97\82µ\82Ä\82¢\82È\82¢\82±\82Æ\82É\92\8d\88Ó\81I\81I\81I
150 procedure ExtractHttpFields(
151         const chrSep : TSysCharSet;
152         const chrWhite : TSysCharSet;
153         const strValue : string;
154         var strResult : TStringList;
155         unknownFlag : boolean = false
156 );
157 var
158         last, p, strLen : Integer;
159 begin
160
161         strLen := Length( strValue );
162         p := 1;
163         last := 1;
164
165         while p <= strLen do
166         begin
167
168                 if strValue[ p ] in chrSep then
169                 begin
170                         strResult.Add( Copy( strValue, last, p - last ) );
171                         last := p + 1;
172                 end;
173
174                 p := p + 1;
175
176         end;
177
178         if last <> p then
179                 strResult.Add( Copy( strValue, last, strLen - last + 1 ) );
180
181 end;
182
183 \rfunction HttpEncode(
184 \r       const strValue : string
185 ) : string;
186 var
187         i : Integer;
188         strLen : Integer;
189         strResult : string;
190         b : Integer;
191 const
192         kHexCode : array [0..15] of char = (
193                                 '0', '1', '2', '3', '4', '5', '6', '7',
194                                 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' );
195 begin
196
197         strLen := Length( strValue );
198         i := 1;
199
200         while i <= strLen do
201         begin
202
203                 case strValue[ i ] of
204                 '0' .. '9', 'a' .. 'z', 'A' .. 'Z', '*', '-', '.', '@', '_':
205                         begin
206                                 strResult := strResult + strValue[ i ];
207                         end;
208                 else
209                         begin
210                                 b := Integer( strValue[ i ] );
211                                 strResult := strResult + '%'
212                                                                 + kHexCode[ b div $10 ]
213                                                                 + kHexCode[ b mod $10 ];
214                         end;
215                 end;
216
217                 i := i + 1;
218
219         end;
220
221         Result := strResult;
222
223 end;
224
225
226
227 // =========================================================================
228 // PlugIn
229 // =========================================================================
230
231 // *************************************************************************
232 // \83v\83\89\83O\83C\83\93\82Ì\83o\81[\83W\83\87\83\93\82ð\97v\8b\81\82³\82ê\82½
233 // *************************************************************************
234 procedure OnVersionInfo(
235         var outAgent            : PChar;        // \83o\81[\83W\83\87\83\93\82ð\88ê\90Ø\8aÜ\82Ü\82È\82¢\8f\83\90\88\82È\96¼\8fÌ
236         var outMajor            : DWORD;        // \83\81\83W\83\83\81[\83o\81[\83W\83\87\83\93
237         var outMinor            : DWORD;        // \83}\83C\83i\81[\83o\81[\83W\83\87\83\93
238         var outRelease  : PChar;        // \83\8a\83\8a\81[\83X\92i\8aK\96¼
239         var outRevision : DWORD         // \83\8a\83r\83W\83\87\83\93\83i\83\93\83o\81[
240 ); stdcall;
241 begin
242
243         try
244                 outAgent                := CreateResultString( PChar( PLUGIN_NAME ) );
245                 outMajor                := MAJOR_VERSION;
246                 outMinor                := MINOR_VERSION;
247                 outRelease      := CreateResultString( PChar( RELEASE_VERSION ) );
248                 outRevision     := REVISION_VERSION;
249         except
250                 outAgent                := nil;
251                 outMajor                := 0;
252                 outMinor                := 0;
253                 outRelease      := nil;
254                 outRevision     := 0;
255         end;
256
257 end;
258
259 // *************************************************************************
260 // \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©
261 // *************************************************************************
262 function OnAcceptURL(
263         inURL                   : PChar                         // \94»\92f\82ð\8bÂ\82¢\82Å\82¢\82é URL
264 ): TAcceptType; stdcall;        // URL \82Ì\8eí\97Þ
265 var
266         uri                             : TIdURI;
267         uriList         : TStringList;
268         foundPos        : Integer;
269 const
270         BBS_HOST                = 'machi.to';
271         THREAD_MARK     = '/bbs/read.pl';
272     THREAD_MARK2= '/bbs/read.cgi';
273 begin
274
275         try
276                 // \83z\83X\83g\96¼\82ª machi.to \82Å\8fI\82í\82é\8fê\8d\87\82Í\8eó\82¯\95t\82¯\82é\82æ\82¤\82É\82µ\82Ä\82¢\82é
277                 uri                     := TIdURI.Create( inURL );
278                 uriList := TStringList.Create;
279                 try
280                         ExtractHttpFields( ['/'], [], uri.Path, uriList );
281                         foundPos := AnsiPos( BBS_HOST, uri.Host );
282                         if (foundPos > 0) and (Length( uri.Host ) - foundPos + 1 = Length( BBS_HOST )) then begin
283                                 foundPos := Pos( THREAD_MARK, inURL );
284                 if (foundPos = 0) then begin
285                     // \90VURL\91Î\89\9e
286                     foundPos := Pos( THREAD_MARK2, inURL );
287                 end;
288                                 if foundPos > 0 then
289                                         Result := atThread
290                                 else if (uriList.Count > 1) and (uri.Path <> '/') then  // \8dÅ\8cã\82ª '/' \82Å\95Â\82ß\82ç\82ê\82Ä\82é\82È\82ç 3
291                                         Result := atBoard
292                                 else
293                                         Result := atBBS;
294                         end else begin
295                                 Result := atNoAccept;
296                         end;
297                 finally
298                         uri.Free;
299                         uriList.Free;
300                 end;
301         except
302                 Result := atNoAccept;
303         end;
304
305 end;
306
307 // *************************************************************************
308 // \8ew\92è\82µ\82½ URL \82ðBoard\82ÌURL\82É\95Ï\8a·
309 // *************************************************************************
310 procedure OnExtractBoardURL(
311         inURL   : PChar;
312         var outURL      : PChar
313 ); stdcall;
314 var
315         uri                     : TIdURI;
316         uriList         : TStringList;
317         URL         : String;
318 const
319         THREAD_MARK     = '/bbs/read.pl';
320     THREAD_MARK2= '/bbs/read.cgi';
321 begin
322         URL := string(inURL);
323         if AnsiPos(THREAD_MARK, URL) > 0 then begin
324                 if Copy( inURL, Length( inURL ), 1 ) = '/' then
325                         uri := TIdURI.Create( URL )
326                 else
327                         uri := TIdURI.Create( URL + '/' );
328
329                 uriList := TStringList.Create;
330                 try
331                         ExtractHttpFields(
332                                 ['&'], [],
333                                 Copy( uri.Params, AnsiPos( '?', uri.Params ) + 1, Length( uri.Params ) ),uriList );
334                         // http://hokkaido.machi.to/bbs/read.pl?BBS=hokkaidou&KEY=1061764446
335                         // http://hokkaido.machi.to/hokkaidou/
336                         URL := uri.Protocol + '://' + uri.Host + '/' + uriList.Values[ 'BBS' ] + '/';
337                         outURL := CreateResultString(URL);
338                 finally
339                         uri.Free;
340                         uriList.Free;
341                 end;
342     end else if AnsiPos(THREAD_MARK2, URL) > 0 then begin
343                 if Copy( inURL, Length( inURL ), 1 ) = '/' then
344                         uri := TIdURI.Create( URL )
345                 else
346                         uri := TIdURI.Create( URL + '/' );
347
348         uriList := TStringList.Create;
349                 try
350                         // http://kanto.machi.to/bbs/read.cgi/kana/1215253035/l50
351                         // http://kanto.machi.to/kana/
352             uriList.Delimiter := '/';
353             uriList.DelimitedText  := uri.Path;
354                         URL := uri.Protocol + '://' + uri.Host + '/';
355             if (uriList.Count >= 4) then begin
356                 URL := URL + uriList[3] + '/';
357             end;
358                         outURL := CreateResultString(URL);
359                 finally
360                         uri.Free;
361             uriList.Free;
362                 end;
363         end else begin
364         outURL := CreateResultString(URL);
365         end;
366
367 end;
368
369
370 // =========================================================================
371 // TMachiBBSThreadItem
372 // =========================================================================
373
374 // *************************************************************************
375 // \83R\83\93\83X\83g\83\89\83N\83^
376 // *************************************************************************
377 constructor TMachiBBSThreadItem.Create(
378         inInstance      : DWORD
379 );
380 var
381         uri                                     : TIdURI;
382         uriList                 : TStringList;
383         FilePath                : String;
384 begin
385
386         inherited;
387
388         OnDownload              := Download;
389         OnWrite                         := Write;
390         OnGetRes                        := GetRes;
391         OnGetDat                        := GetDat;
392         OnGetHeader             := GetHeader;
393         OnGetFooter             := GetFooter;
394         OnGetBoardURL   := GetBoardURL;
395
396         //FFilePath                     := '';
397         FIsTemporary    := False;
398         FDat                                    := nil;
399         URL                                             := ReadURL + '&LAST=50';
400
401         uri                     := TIdURI.Create( URL );
402         uriList := TStringList.Create;
403         try
404                 // http://hokkaido.machi.to/bbs/read.pl?BBS=hokkaidou&KEY=1061764446&LAST=50
405                 ExtractHttpFields(
406                         ['&'], [],
407                         Copy( uri.Params, AnsiPos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
408                 FileName        := uriList.Values[ 'KEY' ] + '.dat';
409                 FilePath        := MyLogFolder + uriList.Values[ 'BBS' ] + '\' + uriList.Values[ 'KEY' ] + '.dat';
410                 IsLogFile       := FileExists( FilePath );
411         finally
412                 uri.Free;
413                 uriList.Free;
414         end;
415
416 end;
417
418 // *************************************************************************
419 // \83f\83X\83g\83\89\83N\83^
420 // *************************************************************************
421 destructor TMachiBBSThreadItem.Destroy;
422 begin
423
424         FreeDat;
425
426         // \88ê\8e\9e\83t\83@\83C\83\8b\82Ì\8fê\8d\87\82Í\8dí\8f\9c\82·\82é
427         if FIsTemporary then
428                 DeleteFile( FilePath );
429
430         inherited;
431
432 end;
433
434 // *************************************************************************
435 // \8ew\92è\82µ\82½ URL \82Ì\83X\83\8c\83b\83h\82Ì\83_\83E\83\93\83\8d\81[\83h\82ð\8ew\8e¦\82³\82ê\82½
436 // *************************************************************************
437 function TMachiBBSThreadItem.Download : TDownloadState;
438 var
439         modified                        : Double;
440         tmp                                             : PChar;
441         downResult              : TStringList;
442         content                         : TStringList;
443         responseCode    : Longint;
444         logStream                       : TFileStream;
445         uri                                             : TIdURI;
446         uriList                         : TStringList;
447         datURL                          : string;
448         foundPos                        : Integer;
449         FilePath                        : String;
450         procedure       downAndParse;
451         begin
452                 responseCode := InternalDownload( PChar( datURL ), modified, tmp, 0 );
453
454                 try
455                         if responseCode = 200 then begin
456                                 downResult      := TStringList.Create;
457                                 try
458                                         downResult.Text := string( tmp );
459
460                                         // \83^\83C\83g\83\8b\82Ì\8eæ\93¾
461                                         foundPos                                := AnsiPos( '<title>', downResult.Text ) + Length( '<title>' );
462                                         Title                                           := Copy(
463                                                 downResult.Text,
464                                                 foundPos,
465                                                 AnsiPos( '</title>', downResult.Text ) - foundPos );
466
467                                         // \83\8c\83X\82Ì\8aJ\8en\88Ê\92u
468                                         foundPos                                := AnsiPos( '<dt', downResult.Text );
469                                         downResult.Text := Copy( downResult.Text, foundPos, Length( downResult.Text ) );
470                                         if foundPos > 0 then begin
471                                                 // \83\8c\83X\82Ì\8fI\97¹\88Ê\92u
472                                                 foundPos := AnsiPos( '<table', downResult.Text ) - 1;
473                                                 if foundPos > 0 then
474                                                         downResult.Text := Copy( downResult.Text, 1, foundPos );
475                                                 // \82Ü\82¿BBS\82Í dat \92¼\93Ç\82Ý\82ª\8fo\97\88\82È\82¢\82µ\81Acgi \88È\8aO\82É\8d·\95ª\93Ç\82Ý\8d\9e\82Ý\82Ì\95û\96@\82ª\82 \82é\82í\82¯\82Å\82à\96³\82¢\82Ì\82Å
476                                                 // \91f\82Ì\82Ü\82Ü\82ð\96³\97\9d\82É\95Û\82Æ\82¤\82Æ\82Í\82¹\82¸\82É 2ch \82Ì dat \8c`\8e®\82É\95Ï\8a·\82µ\82½\82à\82Ì\82ð\95Û\91\82µ\82Ä\82µ\82Ü\82¤
477                                                 To2chDat( downResult, Count + 1 );
478                                                 content.Text := content.Text + downResult.Text;
479                                         end;
480                                 finally
481                                         downResult.Free;
482                                 end;
483                         end else begin
484                                 Result := dsNotModify;
485                                 Exit;
486                         end;
487                 finally
488                         DisposeResultString( tmp );
489                 end;
490         end;
491 begin
492
493         Result := dsError;
494
495         uri                     := TIdURI.Create( URL );
496         uriList := TStringList.Create;
497         content := TStringList.Create;
498         try
499                 ExtractHttpFields(
500                         ['&'], [],
501                         Copy( uri.Params, AnsiPos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
502                 FileName := uriList.Values[ 'KEY' ] + '.dat';
503                 if MyLogFolder = '' then begin
504                         // \82Ç\82±\82É\95Û\91\82µ\82Ä\82¢\82¢\82Ì\82©\95ª\82©\82ç\82È\82¢\82Ì\82Å\88ê\8e\9e\83t\83@\83C\83\8b\82É\95Û\91
505                         FilePath                        := TemporaryFile;
506                         FIsTemporary    := True;
507                 end else begin
508                         FilePath        := MyLogFolder + uriList.Values[ 'BBS' ] + '\' + uriList.Values[ 'KEY' ] + '.dat';
509                         FIsTemporary    := False;
510                 end;
511
512                 // \95Û\91\97p\82Ì\83f\83B\83\8c\83N\83g\83\8a\82ð\8c@\82é
513                 ForceDirectoriesEx( Copy( FilePath, 1, LastDelimiter( '\', FilePath ) ) );
514
515                 // \93Æ\8e©\82É\83_\83E\83\93\83\8d\81[\83h\82â\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í
516                 // InternalDownload \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
517                 modified        := LastModified;
518                 if Count = 0 then
519                         // 1\81`
520                         datURL          :=
521                                 uri.Protocol + '://' + uri.Host + '/bbs/read.cgi?' +
522                                 'BBS=' + uriList.Values[ 'BBS' ] + '&KEY=' + uriList.Values[ 'KEY' ] +
523                                 '&START=' + IntToStr( 1 )
524                 else
525                         // \90V\92\85\82Ì\82Ý
526                         datURL          :=
527                                 uri.Protocol + '://' + uri.Host + '/bbs/read.cgi?' +
528                                 'BBS=' + uriList.Values[ 'BBS' ] + '&KEY=' + uriList.Values[ 'KEY' ] +
529                                 '&START=' + IntToStr( Count + 1 ) + '&NOFIRST=TRUE';
530                 // \83_\83E\83\93\83\8d\81[\83h
531                 downAndParse;
532
533                 if content.Count > 0 then begin
534                         if Count <= 0 then begin
535                                 Result := dsComplete;
536                                 // \90V\8bK\8f\91\82«\8d\9e\82Ý
537                                 content[ 0 ]    := content[ 0 ] + Title;
538                                 logStream                       := TFileStream.Create( FilePath, fmCreate or fmShareDenyWrite );
539                                 try
540                                         logStream.Position      := logStream.Size;
541                                         logStream.Write( PChar( content.Text )^, Length( content.Text ) );
542                                 finally
543                                         logStream.Free;
544                                 end;
545                                 NewReceive      := 1;
546                                 Count                           := content.Count;
547                         end else begin
548                 if (content.Count > 1) or (Trim(content.Text) <> '') then begin
549                                 Result := dsDiffComplete;
550                     // \92Ç\8bL
551                     logStream := TFileStream.Create( FilePath, fmOpenReadWrite or fmShareDenyWrite );
552                     try
553                         logStream.Position      := logStream.Size;
554                         logStream.Write( PChar( content.Text )^, Length( content.Text ) );
555                     finally
556                         logStream.Free;
557                     end;
558                     NewReceive  := Count + 1;
559                     Count                               := Count + content.Count;
560                 end else begin
561                     Result := dsNotModify;
562                 end;
563                         end;
564             if (Result <> dsNotModify) then begin
565                         // CGI \82©\82ç\82Í\90³\82µ\82¢\93ú\95t\82ª\93¾\82ç\82ê\82È\82¢\82Ì\82Å\8c»\8dÝ\82É\90Ý\92è
566                         LastModified    := Now;
567                         NewResCount             := content.Count;
568             end;
569                 end else begin
570                         Result := dsNotModify;
571                 end;
572         finally
573                 uri.Free;
574                 uriList.Free;
575                 content.Free;
576         end;
577
578 end;
579
580 // *************************************************************************
581 // \8f\91\82«\8d\9e\82Ý\82ð\8ew\8e¦\82³\82ê\82½
582 // *************************************************************************
583 function        TMachiBBSThreadItem.Write(
584         inName                          : string;       // \96¼\91O(\83n\83\93\83h\83\8b)
585         inMail                          : string;       // \83\81\81[\83\8b\83A\83h\83\8c\83X
586         inMessage                       : string        // \96{\95
587 ) : TDownloadState;                             // \8f\91\82«\8d\9e\82Ý\82ª\90¬\8c÷\82µ\82½\82©\82Ç\82¤\82©
588 var
589         postURL                         : string;
590         postData                        : string;
591         postResult              : PChar;
592         uri                                             : TIdURI;
593         uriList                         : TStringList;
594 begin
595
596         uri                     := TIdURI.Create( URL );
597         uriList := TStringList.Create;
598         try
599                 ExtractHttpFields(
600                         ['&'], [],
601                         Copy( uri.Params, AnsiPos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
602
603                 postURL         := uri.Protocol + '://' + uri.Host + '/bbs/write.cgi';
604                 postData        :=
605                         'NAME='                 + HttpEncode( inName ) +
606                         '&MAIL='                + HttpEncode( inMail ) +
607                         '&MESSAGE='     + HttpEncode( inMessage ) +
608                         '&BBS='                 + uriList.Values[ 'BBS' ] +
609                         '&KEY='                 + uriList.Values[ 'KEY' ] +
610                         '&TIME='                + IntToStr( DateTimeToUnix( Now ) ) +
611                         '&submit='      + HttpEncode( '\8f\91\82«\8d\9e\82Þ' );
612
613                 // \93Æ\8e©\82É\92Ê\90M\82µ\82È\82¢\8fê\8d\87\82Í InternalPost \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
614                 InternalPost( PChar( postURL ), PChar( postData ),PChar(URL), postResult );
615                 DisposeResultString( postResult );
616
617                 Result := dsComplete
618         finally
619                 uri.Free;
620                 uriList.Free;
621         end;
622
623 end;
624
625 // *************************************************************************
626 // \83\8c\83X\94Ô\8d\86 inNo \82É\91Î\82·\82é html \82ð\97v\8b\81\82³\82ê\82½
627 // *************************************************************************
628 function TMachiBBSThreadItem.GetRes(
629         inNo            : Integer               // \97v\8b\81\82³\82ê\82½\83\8c\83X\94Ô\8d\86
630 ) : string;                                             // \91Î\89\9e\82·\82é HTML
631 var
632         res                     : string;
633         tmp                     : PChar;
634 begin
635
636         // \93Æ\8e©\82É\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í
637         // InternalAbon \82¨\82æ\82Ñ Dat2HTML \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
638         LoadDat;
639         if (FDat = nil) or (inNo - 1 < 0 ) or (inNo - 1 >= FDat.Count) then begin
640                 // \83\8d\83O\82É\91\8dÝ\82µ\82È\82¢\82Ì\82Å\82±\82Ì\82Ü\82Ü\8fI\97¹
641                 Result := '';
642                 Exit;
643         end;
644         res                     := FDat[ inNo - 1 ];
645         tmp                     := InternalAbonForOne( PChar( res ), PChar(FilePath), inNo);
646     try
647                 Result  := Dat2HTML( string( tmp ), inNo );
648         finally
649                 DisposeResultString( tmp );
650         end;
651
652 end;
653
654 // *************************************************************************
655 // \83\8c\83X\94Ô\8d\86 inNo \82É\91Î\82·\82é Dat \82ð\97v\8b\81\82³\82ê\82½
656 // *************************************************************************
657 function TMachiBBSThreadItem.GetDat(
658         inNo            : Integer               // \97v\8b\81\82³\82ê\82½\83\8c\83X\94Ô\8d\86
659 ) : string;                                             // \82Q\82¿\82á\82ñ\82Ë\82é\82ÌDat\8c`\8e®
660 var
661         //res: string;
662         tmp: PChar;
663 begin
664         //Result        := '';
665         // \93Æ\8e©\82É\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í
666         LoadDat;
667         if (FDat = nil) or (inNo - 1 < 0 ) or (inNo - 1 >= FDat.Count)  then begin
668                 // \83\8d\83O\82É\91\8dÝ\82µ\82È\82¢\82Ì\82Å\82±\82Ì\82Ü\82Ü\8fI\97¹
669                 tmp := CreateResultString('');
670                 Result := tmp;
671                 DisposeResultString(tmp);
672                 Exit;
673         end;
674         tmp := CreateResultString(FDat[ inNo - 1]);
675         try
676                 Result := string(tmp);
677         finally
678                 DisposeResultString(tmp);
679         end;
680
681 end;
682
683 // *************************************************************************
684 // \83X\83\8c\83b\83h\82Ì\83w\83b\83_ html \82ð\97v\8b\81\82³\82ê\82½
685 // *************************************************************************
686 function TMachiBBSThreadItem.GetHeader(
687         inOptionalHeader        : string
688 ) : string;
689 begin
690
691         // \93Æ\8e©\82É\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í
692         // InternalHeader \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
693         Result := InternalHeader(
694                 '<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">' +
695                 inOptionalHeader );
696
697
698         // GetRes \82ð\8cÄ\82Î\82ê\82é\82±\82Æ\82ª\97\\91z\82³\82ê\82é\82Ì\82Å FDat \82ð\90\90¬\82µ\82Ä\82¨\82­
699         try
700                 FreeDat;
701                 LoadDat;
702         except
703         end;
704
705 end;
706
707 // *************************************************************************
708 // \83X\83\8c\83b\83h\82Ì\83t\83b\83^ html \82ð\97v\8b\81\82³\82ê\82½
709 // *************************************************************************
710 function TMachiBBSThreadItem.GetFooter(
711         inOptionalFooter : string
712 ) : string;
713 begin
714
715         // \93Æ\8e©\82É\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í
716         // InternalFooter \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
717         Result := InternalFooter( inOptionalFooter );
718
719         // \82à\82¤ GetRes \82Í\8cÄ\82Î\82ê\82È\82¢\82Æ\8ev\82¤\82Ì\82Å FDat \82ð\8aJ\95ú\82µ\82Ä\82¨\82­
720         try
721                 FreeDat;
722         except
723         end;
724
725 end;
726
727 // *************************************************************************
728 // \82±\82Ì ThreadItem \82ª\91®\82·\82é\94Â\82Ì URL \82ð\97v\8b\81\82³\82ê\82½
729 // *************************************************************************
730 function        TMachiBBSThreadItem.GetBoardURL : string;
731 var
732         uri                                             : TIdURI;
733         uriList                         : TStringList;
734         tmp: PChar;
735 begin
736     tmp := nil;
737         if Copy( URL, Length( URL ), 1 ) = '/' then
738                 uri := TIdURI.Create( URL )
739         else
740                 uri := TIdURI.Create( URL + '/' );
741         uriList := TStringList.Create;
742         try
743                 ExtractHttpFields(
744                         ['&'], [],
745                         Copy( uri.Params, AnsiPos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
746                 FileName := uriList.Values[ 'KEY' ] + '.dat';
747                 // http://hokkaido.machi.to/bbs/read.pl?BBS=hokkaidou&KEY=1061764446
748                 // http://hokkaido.machi.to/hokkaidou/
749                 tmp             := CreateResultString(
750                         uri.Protocol + '://' + uri.Host + '/' + uriList.Values[ 'BBS' ] + '/' );
751                 Result := string(tmp);
752         finally
753                 DisposeResultString(tmp);
754                 uri.Free;
755                 uriList.Free;
756         end;
757
758 end;
759
760 // *************************************************************************
761 // \82Ü\82¿BBS\82Ì HTML \82ð 2ch \82Ì dat \8c`\8e®\82É
762 // *************************************************************************
763 procedure       TMachiBBSThreadItem.To2chDat(
764         ioHTML                          : TStringList;
765         inStartNo                       : Integer = 1
766 );
767 var
768         i, bound                        : Integer;
769         foundPos,foundPos2                      : Integer;
770         strTmp                          : string;
771         res                                             : TStringList;
772         no                                              : Integer;
773 const
774         MAIL_TAG                        = '<a href="mailto:';
775 begin
776
777         //===== 2ch \82Ì dat \8c`\8e®\82É\95Ï\8a·
778         // \83z\83X\83g\96¼\82Ì\8cã\82Å\89ü\8ds\82³\82ê\82Ä\82¢\82½\82è\82·\82é\82Ì\82Å\89ü\8ds\82ð\82·\82×\82Ä\8eæ\82è\8f\9c\82­
779         ioHTML.Text     := CustomStringReplace( ioHTML.Text, #13#10, '');
780         //StringReplace( ioHTML.Text, #13#10, '', [rfReplaceAll] );
781         // \91ã\82í\82è\82É <dt> \82ð\8ds\82Ì\8bæ\90Ø\82è\82É\82·\82é
782         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '<dt>', #10 );
783         //StringReplace( ioHTML.Text, '<dt>', #10, [rfReplaceAll] );
784         // <dt> \82©\82ç\8en\82Ü\82Á\82Ä\82¢\82é\82Ì\82Å\8dÅ\8f\89\82Í\8bó\82Ì\82Í\82¸
785         if Length( ioHTML[ 0 ] ) = 0 then
786                 ioHTML.Delete( 0 );
787
788         // \8cy\82­\82 \82Ú\81[\82ñ\83`\83F\83b\83N
789         // \81¦\91å\8eG\94c\82¾\82©\82ç\82¿\82á\82ñ\82Æ\8fo\97\88\82Ä\82È\82¢\82©\82à
790         try
791                 i                       := 0;
792                 while i < ioHTML.Count do begin
793                         foundPos := AnsiPos( ' ', ioHTML[ i ] );
794                         if foundPos > 0 then begin
795                                 no := StrToInt( Copy( ioHTML[ i ], 1, foundPos - 1 ) );
796                                 if inStartNo < no then
797                                         ioHTML.Insert( i, '<><><><>' );
798                         end;
799                         Inc( i );
800                         Inc( inStartNo );
801                 end;
802         except
803                 // \82 \82Ú\81[\82ñ\83`\83F\83b\83N\82Å\96â\91è\82ª\94­\90\82µ\82Ä\82à\90æ\82Ö\90i\82ß\82½\82¢\82Ì\82Å
804         end;
805
806
807         // \83g\83\8a\83b\83v\82Ì\8cã\82Ì '<b> </b>' \82ð\8bó\82É
808     if AnsiPos('\81\9f</b>', ioHTML.Text) <> 0 then begin
809         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '<b> </b></font>', '</b></font>', true );
810         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '<b> </B></a>', '</b></a>', true );
811     end;
812         //ioHTML.Text   := CustomStringReplace( ioHTML.Text, '<b> </b>', '', true );
813         //StringReplace( ioHTML.Text, '<b> </b>', '', [rfReplaceAll, rfIgnoreCase] );
814         // '<b>' \82Í\83\81\81[\83\8b\82Æ\96¼\91O\82Ì\8bæ\90Ø\82è
815         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '<b>', '<>', true );
816         //StringReplace( ioHTML.Text, '<b>', '<>', [rfReplaceAll, rfIgnoreCase] );
817         // \83\81\81[\83\8b\82Æ\96¼\91O\82É\82Â\82¢\82Ä\82­\82é\95Â\82\83^\83O\82ð\93\8a\8de\93ú\82Æ\82Ì\8bæ\90Ø\82è\82É
818         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '</b></a>', '<>', true );
819         //StringReplace( ioHTML.Text, '</b></a>', '<>', [rfReplaceAll, rfIgnoreCase] );
820         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '</b>', '<>', true );
821     ioHTML.Text := CustomStringReplace( ioHTML.Text, '\81\9f<>', '\81\9f</b>', true );
822         //StringReplace( ioHTML.Text, '</b>', '<>', [rfReplaceAll, rfIgnoreCase] );
823         // '<dd>' \82ð\96{\95\82Æ\82Ì\8bæ\90Ø\82è\82É
824         ioHTML.Text     := CustomStringReplace( ioHTML.Text, '<dd>', '<>', true );
825         //StringReplace( ioHTML.Text, '<dd>', '<>', [rfReplaceAll, rfIgnoreCase] );
826
827         res := TStringList.Create;
828         try
829                 bound := ioHTML.Count - 1;
830                 for i := 0 to bound do begin
831             // \83X\83N\83\8a\83v\83g\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82ç\8dí\8f\9c\82·\82é\81i\8dL\8d\90\91Î\8dô\81j
832                         res.Text := CustomStringReplace( ioHTML[ i ], '<>', #10 );
833                                                 //StringReplace( ioHTML[ i ], '<>', #10, [rfReplaceAll] );
834                         if res.Count >= 3 then begin    // 3 \96¢\96\9e\82Í\82 \82è\82¦\82È\82¢\82Æ\8ev\82¤\82¯\82Ç\88À\91S\82Ì\82½\82ß
835                                 foundPos := AnsiPos( MAIL_TAG, res[ 0 ] );
836                                 if foundPos > 0 then begin
837                                         // \83\81\81[\83\8b\83A\83h\83\8c\83X\82ð\94²\82«\8fo\82·
838                                         foundPos        := foundPos + Length( MAIL_TAG );
839                                         res[ 0 ]        := Copy( res[ 0 ], foundPos, Length( res[ 0 ] ) );
840                                         strTmp          := Copy( res[ 0 ], 1, AnsiPos( '">', res[ 0 ] ) - 1 );
841                                         // \83\81\81[\83\8b\82Æ\96¼\91O\82ª\8bt\82È\82Ì\82Å\82Ð\82Á\82­\82è\95Ô\82µ\82Ä\96ß\82·
842                                         res[ 0 ]        := res[ 1 ];
843                                         res[ 1 ]        := strTmp;
844                                 end else begin
845                                         // \83\81\81[\83\8b\82Æ\96¼\91O\82ª\8bt\82È\82Ì\82Å\82Ð\82Á\82­\82è\95Ô\82·
846                                         res[ 0 ]        := res[ 1 ];
847                                         res[ 1 ]        := '';
848                                 end;
849                                 res[ 2 ] := StringReplace( res[ 2 ], '[', 'IP:', [] );
850                                 res[ 2 ] := StringReplace( res[ 2 ], ']', '', [] );
851
852                 if AnsiPos('</font> \93\8a\8de\93ú\81F', res[ 2 ]) = 1 then begin
853                         res[ 2 ] := StringReplace( res[ 2 ], '</font> \93\8a\8de\93ú\81F', '', [] );
854                 end else if AnsiPos(' \93\8a\8de\93ú\81F', res[ 2 ]) = 1 then begin
855                     res[ 2 ] := StringReplace( res[ 2 ], ' \93\8a\8de\93ú\81F', '', [] );
856                 end;
857                         end;
858                         ioHTML[ i ] := CustomStringReplace( res.Text, #13#10, '<>');
859             // \8dL\8d\90\83X\83N\83\8a\83v\83g\91Î\8dô
860             foundPos := Pos( '<script', ioHTML[ i ] );
861             if foundPos > 0 then begin
862                 foundPos2 := Pos( '</script>', ioHTML[ i ] );
863                 if (foundPos2 > foundPos) then begin
864                     ioHTML[ i ] := Copy(ioHTML[ i ], 1, foundPos-1) +
865                                    Copy(ioHTML[ i ], foundPos2 + 9, Length(ioHTML[ i ]));
866                 end;
867             end;
868                 end;
869         finally
870                 res.Free;
871         end;
872
873 end;
874
875 // *************************************************************************
876 // FDat \82Ì\90\90¬
877 // *************************************************************************
878 procedure       TMachiBBSThreadItem.LoadDat;
879 begin
880
881         if FDat = nil then begin
882                 if IsLogFile then begin
883                         // dat \82Ì\93Ç\82Ý\8d\9e\82Ý
884                         FDat := TStringList.Create;
885                         FDat.LoadFromFile( FilePath );
886                 end;
887         end;
888
889 end;
890
891 // *************************************************************************
892 // FDat \82Ì\8aJ\95ú
893 // *************************************************************************
894 procedure       TMachiBBSThreadItem.FreeDat;
895 begin
896
897         if FDat <> nil then begin
898                 FDat.Free;
899                 FDat := nil;
900         end;
901
902 end;
903
904 // *************************************************************************
905 // \88À\91S\82È( '/' \82Å\8fI\82í\82é )\93Ç\82Ý\8d\9e\82Ý\82Ì URL
906 // *************************************************************************
907 function        TMachiBBSThreadItem.ReadURL : string;
908 var
909         uri                             : TIdURI;
910         uriList         : TStringList;
911         foundPos        : Integer;
912 const
913     THREAD_MARK2= '/bbs/read.cgi';
914 begin
915
916         foundPos := AnsiPos( '?', URL );
917         if foundPos > 0 then begin
918                 uri := TIdURI.Create( URL );
919                 uriList := TStringList.Create;
920                 try
921                         ExtractHttpFields( ['&'], [], Copy( URL, foundPos + 1, MaxInt ), uriList );
922                         Result :=
923                                 uri.Protocol + '://' + uri.Host + '/bbs/read.pl?' +
924                                 'BBS=' + uriList.Values[ 'BBS' ] + '&KEY=' + uriList.Values[ 'KEY' ];
925                 finally
926                         uri.Free;
927                         uriList.Free;
928                 end;
929         end else begin
930         // \90V\8c`\8e® ?
931         foundPos := AnsiPos(THREAD_MARK2, URL);
932         if (foundPos > 0) then begin
933             uri := TIdURI.Create( URL );
934             uriList := TStringList.Create;
935             try
936                 uriList.Delimiter := '/';
937                 uriList.DelimitedText  := uri.Path;
938                 if (uriList.Count >= 5) then begin
939                             Result :=
940                                     uri.Protocol + '://' + uri.Host + '/bbs/read.pl?' +
941                                     'BBS=' + uriList[3] + '&KEY=' + uriList[4];
942                 end;
943             finally
944                         uri.Free;
945                         uriList.Free;
946             end;
947         end;
948     end;
949
950 end;
951
952 // *************************************************************************
953 // TThreadItem \82ª\90\90¬\82³\82ê\82½\8fê\8d\87\82Ì\8f\88\92u(TMachiBBSThreadItem \82ð\90\90¬\82·\82é)
954 // *************************************************************************
955 procedure ThreadItemOnCreateOfTMachiBBSThreadItem(
956         inInstance : DWORD
957 );
958 var
959         threadItem : TMachiBBSThreadItem;
960 begin
961
962         threadItem := TMachiBBSThreadItem.Create( inInstance );
963         ThreadItemSetLong( inInstance, tipContext, DWORD( threadItem ) );
964
965 end;
966
967 // *************************************************************************
968 // TThreadItem \82ª\94j\8aü\82³\82ê\82½\8fê\8d\87\82Ì\8f\88\92u(TMachiBBSThreadItem \82ð\94j\8aü\82·\82é)
969 // *************************************************************************
970 procedure ThreadItemOnDisposeOfTMachiBBSThreadItem(
971         inInstance : DWORD
972 );
973 var
974         threadItem : TMachiBBSThreadItem;
975 begin
976
977         threadItem := TMachiBBSThreadItem( ThreadItemGetLong( inInstance, tipContext ) );
978         threadItem.Free;
979
980 end;
981
982 // =========================================================================
983 // TMachiBBSBoardItem
984 // =========================================================================
985
986 // *************************************************************************
987 // \83R\83\93\83X\83g\83\89\83N\83^
988 // *************************************************************************
989 constructor TMachiBBSBoardItem.Create(
990         inInstance      : DWORD
991 );
992 var
993         uri                                     : TIdURI;
994         uriList                 : TStringList;
995 begin
996
997         inherited;
998
999         OnDownload                                              := Download;
1000         OnCreateThread                          := CreateThread;
1001         OnEnumThread                                    := EnumThread;
1002         OnFileName2ThreadURL    := ToThreadURL;
1003
1004         FilePath                        := '';
1005         FIsTemporary    := False;
1006         FDat                                    := nil;
1007     Is2ch                       := False;
1008
1009         uri                     := TIdURI.Create( SubjectURL );
1010         uriList := TStringList.Create;
1011         try
1012                 ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
1013                 // http://hokkaido.machi.to/hokkaidou/subject.txt
1014                 FilePath        := MyLogFolder + uriList[ 1 ] + '\' + uri.Document;
1015                 IsLogFile       := FileExists( FilePath );
1016         finally
1017                 uri.Free;
1018                 uriList.Free;
1019         end;
1020
1021 end;
1022  
1023 // *************************************************************************
1024 // \83f\83X\83g\83\89\83N\83^
1025 // *************************************************************************
1026 destructor TMachiBBSBoardItem.Destroy;
1027 begin
1028
1029         if FDat <> nil then begin
1030                 try
1031                         FDat.Free;
1032                         FDat := nil;
1033                 except
1034                 end;
1035         end;
1036
1037         // \88ê\8e\9e\83t\83@\83C\83\8b\82Ì\8fê\8d\87\82Í\8dí\8f\9c\82·\82é
1038         if FIsTemporary then
1039                 DeleteFile( FilePath );
1040
1041         inherited;
1042
1043 end;
1044
1045 // *************************************************************************
1046 // \8ew\92è\82µ\82½\83X\83\8c\88ê\97\97\82Ì\83_\83E\83\93\83\8d\81[\83h\82ð\97v\8b\81\82³\82ê\82½
1047 // *************************************************************************
1048 function TMachiBBSBoardItem.Download : TDownloadState;
1049 var
1050         modified                        : Double;
1051         downResult              : PChar;
1052         responseCode    : Longint;
1053         uri                                             : TIdURI;
1054         uriList                         : TStringList;
1055 begin
1056
1057         Result := dsError;
1058
1059         if FDat <> nil then begin
1060                 try
1061                         FDat.Free;
1062                         FDat := nil;
1063                 except
1064                 end;
1065         end;
1066         FDat            := TStringList.Create;
1067         uri                     := TIdURI.Create( SubjectURL );
1068         uriList := TStringList.Create;
1069         // \93Æ\8e©\82É\83_\83E\83\93\83\8d\81[\83h\82â\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í
1070         // InternalDownload \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
1071         modified                        := LastModified;
1072         responseCode    := InternalDownload( PChar( uri.URI ), modified, downResult );
1073         try
1074                 if responseCode = 200 then begin
1075                         try
1076                                 // \83p\83X\82ð\8eZ\8fo
1077                                 ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
1078                                 if MyLogFolder = '' then begin
1079                                         // \82Ç\82±\82É\95Û\91\82µ\82Ä\82¢\82¢\82Ì\82©\95ª\82©\82ç\82È\82¢\82Ì\82Å\88ê\8e\9e\83t\83@\83C\83\8b\82É\95Û\91
1080                                         FilePath                        := TemporaryFile;
1081                                         FIsTemporary    := True;
1082                                 end else begin
1083                                         FilePath                        := MyLogFolder + uriList[ 1 ] + '\' + uri.Document;
1084                                         FIsTemporary    := False
1085                                 end;
1086
1087                                 // \95Û\91\97p\82Ì\83f\83B\83\8c\83N\83g\83\8a\82ð\8c@\82é
1088                                 ForceDirectoriesEx( Copy( FilePath, 1, LastDelimiter( '\', FilePath ) ) );
1089
1090                                 FDat.Text := string( downResult );
1091                                 // \95Û\91
1092                                 FDat.SaveToFile( FilePath );
1093
1094                                 IsLogFile                       := True;
1095                                 RoundDate                       := Now;
1096                                 LastModified    := modified;
1097                                 LastGetTime             := Now;
1098                         finally
1099                                 uri.Free;
1100                                 uriList.Free;
1101                         end;
1102                         Result := dsComplete;
1103                 end;
1104         finally
1105                 DisposeResultString( downResult );
1106         end;
1107
1108 end;
1109
1110 // *************************************************************************
1111 // \83X\83\8c\97§\82Ä\82ð\8ew\8e¦\82³\82ê\82½
1112 // *************************************************************************
1113 function        TMachiBBSBoardItem.CreateThread(
1114         inSubject                       : string;       // \83X\83\8c\83^\83C
1115         inName                          : string;       // \96¼\91O(\83n\83\93\83h\83\8b)
1116         inMail                          : string;       // \83\81\81[\83\8b\83A\83h\83\8c\83X
1117         inMessage                       : string        // \96{\95
1118 ) : TDownloadState;                             // \8f\91\82«\8d\9e\82Ý\82ª\90¬\8c÷\82µ\82½\82©\82Ç\82¤\82©
1119 var
1120         postURL                         : string;
1121         postData                        : string;
1122         postResult              : PChar;
1123         uri                                             : TIdURI;
1124         uriList                         : TStringList;
1125 begin
1126
1127         uri                     := TIdURI.Create( URL );
1128         uriList := TStringList.Create;
1129         try
1130                 ExtractHttpFields(
1131                         ['&'], [],
1132                         Copy( uri.Params, AnsiPos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
1133
1134                 postURL         := uri.Protocol + '://' + uri.Host + '/bbs/write.cgi';
1135                 postData        :=
1136                         'SUBJECT='      + HttpEncode( inSubject ) +
1137                         '&NAME='                + HttpEncode( inName ) +
1138                         '&MAIL='                + HttpEncode( inMail ) +
1139                         '&MESSAGE='     + HttpEncode( inMessage ) +
1140                         '&BBS='                 + uriList[ 1 ] +
1141                         '&TIME='                + IntToStr( DateTimeToUnix( Now ) ) +
1142                         '&submit='      + HttpEncode( '\90V\8bK\8f\91\82«\8d\9e\82Ý' );
1143
1144                 // \93Æ\8e©\82É\92Ê\90M\82µ\82È\82¢\8fê\8d\87\82Í InternalPost \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
1145                 InternalPost( PChar( postURL ), PChar( postData ),PChar(URL), postResult );
1146                 DisposeResultString( postResult );
1147
1148                 Result := dsComplete
1149         finally
1150                 uri.Free;
1151                 uriList.Free;
1152         end;
1153
1154 end;
1155
1156 // *************************************************************************
1157 // \83X\83\8c\88ê\97\97\82Ì URL \82©\82ç\83X\83\8c\83b\83h\82Ì URL \82ð\93±\82«\8fo\82·
1158 // *************************************************************************
1159 function TMachiBBSBoardItem.ToThreadURL(
1160         inFileName      : string        // \83X\83\8c\83b\83h\83t\83@\83C\83\8b\96¼
1161 ) : string;                                                     // \83X\83\8c\83b\83h\82Ì URL
1162 var
1163         threadURL               : string;
1164         uri                                     : TIdURI;
1165         uriList                 : TStringList;
1166         found                           : Integer;
1167 begin
1168
1169         found := AnsiPos( '.', inFileName );
1170         if found > 0 then
1171                 inFileName := Copy( inFileName, 1, found - 1 );
1172
1173         uri                     := TIdURI.Create( SubjectURL );
1174         uriList := TStringList.Create;
1175         try
1176                 try
1177                         // http://hokkaido.machi.to/hokkaidou/
1178                         // http://hokkaido.machi.to/bbs/read.pl?BBS=hokkaidou&KEY=1061764446&LAST=50
1179                         ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
1180                         threadURL       := uri.Protocol + '://' + uri.Host + '/bbs/read.pl?' +
1181                                 'BBS=' + uriList[ 1 ] + '&KEY=' + inFileName + '&LAST=50';
1182                         Result          := threadURL;
1183                 finally
1184                         uri.Free;
1185                         uriList.Free;
1186                 end;
1187         except
1188                 Result := '';
1189         end;
1190
1191 end;
1192
1193 // *************************************************************************
1194 // \82±\82Ì\94Â\82É\82¢\82­\82Â\82Ì\83X\83\8c\82ª\82 \82é\82©\97v\8b\81\82³\82ê\82½
1195 // *************************************************************************
1196 procedure       TMachiBBSBoardItem.EnumThread(
1197         inCallBack      : TBoardItemEnumThreadCallBack
1198 );
1199 var
1200         uri                                     : TIdURI;
1201         uriList                 : TStringList;
1202 begin
1203
1204         try
1205                 if FDat = nil then begin
1206                         FDat := TStringList.Create;
1207
1208                         uri                     := TIdURI.Create( SubjectURL );
1209                         uriList := TStringList.Create;
1210                         try
1211                                 // \83p\83X\82ð\8eZ\8fo
1212                                 ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
1213                                 // http://hokkaido.machi.to/hokkaidou/subject.txt
1214                                 FilePath        := MyLogFolder + uriList[ 1 ] + '\' + uri.Document;
1215                                 if FileExists( FilePath ) then
1216                                         // \93Ç\82Ý\8d\9e\82Ý
1217                                         FDat.LoadFromFile( FilePath );
1218                         finally
1219                                 uri.Free;
1220                                 uriList.Free;
1221                         end;
1222                 end;
1223
1224                 // \93Æ\8e©\82É\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\8ds\82í\82È\82¢\8fê\8d\87\82Í EnumThread \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
1225                 inherited EnumThread( inCallBack, CustomStringReplace( FDat.Text, ',', '<>' ) );
1226         except
1227         end;
1228
1229 end;
1230
1231 // *************************************************************************
1232 // \83X\83\8c\88ê\97\97\82Ì URL \82ð\8b\81\82ß\82é
1233 // *************************************************************************
1234 function        TMachiBBSBoardItem.SubjectURL : string;
1235 var
1236         uri                     : TIdURI;
1237         uriList : TStringList;
1238 begin
1239
1240         uri                     := TIdURI.Create( URL );
1241         uriList := TStringList.Create;
1242         try
1243                 if uri.Document <> SUBJECT_NAME then begin
1244                         if Copy( URL, Length( URL ), 1 ) = '/' then
1245                                 Result := URL + SUBJECT_NAME
1246                         else
1247                                 Result := URL + '/' + SUBJECT_NAME;
1248                 end else begin
1249                         // \82±\82±\82É\82Í\97\88\82È\82¢\82Æ\8ev\82¤\82¯\82Ç
1250                         Result := URL;
1251                 end;
1252         finally
1253                 uri.Free;
1254                 uriList.Free;
1255         end;
1256
1257 end;
1258
1259 // *************************************************************************
1260 // TBoardItem \82ª\90\90¬\82³\82ê\82½\8fê\8d\87\82Ì\8f\88\92u(TMachiBBSBoardItem \82ð\90\90¬\82·\82é)
1261 // *************************************************************************
1262 procedure BoardItemOnCreateOfTMachiBBSBoardItem(
1263         inInstance : DWORD
1264 );
1265 var
1266         boardItem : TMachiBBSBoardItem;
1267 begin
1268
1269         boardItem := TMachiBBSBoardItem.Create( inInstance );
1270         BoardItemSetLong( inInstance, bipContext, DWORD( boardItem ) );
1271
1272 end;
1273
1274 // *************************************************************************
1275 // TBoardItem \82ª\94j\8aü\82³\82ê\82½\8fê\8d\87\82Ì\8f\88\92u(TMachiBBSBoardItem \82ð\94j\8aü\82·\82é)
1276 // *************************************************************************
1277 procedure BoardItemOnDisposeOfTMachiBBSBoardItem(
1278         inInstance : DWORD
1279 );
1280 var
1281         boardItem : TMachiBBSBoardItem;
1282 begin
1283
1284         boardItem := TMachiBBSBoardItem( BoardItemGetLong( inInstance, bipContext ) );
1285         boardItem.Free;
1286
1287 end;
1288
1289
1290
1291 // =========================================================================
1292 // \83G\83\93\83g\83\8a\83|\83C\83\93\83g
1293 // =========================================================================
1294 procedure DLLEntry(
1295         ul_reason_for_call : DWORD
1296 );
1297 var
1298         module : HMODULE;
1299 begin
1300
1301         case ul_reason_for_call of
1302                 DLL_PROCESS_ATTACH:
1303                 begin
1304                         Randomize;
1305
1306                         module := GetModuleHandle( nil );
1307
1308                         LoadInternalAPI( module );
1309                         LoadInternalFilePathAPI( module );
1310                         LoadInternalThreadItemAPI( module );
1311                         LoadInternalBoardItemAPI( module );
1312
1313                         // ===== \83C\83\93\83X\83^\83\93\83X\82Ì\8eæ\82è\88µ\82¢\82ð TThreadItem \82©\82ç TMachiBBSThreadItem \82É\95Ï\8dX\82·\82é
1314                         ThreadItemOnCreate      := ThreadItemOnCreateOfTMachiBBSThreadItem;
1315                         ThreadItemOnDispose     := ThreadItemOnDisposeOfTMachiBBSThreadItem;
1316                         // ===== \83C\83\93\83X\83^\83\93\83X\82Ì\8eæ\82è\88µ\82¢\82ð TBoardItem \82©\82ç TMachiBBSBoardItem \82É\95Ï\8dX\82·\82é
1317                         BoardItemOnCreate               := BoardItemOnCreateOfTMachiBBSBoardItem;
1318                         BoardItemOnDispose      := BoardItemOnDisposeOfTMachiBBSBoardItem;
1319                 end;
1320                 DLL_PROCESS_DETACH:
1321                         ;
1322                 DLL_THREAD_ATTACH:
1323                         ;
1324                 DLL_THREAD_DETACH:
1325                         ;
1326         end;
1327
1328 end;
1329
1330 exports
1331         OnVersionInfo,
1332         OnAcceptURL,
1333     OnExtractBoardURL;
1334 begin
1335
1336         try
1337                 DllProc := @DLLEntry;
1338                 DLLEntry( DLL_PROCESS_ATTACH );
1339         except end;
1340
1341 end.