From c6b96a9cb2c6949893d69c5010a1386648321e2c Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Thu, 15 Oct 2020 14:30:42 +0100 Subject: [PATCH] replace `ERROR SYNTAX 7` with `ERROR SIZE` for bad message body size --- src/ConnStore.hs | 5 +++++ src/Transmission.hs | 5 +---- src/Transport.hs | 2 +- tests/Test.hs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ConnStore.hs b/src/ConnStore.hs index 6a8bf6946..0cdf84af7 100644 --- a/src/ConnStore.hs +++ b/src/ConnStore.hs @@ -34,3 +34,8 @@ newConnection rKey = senderKey = Nothing, status = ConnActive } + +-- class MonadMsgStore s m where +-- addMsg :: s -> SenderId -> MsgBody -> m (Either ErrorType ()) +-- getMsg :: s -> RecipientId -> m (Either ErrorType Message) +-- delMsg :: s -> RecipientId -> m (Either ErrorType ()) diff --git a/src/Transmission.hs b/src/Transmission.hs index e8c7c4197..fa1e9c3fb 100644 --- a/src/Transmission.hs +++ b/src/Transmission.hs @@ -123,7 +123,7 @@ type Timestamp = Encoded type MsgBody = B.ByteString -data ErrorType = UNKNOWN | PROHIBITED | SYNTAX Int | AUTH | INTERNAL deriving (Show, Eq) +data ErrorType = UNKNOWN | PROHIBITED | SYNTAX Int | SIZE | AUTH | INTERNAL deriving (Show, Eq) errBadParameters :: Int errBadParameters = 2 @@ -139,6 +139,3 @@ errNoConnectionId = 5 errMessageBody :: Int errMessageBody = 6 - -errMessageBodySize :: Int -errMessageBodySize = 7 diff --git a/src/Transport.hs b/src/Transport.hs index 33931a72f..4c49c5937 100644 --- a/src/Transport.hs +++ b/src/Transport.hs @@ -152,5 +152,5 @@ tGet fromParty h = do Just size -> do body <- getBytes h size s <- getLn h - return if null s then Right body else Left $ SYNTAX errMessageBodySize + return if null s then Right body else Left SIZE Nothing -> return . Left $ SYNTAX errMessageBody diff --git a/tests/Test.hs b/tests/Test.hs index caa839706..f5aca4a7b 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -143,7 +143,7 @@ syntaxTests = do it "many parameters" $ [("123", "1", "SEND 11 hello")] >#> [("", "1", "ERROR SYNTAX 2")] it "no connection ID" $ [("123", "", "SEND :hello")] >#> [("", "", "ERROR SYNTAX 5")] it "bad message body" $ [("123", "1", "SEND hello")] >#> [("", "1", "ERROR SYNTAX 6")] - it "bigger body" $ [("123", "1", "SEND 4\nhello\n")] >#> [("", "1", "ERROR SYNTAX 7")] + it "bigger body" $ [("123", "1", "SEND 4\nhello\n")] >#> [("", "1", "ERROR SIZE")] describe "broker response not allowed" do it "OK" $ [("123", "1", "OK")] >#> [("", "1", "ERROR PROHIBITED")] where