OSDN Git Service

フシアナトラップの処理のリファクタリング。
authorh677 <h677>
Fri, 18 Aug 2006 22:51:44 +0000 (22:51 +0000)
committerh677 <h677>
Fri, 18 Aug 2006 22:51:44 +0000 (22:51 +0000)
送信時のCookie作成のメソッド化

Editor.pas

index 3d007e8..c4d20c5 100644 (file)
@@ -212,7 +212,7 @@ type
                procedure Preview;
                function Check: Boolean;
                procedure SetNameList(sName, sMail: string);
-               procedure Send(ACOOKIE: string; SPID: string; PON: string; FirstWriting: Boolean);
+               procedure Send(const ACOOKIE: string; const SPID: string; const PON: string; FirstWriting: Boolean);
                function GetActiveControlHandle: THandle;
                procedure GetSendData(Source: TStringStream);
                procedure SaveSendFile;
@@ -257,6 +257,13 @@ type
              Modified: TDateTime; stream: TStream);
         //! GikoForm\82É\90V\92\85\83\81\83b\83Z\81[\83W\82ð\92Ç\89Á\82·\82é
         procedure AddFormMessageNew(icon: TGikoMessageIcon);
+        //! \83\8d\81[\83J\83\8bfusiana\83g\83\89\83b\83v
+        function isLocalFusianaTrap(const MSG: string): Boolean;
+        //! \83\8d\81[\83J\83\8bfusiana\83g\83\89\83b\83v
+        function isRemoteFusianaTrap(const MSG: string): Boolean;
+        //! Header\95\8e\9a\97ñ\8eæ\93¾
+        function getHeaderStr(const ACOOKIE: string; const SPID : string;
+            const PON : string; Board : TBoard) : string;
        protected
                procedure CreateParams(var Params: TCreateParams); override;
        public
@@ -731,7 +738,8 @@ begin
        DrawMenuBar(Handle);
 end;
 
-procedure TEditorForm.Send(ACOOKIE: string; SPID: string; PON: string; FirstWriting: Boolean);
+procedure TEditorForm.Send( const ACOOKIE: string; const SPID: string;
+ const PON: string; FirstWriting: Boolean);
 const
        MSG_FUSIANA : string =  '\83\8a\83\82\81[\83g\83z\83X\83g\82ð\95\\8e¦\82·\82é\8b@\94\\82ª\8eg\82í\82ê\82Ä\82¢\82Ü\82·'#13#10 +
                '\82à\82µ\82à\8aÔ\88á\82Á\82Ä\82±\82Ì\95û\96@\82Å\83z\83X\83g\82ª\95\\8e¦\82³\82ê\82½\82Æ\82µ\82Ä\82à\81A\8e©\8cÈ\90Ó\94C\82È\82Ì\82Å\8dí\8f\9c\88Ë\97\8a\82É\82Í\89\9e\82\82Ü\82¹\82ñ\81B' +
@@ -741,65 +749,27 @@ var
        Source: TStringStream;
        ResponseText: string;
        URL: string;
-       RefURL: string;
        State: TGikoDownloadState;
        ResultType: TGikoResultType;
        MsgResult: Integer;
-       Cookie: string;
        Board: TBoard;
        sysMenu : HMENU;
-       //fusianasan\83g\83\89\83b\83v by\92è\8aú\95Ö
-       Namae : String;
-       body : TStringList;
-       Remote : String;
-       ABoard : TBoard;
     {Protocol,Host, Path, Document, Port, Bookmark : String;}
 begin
        FAbort := False;
        State := gdsError;
-       Namae := THTMLCreate.RepHtml(NameComboBox.Text);
     Board := GetBoard;
 
 
-//    tmpRawheader := '';
        InitIdHTTP(Indy);
        if FThreadItem = nil then begin
                URL := FBoard.GetSendURL;
-               RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
+               Indy.Request.Referer := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
        end else begin
                URL := FThreadItem.GetSendURL;
-               RefURL := FThreadItem.URL;
-       end;
-//     Indy.Request.UserAgent := GikoSys.GetUserAgent;
-       Indy.Request.Referer := RefURL;
-//     Indy.Request.AcceptEncoding := '';
-
-       Cookie := '';
-       if ACOOKIE <> '' then
-          Cookie := ACOOKIE;
-       if SPID <> '' then
-               Cookie := Cookie + 'SPID=' + SPID + '; ';
-       if PON <> '' then
-               Cookie := Cookie + 'PON=' + PON + '; ';
-
-       //\83z\83X\83g\82ª2ch\82Å\81ABe\82ÉLogin\82µ\82Ä\82¢\82ê\82ÎBE\82Ì\83f\81[\83^\82ð\91\97\82é
-       //GikoSys.ParseURI( URL, Protocol,Host, Path, Document, Port, Bookmark );
-       //if GikoSys.Is2chHost(Host) and GikoSys.Setting.BeLogin then
-       if (Board.Is2ch) then begin
-               // \8cÅ\92è\82Ì\83N\83b\83L\81[\82ª\82 \82ê\82Î\90H\82í\82¹\82é
-               if Length(GikoSys.Setting.FixedCookie) > 0 then begin
-                       // \83z\83X\83g\82ª2ch\82Ì\8fê\8d\87\81C\8cÅ\92è\82Ì\83N\83b\83L\81[\82ð\90H\82í\82¹\82é
-                       Cookie := Cookie + GikoSys.Setting.FixedCookie + '; ';
-               end;
-               if (GikoSys.Setting.BeLogin) then begin
-                       Cookie := Cookie + 'MDMD=' + GikoSys.Setting.BeCode + '; '
-                                       + 'DMDM=' + GikoSys.Setting.BeUserID + '; ';
-               end;
-
+               Indy.Request.Referer := FThreadItem.URL;
        end;
 
-       Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
-
        sysMenu := GetSystemMenu( Handle, false );
        EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
 {
@@ -812,7 +782,7 @@ begin
        Indy.Request.AcceptLanguage := 'ja';
        Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
        Indy.Request.ContentType := 'application/x-www-form-urlencoded';
-       Indy.Request.CustomHeaders.Add(Cookie);
+       Indy.Request.CustomHeaders.Add(getHeaderStr(ACOOKIE, SPID, PON, Board));
        TextStream := TStringStream.Create('');
        Source := TStringStream.Create('');
        try
@@ -822,64 +792,15 @@ begin
 
                        if (FirstWriting) then begin
                                //\83t\83V\83A\83i\83g\83\89\83b\83v\8cx\8d\90(LocalMode) by \92è\8aú\95Ö
-                               if GikoSys.Setting.LocalTrapAtt then begin
-                                       if LFusianaGet(Namae) then begin
-                                               MsgResult := MsgBox( Handle, MSG_FUSIANA, '\8fî\95ñ',
-                                                       MB_YESNO or MB_ICONQUESTION);
-                                               if MsgResult = IDNO  then begin
-                                                       CancelSend( Board, SysMenu );
-                                                       Exit;
-                                               end;
-                                       end;
-                                       if ((Namae = '\8eR\8dè\8fÂ') or (Namae = 'fusianasan')) then begin
-                                               MsgResult := MsgBox(Handle, MSG_FUSIANA, '\8fî\95ñ',
-                                               MB_YESNO or MB_ICONQUESTION);
-                                               if MsgResult = IDNO  then begin
-                                                       CancelSend( Board, SysMenu );
-                                                       Exit;
-                                               end;
-                                       end;
-                               end;
-
-                               if GikoSys.Setting.RemoteTrapAtt then begin
-                    ABoard := GetBoard;
-
-                                       if ABoard = nil then Exit;
-
-                                       if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
-                                               body := TStringList.Create;
-                                               try
-                                                       body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
-                                                       Remote := GetFusianaName(body, ABoard);
-                                               finally
-                                                       body.Free;
-                                               end;
-                                       end else begin
-                                       //Setting.txt\82ª\82È\82©\82Á\82½\82ç\8eæ\93¾
-                                       //\8eI\82É\95\89\89×\82ª\82©\82©\82è\82»\82¤...
-                                       //if not FileExists(ABoard.GetSETTINGTXTFileName) then begin
-                                               GetSETTINGTXTAction.Execute;
-                                               body := TStringList.Create;
-                                               try
-                                                       if FileExists(ABoard.GetSETTINGTXTFileName) then begin
-                                                               body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
-                                                               Remote := GetFusianaName(body, ABoard);
-                                                       end;
-                                               finally
-                                                       body.Free;
-                                               end;
-                                       end;
-
-                                       if Remote = 'fusianasan' then begin
-                                               MsgResult := MsgBox(
-                                                       Handle, MSG_FUSIANA, '\8fî\95ñ',
-                                                       MB_YESNO or MB_ICONQUESTION);
-                                               if MsgResult = IDNO  then begin
-                                                       CancelSend( Board, SysMenu );
-                                                       Exit;
-                                               end;
-                                       end;
-                               end;
+                if (isLocalFusianaTrap(MSG_FUSIANA)) then begin
+                    CancelSend( Board, SysMenu );
+                    Exit;
+                end;
+                //\83t\83V\83A\83i\83g\83\89\83b\83v\8cx\8d\90(Remote)
+                if (isRemoteFusianaTrap(MSG_FUSIANA)) then begin
+                    CancelSend( Board, SysMenu );
+                    Exit;
+                end;
                        end;
 
                        GetSendData(Source);
@@ -2287,5 +2208,114 @@ begin
     end;
 
 end;
+{
+\brief  \83\8d\81[\83J\83\8bfusiana\83g\83\89\83b\83v
+\param  MSG \83\81\83b\83Z\81[\83W\83_\83C\83A\83\8d\83O\82Ì\83\81\83b\83Z\81[\83W
+\return true:\91\97\90M\92\86\8e~ false:\91\97\90M
+}
+function TEditorForm.isLocalFusianaTrap(const MSG: string): Boolean;
+var
+    MsgResult : Integer;
+    Namae : string;
+begin
+    Result := False;
+    if GikoSys.Setting.LocalTrapAtt then begin
+        Namae := THTMLCreate.RepHtml(NameComboBox.Text);
+        if (LFusianaGet(Namae))
+            or ((Namae = '\8eR\8dè\8fÂ') or (Namae = 'fusianasan')) then begin
+            MsgResult := MsgBox( Handle, MSG, '\8fî\95ñ',
+                MB_YESNO or MB_ICONQUESTION);
+            if MsgResult = IDNO  then begin
+                Result := True;
+            end;
+        end;
+    end;
+end;
+{
+\brief  \83\8d\81[\83J\83\8bfusiana\83g\83\89\83b\83v
+\param  MSG \83\81\83b\83Z\81[\83W\83_\83C\83A\83\8d\83O\82Ì\83\81\83b\83Z\81[\83W
+\return true:\91\97\90M\92\86\8e~ false:\91\97\90M
+}
+function TEditorForm.isRemoteFusianaTrap(const MSG: string): Boolean;
+var
+    Namae : string;
+    Board : TBoard;
+    Remote: string;
+    body : TStringList;
+    MsgResult : Integer;
+begin
+    Result := False;
+    Namae := THTMLCreate.RepHtml(NameComboBox.Text);
+    if (GikoSys.Setting.RemoteTrapAtt) and (Length(Namae) = 0) then begin
+        Board := GetBoard;
+
+        if Board = nil then Exit;
+
+        if not FileExists(Board.GetSETTINGTXTFileName)  then begin
+            //Setting.txt\82ª\82È\82©\82Á\82½\82ç\8eæ\93¾
+            //\8eI\82É\95\89\89×\82ª\82©\82©\82è\82»\82¤...
+            try
+                GetSETTINGTXTAction.Execute;
+            except
+            end;
+        end;
+
+        Remote := '';
+        if FileExists(Board.GetSETTINGTXTFileName)  then begin
+            body := TStringList.Create;
+            try
+                body.LoadFromFile(Board.GetSETTINGTXTFileName);
+                Remote := GetFusianaName(body, Board);
+            finally
+                body.Free;
+            end;
+        end;
+
+        if (Remote = 'fusianasan') then begin
+            MsgResult := MsgBox(
+                Handle, MSG, '\8fî\95ñ',
+                MB_YESNO or MB_ICONQUESTION);
+            if MsgResult = IDNO  then begin
+                Result := True;
+            end;
+        end;
+    end;
+end;
+{
+\brief  Header\95\8e\9a\97ñ\8eæ\93¾
+\param  ACOOKIE Cookie
+\param  SPID    SPID
+\param  PON    PON
+\param  Board   \94Â
+\return Header\95\8e\9a\97ñ
+}
+function TEditorForm.getHeaderStr(const ACOOKIE: string; const SPID : string;
+    const PON : string; Board : TBoard) : string;
+begin
+       Result := ACOOKIE;
+       if SPID <> '' then
+               Result := Result + 'SPID=' + SPID + '; ';
+       if PON <> '' then
+               Result := Result + 'PON=' + PON + '; ';
+
+       //\83z\83X\83g\82ª2ch\82Å\81ABe\82ÉLogin\82µ\82Ä\82¢\82ê\82ÎBE\82Ì\83f\81[\83^\82ð\91\97\82é
+       //GikoSys.ParseURI( URL, Protocol,Host, Path, Document, Port, Bookmark );
+       //if GikoSys.Is2chHost(Host) and GikoSys.Setting.BeLogin then
+       if (Board.Is2ch) then begin
+               // \8cÅ\92è\82Ì\83N\83b\83L\81[\82ª\82 \82ê\82Î\90H\82í\82¹\82é
+               if Length(GikoSys.Setting.FixedCookie) > 0 then begin
+                       // \83z\83X\83g\82ª2ch\82Ì\8fê\8d\87\81C\8cÅ\92è\82Ì\83N\83b\83L\81[\82ð\90H\82í\82¹\82é
+                       Result := Result + GikoSys.Setting.FixedCookie + '; ';
+               end;
+               if (GikoSys.Setting.BeLogin) then begin
+                       Result := Result + 'MDMD=' + GikoSys.Setting.BeCode + '; '
+                                       + 'DMDM=' + GikoSys.Setting.BeUserID + '; ';
+               end;
+
+       end;
+
+       Result := 'Cookie: ' + Result + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
+
+end;
 
 end.