{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}

module Simplex.FileTransfer.Server.Stats
  ( FileServerStats (..),
    FileServerStatsData (..),
    newFileServerStats,
    getFileServerStatsData,
    setFileServerStats,
  ) where

import Control.Applicative ((<|>))
import qualified Data.Attoparsec.ByteString.Char8 as A
import qualified Data.ByteString.Char8 as B
import Data.IORef
import Data.Int (Int64)
import Data.Time.Clock (UTCTime)
import Simplex.Messaging.Encoding.String
import Simplex.Messaging.Server.Stats (PeriodStats, PeriodStatsData, getPeriodStatsData, newPeriodStats, setPeriodStats)

data FileServerStats = FileServerStats
  { FileServerStats -> IORef UTCTime
fromTime :: IORef UTCTime,
    FileServerStats -> IORef Int
filesCreated :: IORef Int,
    FileServerStats -> IORef Int
fileRecipients :: IORef Int,
    FileServerStats -> IORef Int
filesUploaded :: IORef Int,
    FileServerStats -> IORef Int
filesExpired :: IORef Int,
    FileServerStats -> IORef Int
filesDeleted :: IORef Int,
    FileServerStats -> IORef Int
filesBlocked :: IORef Int,
    FileServerStats -> PeriodStats
filesDownloaded :: PeriodStats,
    FileServerStats -> IORef Int
fileDownloads :: IORef Int,
    FileServerStats -> IORef Int
fileDownloadAcks :: IORef Int,
    FileServerStats -> IORef Int
filesCount :: IORef Int,
    FileServerStats -> IORef Int64
filesSize :: IORef Int64
  }

data FileServerStatsData = FileServerStatsData
  { FileServerStatsData -> UTCTime
_fromTime :: UTCTime,
    FileServerStatsData -> Int
_filesCreated :: Int,
    FileServerStatsData -> Int
_fileRecipients :: Int,
    FileServerStatsData -> Int
_filesUploaded :: Int,
    FileServerStatsData -> Int
_filesExpired :: Int,
    FileServerStatsData -> Int
_filesDeleted :: Int,
    FileServerStatsData -> Int
_filesBlocked :: Int,
    FileServerStatsData -> PeriodStatsData
_filesDownloaded :: PeriodStatsData,
    FileServerStatsData -> Int
_fileDownloads :: Int,
    FileServerStatsData -> Int
_fileDownloadAcks :: Int,
    FileServerStatsData -> Int
_filesCount :: Int,
    FileServerStatsData -> Int64
_filesSize :: Int64
  }
  deriving (Int -> FileServerStatsData -> ShowS
[FileServerStatsData] -> ShowS
FileServerStatsData -> String
(Int -> FileServerStatsData -> ShowS)
-> (FileServerStatsData -> String)
-> ([FileServerStatsData] -> ShowS)
-> Show FileServerStatsData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileServerStatsData -> ShowS
showsPrec :: Int -> FileServerStatsData -> ShowS
$cshow :: FileServerStatsData -> String
show :: FileServerStatsData -> String
$cshowList :: [FileServerStatsData] -> ShowS
showList :: [FileServerStatsData] -> ShowS
Show)

newFileServerStats :: UTCTime -> IO FileServerStats
newFileServerStats :: UTCTime -> IO FileServerStats
newFileServerStats UTCTime
ts = do
  IORef UTCTime
fromTime <- UTCTime -> IO (IORef UTCTime)
forall a. a -> IO (IORef a)
newIORef UTCTime
ts
  IORef Int
filesCreated <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
fileRecipients <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
filesUploaded <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
filesExpired <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
filesDeleted <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
filesBlocked <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  PeriodStats
filesDownloaded <- IO PeriodStats
newPeriodStats
  IORef Int
fileDownloads <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
fileDownloadAcks <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
filesCount <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int64
filesSize <- Int64 -> IO (IORef Int64)
forall a. a -> IO (IORef a)
newIORef Int64
0
  FileServerStats -> IO FileServerStats
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FileServerStats {IORef UTCTime
$sel:fromTime:FileServerStats :: IORef UTCTime
fromTime :: IORef UTCTime
fromTime, IORef Int
$sel:filesCreated:FileServerStats :: IORef Int
filesCreated :: IORef Int
filesCreated, IORef Int
$sel:fileRecipients:FileServerStats :: IORef Int
fileRecipients :: IORef Int
fileRecipients, IORef Int
$sel:filesUploaded:FileServerStats :: IORef Int
filesUploaded :: IORef Int
filesUploaded, IORef Int
$sel:filesExpired:FileServerStats :: IORef Int
filesExpired :: IORef Int
filesExpired, IORef Int
$sel:filesDeleted:FileServerStats :: IORef Int
filesDeleted :: IORef Int
filesDeleted, IORef Int
$sel:filesBlocked:FileServerStats :: IORef Int
filesBlocked :: IORef Int
filesBlocked, PeriodStats
$sel:filesDownloaded:FileServerStats :: PeriodStats
filesDownloaded :: PeriodStats
filesDownloaded, IORef Int
$sel:fileDownloads:FileServerStats :: IORef Int
fileDownloads :: IORef Int
fileDownloads, IORef Int
$sel:fileDownloadAcks:FileServerStats :: IORef Int
fileDownloadAcks :: IORef Int
fileDownloadAcks, IORef Int
$sel:filesCount:FileServerStats :: IORef Int
filesCount :: IORef Int
filesCount, IORef Int64
$sel:filesSize:FileServerStats :: IORef Int64
filesSize :: IORef Int64
filesSize}

getFileServerStatsData :: FileServerStats -> IO FileServerStatsData
getFileServerStatsData :: FileServerStats -> IO FileServerStatsData
getFileServerStatsData FileServerStats
s = do
  UTCTime
_fromTime <- IORef UTCTime -> IO UTCTime
forall a. IORef a -> IO a
readIORef (IORef UTCTime -> IO UTCTime) -> IORef UTCTime -> IO UTCTime
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef UTCTime
fromTime (FileServerStats
s :: FileServerStats)
  Int
_filesCreated <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
filesCreated FileServerStats
s
  Int
_fileRecipients <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
fileRecipients FileServerStats
s
  Int
_filesUploaded <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
filesUploaded FileServerStats
s
  Int
_filesExpired <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
filesExpired FileServerStats
s
  Int
_filesDeleted <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
filesDeleted FileServerStats
s
  Int
_filesBlocked <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
filesBlocked FileServerStats
s
  PeriodStatsData
_filesDownloaded <- PeriodStats -> IO PeriodStatsData
getPeriodStatsData (PeriodStats -> IO PeriodStatsData)
-> PeriodStats -> IO PeriodStatsData
forall a b. (a -> b) -> a -> b
$ FileServerStats -> PeriodStats
filesDownloaded FileServerStats
s
  Int
_fileDownloads <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
fileDownloads FileServerStats
s
  Int
_fileDownloadAcks <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
fileDownloadAcks FileServerStats
s
  Int
_filesCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int
filesCount FileServerStats
s
  Int64
_filesSize <- IORef Int64 -> IO Int64
forall a. IORef a -> IO a
readIORef (IORef Int64 -> IO Int64) -> IORef Int64 -> IO Int64
forall a b. (a -> b) -> a -> b
$ FileServerStats -> IORef Int64
filesSize FileServerStats
s
  FileServerStatsData -> IO FileServerStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FileServerStatsData {UTCTime
$sel:_fromTime:FileServerStatsData :: UTCTime
_fromTime :: UTCTime
_fromTime, Int
$sel:_filesCreated:FileServerStatsData :: Int
_filesCreated :: Int
_filesCreated, Int
$sel:_fileRecipients:FileServerStatsData :: Int
_fileRecipients :: Int
_fileRecipients, Int
$sel:_filesUploaded:FileServerStatsData :: Int
_filesUploaded :: Int
_filesUploaded, Int
$sel:_filesExpired:FileServerStatsData :: Int
_filesExpired :: Int
_filesExpired, Int
$sel:_filesDeleted:FileServerStatsData :: Int
_filesDeleted :: Int
_filesDeleted, Int
$sel:_filesBlocked:FileServerStatsData :: Int
_filesBlocked :: Int
_filesBlocked, PeriodStatsData
$sel:_filesDownloaded:FileServerStatsData :: PeriodStatsData
_filesDownloaded :: PeriodStatsData
_filesDownloaded, Int
$sel:_fileDownloads:FileServerStatsData :: Int
_fileDownloads :: Int
_fileDownloads, Int
$sel:_fileDownloadAcks:FileServerStatsData :: Int
_fileDownloadAcks :: Int
_fileDownloadAcks, Int
$sel:_filesCount:FileServerStatsData :: Int
_filesCount :: Int
_filesCount, Int64
$sel:_filesSize:FileServerStatsData :: Int64
_filesSize :: Int64
_filesSize}

-- this function is not thread safe, it is used on server start only
setFileServerStats :: FileServerStats -> FileServerStatsData -> IO ()
setFileServerStats :: FileServerStats -> FileServerStatsData -> IO ()
setFileServerStats FileServerStats
s FileServerStatsData
d = do
  IORef UTCTime -> UTCTime -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef UTCTime
fromTime (FileServerStats
s :: FileServerStats)) (UTCTime -> IO ()) -> UTCTime -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> UTCTime
_fromTime (FileServerStatsData
d :: FileServerStatsData)
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
filesCreated FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_filesCreated FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
fileRecipients FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_fileRecipients FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
filesUploaded FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_filesUploaded FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
filesExpired FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_filesExpired FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
filesDeleted FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_filesDeleted FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
filesBlocked FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_filesBlocked FileServerStatsData
d
  PeriodStats -> PeriodStatsData -> IO ()
setPeriodStats (FileServerStats -> PeriodStats
filesDownloaded FileServerStats
s) (PeriodStatsData -> IO ()) -> PeriodStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> PeriodStatsData
_filesDownloaded FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
fileDownloads FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_fileDownloads FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
fileDownloadAcks FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_fileDownloadAcks FileServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int
filesCount FileServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int
_filesCount FileServerStatsData
d
  IORef Int64 -> Int64 -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (FileServerStats -> IORef Int64
filesSize FileServerStats
s) (Int64 -> IO ()) -> Int64 -> IO ()
forall a b. (a -> b) -> a -> b
$! FileServerStatsData -> Int64
_filesSize FileServerStatsData
d

instance StrEncoding FileServerStatsData where
  strEncode :: FileServerStatsData -> ByteString
strEncode FileServerStatsData {UTCTime
$sel:_fromTime:FileServerStatsData :: FileServerStatsData -> UTCTime
_fromTime :: UTCTime
_fromTime, Int
$sel:_filesCreated:FileServerStatsData :: FileServerStatsData -> Int
_filesCreated :: Int
_filesCreated, Int
$sel:_fileRecipients:FileServerStatsData :: FileServerStatsData -> Int
_fileRecipients :: Int
_fileRecipients, Int
$sel:_filesUploaded:FileServerStatsData :: FileServerStatsData -> Int
_filesUploaded :: Int
_filesUploaded, Int
$sel:_filesExpired:FileServerStatsData :: FileServerStatsData -> Int
_filesExpired :: Int
_filesExpired, Int
$sel:_filesDeleted:FileServerStatsData :: FileServerStatsData -> Int
_filesDeleted :: Int
_filesDeleted, Int
$sel:_filesBlocked:FileServerStatsData :: FileServerStatsData -> Int
_filesBlocked :: Int
_filesBlocked, PeriodStatsData
$sel:_filesDownloaded:FileServerStatsData :: FileServerStatsData -> PeriodStatsData
_filesDownloaded :: PeriodStatsData
_filesDownloaded, Int
$sel:_fileDownloads:FileServerStatsData :: FileServerStatsData -> Int
_fileDownloads :: Int
_fileDownloads, Int
$sel:_fileDownloadAcks:FileServerStatsData :: FileServerStatsData -> Int
_fileDownloadAcks :: Int
_fileDownloadAcks, Int
$sel:_filesCount:FileServerStatsData :: FileServerStatsData -> Int
_filesCount :: Int
_filesCount, Int64
$sel:_filesSize:FileServerStatsData :: FileServerStatsData -> Int64
_filesSize :: Int64
_filesSize} =
    [ByteString] -> ByteString
B.unlines
      [ ByteString
"fromTime=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> UTCTime -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode UTCTime
_fromTime,
        ByteString
"filesCreated=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_filesCreated,
        ByteString
"fileRecipients=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_fileRecipients,
        ByteString
"filesUploaded=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_filesUploaded,
        ByteString
"filesExpired=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_filesExpired,
        ByteString
"filesDeleted=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_filesDeleted,
        ByteString
"filesBlocked=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_filesBlocked,
        ByteString
"filesCount=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_filesCount,
        ByteString
"filesSize=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int64 -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int64
_filesSize,
        ByteString
"filesDownloaded:",
        PeriodStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode PeriodStatsData
_filesDownloaded,
        ByteString
"fileDownloads=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_fileDownloads,
        ByteString
"fileDownloadAcks=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_fileDownloadAcks
      ]
  strP :: Parser FileServerStatsData
strP = do
    UTCTime
_fromTime <- Parser ByteString ByteString
"fromTime=" Parser ByteString ByteString
-> Parser ByteString UTCTime -> Parser ByteString UTCTime
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString UTCTime
forall a. StrEncoding a => Parser a
strP Parser ByteString UTCTime
-> Parser ByteString () -> Parser ByteString UTCTime
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_filesCreated <- Parser ByteString ByteString
"filesCreated=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_fileRecipients <- Parser ByteString ByteString
"fileRecipients=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_filesUploaded <- Parser ByteString ByteString
"filesUploaded=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_filesExpired <- Parser ByteString ByteString
"filesExpired=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine Parser ByteString Int
-> Parser ByteString Int -> Parser ByteString Int
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Parser ByteString Int
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0
    Int
_filesDeleted <- Parser ByteString ByteString
"filesDeleted=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_filesBlocked <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"filesBlocked="
    Int
_filesCount <- Parser ByteString ByteString
"filesCount=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine Parser ByteString Int
-> Parser ByteString Int -> Parser ByteString Int
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Parser ByteString Int
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
0
    Int64
_filesSize <- Parser ByteString ByteString
"filesSize=" Parser ByteString ByteString
-> Parser ByteString Int64 -> Parser ByteString Int64
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int64
forall a. StrEncoding a => Parser a
strP Parser ByteString Int64
-> Parser ByteString () -> Parser ByteString Int64
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine Parser ByteString Int64
-> Parser ByteString Int64 -> Parser ByteString Int64
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int64 -> Parser ByteString Int64
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int64
0
    PeriodStatsData
_filesDownloaded <- Parser ByteString ByteString
"filesDownloaded:" Parser ByteString ByteString
-> Parser ByteString () -> Parser ByteString ()
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString ()
A.endOfLine Parser ByteString ()
-> Parser ByteString PeriodStatsData
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString PeriodStatsData
forall a. StrEncoding a => Parser a
strP Parser ByteString PeriodStatsData
-> Parser ByteString () -> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_fileDownloads <- Parser ByteString ByteString
"fileDownloads=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_fileDownloadAcks <- Parser ByteString ByteString
"fileDownloadAcks=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    FileServerStatsData -> Parser FileServerStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FileServerStatsData {UTCTime
$sel:_fromTime:FileServerStatsData :: UTCTime
_fromTime :: UTCTime
_fromTime, Int
$sel:_filesCreated:FileServerStatsData :: Int
_filesCreated :: Int
_filesCreated, Int
$sel:_fileRecipients:FileServerStatsData :: Int
_fileRecipients :: Int
_fileRecipients, Int
$sel:_filesUploaded:FileServerStatsData :: Int
_filesUploaded :: Int
_filesUploaded, Int
$sel:_filesExpired:FileServerStatsData :: Int
_filesExpired :: Int
_filesExpired, Int
$sel:_filesDeleted:FileServerStatsData :: Int
_filesDeleted :: Int
_filesDeleted, Int
$sel:_filesBlocked:FileServerStatsData :: Int
_filesBlocked :: Int
_filesBlocked, PeriodStatsData
$sel:_filesDownloaded:FileServerStatsData :: PeriodStatsData
_filesDownloaded :: PeriodStatsData
_filesDownloaded, Int
$sel:_fileDownloads:FileServerStatsData :: Int
_fileDownloads :: Int
_fileDownloads, Int
$sel:_fileDownloadAcks:FileServerStatsData :: Int
_fileDownloadAcks :: Int
_fileDownloadAcks, Int
$sel:_filesCount:FileServerStatsData :: Int
_filesCount :: Int
_filesCount, Int64
$sel:_filesSize:FileServerStatsData :: Int64
_filesSize :: Int64
_filesSize}
    where
      opt :: ByteString -> Parser ByteString a
opt ByteString
s = ByteString -> Parser ByteString ByteString
A.string ByteString
s Parser ByteString ByteString
-> Parser ByteString a -> Parser ByteString a
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString a
forall a. StrEncoding a => Parser a
strP Parser ByteString a -> Parser ByteString () -> Parser ByteString a
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> Parser ByteString a
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
0