12 KnownCommands
: array[1..26] of string =
31 'DATE', {returns "111 YYYYMMDDHHNNSS"}
32 'LISTGROUP', {returns all the article numbers for specified group}
33 'MODE', {for the MODE command}
34 'TAKETHIS', {streaming nntp}
35 'CHECK', {streaming nntp need this to go with takethis}
36 'XTHREAD', {Useful mainly for the TRN newsreader }
37 'XGTITLE', {legacy support}
38 'XPAT' {Header Pattern matching}
42 TGetEvent
= procedure(AThread
: TIdPeerThread
) of object;
43 TOtherEvent
= procedure(AThread
: TIdPeerThread
; ACommand
: string; AParm
:
44 string; var AHandled
: Boolean) of object;
45 TDoByIDEvent
= procedure(AThread
: TIdPeerThread
; AActualID
: string) of object;
46 TDoByNoEvent
= procedure(AThread
: TIdPeerThread
; AActualNumber
: Cardinal) of
48 TGroupEvent
= procedure(AThread
: TIdPeerThread
; AGroup
: string) of object;
49 TNewsEvent
= procedure(AThread
: TIdPeerThread
; AParm
: string) of object;
50 TDataEvent
= procedure(AThread
: TIdPeerThread
; AData
: TObject
) of object;
52 TIdNNTPServer
= object(TIdTCPServer
)
54 fOnCommandAuthInfo
: TOtherEvent
;
55 fOnCommandArticleID
: TDoByIDEvent
;
56 fOnCommandArticleNO
: TDoByNoEvent
;
57 fOnCommandBodyID
: TDoByIDEvent
;
58 fOnCommandBodyNO
: TDoByNoEvent
;
59 fOnCommandHeadID
: TDoByIDEvent
;
60 fOnCommandHeadNO
: TDoByNoEvent
;
61 fOnCommandStatID
: TDoByIDEvent
;
62 fOnCommandStatNO
: TDoByNoEvent
;
63 fOnCommandGroup
: TGroupEvent
;
64 fOnCommandList
: TNewsEvent
;
65 fOnCommandHelp
: TGetEvent
;
66 fOnCommandIHave
: TDoByIDEvent
;
67 fOnCommandLast
: TGetEvent
;
68 fOnCommandMode
: TNewsEvent
;
69 fOnCommandNewGroups
: TNewsEvent
;
70 fOnCommandNewNews
: TNewsEvent
;
71 fOnCommandNext
: TGetEvent
;
72 fOnCommandPost
: TGetEvent
;
73 fOnCommandQuit
: TGetEvent
;
74 fOnCommandSlave
: TGetEvent
;
76 fOnCommandXOver
: TNewsEvent
;
77 fOnCommandXHDR
: TNewsEvent
;
78 fOnCommandDate
: TGetEvent
;
79 fOnCommandListgroup
: TNewsEvent
;
80 fOnCommandTakeThis
: TDoByIDEvent
;
81 fOnCommandCheck
: TDoByIDEvent
;
82 fOnCommandXThread
: TNewsEvent
;
83 fOnCommandXGTitle
: TNewsEvent
;
84 fOnCommandXPat
: TNewsEvent
;
86 fOnCommandOther
: TOtherEvent
;
88 function DoExecute(AThread
: TIdPeerThread
): boolean; virtual;// override;
90 // constructor Create(AOwner: TComponent); override;
92 property OnCommandAuthInfo
: TOtherEvent read fOnCommandAuthInfo write
94 property OnCommandArticleID
: TDoByIDEvent read fOnCommandArticleID write
96 property OnCommandArticleNo
: TDoByNoEvent read fOnCommandArticleNo write
98 property OnCommandBodyID
: TDoByIDEvent read fOnCommandBodyID write
100 property OnCommandBodyNo
: TDoByNoEvent read fOnCommandBodyNo write
102 property OnCommandCheck
: TDoByIDEvent read fOnCommandCheck write
104 property OnCommandHeadID
: TDoByIDEvent read fOnCommandHeadID write
106 property OnCommandHeadNo
: TDoByNoEvent read fOnCommandHeadNo write
108 property OnCommandStatID
: TDoByIDEvent read fOnCommandStatID write
110 property OnCommandStatNo
: TDoByNoEvent read fOnCommandStatNo write
112 property OnCommandGroup
: TGroupEvent read fOnCommandGroup write
114 property OnCommandList
: TNewsEvent read fOnCommandList write fOnCommandList
;
115 property OnCommandHelp
: TGetEvent read fOnCommandHelp write fOnCommandHelp
;
116 property OnCommandIHave
: TDoByIDEvent read fOnCommandIHave write
118 property OnCommandLast
: TGetEvent read fOnCommandLast write fOnCommandLast
;
119 property OnCommandMode
: TNewsEvent read fOnCommandMode write fOnCommandMode
;
120 property OnCommandNewGroups
: TNewsEvent read fOnCommandNewGroups write
122 property OnCommandNewNews
: TNewsEvent read fOnCommandNewNews write
124 property OnCommandNext
: TGetEvent read fOnCommandNext write fOnCommandNext
;
125 property OnCommandPost
: TGetEvent read fOnCommandPost write fOnCommandPost
;
126 property OnCommandQuit
: TGetEvent read fOnCommandQuit write fOnCommandQuit
;
127 property OnCommandSlave
: TGetEvent read fOnCommandSlave write
129 property OnCommandTakeThis
: TDoByIDEvent read fOnCommandTakeThis write
131 property OnCommandXOver
: TNewsEvent read fOnCommandXOver write
133 property OnCommandXHDR
: TNewsEvent read fOnCommandXHDR write fOnCommandXHDR
;
134 property OnCommandDate
: TGetEvent read fOnCommandDate write fOnCommandDate
;
135 property OnCommandListgroup
: TNewsEvent read fOnCommandListGroup write
137 property OnCommandXThread
: TNewsEvent read fOnCommandXThread write
139 property OnCommandXGTitle
: TNewsEvent read fOnCommandXGTitle write
141 property OnCommandXPat
: TNewsEvent read fOnCommandXPat write fOnCommandXPat
;
142 property OnCommandOther
: TOtherEvent read fOnCommandOther write
144 property DefaultPort default IdPORT_NNTP
;
147 PIdNNTPServer
=^TIdNNTPServer
;
148 function NewIdNNTPServer(AOwner
: PControl
):PIdNNTPServer
;
157 { constructor TIdNNTPServer.Create(AOwner: TComponent);
159 function NewIdNNTPServer (AOwner
: PControl
):PIdNNTPServer
;
161 New( Result
, Create
);
164 // inherited Create(AOwner);
165 // DefaultPort := IdPORT_NNTP;
169 function TIdNNTPServer
.DoExecute(AThread
: TIdPeerThread
): boolean;
175 procedure NotHandled(CMD
: string);
177 AThread
.Connection
.Writeln('500 ' + Format(RSNNTPServerNotRecognized
,
181 function isNumericString(Str
: string): Boolean;
183 if Length(str
) = 0 then
186 Result
:= IsNumeric(Str
[1]);
192 with AThread
.Connection
do
202 sCmd
:= Fetch(s
, ' ');
203 i
:= Succ(PosInStrArray(UpperCase(sCmd
), KnownCommands
));
206 if isNumericString(s
) then
208 if Assigned(OnCommandArticleNo
) then
209 OnCommandArticleNo(AThread
, StrToCard(S
))
215 if Assigned(OnCommandArticleID
) then
216 OnCommandArticleID(AThread
, S
)
221 if isNumericString(s
) then
223 if assigned(OnCommandBodyNo
) then
224 OnCommandBodyNo(AThread
, StrToCard(S
))
230 if assigned(OnCommandBodyID
) then
231 OnCommandBodyID(AThread
, S
)
236 if isNumericString(s
) then
238 if assigned(OnCommandHeadNo
) then
239 OnCommandHeadNo(AThread
, StrToCard(S
))
245 if assigned(OnCommandHeadID
) then
246 OnCommandHeadID(AThread
, S
)
251 if isNumericString(s
) then
253 if assigned(OnCommandStatNo
) then
254 OnCommandStatNo(AThread
, StrToCard(S
))
260 if assigned(OnCommandStatID
) then
261 OnCommandStatID(AThread
, S
)
266 if assigned(OnCommandGroup
) then
267 OnCommandGroup(AThread
, S
)
271 if assigned(OnCommandList
) then
272 OnCommandList(AThread
, S
)
276 if assigned(OnCommandHelp
) then
277 OnCommandHelp(AThread
)
281 if assigned(OnCommandIHave
) then
282 OnCommandIHave(AThread
, S
)
286 if assigned(OnCommandLast
) then
287 OnCommandLast(AThread
)
291 if assigned(OnCommandNewGroups
) then
292 OnCommandNewGroups(AThread
, S
)
296 if assigned(OnCommandNewNews
) then
297 OnCommandNewNews(AThread
, S
)
301 if assigned(OnCommandNext
) then
302 OnCommandNext(AThread
)
306 if assigned(OnCommandPost
) then
307 OnCommandPost(AThread
)
312 if assigned(OnCommandQuit
) then
313 OnCommandQuit(AThread
)
315 AThread
.Connection
.WriteLn('205 ' + RSNNTPServerGoodBye
);
316 AThread
.Connection
.Disconnect
;
319 if assigned(OnCommandSlave
) then
320 OnCommandSlave(AThread
)
324 if assigned(OnCommandAuthInfo
) then
326 sCmd
:= UpperCase(Fetch(s
, ' '));
328 OnCommandAuthInfo(AThread
, SCmd
, S
, WasHandled
);
329 if not WasHandled
then NotHandled(sCmd
);
334 if assigned(OnCommandXOver
) then
335 OnCommandXOver(AThread
, S
)
339 if assigned(OnCommandXHDR
) then
340 OnCommandXHDR(AThread
, S
)
344 if assigned(OnCommandDate
) then
345 OnCommandDate(AThread
)
349 if assigned(OnCommandListGroup
) then
350 OnCommandListGroup(AThread
, S
)
354 if assigned(OnCommandMode
) then
355 OnCommandMode(AThread
, S
)
359 if assigned(OnCommandTakeThis
) then
360 OnCommandTakeThis(AThread
, S
)
364 if assigned(OnCommandCheck
) then
365 OnCommandCheck(AThread
, S
)
369 if assigned(OnCommandXThread
) then
370 OnCommandXThread(AThread
, S
)
374 if assigned(OnCommandXGTitle
) then
375 OnCommandXGTitle(AThread
, S
)
380 if assigned(OnCommandOther
) then
383 OnCommandOther(AThread
, sCmd
, S
, WasHandled
);
384 if not WasHandled
then NotHandled(sCmd
);