From a7171757dc695b78a161af3d3f4369911873e42e Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org> Date: Sun, 15 Feb 2015 13:04:55 +0530 Subject: [PATCH] first attempt (buggy) at urlencode --- src/Tracker.hs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Tracker.hs b/src/Tracker.hs index 6db0c36..57b813d 100644 --- a/src/Tracker.hs +++ b/src/Tracker.hs @@ -1,16 +1,26 @@ module Tracker where -import qualified Bencode as Benc -import Data.Conduit -import Network.HTTP +-- import qualified Bencode as Benc +import qualified Data.ByteString.Char8 as BC +import qualified Network.HTTP.Base as HB +import Data.Char +-- import Network.HTTP type Url = String -requestUrl :: String +splitN :: Int -> BC.ByteString -> [BC.ByteString] +splitN n bs | BC.null bs = [] + | otherwise = (BC.take n bs) : splitN n (BC.drop n bs) +urlEncode :: BC.ByteString -> String +urlEncode bs = let bss = splitN 2 bs + chars = map (chr . read . ("0x" ++) . BC.unpack) bss + in + HB.urlEncode chars -connect :: Url -> String -> IO (Benc.BVal) -connect url infoHash = case (parseUrl url) of - Nothing -> putStrLn "invalid tracker URL" - Just req -> let + +-- connect :: Url -> String -> IO (Benc.BVal) +-- connect url infoHash = case (parseUrl url) of +-- Nothing -> putStrLn "invalid tracker URL" +-- Just req -> let -- 2.45.2