mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-04 02:36:10 +00:00
* log control port commands * auth * add auth to xftp, config and commands * log missing auth * put smp save under auth * corrections --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
39 lines
1.0 KiB
Haskell
39 lines
1.0 KiB
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Simplex.FileTransfer.Server.Control where
|
|
|
|
import qualified Data.Attoparsec.ByteString.Char8 as A
|
|
import Data.ByteString (ByteString)
|
|
import qualified Simplex.Messaging.Crypto as C
|
|
import Simplex.Messaging.Encoding.String
|
|
import Simplex.Messaging.Protocol (BasicAuth)
|
|
|
|
data CPClientRole = CPRNone | CPRUser | CPRAdmin
|
|
|
|
data ControlProtocol
|
|
= CPAuth BasicAuth
|
|
| CPStatsRTS
|
|
| CPDelete ByteString C.APublicAuthKey
|
|
| CPHelp
|
|
| CPQuit
|
|
| CPSkip
|
|
|
|
instance StrEncoding ControlProtocol where
|
|
strEncode = \case
|
|
CPAuth tok -> "auth " <> strEncode tok
|
|
CPStatsRTS -> "stats-rts"
|
|
CPDelete fId fKey -> strEncode (Str "delete", fId, fKey)
|
|
CPHelp -> "help"
|
|
CPQuit -> "quit"
|
|
CPSkip -> ""
|
|
strP =
|
|
A.takeTill (== ' ') >>= \case
|
|
"auth" -> CPAuth <$> _strP
|
|
"stats-rts" -> pure CPStatsRTS
|
|
"delete" -> CPDelete <$> _strP <*> _strP
|
|
"help" -> pure CPHelp
|
|
"quit" -> pure CPQuit
|
|
"" -> pure CPSkip
|
|
_ -> fail "bad ControlProtocol command"
|