Capabilities command and documentation update.

This commit is contained in:
Stanislav Nikitin 2019-09-02 22:32:52 +05:00
parent 5452ea5b1a
commit 4e614c094e
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
4 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,44 @@
package capabilities
import (
// stdlib
"log"
// local
"develop.pztrn.name/gonews/gonews/eventer"
"develop.pztrn.name/gonews/gonews/networker"
)
var capabilities = []string{
"VERSION 2",
}
func Initialize() {
log.Println("Initializing capabilities command...")
eventer.AddEventHandler(&eventer.EventHandler{
Command: "internal/capability_add",
Handler: addCapability,
})
eventer.AddEventHandler(&eventer.EventHandler{
Command: "commands/capabilities",
Handler: handler,
})
}
func addCapability(data interface{}) interface{} {
capabilities = append(capabilities, data.(string))
return nil
}
func handler(data interface{}) interface{} {
dataToReturn := "Capability list:\r\n"
for _, cap := range capabilities {
dataToReturn += cap + "\r\n"
}
dataToReturn += ".\r\n"
return &networker.Reply{Code: "101", Data: dataToReturn}
}

View File

@ -5,6 +5,7 @@ import (
"log"
// local
"develop.pztrn.name/gonews/gonews/commands/capabilities"
"develop.pztrn.name/gonews/gonews/commands/greeting"
"develop.pztrn.name/gonews/gonews/commands/quit"
)
@ -14,4 +15,5 @@ func Initialize() {
greeting.Initialize()
quit.Initialize()
capabilities.Initialize()
}

View File

@ -13,10 +13,10 @@ This document will be updated with new RFCs data in process of development.
RFC3977:
* [ ] Connection handling ([section 5](https://tools.ietf.org/html/rfc3977#section-5)):
* [ ] Concurrent connection handling
* [ ] CAPABILITIES command ([section 5.2](https://tools.ietf.org/html/rfc3977#section-5.2))
* [x] Concurrent connection handling
* [x] CAPABILITIES command ([section 5.2](https://tools.ietf.org/html/rfc3977#section-5.2))
* [ ] MODE command ([section 5.3](https://tools.ietf.org/html/rfc3977#section-5.3))
* [ ] QUIT command ([section 5.4](https://tools.ietf.org/html/rfc3977#section-5.4))
* [x] QUIT command ([section 5.4](https://tools.ietf.org/html/rfc3977#section-5.4))
* [ ] Article retrieval and posting, working with groups ([section 6](https://tools.ietf.org/html/rfc3977#section-6)):
* [ ] Group selection and information retrieval ([section 6.1.1](https://tools.ietf.org/html/rfc3977#section-6.1.1))
* [ ] Group selection and information retrieval with articles numbers ([section 6.1.2](https://tools.ietf.org/html/rfc3977#section-6.1.2))

View File

@ -57,7 +57,7 @@ func connectionWorker(conn net.Conn) {
// ToDo: what if we'll upload binary data here?
// Not supported yet.
data := strings.Split(scanr.Text(), " ")
replyRaw, err := eventer.LaunchEvent("commands/"+data[0], data[1:])
replyRaw, err := eventer.LaunchEvent("commands/"+strings.ToLower(data[0]), data[1:])
if err != nil {
// We won't break here as this is just logging of appeared error.
log.Println("Error appeared while processing command '" + data[0] + "' for " + remoteAddr.String() + ": " + err.Error())