From 544fb266e00229f9960b13dda864408a3500dd27 Mon Sep 17 00:00:00 2001 From: Baylac-Jacqué Félix Date: Wed, 13 Sep 2017 17:25:27 +0200 Subject: Implemented rpc request parser. --- src/Network/WireGuard/Internal/Data/RpcTypes.hs | 4 ++-- src/Network/WireGuard/Internal/RpcParsers.hs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Network/WireGuard') diff --git a/src/Network/WireGuard/Internal/Data/RpcTypes.hs b/src/Network/WireGuard/Internal/Data/RpcTypes.hs index a78d9df..088bbb5 100644 --- a/src/Network/WireGuard/Internal/Data/RpcTypes.hs +++ b/src/Network/WireGuard/Internal/Data/RpcTypes.hs @@ -17,7 +17,7 @@ import Network.WireGuard.Internal.Data.Types (PublicKey, KeyPair, -- | Kind of client operation. -- -- See for more informations. -data OpType = Get | Set +data OpType = Get | Set deriving (Eq, Show) -- | Request wrapper. The payload is set only for Set operations. -- @@ -25,7 +25,7 @@ data OpType = Get | Set data RpcRequest = RpcRequest { opType :: !OpType, payload :: !(Maybe RpcSetPayload) -} +} deriving (Eq, Show) -- | Payload sent together with a set RPC operation. data RpcSetPayload = RpcSetPayload { diff --git a/src/Network/WireGuard/Internal/RpcParsers.hs b/src/Network/WireGuard/Internal/RpcParsers.hs index e5e38d1..d2eac92 100644 --- a/src/Network/WireGuard/Internal/RpcParsers.hs +++ b/src/Network/WireGuard/Internal/RpcParsers.hs @@ -38,15 +38,15 @@ import Network.WireGuard.Internal.Data.RpcTypes (OpType(..), requestParser :: Parser RpcRequest requestParser = do op <- requestTypeParser - let p = case op of - Set -> undefined - Get -> Nothing - _ <- string $ BC.pack "\n\n" + p <- case op of + Set -> Just <$> setPayloadParser + Get -> return Nothing + _ <- string $ BC.pack "\n" return $ RpcRequest op p requestTypeParser :: Parser OpType -requestTypeParser = "get=1" *> return Get - <|> "set=1" *> return Set +requestTypeParser = "get=1\n" *> return Get + <|> "set=1\n" *> return Set setPayloadParser :: Parser RpcSetPayload setPayloadParser = do -- cgit v1.2.3-59-g8ed1b