[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:45:37 UTC 2010


The following commit has been merged in the master branch:
commit d68876e738af587d0cf5c379b93051c3ea367e62
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sun Oct 24 01:54:14 2004 +0100

    Checkpointing
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-108)

diff --git a/ChangeLog b/ChangeLog
index f834458..5936b28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
 #
 
+2004-10-23 19:54:14 GMT	John Goerzen <jgoerzen at complete.org>	patch-108
+
+    Summary:
+      Checkpointing
+    Revision:
+      missingh--head--1.0--patch-108
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/Network.hs
+     libsrc/MissingH/Network/FTP/Client.hs
+     libsrc/MissingH/Network/FTP/Parser.hs
+
+
 2004-10-23 19:18:39 GMT	John Goerzen <jgoerzen at complete.org>	patch-107
 
     Summary:
diff --git a/libsrc/MissingH/Network.hs b/libsrc/MissingH/Network.hs
index c278b1a..2b7ccac 100644
--- a/libsrc/MissingH/Network.hs
+++ b/libsrc/MissingH/Network.hs
@@ -31,8 +31,22 @@ This module provides various helpful utilities for dealing with networking
 Written by John Goerzen, jgoerzen\@complete.org
 -}
 
-module MissingH.Network(
+module MissingH.Network(connectTCP, connectTCPAddr
                        )
 where
-
--- nothing yet
\ No newline at end of file
+import Network.Socket
+import Network.BSD
+import System.IO
+
+connectTCP :: HostName -> PortNumber -> IO Socket
+connectTCP host port = do
+                       he <- getHostByName host
+                       connectTCPAddr (SockAddrInet port (hostAddress he))
+
+connectTCPAddr :: SockAddr -> IO Socket
+connectTCPAddr addr = do
+                      proto <- getProtocolNumber "tcp"
+                      s <- socket AF_INET Stream proto
+                      connect s addr
+                      return s
+                      
diff --git a/libsrc/MissingH/Network/FTP/Client.hs b/libsrc/MissingH/Network/FTP/Client.hs
index 5f52f87..aa65571 100644
--- a/libsrc/MissingH/Network/FTP/Client.hs
+++ b/libsrc/MissingH/Network/FTP/Client.hs
@@ -61,11 +61,11 @@ import qualified Network
 import System.IO
 import System.IO.Unsafe
 import MissingH.Logging.Logger
-
+import MissingH.Network
+import MissingH.Str
 data FTPConnection = FTPConnection {readh :: IO String,
                                     writeh :: Handle,
                                     isPassive :: Bool}
-                   deriving Eq
 
 {-
 getresp h = do c <- hGetContents h
@@ -76,18 +76,6 @@ getresp h = do
             c <- (readh h)
             debugParseGoodReply c
 
-unexpectedresp m r = "Expected " ++ m ++ ", got " ++ (show r)
-
-isxresp desired (r, _) = r >= desired && r < (desired + 100)
-
-forcexresp desired r = if isxresp desired r
-                       then r
-                       else error ((unexpectedresp (show desired)) r)
-
-forceioresp :: Int -> FTPResult -> IO ()
-forceioresp desired r = if isxresp desired r
-                        then return ()
-                        else fail (unexpectedresp (show desired) r)
 
 logsend m = debugM "MissingH.Network.FTP.Client" ("FTP sent: " ++ m)
 sendcmd h c = do logsend c
@@ -113,10 +101,7 @@ connectTo h p =
     do
     updateGlobalLogger "MissingH.Network.FTP.Parser" (setLevel DEBUG)
     updateGlobalLogger "MissingH.Network.FTP.Client" (setLevel DEBUG)
-    proto <- getProtocolNumber "tcp"
-    he <- getHostByName h
-    s <- socket AF_INET Stream proto
-    connect s (SockAddrInet p (hostAddress he))
+    s <- connectTCP h p
     r <- socketToHandle s ReadMode
     hSetBuffering r LineBuffering
     w <- socketToHandle s WriteMode
@@ -166,10 +151,40 @@ connection object reflecting this) -}
 setPassive :: FTPConnection -> Bool -> FTPConnection            
 setPassive f b = f{isPassive = True}
 
-{- | Establishes a passive connection to the remote. -}
-
-makepasv :: FTPConnection -> 
-makspasv h =
+{- | Finds the addres sof the remote. -}
+makepasv :: FTPConnection -> IO SockAddr
+makepasv h =
     do
-    r <- sendcmd("PASV")
-    
\ No newline at end of file
+    r <- sendcmd h "PASV"
+    return (respToSockAddr r)
+
+{- | Establishes a connection to the remote. 
+
+FIXME: need support for rest
+-}
+ntransfercmd :: FTPConnection -> String -> IO (Handle, Maybe Integer)
+ntransfercmd h cmd =
+    let sock = if isPassive h
+               then do
+                    addr <- makepasv h
+                    connectTCPAddr addr
+               else fail "FIXME: No support for non-passive yet"
+        in do
+           s <- sock
+           newh <- socketToHandle s ReadWriteMode
+           r <- sendcmd h cmd
+           forceioresp 100 r
+           return (newh, Nothing)
+
+{- | Returns the socket part from calling 'ntransfercmd'. -}
+transfercmd :: FTPConnection -> String -> IO Handle
+transfercmd h cmd = do x <- ntransfercmd h cmd
+                       return (fst x)
+
+{- | Retrieves lines of data from the remote. -}
+retrlines :: FTPConnection -> String -> IO [String]
+retrlines h cmd = do
+              sendcmd h "TYPE A"
+              newh <- transfercmd h cmd
+              c <- hGetContents newh
+              return $ split "\r\n" c
diff --git a/libsrc/MissingH/Network/FTP/Parser.hs b/libsrc/MissingH/Network/FTP/Parser.hs
index e056ba1..2f31bb3 100644
--- a/libsrc/MissingH/Network/FTP/Parser.hs
+++ b/libsrc/MissingH/Network/FTP/Parser.hs
@@ -38,7 +38,11 @@ module MissingH.Network.FTP.Parser(parseReply, parseGoodReply,
                                    toPortString, fromPortString,
                                    debugParseGoodReply,
                                    respToSockAddr,
-                                   FTPResult)
+                                   FTPResult,
+                                  -- * Utilities
+                                  unexpectedresp, isxresp,
+                                  forcexresp,
+                                  forceioresp)
 where
 
 import Text.ParserCombinators.Parsec
@@ -50,6 +54,7 @@ import MissingH.Logging.Logger
 import Network.Socket(SockAddr(..), PortNumber(..))
 import System.IO(Handle, hGetContents)
 import System.IO.Unsafe
+import Text.Regex
 type FTPResult = (Int, [String])
 
 -- import Control.Exception(Exception(PatternMatchFail), throw)
@@ -61,6 +66,20 @@ logit m = debugM "MissingH.Network.FTP.Parser" ("FTP received: " ++ m)
 -- Utilities
 ----------------------------------------------------------------------
 
+unexpectedresp m r = "Expected " ++ m ++ ", got " ++ (show r)
+
+isxresp desired (r, _) = r >= desired && r < (desired + 100)
+
+forcexresp desired r = if isxresp desired r
+                       then r
+                       else error ((unexpectedresp (show desired)) r)
+
+forceioresp :: Int -> FTPResult -> IO ()
+forceioresp desired r = if isxresp desired r
+                        then return ()
+                        else fail (unexpectedresp (show desired) r)
+
+
 crlf :: Parser String
 crlf = string "\r\n" <?> "CRLF"
 
@@ -206,7 +225,16 @@ fromPortString instr =
         hostbytes = map read (take 4 inbytes)
         portbytes = map read (drop 4 inbytes)
         in
-        SockAddrInet (fromBytes portbytes) (fromBytes hostbytes)
+        SockAddrInet (fromInteger (fromBytes portbytes)) (fromBytes hostbytes)
 
+respToSockAddrRe = mkRegex("([0-9]+,){5}[0-9]+")
 -- | Converts a response code to a socket address
 respToSockAddr :: FTPResult -> SockAddr
+respToSockAddr f =
+    let r = forcexresp 200 f
+        in
+        case matchRegexAll respToSockAddrRe (head (snd r)) of
+             Nothing -> error ("Could not find remote endpoint in " ++ (show r))
+             Just (_, x, _, _) -> fromPortString x
+
+    
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list