Implement HELP command

This commit is contained in:
ChronosX88 2022-02-05 18:32:38 +03:00
parent 164c296835
commit 5981fd1415
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
3 changed files with 46 additions and 1 deletions

View File

@ -45,7 +45,7 @@
- :x: `LIST DISTRIB.PATS` - :x: `LIST DISTRIB.PATS`
- :construction: Information Commands - :construction: Information Commands
- :heavy_check_mark: `DATE` - :heavy_check_mark: `DATE`
- :x: `HELP` - :heavy_check_mark: `HELP`
- :heavy_check_mark: `NEWGROUPS` - :heavy_check_mark: `NEWGROUPS`
- :x: `NEWNEWS` - :x: `NEWNEWS`

View File

@ -60,6 +60,7 @@ const (
CommandHead = "HEAD" CommandHead = "HEAD"
CommandBody = "BODY" CommandBody = "BODY"
CommandStat = "STAT" CommandStat = "STAT"
CommandHelp = "HELP"
) )
const ( const (

View File

@ -40,6 +40,7 @@ func NewHandler(b backend.StorageBackend, serverDomain string) *Handler {
protocol.CommandHead: h.handleArticle, protocol.CommandHead: h.handleArticle,
protocol.CommandBody: h.handleArticle, protocol.CommandBody: h.handleArticle,
protocol.CommandStat: h.handleArticle, protocol.CommandStat: h.handleArticle,
protocol.CommandHelp: h.handleHelp,
} }
h.serverDomain = serverDomain h.serverDomain = serverDomain
return h return h
@ -512,6 +513,49 @@ func (h *Handler) handleArticle(s *Session, command string, arguments []string,
return nil return nil
} }
func (h *Handler) handleHelp(s *Session, command string, arguments []string, id uint) error {
s.tconn.StartResponse(id)
defer s.tconn.EndResponse(id)
help :=
" ARTICLE [message-ID|number]\r\n" +
" BODY [message-ID|number]\r\n" +
" CAPABILITIES [keyword]\r\n" +
" DATE\r\n" +
" GROUP newsgroup\r\n" +
" HEAD [message-ID|number]\r\n" +
" HELP\r\n" +
" LAST\r\n" +
" LIST [ACTIVE [wildmat]|NEWSGROUPS [wildmat]]\r\n" +
" LISTGROUP [newsgroup [range]]\r\n" +
" MODE READER\r\n" +
" NEWGROUPS [yy]yymmdd hhmmss [GMT]\r\n" +
" NEXT\r\n" +
" POST\r\n" +
" QUIT\r\n" +
" STAT [message-ID|number]\r\n"
dw := s.tconn.DotWriter()
w := bufio.NewWriter(dw)
_, err := w.Write([]byte(protocol.NNTPResponse{Code: 100, Message: "Legal commands"}.String() + protocol.CRLF))
if err != nil {
return err
}
_, err = w.Write([]byte(help))
if err != nil {
return err
}
err = w.Flush()
if err != nil {
return err
}
return dw.Close()
}
func (h *Handler) Handle(s *Session, message string, id uint) error { func (h *Handler) Handle(s *Session, message string, id uint) error {
splittedMessage := strings.Split(message, " ") splittedMessage := strings.Split(message, " ")
for i, v := range splittedMessage { for i, v := range splittedMessage {