diff --git a/commands/capabilities/exported.go b/commands/capabilities/exported.go new file mode 100644 index 0000000..d7b8fa1 --- /dev/null +++ b/commands/capabilities/exported.go @@ -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} +} diff --git a/commands/exported.go b/commands/exported.go index d2e02e8..5d7aa83 100644 --- a/commands/exported.go +++ b/commands/exported.go @@ -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() } diff --git a/doc/implementation.md b/doc/implementation.md index 0192ee4..3bb2448 100644 --- a/doc/implementation.md +++ b/doc/implementation.md @@ -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)) diff --git a/networker/connection.go b/networker/connection.go index 6701553..f97eaec 100644 --- a/networker/connection.go +++ b/networker/connection.go @@ -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())