From: Ramakrishnan Muthukrishnan Date: Sun, 15 Feb 2015 07:34:55 +0000 (+0530) Subject: first attempt (buggy) at urlencode X-Git-Url: https://git.rkrishnan.org/vdrive/components/com_hotproperty/frontends/index.php?a=commitdiff_plain;h=a7171757dc695b78a161af3d3f4369911873e42e;p=functorrent.git first attempt (buggy) at urlencode --- 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