⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxnntpservercore.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 2 页
字号:
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PNNTPComplexEvent(fEventArray[Loop]).Command=Command then Begin
         PNNTPComplexEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PComplexEvent);
   PComplexEvent.Tag:=3;      // Denotes Event in fEventArray is a TComplexEvent!
   PComplexEvent.Command:=Command;
   PComplexEvent.EventProcedure:=EventProc;
   fEventArray.Add(PComplexEvent);
End;

Procedure TDXNNTPServerCore.AddDoByIDEvent(Command:String;EventProc:NNTPTDoByIDEvent);
Var
   PDoByIDEvent:PNNTPDoByIDEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PNNTPDoByIDEvent(fEventArray[Loop]).Command=Command then Begin
         PNNTPDoByIDEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PDoByIDEvent);
   PDoByIDEvent.Tag:=4;      // Denotes Event in fEventArray is a TDoByIDEvent!
   PDoByIDEvent.Command:=Command;
   PDoByIDEvent.EventProcedure:=EventProc;
   fEventArray.Add(PDoByIDEvent);
End;

Procedure TDXNNTPServerCore.AddDoByNOEvent(Command:String;EventProc:NNTPTDoByNOEvent);
Var
   PDoByNOEvent:PNNTPDoByNOEvent;
   Loop:Integer;

Begin
   Command:=Uppercase(Command);
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PNNTPDoByNOEvent(fEventArray[Loop]).Command=Command then Begin
         PNNTPDoByNOEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PDoByNOEvent);
   PDoByNOEvent.Tag:=5;      // Denotes Event in fEventArray is a TDoByNOEvent!
   PDoByNOEvent.Command:=Command;
   PDoByNOEvent.EventProcedure:=EventProc;
   fEventArray.Add(PDoByNOEvent);
End;

Procedure TDXNNTPServerCore.SetOnCommandAuthInfo(value:NNTPTComplexEvent);
Begin
   fOnCommandAuthINFO:=Value;
   AddComplexEvent('AUTHINFO',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandArticleID(value:NNTPTDoByIDEvent);
Begin
   fOnCommandARTICLEID:=Value;
   AddDoByIDEvent('ARTICLEID',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandArticleNO(value:NNTPTDoByNOEvent);
Begin
   fOnCommandARTICLENO:=Value;
   AddDoByNoEvent('ARTICLENO',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandBodyID(value:NNTPTDoByIDEvent);
Begin
   fOnCommandBODYID:=Value;
   AddDoByIDEvent('BODYID',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandBodyNO(value:NNTPTDoByNOEvent);
Begin
   fOnCommandBODYNO:=Value;
   AddDoByNoEvent('BODYNO',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandHeadID(value:NNTPTDoByIDEvent);
Begin
   fOnCommandHEADID:=Value;
   AddDoByIDEvent('HEADID',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandHeadNO(value:NNTPTDoByNOEvent);
Begin
   fOnCommandHEADNO:=Value;
   AddDoByNoEvent('HEADNO',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandStatID(value:NNTPTDoByIDEvent);
Begin
   fOnCommandSTATID:=Value;
   AddDoByIDEvent('STATID',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandStatNO(value:NNTPTDoByNOEvent);
Begin
   fOnCommandSTATNO:=Value;
   AddDoByNoEvent('STATNO',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandGroup(value:NNTPTBasicEvent);
Begin
   fOnCommandGROUP:=Value;
   AddBasicEvent('GROUP',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandList(value:NNTPTBasicEvent);
Begin
   fOnCommandLIST:=Value;
   AddBasicEvent('LIST',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandHelp(value:NNTPTSimpleEvent);
Begin
   fOnCommandHELP:=Value;
   AddSimpleEvent('HELP',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandIHave(value:NNTPTDoByIDEvent);
Begin
   fOnCommandIHAVE:=Value;
   AddDoByIDEvent('IHAVE',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandLast(value:NNTPTSimpleEvent);
Begin
   fOnCommandLAST:=Value;
   AddSimpleEvent('LAST',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandMode(value:NNTPTBasicEvent);
Begin
   fOnCommandMODE:=Value;
   AddBasicEvent('MODE',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandNewGroups(value:NNTPTBasicEvent);
Begin
   fOnCommandNEWGROUPS:=Value;
   AddBasicEvent('NEWGROUPS',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandNewNews(value:NNTPTBasicEvent);
Begin
   fOnCommandNEWNEWS:=Value;
   AddBasicEvent('NEWNEWS',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandNext(value:NNTPTSimpleEvent);
Begin
   fOnCommandNEXT:=Value;
   AddSimpleEvent('NEXT',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandPost(value:NNTPTSimpleEvent);
Begin
   fOnCommandPOST:=Value;
   AddSimpleEvent('POST',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandQuit(value:NNTPTSimpleEvent);
Begin
   fOnCommandQUIT:=Value;
   AddSimpleEvent('QUIT',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandSlave(value:NNTPTSimpleEvent);
Begin
   fOnCommandSLAVE:=Value;
   AddSimpleEvent('SLAVE',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXOver(value:NNTPTBasicEvent);
Begin
   fOnCommandXOVER:=Value;
   AddBasicEvent('XOVER',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXHDR(value:NNTPTBasicEvent);
Begin
   fOnCommandXHDR:=Value;
   AddBasicEvent('XHDR',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandDate(value:NNTPTSimpleEvent);
Begin
   fOnCommandDATE:=Value;
   AddSimpleEvent('DATE',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandListGroup(value:NNTPTBasicEvent);
Begin
   fOnCommandLISTGROUP:=Value;
   AddBasicEvent('LISTGROUP',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandCheck(value:NNTPTDoByIDEvent);
Begin
   fOnCommandCHECK:=Value;
   AddDoByIDEvent('CHECK',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandTakeThis(value:NNTPTDoByIDEvent);
Begin
   fOnCommandTAKETHIS:=Value;
   AddDoByIDEvent('TAKETHIS',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXReplic(value:NNTPTBasicEvent);
Begin
   fOnCommandXREPLIC:=Value;
   AddBasicEvent('XREPLIC',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXGTitle(value:NNTPTBasicEvent);
Begin
   fOnCommandXGTITLE:=Value;
   AddBasicEvent('XGTITLE',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXIndex(value:NNTPTBasicEvent);
Begin
   fOnCommandXINDEX:=Value;
   AddBasicEvent('XINDEX',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXPAT(value:NNTPTComplexEvent);
Begin
   fOnCommandXPAT:=Value;
   AddComplexEvent('XPAT',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXPATH(value:NNTPTDoByIDEvent);
Begin
   fOnCommandXPATH:=Value;
   AddDoByIDEvent('XPATH',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandXThread(value:NNTPTBasicEvent);
Begin
   fOnCommandXTHREAD:=Value;
   AddBasicEvent('XTHREAD',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandCancel(value:NNTPTDoByIDEvent);
Begin
   fOnCommandCANCEL:=Value;
   AddDoByIDEvent('CANCEL',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandSendMe(value:NNTPTDoByIDEvent);
Begin
   fOnCommandSENDME:=Value;
   AddDoByIDEvent('SENDME',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandRMGroup(value:NNTPTBasicEvent);
Begin
   fOnCommandRMGROUP:=Value;
   AddBasicEvent('RMGROUP',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandSendSys(value:NNTPTSimpleEvent);
Begin
   fOnCommandSENDSYS:=Value;
   AddSimpleEvent('SENDSYS',Value);
End;

Procedure TDXNNTPServerCore.SetOnCommandVersion(value:NNTPTSimpleEvent);
Begin
   fOnCommandVERSION:=Value;
   AddSimpleEvent('VERSION',Value);
End;

procedure TDXNNTPServerCore.SayHello(ClientThread:TDXClientThread;Header:String);
Begin
   If Header<>'' then
      ClientThread.Socket.Writeln('200 '+Header)
   Else
      ClientThread.Socket.Writeln('200 NNTP Server (ready).');
End;

procedure TDXNNTPServerCore.SayGoodbye(ClientThread:TDXClientThread;Footer:String);
Begin
   If Footer<>'' then
      ClientThread.Socket.Writeln('205 '+Footer)
   Else
      ClientThread.Socket.Writeln('205 Goodbye.');
End;

procedure TDXNNTPServerCore.ProcessSession(ClientThread:TDXClientThread);
var
   s, sCmd: string;
   Loop:Integer;
   WasHandled:Boolean;
   OutData:Pointer;

begin
   fbForceAbort:=False;
   with ClientThread.Socket do begin
      while Connected and
         ((LastCommandStatus<9999) or
         (LastCommandStatus=10060)) do begin
         if fbForceAbort then Exit;
         s:=ReadLn(Timeout);
         If LastReadTimeout or Not Connected then Exit;
         if assigned({$IFDEF TLS_EDITION}OnReadFilter{$ELSE}OnFilter{$ENDIF}) then begin
            Loop:=FilterRead(@S[1],OutData,Length(S),ClientThread);
            SetLength(S,Loop);
            If Assigned(OutData) then Begin
               FastMove(TDXBSArray(OutData^),S[1],Loop);
{$IFDEF TLS_EDITION}OnReadFilter{$ELSE}OnFilter{$ENDIF}(ddFreePointer,nil,OutData,Loop,Loop,WasHandled,ClientThread) ;
            End;
         End;
         sCmd:=UpperCase(Fetch(s,#32,False));
         Loop:=0;
         WasHandled:=False;
         If (sCMD='HEAD') or (sCMD='BODY') or (sCMD='STAT') or (sCMD='ARTICLE') then Begin
            if (isNumericString(s)) or (S='') then sCMD:=sCMD+'NO'
            Else sCMD:=sCMD+'ID';
         End;
         While (Loop<fEventArray.Count) and (Not WasHandled) do Begin
            If PNNTPBasicEvent(fEventArray[Loop]).Command=sCMD then Begin
               Case PNNTPBasicEvent(fEventArray[Loop]).Tag of
                  1:if Assigned(PNNTPBasicEvent(fEventArray[Loop]).EventProcedure) then
                       NNTPTBasicEvent(PNNTPBasicEvent(fEventArray[Loop]).EventProcedure)(ClientThread,S);
                  2:if Assigned(PNNTPSimpleEvent(fEventArray[Loop]).EventProcedure) then
                       NNTPTSimpleEvent(PNNTPSimpleEvent(fEventArray[Loop]).EventProcedure)(ClientThread);
                  3:if Assigned(PNNTPComplexEvent(fEventArray[Loop]).EventProcedure) then
                       NNTPTComplexEvent(PNNTPComplexEvent(fEventArray[Loop]).EventProcedure)(ClientThread,Uppercase(Fetch(S,#32,False)),S);
                  4:if Assigned(PNNTPDoByIDEvent(fEventArray[Loop]).EventProcedure) then
                       NNTPTDoByIDEvent(PNNTPDoByIDEvent(fEventArray[Loop]).EventProcedure)(ClientThread,NoAngleBrackets(s));
                  5:if Assigned(PNNTPDoByNoEvent(fEventArray[Loop]).EventProcedure) then
                       NNTPTDoByNoEvent(PNNTPDoByNoEvent(fEventArray[Loop]).EventProcedure)(ClientThread,StringToInteger(S));
               End;
               WasHandled:=True;
            End
            Else Inc(Loop);
         End; {while}
         if sCMD='QUIT' then Exit; {terminate!}
         If Not WasHandled then Begin
            if assigned(OnCommandOther) then
               OnCommandOther(ClientThread,sCmd,s,WasHandled);
         end;
         if not WasHandled then
            WriteResultCode(500,'command not recognized (' + sCMD + ')');
      end; {while}
   end; {with}
end; {doExecute}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -