OSDN Git Service

・新たにしたらば(≠JBBS)プラグインを作成。
authoryoffy <yoffy>
Sun, 23 Nov 2003 04:51:00 +0000 (04:51 +0000)
committeryoffy <yoffy>
Sun, 23 Nov 2003 04:51:00 +0000 (04:51 +0000)
res/ExternalBoardPlugIn/ShitarabaPlugIn.dpr

index 9d57f20..88cbc05 100644 (file)
@@ -1,7 +1,7 @@
 library ShitarabaPlugIn;
 
 {
-       ShitarabaBoardPlugIn
+       ShitarabaPlugIn
        \82µ\82½\82ç\82Î\8f\88\97\9d\83\86\83j\83b\83g
 }
 
@@ -39,8 +39,6 @@ type
 
                procedure       LoadDat;
                procedure       FreeDat;
-               function        ReadURL : string;
-               function        WriteURL : string;
        end;
 
        // =========================================================================
@@ -65,14 +63,14 @@ type
        end;
 
 const
-       LOG_DIR                                         = 'shitaraba\';
+       LOG_DIR                                         = 'Shitaraba\';
        SUBJECT_NAME                    = 'subject.txt';
 
-       PLUGIN_NAME                             = 'ShitarabaPlugIn';
+       PLUGIN_NAME                             = 'Shitaraba';
        MAJOR_VERSION                   = 1;
        MINOR_VERSION                   = 0;
        RELEASE_VERSION         = 'beta';
-       REVISION_VERSION        = 10;
+       REVISION_VERSION        = 1;
 
 // =========================================================================
 // \8eG\97p\8aÖ\90\94
@@ -255,12 +253,12 @@ var
        uriList         : TStringList;
        foundPos        : Integer;
 const
-       BBS_HOST                = 'jbbs.shitaraba.com';
-       THREAD_MARK     = '/bbs/read.cgi/';
+       BBS_HOST                = 'www.shitaraba.com';
+       THREAD_MARK     = '/cgi-bin/read.cgi?';
 begin
 
        try
-               // \83z\83X\83g\96¼\82ª jbbs.shitaraba.com \82Å\8fI\82í\82é\8fê\8d\87\82Í\8eó\82¯\95t\82¯\82é\82æ\82¤\82É\82µ\82Ä\82¢\82é
+               // \83z\83X\83g\96¼\82ª www.shitaraba.com \82Å\8fI\82í\82é\8fê\8d\87\82Í\8eó\82¯\95t\82¯\82é\82æ\82¤\82É\82µ\82Ä\82¢\82é
                uri                     := TIdURI.Create( inURL );
                uriList := TStringList.Create;
                try
@@ -317,12 +315,15 @@ begin
        FIsTemporary    := False;
        FDat                                    := nil;
 
-       uri                     := TIdURI.Create( ReadURL );
+       uri                     := TIdURI.Create( URL );
        uriList := TStringList.Create;
        try
-               ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-               FileName        := uriList[ 5 ] + '.dat';
-               FilePath        := MyLogFolder + uriList[ 3 ] + '\' + uriList[ 4 ] + '\' + uriList[ 5 ] + '.dat';
+               // http://www.shitaraba.com/cgi-bin/read.cgi?key=1032678843_1&bbs=jbbs
+               ExtractHttpFields(
+                       ['&'], [],
+                       Copy( uri.Params, Pos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
+               FileName        := uriList.Values[ 'key' ] + '.dat';
+               FilePath        := MyLogFolder + uriList.Values[ 'bbs' ] + '\' + uriList.Values[ 'key' ] + '.dat';
                IsLogFile       := FileExists( FilePath );
        finally
                uri.Free;
@@ -353,87 +354,121 @@ end;
 function TShitarabaThreadItem.Download : TDownloadState;
 var
        modified                        : Double;
-       tmp                                             : PChar;
-       downResult              : TStringList;
+       tmp, tmp2                       : PChar;
+       tmpLen                          : Integer;
        responseCode    : Longint;
        logStream                       : TFileStream;
        uri                                             : TIdURI;
        uriList                         : TStringList;
        datURL                          : string;
+       downResult              : TStringList;
+const
+       LF                                              = #10;
 begin
 
        Result := dsError;
 
-       uri := TIdURI.Create( ReadURL );
-       uriList := TStringList.Create;
+       uri                     := TIdURI.Create( URL );
+       uriList := TStringList.Create;
        try
-               ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-               FileName := uriList[ 5 ] + '.dat';
-               // http://jbbs.shitaraba.com/bbs/rawmode.cgi/game/1578/1067968274/l100
-               // protocol://host/1/2/3/4/5/uriList.Count - 1
+               // http://www.shitaraba.com/cgi-bin/read.cgi?key=1032678843_1&bbs=jbbs
+               ExtractHttpFields(
+                       ['&'], [],
+                       Copy( uri.Params, Pos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
+               FileName := uriList.Values[ 'key' ] + '.dat';
                if MyLogFolder = '' then begin
                        // \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
                        FilePath                        := TemporaryFile;
                        FIsTemporary    := True;
                end else begin
-                       FilePath                        := MyLogFolder + uriList[ 3 ] + '\' + uriList[ 4 ] + '\' + uriList[ 5 ] + '.dat';
+                       FilePath        := MyLogFolder + uriList.Values[ 'bbs' ] + '\' + uriList.Values[ 'key' ] + '.dat';
                        FIsTemporary    := False;
                end;
-       finally
-               uri.Free;
-               uriList.Free;
-       end;
 
-       // \95Û\91\97p\82Ì\83f\83B\83\8c\83N\83g\83\8a\82ð\8c@\82é
-       ForceDirectoriesEx( Copy( FilePath, 1, LastDelimiter( '\', FilePath ) ) );
+               // \95Û\91\97p\82Ì\83f\83B\83\8c\83N\83g\83\8a\82ð\8c@\82é
+               ForceDirectoriesEx( Copy( FilePath, 1, LastDelimiter( '\', FilePath ) ) );
 
-       // \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Í
-       // InternalDownload \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
-       modified        := LastModified;
-       datURL          := ReadURL + IntToStr( Count + 1 ) + '-'; // \90V\92\85\82Ì\82Ý
-       responseCode := InternalDownload( PChar( datURL ), modified, tmp, 0 );
+               if FileExists( FilePath ) then
+                       logStream := TFileStream.Create( FilePath, fmOpenReadWrite or fmShareDenyWrite )
+               else
+                       logStream := TFileStream.Create( FilePath, fmCreate or fmShareDenyWrite );
+               try
+                       // \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Í
+                       // InternalDownload \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
+                       modified        := LastModified;
+                       // http://www.shitaraba.com/cgi-bin/read.cgi?key=1032678843_1&bbs=jbbs
+                       // http://www.shitaraba.com/bbs/jbbs/dat/1032678843_1.dat
+                       datURL          :=
+                               uri.Protocol + '://' + uri.Host + '/bbs/' +
+                               uriList.Values[ 'bbs' ] + '/dat/' + uriList.Values[ 'key' ] + '.dat';
+                       // \82 \82Ú\81[\82ñ\83`\83F\83b\83N\82Ì\82½\82ß 1 \83o\83C\83g\91O\82©\82ç\8eæ\93¾\82·\82é
+                       // \81¦\83\8d\83O\82Æ\8eI\82Ì dat \82Í\89ü\8ds\83R\81[\83h\82ª\88á\82¤\82½\82ß\83t\83@\83C\83\8b\83T\83C\83Y\82ª\95Ï\82í\82Á\82Ä\82¢\82é\82±\82Æ\82É\92\8d\88Ó
+                       responseCode := InternalDownload( PChar( datURL ), modified, tmp, Max( 0, Size - 1 ) );
 
-       try
-               if (responseCode = 200) or (responseCode = 206) then begin
-                       downResult := TStringList.Create;
                        try
-                               downResult.Text := EUCtoSJIS( string( tmp ) );
-
-                               if downResult.Count > 0 then begin
-                                       logStream := TFileStream.Create( FilePath, fmCreate or fmShareDenyWrite );
+                               if (responseCode = 200) or (responseCode = 206) then begin
+                                       downResult := TStringList.Create;
                                        try
-                                               logStream.Position      := logStream.Size;
-                                               logStream.Write( PChar( downResult.Text )^, Length( downResult.Text ) );
+                                               tmpLen                                  := StrLen( tmp );
+
+                                               if Count = 0 then begin
+                                                       Result := dsComplete;
+                                                       downResult.Text                 := EUCtoSJIS( string( tmp ) );
+                                                       logStream.Position      := logStream.Size;
+                                                       logStream.Write( PChar( downResult.Text )^, Length( downResult.Text ) );
+
+                                                       NewReceive              := Count + 1;
+                                                       Count                                   := Count + downResult.Count;
+                                                       NewResCount             := downResult.Count;
+                                                       Size                                    := tmpLen;
+                                               end else if LF = tmp^ then begin
+                                                       // \90V\8bK\81A\82Ü\82½\82Í\92Ç\8bL
+                                                       Result := dsDiffComplete;
+                                                       downResult.Text                 := EUCtoSJIS( string( tmp + 1 ) );
+                                                       logStream.Position      := logStream.Size;
+                                                       logStream.Write( PChar( downResult.Text )^, Length( downResult.Text ) );
+
+                                                       NewReceive              := Count + 1;
+                                                       Count                                   := Count + downResult.Count;
+                                                       NewResCount             := downResult.Count;
+                                                       Size                                    := Size + tmpLen - 1;
+                                               end else begin
+                                                       // \82 \82Ú\81[\82ñ
+                                                       Result := dsDiffComplete;
+                                                       // \8dÄ\8eæ\93¾
+                                                       modified                        := LastModified;
+                                                       responseCode    := InternalDownload(
+                                                               PChar( datURL ), modified, tmp2, 0, Size );
+                                                       downResult.Text := EUCtoSJIS( string( tmp2 ) + string( tmp ) );
+                                                       logStream.Position := 0;
+                                                       logStream.Write( PChar( downResult.Text )^, Length( downResult.Text ) );
+
+                                                       LastModified    := modified;
+                                                       if downResult.Count > Count then
+                                                               NewReceive := Count + 1
+                                                       else
+                                                               NewReceive := 1;
+                                                       Count                                   := downResult.Count;
+                                                       NewResCount             := Count - NewReceive + 1;
+                                                       Size                                    := StrLen( tmp2 ) + tmpLen;
+                                               end;
+
+                                               LastModified    := modified;
                                        finally
-                                               logStream.Free;
+                                               downResult.Free;
                                        end;
-
-                                       NewReceive              := Count + 1;
-                                       Count                                   := Count + downResult.Count;
-                                       NewResCount             := downResult.Count;
-                                       Size                                    := Size + Length( downResult.Text );
-
-                                       // CGI \82©\82ç\82Í\90³\82µ\82¢\93ú\95t\82ª\93¾\82ç\82ê\82È\82¢\82Ì\82Å\8c»\8dÝ\82É\90Ý\92è
-                                       LastModified    := Now;
-                                       NewResCount             := downResult.Count;
-
-                                       if Count = 0 then
-                                               // \90V\8bK
-                                               Result := dsComplete
-                                       else
-                                               // \92Ç\8bL
-                                               Result := dsDiffComplete;
-                               end else begin
+                               end else if responseCode = 304 then begin
                                        Result := dsNotModify;
                                end;
                        finally
-                               downResult.Free;
+                               DisposeResultString( tmp );
                        end;
-               end else if responseCode = 304 then begin
-                       Result := dsNotModify;
+               finally
+                       logStream.Free;
                end;
        finally
-               DisposeResultString( tmp );
+               uri.Free;
+               uriList.Free;
        end;
 
 end;
@@ -456,21 +491,21 @@ begin
        uri                     := TIdURI.Create( URL );
        uriList := TStringList.Create;
        try
-               ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
+               ExtractHttpFields(
+                       ['&'], [],
+                       Copy( uri.Params, Pos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
 
-               // http://jbbs.shitaraba.com/bbs/read.cgi/game/1578/1067968274/l100
+               // http://cgi.shitaraba.com/cgi-bin/bbs.cgi
                postData        :=
-                       'NAME='                 + HttpEncode( SJIStoEUC( inName ) ) +
-                       '&MAIL='                + HttpEncode( SJIStoEUC( inMail ) ) +
+                       'FROM='                 + HttpEncode( SJIStoEUC( inName ) ) +
+                       '&mail='                + HttpEncode( SJIStoEUC( inMail ) ) +
                        '&MESSAGE='     + HttpEncode( SJIStoEUC( inMessage ) ) +
-                       '&BBS='                 + uriList[ 4 ] +
-                       '&KEY='                 + uriList[ 5 ] +
-                       '&DIR='                 + uriList[ 3 ] +
-                       '&TIME='                + IntToStr( DateTimeToUnix( Now ) ) +
-                       '&submit='      + HttpEncode( SJIStoEUC( '\8f\91\82«\8d\9e\82Þ' ) );
+                       '&BBS='                 + uriList.Values[ 'bbs' ] +
+                       '&KEY='                 + uriList.Values[ 'key' ] +
+                       '&submit='      + HttpEncode( SJIStoEUC( '\82©\82«\82±\82Þ' ) );
 
                // \93Æ\8e©\82É\92Ê\90M\82µ\82È\82¢\8fê\8d\87\82Í InternalPost \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
-               InternalPost( PChar( WriteURL ), PChar( postData ), postResult );
+               InternalPost( PChar( 'http://cgi.shitaraba.com/cgi-bin/bbs.cgi' ), PChar( postData ), postResult );
                DisposeResultString( postResult );
 
                Result := dsComplete
@@ -563,15 +598,17 @@ var
        uriList                         : TStringList;
 begin
 
-       uri                     := TIdURI.Create( ReadURL );
+       uri                     := TIdURI.Create( URL );
        uriList := TStringList.Create;
        try
-               ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-               FileName := uriList[ 5 ] + '.dat';
-               // http://jbbs.shitaraba.com/bbs/read.cgi/game/1578/1067968274/l100
-               // http://jbbs.shitaraba.com/game/1000/subject.txt
+               // http://www.shitaraba.com/cgi-bin/read.cgi?key=1032678843_1&bbs=jbbs
+               // http://www.shitaraba.com/bbs/jbbs/
+               ExtractHttpFields(
+                       ['&'], [],
+                       Copy( uri.Params, Pos( '?', uri.Params ) + 1, Length( uri.Params ) ), uriList );
+               FileName := uriList.Values[ 'key' ] + '.dat';
                Result          := CreateResultString(
-                       uri.Protocol + '://' + uri.Host + '/' + uriList[ 3 ] + '/' + uriList[ 4 ] + '/' );
+                       uri.Protocol + '://' + uri.Host + '/bbs/' + uriList.Values[ 'bbs' ] + '/' );
        finally
                uri.Free;
                uriList.Free;
@@ -609,60 +646,6 @@ begin
 end;
 
 // *************************************************************************
-// \88À\91S\82È( '/' \82Å\8fI\82í\82é )\93Ç\82Ý\8d\9e\82Ý\82Ì URL
-// *************************************************************************
-function       TShitarabaThreadItem.ReadURL : string;
-var
-       uri                     : TIdURI;
-       uriList : TStringList;
-begin
-
-       if Copy( URL, Length( URL ), 1 ) = '/' then
-               uri := TIdURI.Create( URL )
-       else
-               uri := TIdURI.Create( URL + '/' );
-       uriList := TStringList.Create;
-       try
-               ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-               // http://jbbs.shitaraba.com/bbs/read.cgi/game/1578/1067968274/l100
-               Result :=
-                       uri.Protocol + '://' + uri.Host + '/bbs/rawmode.cgi/' +
-                       uriList[ 3 ] + '/' + uriList[ 4 ] + '/' + uriList[ 5 ] + '/';
-       finally
-               uri.Free;
-               uriList.Free;
-       end;
-
-end;
-
-// *************************************************************************
-// \88À\91S\82È( '/' \82Å\8fI\82í\82é )\8f\91\82«\8d\9e\82Ý\82Ì URL
-// *************************************************************************
-function       TShitarabaThreadItem.WriteURL : string;
-var
-       uri                     : TIdURI;
-       uriList : TStringList;
-begin
-
-       if Copy( URL, Length( URL ), 1 ) = '/' then
-               uri := TIdURI.Create( URL )
-       else
-               uri := TIdURI.Create( URL + '/' );
-       uriList := TStringList.Create;
-       try
-               ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-               // http://jbbs.shitaraba.com/bbs/read.cgi/game/1578/1067968274/l100
-               Result          :=
-                       uri.Protocol + '://' + uri.Host + '/bbs/write.cgi/' +
-                       uriList[ 3 ] + '/' + uriList[ 4 ] + '/' + uriList[ 5 ] + '/';
-       finally
-               uri.Free;
-               uriList.Free;
-       end;
-
-end;
-
-// *************************************************************************
 // TThreadItem \82ª\90\90¬\82³\82ê\82½\8fê\8d\87\82Ì\8f\88\92u(TShitarabaThreadItem \82ð\90\90¬\82·\82é)
 // *************************************************************************
 procedure ThreadItemOnCreateOfTShitarabaThreadItem(
@@ -722,8 +705,8 @@ begin
        uriList := TStringList.Create;
        try
                ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-               // http://jbbs.shitaraba.com/game/1000/subject.txt
-               FilePath        := MyLogFolder + uriList[ 1 ] + '\' + uriList[ 2 ] + '\' + uri.Document;
+               // http://www.shitaraba.com/bbs/jbbs/
+               FilePath        := MyLogFolder + uriList[ 2 ] + '\' + uri.Document;
                IsLogFile       := FileExists( FilePath );
        finally
                uri.Free;
@@ -792,7 +775,7 @@ begin
                                        FilePath                        := TemporaryFile;
                                        FIsTemporary    := True;
                                end else begin
-                                       FilePath                        := MyLogFolder + uriList[ 1 ] + '\' + uriList[ 2 ] + '\' + uri.Document;
+                                       FilePath                        := MyLogFolder + uriList[ 2 ] + '\' + uri.Document;
                                        FIsTemporary    := False
                                end;
 
@@ -842,20 +825,14 @@ begin
        try
                ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
 
-               // http://jbbs.shitaraba.com/bbs/write.cgi/game/1578/new/
-               // http://jbbs.shitaraba.com/game/1000/subject.txt
-               postURL         :=
-                       uri.Protocol + '://' + uri.Host + '/bbs/write.cgi/' +
-                       uriList[ 1 ] + '/' + uriList[ 2 ] + '/new/';
+               postURL         := 'http://cgi.shitaraba.com/cgi-bin/bbs.cgi';
                postData        :=
-                       'SUBJECT='      + HttpEncode( SJIStoEUC( inSubject ) ) +
-                       '&NAME='                + HttpEncode( SJIStoEUC( inName ) ) +
-                       '&MAIL='                + HttpEncode( SJIStoEUC( inMail ) ) +
+                       'subject='      + HttpEncode( SJIStoEUC( inSubject ) ) +
+                       '&FROM='                + HttpEncode( SJIStoEUC( inName ) ) +
+                       '&mail='                + HttpEncode( SJIStoEUC( inMail ) ) +
                        '&MESSAGE='     + HttpEncode( SJIStoEUC( inMessage ) ) +
-                       '&BBS='                 + uriList[ 4 ] +
-                       '&DIR='                 + uriList[ 3 ] +
-                       '&TIME='                + IntToStr( DateTimeToUnix( Now ) ) +
-                       '&submit='      + HttpEncode( SJIStoEUC( '\90V\8bK\8f\91\82«\8d\9e\82Ý' ) );
+                       '&bbs='                 + uriList[ 2 ] +
+                       '&submit='      + HttpEncode( SJIStoEUC( '\90V\8bK\83X\83\8c\83b\83h\8dì\90¬' ) );
 
                // \93Æ\8e©\82É\92Ê\90M\82µ\82È\82¢\8fê\8d\87\82Í InternalPost \82É\94C\82¹\82é\82±\82Æ\82ª\8fo\97\88\82é
                InternalPost( PChar( postURL ), PChar( postData ), postResult );
@@ -890,9 +867,11 @@ begin
        uriList := TStringList.Create;
        try
                try
+                       // http://www.shitaraba.com/cgi-bin/read.cgi?key=1032678843_1&bbs=jbbs
+                       // http://www.shitaraba.com/bbs/jbbs/
                        ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-                       threadURL       := uri.Protocol + '://' + uri.Host + '/bbs/read.cgi/' +
-                               uriList[ 1 ] + '/' + uriList[ 2 ] + '/' + inFileName + '/l100';
+                       threadURL       := uri.Protocol + '://' + uri.Host + '/cgi-bin/read.cgi?' +
+                               'bbs=' + uriList[ 2 ] + '&key=' + inFileName + '&ls=100';
                        Result          := threadURL;
                finally
                        uri.Free;
@@ -913,6 +892,8 @@ procedure   TShitarabaBoardItem.EnumThread(
 var
        uri                                     : TIdURI;
        uriList                 : TStringList;
+       i, bound                : Integer;
+       lineRec                 : TStringList;
 begin
 
        try
@@ -923,8 +904,7 @@ begin
                        try
                                // \83p\83X\82ð\8eZ\8fo
                                ExtractHttpFields( ['/', '?'], [], uri.Path, uriList );
-                               // http://jbbs.shitaraba.com/game/1000/subject.txt
-                               FilePath        := MyLogFolder + uriList[ 1 ] + '\' + uriList[ 2 ] + '\' + uri.Document;
+                               FilePath        := MyLogFolder + uriList[ 2 ] + '\' + uri.Document;
                                if FileExists( FilePath ) then
                                        // \93Ç\82Ý\8d\9e\82Ý
                                        FDat.LoadFromFile( FilePath );
@@ -934,8 +914,21 @@ begin
                        end;
                end;
 
-               // \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é
-               inherited EnumThread( inCallBack, FDat.Text );
+               lineRec := TStringList.Create;
+               try
+                       bound := FDat.Count - 1;
+                       for i := 0 to bound do begin
+                               lineRec.Text := StringReplace( FDat[ i ], '<>', #10, [ rfReplaceAll ] );
+                               if not inCallBack(
+                                       Instance,
+                                       PChar( ToThreadURL( lineRec[ 0 ] ) ),
+                                       PChar( lineRec[ 1 ] ),
+                                       StrToInt( lineRec[ 2 ] ) ) then
+                                       Break;
+                       end;
+               finally
+                       lineRec.Free;
+               end;
        except
        end;