server: control port (#804)

* server: control port

* do not remove messages when saving via control port

* remove unused record fields

* fix tests
This commit is contained in:
Evgeny Poberezkin
2023-07-15 13:33:00 +01:00
committed by GitHub
parent d989d11478
commit 4fae7dcaee
8 changed files with 126 additions and 14 deletions
+36
View File
@@ -0,0 +1,36 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Simplex.Messaging.Server.Control where
import qualified Data.Attoparsec.ByteString.Char8 as A
import Simplex.Messaging.Encoding.String
data ControlProtocol
= CPSuspend
| CPResume
| CPClients
| CPStats
| CPSave
| CPHelp
| CPQuit
instance StrEncoding ControlProtocol where
strEncode = \case
CPSuspend -> "suspend"
CPResume -> "resume"
CPClients -> "clients"
CPStats -> "stats"
CPSave -> "save"
CPHelp -> "help"
CPQuit -> "quit"
strP =
A.takeTill (== ' ') >>= \case
"suspend" -> pure CPSuspend
"resume" -> pure CPResume
"clients" -> pure CPClients
"stats" -> pure CPStats
"save" -> pure CPSave
"help" -> pure CPHelp
"quit" -> pure CPQuit
_ -> fail "bad ControlProtocol command"