conjure-0.1: src/Conjure/Protocol/THP/Parser.hs
-----------------------------------------------------------------------------
-- |
-- Module : Conjure.Protocol.THP.Parser
-- Copyright : (c) Lemmih 2005-2006
-- License : BSD-like
--
-- Maintainer : lemmih@gmail.com
-- Stability : experimental
-- Portability : non-portable
--
-- Parser for the Tracker HTTP Protocol.
-----------------------------------------------------------------------------
module Conjure.Protocol.THP.Parser
( parseResponse
) where
import BEncode.BParser
import Conjure.Protocol.THP.Types
parseResponse :: BParser Response
parseResponse =
errorResponse <|> okResponse
errorResponse :: BParser Response
errorResponse =
do reason <- bstring $ dict "failure reason"
return $ Error reason
okResponse :: BParser Response
okResponse =
do interval <- bint $ dict "interval"
complete <- optional $ bint $ dict "complete"
incomplete <- optional $ bint $ dict "incomplete"
peers <- list "peers" $ do peerID <- bfaststring $ dict "peer id"
peerIP <- bstring $ dict "ip"
peerPort <- bint $ dict "port"
return $ PeerInfo peerID peerIP peerPort
return $ Info interval complete incomplete peers
{-
-}