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

📄 idnntpserver.pas

📁 Indy控件的使用源代码
💻 PAS
📖 第 1 页 / 共 4 页
字号:
   used by a news reading program to skip duplicate displays of articles
   that have been posted more than once, or to more than one newsgroup.

3.1.3.  Responses

   220 n <a> article retrieved - head and body follow
           (n = article number, <a> = message-id)
   221 n <a> article retrieved - head follows
   222 n <a> article retrieved - body follows
   223 n <a> article retrieved - request text separately
   412 no newsgroup has been selected
   420 no current article has been selected
   423 no such article number in this group
   430 no such article found
*)

procedure TIdNNTPServer.CommandArticle(ASender: TIdCommand);
var
  LMsgID: string;
  LMsgNo: Integer;
  LThread: TIdNNTPThread;
begin
  if not Assigned (OnArticleByNo) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if not AuthRequired (ASender) then
  begin
    if LookupMessage (ASender, LMsgNo, LMsgID) then
    begin
      LThread := TidNNTPThread (ASender.Thread);
      ASender.Reply.SetReply(220, IntToStr(LMsgNo) + ' ' + LMsgID + ' article retrieved - head and body follows');
      ASender.SendReply;
      OnArticleByNo(LThread, LMsgNo)
    end;
  end
end;


procedure TIdNNTPServer.CommandBody(ASender: TIdCommand);
var
  LMsgID: string;
  LMsgNo: Integer;
  LThread: TIdNNTPThread;
begin
  if not Assigned (OnBodyByNo) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if not AuthRequired (ASender) then
  begin
    if LookupMessage (ASender, LMsgNo, LMsgID) then
    begin
      LThread := TidNNTPThread (ASender.Thread);
      ASender.Reply.SetReply(222, IntToStr(LMsgNo) + ' ' + LMsgID + ' article retrieved - body follows');
      ASender.SendReply;
      OnBodyByNo(LThread, LMsgNo)
    end;
  end
end;

procedure TIdNNTPServer.CommandDate(ASender: TIdCommand);
begin
  ASender.Reply.SetReply(111,FormatDateTime('yyyymmddhhnnss',Now + IdGlobal.TimeZoneBias));
end;

(*
3.2.  The GROUP command

3.2.1.  GROUP

   GROUP ggg

   The required parameter ggg is the name of the newsgroup to be
   selected (e.g. "net.news").  A list of valid newsgroups may be
   obtained from the LIST command.

   The successful selection response will return the article numbers of
   the first and last articles in the group, and an estimate of the
   number of articles on file in the group.  It is not necessary that
   the estimate be correct, although that is helpful; it must only be
   equal to or larger than the actual number of articles on file.  (Some
   implementations will actually count the number of articles on file.
   Others will just subtract first article number from last to get an
   estimate.)

   When a valid group is selected by means of this command, the
   internally maintained "current article pointer" is set to the first
   article in the group.  If an invalid group is specified, the
   previously selected group and article remain selected.  If an empty
   newsgroup is selected, the "current article pointer" is in an
   indeterminate state and should not be used.

   Note that the name of the newsgroup is not case-dependent.  It must
   otherwise match a newsgroup obtained from the LIST command or an
   error will result.

3.2.2.  Responses

   211 n f l s group selected
           (n = estimated number of articles in group,
           f = first article number in the group,
           l = last article number in the group,
           s = name of the group.)
   411 no such news group
*)
procedure TIdNNTPServer.CommandGroup(ASender: TIdCommand);
var
  LGroup: string;
  LGroupExists: Boolean;
  LMsgCount: Integer;
  LMsgFirst: Integer;
  LMsgLast: Integer;
  LThread: TIdNNTPThread;
begin
  if not AuthRequired(ASender) then begin
    LGroup := Trim(ASender.UnparsedParams);
    LThread := TIdNNTPThread(ASender.Thread);
    DoSelectGroup(TIdNNTPThread(ASender.Thread), LGroup, LMsgCount, LMsgFirst, LMsgLast
     , LGroupExists);
    if LGroupExists then begin
      TIdNNTPThread(ASender.Thread).FCurrentGroup := LGroup;
      ASender.Reply.SetReply(211, Format('%d %d %d %s', [LMsgCount, LMsgFirst, LMsgLast, LGroup]));
      LThread.FCurrentArticle := LMsgFirst;
    end;
  end;
end;

procedure TIdNNTPServer.CommandHead(ASender: TIdCommand);
var
  LMsgID: string;
  LMsgNo: Integer;
  LThread: TIdNNTPThread;
begin
  if not Assigned (OnHeadByNo) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if not AuthRequired (ASender) then
  begin
    if LookupMessage (ASender, LMsgNo, LMsgID) then
    begin
      LThread := TidNNTPThread (ASender.Thread);
      ASender.Reply.SetReply (221, IntToStr(LMsgNo) + ' ' + LMsgID + ' article retrieved - head follows');
      ASender.SendReply;
      OnHeadByNo(LThread, LMsgNo)
    end;
  end;
end;

procedure TIdNNTPServer.CommandIHave(ASender: TIdCommand);
var LThread : TIdNNTPThread;
    LMsgID : String;
    LAccept:Boolean;
    LErrorText : String;
begin
  if not Assigned (OnIHaveCheck) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if AuthRequired(ASender) then begin
    Exit;
  end;
  LThread := TIdNNTPThread(ASender.Thread);
  LMsgID := Trim(ASender.UnparsedParams);
  if (Copy(LMsgID, 1, 1) = '<') then begin
    FOnIHaveCheck(LThread,LMsgID,LAccept);
    if LAccept then
    begin
      ASender.Reply.SetReply(335,'News to me!  <CRLF.CRLF> to end.');
      ASender.SendReply;
      LErrorText := '';
      OnPost(TIdNNTPThread(ASender.Thread), LAccept, LErrorText);
      ASender.Reply.SetReply(iif(LAccept, 235, 436), LErrorText);
    end
    else
    begin
      ASender.Reply.NumericCode := 435;
    end;
  end;
end;

procedure TIdNNTPServer.CommandLast(ASender: TIdCommand);
var
  LMsgNo: Integer;
  LThread: TIdNNTPThread;
  LMsgID : String;
begin
  if not Assigned (OnPrevArticle) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if Assigned(OnPrevArticle) then
  begin
    if not AuthRequired(ASender) then
    begin
      LThread := TIdNNTPThread(ASender.Thread);
      if Length(LThread.CurrentGroup) = 0 then
        ASender.Reply.NumericCode := 412
      else
      begin
        LMsgID := RawNavigate(LThread,OnPrevArticle);
        if LMsgID<>'' then
        begin
          LMsgNo := LThread.CurrentArticle;
          ASender.Reply.SetReply(223, IntToStr(LMsgNo) + ' ' + LMsgID + ' article retrieved - request text separately')
        end
        else
          ASender.Reply.NumericCode := 422;
      end;
    end;
  end;
end;

(*
3.6.  The LIST command

3.6.1.  LIST

   LIST

   Returns a list of valid newsgroups and associated information.  Each
   newsgroup is sent as a line of text in the following format:

      group last first p

   where <group> is the name of the newsgroup, <last> is the number of
   the last known article currently in that newsgroup, <first> is the
   number of the first article currently in the newsgroup, and <p> is
   either 'y' or 'n' indicating whether posting to this newsgroup is
   allowed ('y') or prohibited ('n').

   The <first> and <last> fields will always be numeric.  They may have
   leading zeros.  If the <last> field evaluates to less than the
   <first> field, there are no articles currently on file in the
   newsgroup.

   Note that posting may still be prohibited to a client even though the
   LIST command indicates that posting is permitted to a particular
   newsgroup. See the POST command for an explanation of client
   prohibitions.  The posting flag exists for each newsgroup because
   some newsgroups are moderated or are digests, and therefore cannot be
   posted to; that is, articles posted to them must be mailed to a
   moderator who will post them for the submitter.  This is independent
   of the posting permission granted to a client by the NNTP server.

   Please note that an empty list (i.e., the text body returned by this
   command consists only of the terminating period) is a possible valid
   response, and indicates that there are currently no valid newsgroups.

3.6.2.  Responses

   215 list of newsgroups follows
*)
procedure TIdNNTPServer.CommandList(ASender: TIdCommand);
begin
  if not Assigned(OnListGroups) then begin
    ASender.Reply.NumericCode := 500;
  end else if not AuthRequired(ASender) then begin
    ASender.SendReply;
    DoListGroups(TIdNNTPThread(ASender.Thread));
    ASender.Thread.Connection.WriteLn('.');
  end;
end;

procedure TIdNNTPServer.CommandListGroup(ASender: TIdCommand);
var LThrd : TIdNNTPThread;
    LGroup : String;
    LFirstIdx : Integer;
    LCanJoin : Boolean;
begin
  if not Assigned (OnCheckListGroup) or not Assigned (FOnListGroup) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if AuthRequired(ASender) then begin
    Exit;
  end;
  LThrd := TIdNNTPThread ( ASender.Thread );
  LGroup := Trim(ASender.UnparsedParams);
  if Length(LGroup)>0 then
  begin
    LGroup := LThrd.CurrentGroup;
  end;
  FOnCheckListGroup(LThrd,LGroup,LCanJoin,LFirstIdx);
  if LCanJoin then
  begin
    LThrd.FCurrentGroup := LGroup;
    LThrd.FCurrentArticle := LFirstIdx;
    ASender.SendReply;
    FOnListGroup(LThrd);
    ASender.Thread.Connection.WriteLn('.');
  end
  else
  begin
    ASender.Reply.SetReply(412,'Not currently in newsgroup');
  end;
end;

procedure TIdNNTPServer.CommandModeReader(ASender: TIdCommand);
(*
2.3 MODE READER

   MODE READER is used by the client to indicate to the server that it
   is a news reading client.  Some implementations make use of this
   information to reconfigure themselves for better performance in
   responding to news reader commands.  This command can be contrasted
   with the SLAVE command in RFC 977, which was not widely implemented.
   MODE READER was first available in INN.

2.3.1 Responses

      200 Hello, you can post
      201 Hello, you can't post
*)
begin
  TIdNNTPThread(ASender.Thread).FModeReader := True;
  ASender.Reply.NumericCode := 200;
end;

(*
3.7.  The NEWGROUPS command

3.7.1.  NEWGROUPS

   NEWGROUPS date time [GMT] [<distributions>]

   A list of newsgroups created since <date and time> will be listed in
   the same format as the LIST command.

   The date is sent as 6 digits in the format YYMMDD, where YY is the
   last two digits of the year, MM is the two digits of the month (with
   leading zero, if appropriate), and DD is the day of the month (with
   leading zero, if appropriate).  The closest century is assumed as
   part of the year (i.e., 86 specifies 1986, 30 specifies 2030, 99 is
   1999, 00 is 2000).

   Time must also be specified.  It must be as 6 digits HHMMSS with HH
   being hours on the 24-hour clock, MM minutes 00-59, and SS seconds
   00-59.  The time is assumed to be in the server's timezone unless the
   token "GMT" appears, in which case both time and date are evaluated
   at the 0 meridian.

   The optional parameter "distributions" is a list of distribution
   groups, enclosed in angle brackets.  If specified, the distribution
   portion of a new newsgroup (e.g, 'net' in 'net.wombat') will be
   examined for a match with the distribution categories listed, and
   only those new newsgroups which match will be listed.  If more than
   one distribution group is to be listed, they must be separated by
   commas within the angle brackets.

   Please note that an empty list (i.e., the text body returned by this
   command consists only of the terminating period) is a possible valid
   response, and indicates that there are currently no new newsgroups.

3.7.2.  Responses

   231 list of new newsgroups follows
*)
procedure TIdNNTPServer.CommandNewGroups(ASender: TIdCommand);
var LDate : TDateTime;
    LDist : String;
begin
  if not Assigned (OnListNewGroups) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

  if AuthRequired(ASender) then begin
    Exit;
  end;
  if (ASender.Params.Count > 1) then
  begin
    LDist := '';
    LDate := NNTPDateTimeToDateTime( ASender.Params[0] );
    LDate := LDate + NNTPTimeToTime( ASender.Params[1] );
    if ASender.Params.Count > 2 then
    begin
      if (UpperCase(ASender.Params[2]) = 'GMT') then {Do not translate}
      begin
        LDate := LDate + OffSetFromUTC;
        if (ASender.Params.Count > 3) then
        begin
          LDist := ASender.Params[3];
        end;
      end
      else
      begin
        LDist := ASender.Params[2];
      end;
    end;
    ASender.SendReply;
    FOnListNewGroups(TIdNNTPThread(ASender.Thread), LDate, LDist);
    ASender.Thread.Connection.WriteLn('.');
  end;
end;

procedure TIdNNTPServer.CommandNewNews(ASender: TIdCommand);
var LDate : TDateTime;
    LDist : String;
begin
  if not Assigned (OnNewNews) then
  begin
    ASender.Reply.NumericCode := 500;
    exit
  end;

⌨️ 快捷键说明

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