diff options
author | James Crayne <jim.crayne@gmail.com> | 2017-01-23 07:29:21 +0000 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2017-01-23 07:29:21 +0000 |
commit | 40bb0d66f492abed328ebd7961588b7c3a8ed7a6 (patch) | |
tree | 41761d9f58f1e5719c9a860f75b20b7fd6db736e /src | |
parent | a41dc208af6180d307553c504d3f7d47dd9b9f0a (diff) |
build fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/BEncode/Pretty.hs | 15 | ||||
-rw-r--r-- | src/Network/KRPC/Manager.hs | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/Data/BEncode/Pretty.hs b/src/Data/BEncode/Pretty.hs index 63efc61c..89fcb489 100644 --- a/src/Data/BEncode/Pretty.hs +++ b/src/Data/BEncode/Pretty.hs | |||
@@ -7,6 +7,9 @@ import qualified Data.ByteString.Lazy as BL | |||
7 | import qualified Data.ByteString.Lazy.Char8 as BL8 | 7 | import qualified Data.ByteString.Lazy.Char8 as BL8 |
8 | import Data.Text (Text) | 8 | import Data.Text (Text) |
9 | import qualified Data.Text as T | 9 | import qualified Data.Text as T |
10 | import Data.Text.Encoding | ||
11 | import Text.Printf | ||
12 | import qualified Data.ByteString.Base16 as Base16 | ||
10 | #ifdef BENCODE_AESON | 13 | #ifdef BENCODE_AESON |
11 | import Data.BEncode.BDict hiding (map) | 14 | import Data.BEncode.BDict hiding (map) |
12 | import Data.Aeson.Types hiding (parse) | 15 | import Data.Aeson.Types hiding (parse) |
@@ -14,12 +17,9 @@ import Data.Aeson.Encode.Pretty | |||
14 | import qualified Data.HashMap.Strict as HashMap | 17 | import qualified Data.HashMap.Strict as HashMap |
15 | import qualified Data.Vector as Vector | 18 | import qualified Data.Vector as Vector |
16 | import Data.Foldable as Foldable | 19 | import Data.Foldable as Foldable |
17 | import Data.Text.Encoding | ||
18 | import Text.Printf | ||
19 | #endif | 20 | #endif |
20 | 21 | ||
21 | #ifdef BENCODE_AESON | 22 | {- |
22 | |||
23 | unhex :: Text -> BS.ByteString | 23 | unhex :: Text -> BS.ByteString |
24 | unhex t = BS.pack $ map unhex1 [0 .. BS.length nibs `div` 2] | 24 | unhex t = BS.pack $ map unhex1 [0 .. BS.length nibs `div` 2] |
25 | where | 25 | where |
@@ -31,6 +31,9 @@ unhex t = BS.pack $ map unhex1 [0 .. BS.length nibs `div` 2] | |||
31 | 31 | ||
32 | hex :: BS.ByteString -> Text | 32 | hex :: BS.ByteString -> Text |
33 | hex bs = T.concat $ map (T.pack . printf "%02X") $ BS.unpack bs | 33 | hex bs = T.concat $ map (T.pack . printf "%02X") $ BS.unpack bs |
34 | -} | ||
35 | |||
36 | #ifdef BENCODE_AESON | ||
34 | 37 | ||
35 | quote_chr :: Char | 38 | quote_chr :: Char |
36 | quote_chr = ' ' | 39 | quote_chr = ' ' |
@@ -39,12 +42,12 @@ quote :: Text -> Text | |||
39 | quote t = quote_chr `T.cons` t `T.snoc` quote_chr | 42 | quote t = quote_chr `T.cons` t `T.snoc` quote_chr |
40 | 43 | ||
41 | encodeByteString :: BS.ByteString -> Text | 44 | encodeByteString :: BS.ByteString -> Text |
42 | encodeByteString s = either (const $ hex s) quote $ decodeUtf8' s | 45 | encodeByteString s = either (const . decodeUtf8 $ Base16.encode s) quote $ decodeUtf8' s |
43 | 46 | ||
44 | decodeByteString :: Text -> BS.ByteString | 47 | decodeByteString :: Text -> BS.ByteString |
45 | decodeByteString s | 48 | decodeByteString s |
46 | | T.head s==quote_chr = encodeUtf8 (T.takeWhile (/=quote_chr) $ T.drop 1 s) | 49 | | T.head s==quote_chr = encodeUtf8 (T.takeWhile (/=quote_chr) $ T.drop 1 s) |
47 | | otherwise = unhex s | 50 | | otherwise = fst (Base16.decode (encodeUtf8 s)) |
48 | 51 | ||
49 | instance ToJSON BValue where | 52 | instance ToJSON BValue where |
50 | toJSON (BInteger x) = Number $ fromIntegral x | 53 | toJSON (BInteger x) = Number $ fromIntegral x |
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs index 7a2120cb..4852eb38 100644 --- a/src/Network/KRPC/Manager.hs +++ b/src/Network/KRPC/Manager.hs | |||
@@ -52,7 +52,8 @@ import Control.Monad.Reader | |||
52 | import Control.Monad.Trans.Control | 52 | import Control.Monad.Trans.Control |
53 | import Data.BEncode as BE | 53 | import Data.BEncode as BE |
54 | import Data.BEncode.Internal as BE | 54 | import Data.BEncode.Internal as BE |
55 | import Data.BEncode.Pretty (showBEncode, hex) | 55 | import Data.BEncode.Pretty (showBEncode) |
56 | import qualified Data.ByteString.Base16 as Base16 | ||
56 | import Data.ByteString as BS | 57 | import Data.ByteString as BS |
57 | import Data.ByteString.Char8 as BC | 58 | import Data.ByteString.Char8 as BC |
58 | import Data.ByteString.Lazy as BL | 59 | import Data.ByteString.Lazy as BL |
@@ -218,7 +219,7 @@ withManager opts addr hs = bracket (newManager opts addr hs) closeManager | |||
218 | querySignature :: MethodName -> TransactionId -> SockAddr -> Text | 219 | querySignature :: MethodName -> TransactionId -> SockAddr -> Text |
219 | querySignature name transaction addr = T.concat | 220 | querySignature name transaction addr = T.concat |
220 | [ "&", T.decodeUtf8 name | 221 | [ "&", T.decodeUtf8 name |
221 | , " #", hex transaction -- T.decodeUtf8 transaction | 222 | , " #", T.decodeUtf8 (Base16.encode transaction) -- T.decodeUtf8 transaction |
222 | , " @", T.pack (show addr) | 223 | , " @", T.pack (show addr) |
223 | ] | 224 | ] |
224 | 225 | ||