From 5981fd1415c766e49d265b463d5a0f12e8161d9e Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sat, 5 Feb 2022 18:32:38 +0300 Subject: [PATCH] Implement HELP command --- README.md | 2 +- internal/protocol/constants.go | 1 + internal/server/handler.go | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 67cbdb6..2dad7af 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ - :x: `LIST DISTRIB.PATS` - :construction: Information Commands - :heavy_check_mark: `DATE` - - :x: `HELP` + - :heavy_check_mark: `HELP` - :heavy_check_mark: `NEWGROUPS` - :x: `NEWNEWS` diff --git a/internal/protocol/constants.go b/internal/protocol/constants.go index 1a63c48..f530a0e 100644 --- a/internal/protocol/constants.go +++ b/internal/protocol/constants.go @@ -60,6 +60,7 @@ const ( CommandHead = "HEAD" CommandBody = "BODY" CommandStat = "STAT" + CommandHelp = "HELP" ) const ( diff --git a/internal/server/handler.go b/internal/server/handler.go index 201405f..d06629d 100644 --- a/internal/server/handler.go +++ b/internal/server/handler.go @@ -40,6 +40,7 @@ func NewHandler(b backend.StorageBackend, serverDomain string) *Handler { protocol.CommandHead: h.handleArticle, protocol.CommandBody: h.handleArticle, protocol.CommandStat: h.handleArticle, + protocol.CommandHelp: h.handleHelp, } h.serverDomain = serverDomain return h @@ -512,6 +513,49 @@ func (h *Handler) handleArticle(s *Session, command string, arguments []string, 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 { splittedMessage := strings.Split(message, " ") for i, v := range splittedMessage {