curl 1.3.3 → 1.3.4
raw patch · 13 files changed
+500/−88 lines, 13 filesdep +bytestringsetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: bytestring
API changes (from Hackage documentation)
- Network.Curl: data CurlResponse
+ Network.Curl: class CurlBuffer bufferTy
+ Network.Curl: class CurlHeader headerTy
+ Network.Curl: curlGetResponse_ :: (CurlHeader hdr, CurlBuffer ty) => URLString -> [CurlOption] -> IO (CurlResponse_ hdr ty)
+ Network.Curl: curlGetString_ :: (CurlBuffer ty) => URLString -> [CurlOption] -> IO (CurlCode, ty)
+ Network.Curl: curlHead_ :: (CurlHeader headers) => URLString -> [CurlOption] -> IO (String, headers)
+ Network.Curl: data CurlResponse_ headerTy bodyTy
+ Network.Curl: do_curl_ :: (CurlHeader headerTy, CurlBuffer bodyTy) => Curl -> URLString -> [CurlOption] -> IO (CurlResponse_ headerTy bodyTy)
+ Network.Curl: gatherOutput_ :: (CStringLen -> IO ()) -> WriteFunction
+ Network.Curl: instance CurlBuffer ByteString
+ Network.Curl: instance CurlBuffer String
+ Network.Curl: instance CurlBuffer [ByteString]
+ Network.Curl: instance CurlHeader [(String, String)]
+ Network.Curl: newIncoming :: (CurlBuffer bufferTy) => IO (IO bufferTy, CStringLen -> IO ())
+ Network.Curl: newIncomingHeader :: (CurlHeader headerTy) => IO (IO (String, headerTy), CStringLen -> IO ())
+ Network.Curl: parseHeader :: String -> (String, String)
+ Network.Curl: perform_with_response_ :: (CurlHeader headerTy, CurlBuffer bodyTy) => Curl -> IO (CurlResponse_ headerTy bodyTy)
+ Network.Curl: type CurlResponse = CurlResponse_ [(String, String)] String
+ Network.Curl.Code: CurlAgain :: CurlCode
+ Network.Curl.Code: CurlSSLCRLBadFile :: CurlCode
+ Network.Curl.Code: CurlSSLIssuerError :: CurlCode
+ Network.Curl.Easy: curl_version_number :: IO Int
+ Network.Curl.Easy: curl_version_string :: IO String
+ Network.Curl.Opts: CurlAddressScope :: Long -> CurlOption
+ Network.Curl.Opts: CurlCRLFile :: FilePath -> CurlOption
+ Network.Curl.Opts: CurlCertInfo :: Long -> CurlOption
+ Network.Curl.Opts: CurlCopyPostFields :: Bool -> CurlOption
+ Network.Curl.Opts: CurlIssuerCert :: FilePath -> CurlOption
+ Network.Curl.Opts: CurlNewDirectoryPerms :: Long -> CurlOption
+ Network.Curl.Opts: CurlNewFilePerms :: Long -> CurlOption
+ Network.Curl.Opts: CurlPostRedirect :: Bool -> CurlOption
+ Network.Curl.Opts: CurlProxyPassword :: String -> CurlOption
+ Network.Curl.Opts: CurlProxyTransferMode :: Long -> CurlOption
+ Network.Curl.Opts: CurlProxyUser :: String -> CurlOption
+ Network.Curl.Opts: CurlSSHHostPublicKeyMD5 :: String -> CurlOption
+ Network.Curl.Opts: CurlUserName :: String -> CurlOption
+ Network.Curl.Opts: CurlUserPassword :: String -> CurlOption
+ Network.Curl.Opts: instance Enum HttpAuth
+ Network.Curl.Opts: instance Show CurlOption
+ Network.Curl.Opts: instance Show HttpAuth
+ Network.Curl.Opts: instance Show HttpVersion
+ Network.Curl.Opts: instance Show NetRcOption
+ Network.Curl.Opts: instance Show SSHAuthType
+ Network.Curl.Opts: instance Show TimeCond
+ Network.Curl.Opts: showCurlOption :: CurlOption -> String
+ Network.Curl.Post: instance Show Content
+ Network.Curl.Post: instance Show HttpPost
- Network.Curl: CurlResponse :: CurlCode -> Int -> String -> [(String, String)] -> String -> (Info -> IO InfoValue) -> CurlResponse
+ Network.Curl: CurlResponse :: CurlCode -> Int -> String -> headerTy -> bodyTy -> (Info -> IO InfoValue) -> CurlResponse_ headerTy bodyTy
- Network.Curl: perform_with_response :: Curl -> IO CurlResponse
+ Network.Curl: perform_with_response :: (CurlHeader hdrTy, CurlBuffer bufTy) => Curl -> IO (CurlResponse_ hdrTy bufTy)
- Network.Curl: respBody :: CurlResponse -> String
+ Network.Curl: respBody :: CurlResponse_ headerTy bodyTy -> bodyTy
- Network.Curl: respCurlCode :: CurlResponse -> CurlCode
+ Network.Curl: respCurlCode :: CurlResponse_ headerTy bodyTy -> CurlCode
- Network.Curl: respGetInfo :: CurlResponse -> (Info -> IO InfoValue)
+ Network.Curl: respGetInfo :: CurlResponse_ headerTy bodyTy -> (Info -> IO InfoValue)
- Network.Curl: respHeaders :: CurlResponse -> [(String, String)]
+ Network.Curl: respHeaders :: CurlResponse_ headerTy bodyTy -> headerTy
- Network.Curl: respStatus :: CurlResponse -> Int
+ Network.Curl: respStatus :: CurlResponse_ headerTy bodyTy -> Int
- Network.Curl: respStatusLine :: CurlResponse -> String
+ Network.Curl: respStatusLine :: CurlResponse_ headerTy bodyTy -> String
Files
- CHANGES +17/−0
- LICENSE +1/−1
- Network/Curl.hs +193/−58
- Network/Curl/Code.hs +8/−4
- Network/Curl/Debug.hs +2/−2
- Network/Curl/Easy.hs +24/−4
- Network/Curl/Info.hs +4/−3
- Network/Curl/Opts.hs +200/−5
- Network/Curl/Post.hs +6/−4
- Network/Curl/Types.hs +3/−3
- Setup.hs +1/−1
- curl.cabal +6/−3
- curlc.c +35/−0
+ CHANGES view
@@ -0,0 +1,17 @@+Version 1.3.4: released 2009-01-18; changes from 1.3.3++ * Overloaded Network.Curl operations over response representation+ of payloads and headers. Controlled via CurlBuffer and CurlHeader+ classes. New actions:+ - curlGetString_, curlGetResponse_, + perform_with_response_, do_curl_, curlHead_+ + * Provided ByteString instances (strict and lazy)+ * No modification in calling interface to existing exports,+ so backwards compatible.+ * Added Show instance for Network.Curl.Opts.CurlOption+ * curl_version_string, curl_version_number now gives you access+ to version info of underlying lib you _compiled_ the package with.+ * Sync'ed wrt libcurl-7.19.2, so bunch of new options added to+ Network.Curl.Opts. Use version functions to determine if they+ are supported though.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2007-8 Galois Inc.+Copyright (c) 2007-2009 Galois Inc. All rights reserved.
Network/Curl.hs view
@@ -1,10 +1,11 @@+{-# OPTIONS_GHC -XTypeSynonymInstances -XFlexibleInstances #-} -------------------------------------------------------------------- -- |--- Module : Curl--- Copyright : (c) Galois Inc 2007-8+-- Module : Network.Curl+-- Copyright : (c) 2007-2009, Galois Inc -- License : BSD3 ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --@@ -33,15 +34,24 @@ , withCurlDo -- :: IO a -> IO a , setopts -- :: Curl -> [CurlOption] -> IO () - , CurlResponse(..)+ , CurlResponse_(..)+ , CurlResponse -- get resources and assoc. metadata.- , curlGet -- :: URLString -> [CurlOption] -> IO ()- , curlGetString -- :: URLString -> [CurlOption] -> IO (CurlCode, String)- , curlGetResponse -- :: URLString -> [CurlOption] -> IO CurlResponse+ , curlGet -- :: URLString -> [CurlOption] -> IO ()+ , curlGetString -- :: URLString -> [CurlOption] -> IO (CurlCode, String)+ , curlGetResponse -- :: URLString -> [CurlOption] -> IO CurlResponse , perform_with_response -- :: Curl -> IO CurlResponse- , do_curl+ , do_curl -- :: Curl -> URLString -> [CurlOption] -> IO CurlResponse + , curlGetString_ -- :: CurlBuffer ty => URLString -> [CurlOption] -> IO (CurlCode, ty)+ , curlGetResponse_ -- :: URLString -> [CurlOption] -> IO (CurlResponse_ a b)+ , perform_with_response_ -- :: Curl -> IO (CurlResponse_ a b)+ , do_curl_ -- :: Curl -> URLString -> [CurlOption] -> IO (CurlResponse_ a b)+ , curlHead_ -- :: URLString+ -- -> [CurlOption]+ -- -> IO (String,ty)+ -- probing for gold.. , curlHead -- :: URLString -- -> [CurlOption]@@ -61,11 +71,18 @@ , ignoreOutput -- :: WriteFunction , gatherOutput -- :: IORef [String] -> WriteFunction + , gatherOutput_ -- :: (CStringLen -> IO ()) -> WriteFunction+ , CurlBuffer(..)+ , CurlHeader(..)+ , method_GET -- :: [CurlOption] , method_HEAD -- :: [CurlOption] , method_POST -- :: [CurlOption] - , parseStatusNHeaders, concRev+ , parseStatusNHeaders+ , parseHeader+ -- ToDo: get rid of (pretty sure I can already...)+ , concRev ) where import Network.Curl.Opts@@ -79,21 +96,67 @@ import Data.IORef import Data.List(isPrefixOf) import System.IO+import Control.Exception ( finally ) -{- pass along the action you want to perform during its lifetime.-{-# OBSOLETE #-}-withCurl :: (Curl -> IO a) -> IO a-withCurl act = act =<< initialize--}+import Data.ByteString ( ByteString, packCStringLen )+import qualified Data.ByteString as BS ( concat ) +import qualified Data.ByteString.Lazy as LazyBS ( ByteString, fromChunks )++-- | The @CurlBuffer@ class encodes the representation+-- of response buffers, allowing you to provide your+-- own app-specific buffer reps to be used..or use+-- one of the standard instances (String and ByteStrings.)+--+class CurlBuffer bufferTy where+ newIncoming :: IO (IO bufferTy, CStringLen -> IO ())+ ++-- | The @CurlHeader@ class encodes the representation+-- of response headers. Similar to 'CurlBuffer'.+--+class CurlHeader headerTy where+ newIncomingHeader :: IO (IO (String{-status-},headerTy), CStringLen -> IO ())++instance CurlHeader [(String,String)] where+ newIncomingHeader = do+ ref <- newIORef []+ let readFinalHeader = do+ hss <- readIORef ref+ let (st,hs) = parseStatusNHeaders (concRev [] hss)+ return (st,hs)+ return (readFinalHeader, \ v -> peekCStringLen v >>= \ x -> modifyIORef ref (x:))++instance CurlBuffer String where+ newIncoming = do+ ref <- newIORef []+ let readFinal = readIORef ref >>= return . concat . reverse+ return (readFinal, \ v -> peekCStringLen v >>= \ x -> modifyIORef ref (x:))++instance CurlBuffer ByteString where+ newIncoming = do+ ref <- newIORef []+ let readFinal = readIORef ref >>= return . BS.concat . reverse+ return (readFinal, \ v -> packCStringLen v >>= \ x -> modifyIORef ref (x:))++instance CurlBuffer [ByteString] where+ newIncoming = do+ ref <- newIORef []+ let readFinal = readIORef ref >>= return . reverse+ return (readFinal, \ v -> packCStringLen v >>= \ x -> modifyIORef ref (x:))++instance CurlBuffer LazyBS.ByteString where+ newIncoming = do+ ref <- newIORef []+ let readFinal = readIORef ref >>= return . LazyBS.fromChunks . reverse+ return (readFinal, \ v -> packCStringLen v >>= \ x -> modifyIORef ref (x:))+ -- | Should be used once to wrap all uses of libcurl. -- WARNING: the argument should not return before it -- is completely done with curl (e.g., no forking or lazy returns) withCurlDo :: IO a -> IO a withCurlDo m = do curl_global_init 3 -- initialize everything- a <- m- curl_global_cleanup- return a+ finally m curl_global_cleanup -- | Set a list of options on a Curl handle. setopts :: Curl -> [CurlOption] -> IO ()@@ -149,68 +212,101 @@ lss <- readIORef ref return (rc, concat $ reverse lss) --- | 'CurlResponse' is a record type encoding all the information+curlGetString_ :: (CurlBuffer ty)+ => URLString+ -> [CurlOption]+ -> IO (CurlCode, ty)+curlGetString_ url opts = initialize >>= \ h -> do+ (finalBody, gatherBody) <- newIncoming+ setopt h (CurlFailOnError True)+ setDefaultSSLOpts h url+ setopt h (CurlURL url)+ setopt h (CurlWriteFunction (gatherOutput_ gatherBody))+ mapM_ (setopt h) opts+ rc <- perform h+ bs <- finalBody+ return (rc, bs)++type CurlResponse = CurlResponse_ [(String,String)] String++-- | 'CurlResponse_' is a record type encoding all the information -- embodied in a response to your Curl request. Currently only used -- to gather up the results of doing a GET in 'curlGetResponse'.-data CurlResponse+data CurlResponse_ headerTy bodyTy = CurlResponse { respCurlCode :: CurlCode , respStatus :: Int , respStatusLine :: String- , respHeaders :: [(String,String)]- , respBody :: String+ , respHeaders :: headerTy+ , respBody :: bodyTy , respGetInfo :: (Info -> IO InfoValue) } --- | 'curlGetResponse' performs a GET, returning all the info+-- | @curlGetResponse url opts@ performs a @GET@, returning all the info -- it can lay its hands on in the response, a value of type 'CurlResponse'.-curlGetResponse :: URLString- -> [CurlOption]- -> IO CurlResponse-curlGetResponse url opts = do+-- The representation of the body is overloaded+curlGetResponse_ :: (CurlHeader hdr, CurlBuffer ty)+ => URLString+ -> [CurlOption]+ -> IO (CurlResponse_ hdr ty)+curlGetResponse_ url opts = do h <- initialize- body_ref <- newIORef []- hdr_ref <- newIORef [] -- Note: later options may (and should, probably) override these defaults. setopt h (CurlFailOnError True) setDefaultSSLOpts h url setopt h (CurlURL url)- setopt h (CurlWriteFunction (gatherOutput body_ref))- setopt h (CurlHeaderFunction (gatherOutput hdr_ref)) mapM_ (setopt h) opts -- note that users cannot over-write the body and header handler -- which makes sense because otherwise we will return a bogus reposnse.- perform_with_response h+ perform_with_response_ h +{-# DEPRECATED curlGetResponse "Switch to using curlGetResponse_" #-}+curlGetResponse :: URLString+ -> [CurlOption]+ -> IO CurlResponse+curlGetResponse url opts = curlGetResponse_ url opts +-- | Perform the actions already specified on the handle.+-- Collects useful information about the returned message.+-- Note that this function sets the+-- 'CurlWriteFunction' and 'CurlHeaderFunction' options.+perform_with_response :: (CurlHeader hdrTy, CurlBuffer bufTy)+ => Curl+ -> IO (CurlResponse_ hdrTy bufTy)+perform_with_response h = perform_with_response_ h +{-# DEPRECATED perform_with_response "Consider switching to perform_with_response_" #-}+ -- | Perform the actions already specified on the handle. -- Collects useful information about the returned message. -- Note that this function sets the -- 'CurlWriteFunction' and 'CurlHeaderFunction' options.-perform_with_response :: Curl -> IO CurlResponse-perform_with_response h =- do body_ref <- newIORef []- hdr_ref <- newIORef []+-- The returned payload is overloaded over the representation of+-- both headers and body via the 'CurlResponse_' type.+perform_with_response_ :: (CurlHeader headerTy, CurlBuffer bodyTy)+ => Curl+ -> IO (CurlResponse_ headerTy bodyTy)+perform_with_response_ h = do+ (finalHeader, gatherHeader) <- newIncomingHeader+ (finalBody, gatherBody) <- newIncoming - -- Insted of allocating a swparate handler for each+ -- Instead of allocating a separate handler for each -- request we could just set this options one and forall -- and just clear the IORefs. - setopt h (CurlWriteFunction (gatherOutput body_ref))- setopt h (CurlHeaderFunction (gatherOutput hdr_ref))- rc <- perform h- bss <- readIORef body_ref- hss <- readIORef hdr_ref- rspCode <- getResponseCode h- let (st,hs) = parseStatusNHeaders (concRev [] hss)- return CurlResponse+ setopt h (CurlWriteFunction (gatherOutput_ gatherBody))+ setopt h (CurlHeaderFunction (gatherOutput_ gatherHeader))+ rc <- perform h+ rspCode <- getResponseCode h+ (st,hs) <- finalHeader+ bs <- finalBody+ return CurlResponse { respCurlCode = rc , respStatus = rspCode , respStatusLine = st , respHeaders = hs- , respBody = concRev [] bss+ , respBody = bs -- note: we're holding onto the handle here.. -- note: with this interface this is not neccessary. , respGetInfo = getInfo h@@ -220,13 +316,22 @@ -- The provided URL will overwride any 'CurlURL' options that -- are provided in the list of options. See also: 'perform_with_response'. do_curl :: Curl -> URLString -> [CurlOption] -> IO CurlResponse-do_curl h url opts =- do setDefaultSSLOpts h url- setopts h opts- setopt h (CurlURL url)- perform_with_response h+do_curl h url opts = do_curl_ h url opts +{-# DEPRECATED do_curl "Consider switching to do_curl_" #-} +do_curl_ :: (CurlHeader headerTy, CurlBuffer bodyTy)+ => Curl+ -> URLString+ -> [CurlOption]+ -> IO (CurlResponse_ headerTy bodyTy)+do_curl_ h url opts = do+ setDefaultSSLOpts h url+ setopts h opts+ setopt h (CurlURL url)+ perform_with_response_ h++ -- | Get the headers associated with a particular URL. -- Returns the status line and the key-value pairs for the headers. curlHead :: URLString -> [CurlOption] -> IO (String,[(String,String)])@@ -241,6 +346,25 @@ lss <- readIORef ref return (parseStatusNHeaders (concRev [] lss)) +-- | Get the headers associated with a particular URL.+-- Returns the status line and the key-value pairs for the headers.+curlHead_ :: (CurlHeader headers)+ => URLString+ -> [CurlOption]+ -> IO (String, headers)+curlHead_ url opts = initialize >>= \ h -> do+ (finalHeader, gatherHeader) <- newIncomingHeader+-- setopt h (CurlVerbose True)+ setopt h (CurlURL url)+ setopt h (CurlNoBody True)+ mapM_ (setopt h) opts+ setopt h (CurlHeaderFunction (gatherOutput_ gatherHeader))+ perform h+ finalHeader+++-- utils+ concRev :: [a] -> [[a]] -> [a] concRev acc [] = acc concRev acc (x:xs) = concRev (x++acc) xs@@ -257,11 +381,12 @@ addLine "" ls = ls addLine l ls = (reverse l) : ls-- parseHeader xs = - case break (':' ==) xs of- (as,_:bs) -> (as, bs)- (as,_) -> (as,"")+ +parseHeader :: String -> (String,String)+parseHeader xs = + case break (':' ==) xs of+ (as,_:bs) -> (as, bs)+ (as,_) -> (as,"") -- | 'curlMultiPost' perform a multi-part POST submission. curlMultiPost :: URLString -> [CurlOption] -> [HttpPost] -> IO ()@@ -286,7 +411,7 @@ return () -- Use 'callbackWriter' instead.-{-# OBSOLETE #-}+{-# DEPRECATED #-} easyWriter :: (String -> IO ()) -> WriteFunction easyWriter = callbackWriter @@ -297,6 +422,13 @@ f =<< peekCStringLen (pBuf,fromIntegral bytes) return bytes +-- | Imports data into the Haskell world and invokes the callback.+callbackWriter_ :: (CStringLen -> IO ()) -> WriteFunction+callbackWriter_ f pBuf sz szI _ = do+ do let bytes = sz * szI + f (pBuf,fromIntegral bytes)+ return bytes+ -- | The output of Curl is ignored. This function -- does not marshall data into Haskell. ignoreOutput :: WriteFunction@@ -304,8 +436,11 @@ -- | Add chunks of data to an IORef as they arrive. gatherOutput :: IORef [String] -> WriteFunction-gatherOutput r = callbackWriter $ \xs -> do xss <- readIORef r- writeIORef r (xs:xss)+gatherOutput r = callbackWriter (\ v -> modifyIORef r (v:))++-- | Add chunks of data to an IORef as they arrive.+gatherOutput_ :: (CStringLen -> IO ()) -> WriteFunction+gatherOutput_ f = callbackWriter_ f getResponseCode :: Curl -> IO Int getResponseCode c = do
Network/Curl/Code.hs view
@@ -1,11 +1,12 @@-{-# OPTIONS -fffi -fvia-C -#include "curl/curl.h" #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# OPTIONS -fvia-C -#include "curl/curl.h" #-} -------------------------------------------------------------------- -- |--- Module : Curl.Code--- Copyright : (c) Galois Inc 2007+-- Module : Network.Curl.Code+-- Copyright : (c) Galois Inc 2007-2009 -- License : BSD3 ----- Maintainer: sof@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --@@ -99,6 +100,9 @@ | CurlRemoveFileNotFound | CurlSSH | CurlSSLShutdownFailed+ | CurlAgain+ | CurlSSLCRLBadFile+ | CurlSSLIssuerError deriving ( Eq, Show, Enum ) toCode :: CInt -> CurlCode
Network/Curl/Debug.hs view
@@ -1,10 +1,10 @@ -------------------------------------------------------------------- -- | -- Module : Network.Curl.Debug--- Copyright : (c) Galois, Inc. 2008+-- Copyright : (c) Galois, Inc. 2008-2009 -- License : BSD3 ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: --
Network/Curl/Easy.hs view
@@ -1,11 +1,12 @@-{-# OPTIONS -fffi -fvia-C -#include "curl/curl.h" #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# OPTIONS -fvia-C -#include "curl/curl.h" #-} -------------------------------------------------------------------- -- |--- Module : Curl.Easy--- Copyright : (c) Galois Inc 2007+-- Module : Network.Curl.Easy+-- Copyright : (c) Galois Inc 2007-2009 -- License : ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --@@ -24,6 +25,9 @@ , curl_global_init -- :: CInt -> IO CurlCode , curl_global_cleanup -- :: IO ()+ + , curl_version_number -- :: IO Int+ , curl_version_string -- :: IO String ) where import Network.Curl.Types@@ -146,8 +150,24 @@ curl_global_init :: CInt -> IO CurlCode curl_global_init v = liftM toCode $ curl_global_init_prim v +curl_version_number :: IO Int+curl_version_number = do+ x <- curl_version_num + return (fromIntegral x)+ +curl_version_string :: IO String+curl_version_string = do+ cs <- curl_version_str+ peekCString cs+ -- FFI decls ++foreign import ccall+ "curl_version_num" curl_version_num :: IO CInt++foreign import ccall+ "curl_version_str" curl_version_str :: IO CString foreign import ccall "curl/easy.h curl_global_init" curl_global_init_prim :: CInt -> IO CInt
Network/Curl/Info.hs view
@@ -1,11 +1,12 @@-{-# OPTIONS -fffi -fvia-C -#include "curl/curl.h" #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# OPTIONS -fvia-C -#include "curl/curl.h" #-} -------------------------------------------------------------------- -- | -- Module : Network.Curl.Info--- Copyright : (c) Galois Inc 2007+-- Copyright : (c) 2007-2009, Galois Inc -- License : BSD3 ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --
Network/Curl/Opts.hs view
@@ -1,10 +1,10 @@ -------------------------------------------------------------------- -- | -- Module : Network.Curl.Opts--- Copyright : (c) Galois Inc 2007+-- Copyright : (c) Galois Inc 2007-2009 -- License : BSD3 ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --@@ -164,25 +164,46 @@ | CurlConnectTimeoutMS Long -- ^ Max number of milliseconds that a connection attempt may take to complete. | CurlHttpTransferDecoding Bool -- ^ Disable transfer decoding; if disabled, curl will turn off chunking. | CurlHttpContentDecoding Bool -- ^ Disable content decoding, getting the raw bits.+ -- sync'ed wrt 7.19.2+ | CurlNewFilePerms Long+ | CurlNewDirectoryPerms Long+ | CurlPostRedirect Bool+ -- no support for open socket callbacks/function overrides.+ | CurlSSHHostPublicKeyMD5 String+ | CurlCopyPostFields Bool+ | CurlProxyTransferMode Long+ -- no support for seeking in the input stream.+ | CurlCRLFile FilePath+ | CurlIssuerCert FilePath+ | CurlAddressScope Long+ | CurlCertInfo Long+ | CurlUserName String+ | CurlUserPassword String+ | CurlProxyUser String+ | CurlProxyPassword String+ +instance Show CurlOption where+ show x = showCurlOption x+ data HttpVersion = HttpVersionNone | HttpVersion10 | HttpVersion11- deriving ( Enum )+ deriving ( Enum,Show ) data TimeCond = TimeCondNone | TimeCondIfModSince | TimeCondIfUnmodSince | TimeCondLastMode- deriving ( Enum )+ deriving ( Enum, Show ) data NetRcOption = NetRcIgnored | NetRcOptional | NetRcRequired- deriving ( Enum )+ deriving ( Enum, Show ) data HttpAuth = HttpAuthNone@@ -192,6 +213,7 @@ | HttpAuthNTLM | HttpAuthAny | HttpAuthAnySafe+ deriving ( Enum, Show ) toHttpAuthMask :: [HttpAuth] -> Long toHttpAuthMask [] = 0@@ -214,6 +236,7 @@ | SSHAuthPassword | SSHAuthHost | SSHAuthKeyboard+ deriving ( Show ) toSSHAuthMask :: [SSHAuthType] -> Long@@ -458,6 +481,20 @@ CurlConnectTimeoutMS x -> u_long um (l 156) x CurlHttpTransferDecoding x -> u_bool um (l 157) x CurlHttpContentDecoding x -> u_bool um (l 158) x+ CurlNewFilePerms x -> u_long um (l 159) x+ CurlNewDirectoryPerms x -> u_long um (l 160) x+ CurlPostRedirect x -> u_bool um (l 161) x+ CurlSSHHostPublicKeyMD5 x -> u_string um (l 162) x+ CurlCopyPostFields x -> u_bool um (l 165) x+ CurlProxyTransferMode x -> u_long um (l 166) x+ CurlCRLFile x -> u_string um (l 169) x+ CurlIssuerCert x -> u_string um (l 170) x+ CurlAddressScope x -> u_long um (l 171) x+ CurlCertInfo x -> u_long um (l 172) x+ CurlUserName x -> u_string um (l 173) x+ CurlUserPassword x -> u_string um (l 174) x+ CurlProxyUser x -> u_string um (l 175) x+ CurlProxyPassword x -> u_string um (l 176) x data Unmarshaller a = Unmarshaller@@ -511,3 +548,161 @@ u_cptr :: Unmarshaller a -> Int -> Ptr CChar -> IO a u_cptr um x p = u_ptr um x (castPtr p)++showCurlOption :: CurlOption -> String+showCurlOption o = + case o of+ CurlFileObj p -> "CurlFileObj " ++ show p+ CurlURL u -> "CurlURL " ++ show u+ CurlPort p -> "CurlPort " ++ show p+ CurlProxy s -> "CurlProxy " ++ show s+ CurlUserPwd p -> "CurlUserPwd " ++ show p+ CurlProxyUserPwd p -> "CurlProxyUserPwd " ++ show p+ CurlRange p -> "CurlRange " ++ show p+ CurlInFile p -> "CurlInFile " ++ show p+ CurlErrorBuffer p -> "CurlErrorBuffer " ++ show p+ CurlWriteFunction{} -> "CurlWriteFunction <fun>"+ CurlReadFunction{} -> "CurlReadFunction <fun>"+ CurlTimeout l -> "CurlTimeout " ++ show l+ CurlInFileSize l -> "CurlInFileSize " ++ show l+ CurlPostFields p -> "CurlPostFields " ++ show p+ CurlReferer p -> "CurlReferer " ++ show p+ CurlFtpPort p -> "CurlFtpPort " ++ show p+ CurlUserAgent p -> "CurlUserAgent " ++ show p+ CurlLowSpeed p -> "CurlLowSpeed " ++ show p+ CurlLowSpeedTime p -> "CurlLowSpeedTime " ++ show p+ CurlResumeFrom p -> "CurlResumeFrom " ++ show p+ CurlCookie p -> "CurlCookie " ++ show p+ CurlHttpHeaders p -> "CurlHttpHeaders " ++ show p+ CurlHttpPost p -> "CurlHttpPost " ++ show p+ CurlSSLCert p -> "CurlSSLCert " ++ show p+ CurlSSLPassword p -> "CurlSSLPassword " ++ show p+ CurlSSLKeyPassword p -> "CurlSSLKeyPassword " ++ show p+ CurlCRLF p -> "CurlCRLF " ++ show p+ CurlQuote p -> "CurlQuote " ++ show p+ CurlWriteHeader p -> "CurlWriteHeader " ++ show p+ CurlCookieFile p -> "CurlCookieFile " ++ show p+ CurlSSLVersion p -> "CurlSSLVersion " ++ show p+ CurlTimeCondition p -> "CurlTimeCondition " ++ show p+ CurlTimeValue p -> "CurlTimeValue " ++ show p+ CurlCustomRequest p -> "CurlCustomRequest " ++ show p+ CurlPostQuote p -> "CurlPostQuote " ++ show p+ CurlWriteInfo p -> "CurlWriteInfo " ++ show p+ CurlVerbose p -> "CurlVerbose " ++ show p+ CurlHeader p -> "CurlHeader " ++ show p+ CurlNoProgress p -> "CurlNoProgress " ++ show p+ CurlNoBody p -> "CurlNoBody " ++ show p+ CurlFailOnError p -> "CurlFailOnError " ++ show p+ CurlUpload p -> "CurlUpload " ++ show p+ CurlPost p -> "CurlPost " ++ show p+ CurlFtpListOnly p -> "CurlFtpListOnly " ++ show p+ CurlFtpAppend p -> "CurlFtpAppend " ++ show p+ CurlUseNetRc p -> "CurlUseNetRc " ++ show p+ CurlFollowLocation p -> "CurlFollowLocation " ++ show p+ CurlTransferTextASCII p -> "CurlTransferTextASCII " ++ show p+ CurlPut p -> "CurlPut " ++ show p+ CurlProgressFunction{} -> "CurlProgressFunction <fun>"+ CurlProgressData p -> "CurlProgressData " ++ show p+ CurlAutoReferer p -> "CurlAutoReferer " ++ show p+ CurlProxyPort p -> "CurlProxyPort " ++ show p+ CurlPostFieldSize p -> "CurlPostFieldSize " ++ show p+ CurlHttpProxyTunnel p -> "CurlHttpProxyTunnel " ++ show p+ CurlInterface p -> "CurlInterface " ++ show p+ CurlKrb4Level p -> "CurlKrb4Level " ++ show p+ CurlSSLVerifyPeer p -> "CurlSSLVerifyPeer " ++ show p+ CurlCAInfo p -> "CurlCAInfo " ++ show p+ CurlMaxRedirs p -> "CurlMaxRedirs " ++ show p+ CurlFiletime p -> "CurlFiletime " ++ show p+ CurlTelnetOptions p -> "CurlTelnetOptions " ++ show p+ CurlMaxConnects p -> "CurlMaxConnects " ++ show p+ CurlClosePolicy p -> "CurlClosePolicy " ++ show p+ CurlFreshConnect p -> "CurlFreshConnect " ++ show p+ CurlForbidReuse p -> "CurlForbidReuse " ++ show p+ CurlRandomFile p -> "CurlRandomFile " ++ show p+ CurlEgdSocket p -> "CurlEgdSocket " ++ show p+ CurlConnectTimeout p -> "CurlConnectTimeout " ++ show p+ CurlHeaderFunction{} -> "CurlHeaderFunction <fun>"+ CurlHttpGet p -> "CurlHttpGet " ++ show p+ CurlSSLVerifyHost p -> "CurlSSLVerifyHost " ++ show p+ CurlCookieJar p -> "CurlCookieJar " ++ show p+ CurlSSLCipherList p -> "CurlSSLCipherList " ++ show p+ CurlHttpVersion p -> "CurlHttpVersion " ++ show p+ CurlFtpUseEPSV p -> "CurlFtpUseEPSV " ++ show p+ CurlSSLCertType p -> "CurlSSLCertType " ++ show p+ CurlSSLKey p -> "CurlSSLKey " ++ show p+ CurlSSLKeyType p -> "CurlSSLKeyType " ++ show p+ CurlSSLEngine p -> "CurlSSLEngine " ++ show p+ CurlSSLEngineDefault-> "CurlSSLEngineDefault"+ CurlDNSUseGlobalCache p -> "CurlDNSUseGlobalCache " ++ show p+ CurlDNSCacheTimeout p -> "CurlDNSCacheTimeout " ++ show p+ CurlPreQuote p -> "CurlPreQuote " ++ show p+ CurlDebugFunction{} -> "CurlDebugFunction <fun>"+ CurlDebugData p -> "CurlDebugData " ++ show p+ CurlCookieSession p -> "CurlCookieSession " ++ show p+ CurlCAPath p -> "CurlCAPath " ++ show p+ CurlBufferSize p -> "CurlBufferSize " ++ show p+ CurlNoSignal p -> "CurlNoSignal " ++ show p+ CurlShare p -> "CurlShare " ++ show p+ CurlProxyType p -> "CurlProxyType " ++ show p+ CurlEncoding p -> "CurlEncoding " ++ show p+ CurlPrivate p -> "CurlPrivate " ++ show p+ CurlHttp200Aliases p -> "CurlHttp200Aliases " ++ show p+ CurlUnrestrictedAuth p -> "CurlUnrestrictedAuth " ++ show p+ CurlFtppUseEPRT p -> "CurlFtppUseEPRT " ++ show p+ CurlHttpAuth p -> "CurlHttpAuth " ++ show p+ CurlSSLCtxFunction{} -> "CurlSSLCtxFunction <fun>"+ CurlSSLCtxData p -> "CurlSSLCtxData " ++ show p+ CurlFtpCreateMissingDirs p -> "CurlFtpCreateMissingDirs " ++ show p+ CurlProxyAuth p -> "CurlProxyAuth " ++ show p+ CurlFtpResponseTimeout p -> "CurlFtpResponseTimeout " ++ show p+ CurlIPResolve p -> "CurlIPResolve " ++ show p+ CurlMaxFileSize p -> "CurlMaxFileSize " ++ show p+ CurlInFileSizeLarge p -> "CurlInFileSizeLarge " ++ show p+ CurlResumeFromLarge p -> "CurlResumeFromLarge " ++ show p+ CurlMaxFileSizeLarge p -> "CurlMaxFileSizeLarge " ++ show p+ CurlNetrcFile p -> "CurlNetrcFile " ++ show p+ CurlFtpSSL p -> "CurlFtpSSL " ++ show p+ CurlPostFieldSizeLarge p -> "CurlPostFieldSizeLarge " ++ show p+ CurlTCPNoDelay p -> "CurlTCPNoDelay " ++ show p+ CurlFtpSSLAuth p -> "CurlFtpSSLAuth " ++ show p+ CurlIOCTLFunction p -> "CurlIOCTLFunction " ++ show p+ CurlIOCTLData p -> "CurlIOCTLData " ++ show p+ CurlFtpAccount p -> "CurlFtpAccount " ++ show p+ CurlCookieList p -> "CurlCookieList " ++ show p+ CurlIgnoreContentLength p -> "CurlIgnoreContentLength " ++ show p+ CurlFtpSkipPASVIP p -> "CurlFtpSkipPASVIP " ++ show p+ CurlFtpFileMethod p -> "CurlFtpFileMethod " ++ show p+ CurlLocalPort p -> "CurlLocalPort " ++ show p+ CurlLocalPortRange p -> "CurlLocalPortRange " ++ show p+ CurlConnectOnly p -> "CurlConnectOnly " ++ show p+ CurlConvFromNetworkFunction p -> "CurlConvFromNetworkFunction " ++ show p+ CurlConvToNetworkFunction p -> "CurlConvToNetworkFunction " ++ show p+ CurlConvFromUtf8Function p -> "CurlConvFromUtf8Function " ++ show p+ CurlMaxSendSpeedLarge p -> "CurlMaxSendSpeedLarge " ++ show p+ CurlMaxRecvSpeedLarge p -> "CurlMaxRecvSpeedLarge " ++ show p+ CurlFtpAlternativeToUser p -> "CurlFtpAlternativeToUser " ++ show p+ CurlSockOptFunction p -> "CurlSockOptFunction " ++ show p+ CurlSockOptData p -> "CurlSockOptData " ++ show p+ CurlSSLSessionIdCache p -> "CurlSSLSessionIdCache " ++ show p+ CurlSSHAuthTypes p -> "CurlSSHAuthTypes " ++ show p+ CurlSSHPublicKeyFile p -> "CurlSSHPublicKeyFile " ++ show p+ CurlSSHPrivateKeyFile p -> "CurlSSHPrivateKeyFile " ++ show p+ CurlFtpSSLCCC p -> "CurlFtpSSLCCC " ++ show p+ CurlTimeoutMS p -> "CurlTimeoutMS " ++ show p+ CurlConnectTimeoutMS p -> "CurlConnectTimeoutMS " ++ show p+ CurlHttpTransferDecoding p -> "CurlHttpTransferDecoding " ++ show p+ CurlHttpContentDecoding p -> "CurlHttpContentDecoding " ++ show p+ CurlNewFilePerms l -> "CurlNewFilePerms " ++ show l+ CurlNewDirectoryPerms p -> "CurlNewDirectoryPerms " ++ show p+ CurlPostRedirect p -> "CurlPostRedirect " ++ show p+ CurlSSHHostPublicKeyMD5 p -> "CurlSSHHostPublicKeyMD5 " ++ show p+ CurlCopyPostFields p -> "CurlCopyPostFields " ++ show p+ CurlProxyTransferMode p -> "CurlProxyTransferMode " ++ show p+ CurlCRLFile p -> "CurlCRLFile " ++ show p+ CurlIssuerCert p -> "CurlIssuerCert " ++ show p+ CurlAddressScope p -> "CurlAddressScope " ++ show p+ CurlCertInfo p -> "CurlCertInfo " ++ show p+ CurlUserName p -> "CurlUserName " ++ show p+ CurlUserPassword p -> "CurlUserPassword " ++ show p+ CurlProxyUser p -> "CurlProxyUser " ++ show p+ CurlProxyPassword p -> "CurlProxyPassword " ++ show p
Network/Curl/Post.hs view
@@ -1,11 +1,12 @@-{-# OPTIONS -fffi -fvia-C -#include "curl/curl.h" #-}+{-# LANGUAGE ForeignFunctionInterface #-}+{-# OPTIONS -fvia-C -#include "curl/curl.h" #-} -------------------------------------------------------------------- -- | -- Module : Network.Curl.Post--- Copyright : (c) Galois Inc 2007+-- Copyright : (c) Galois Inc 2007-2009 -- License : BSD3 ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --@@ -35,12 +36,13 @@ , extraHeaders :: [Header] -- not yet: , extraEntries :: [HttpPost] , showName :: Maybe String- }+ } deriving ( Show ) data Content = ContentFile FilePath | ContentBuffer (Ptr CChar) Long -- byte arrays also? | ContentString String+ deriving ( Show ) multiformString :: String -> String -> HttpPost multiformString x y =
Network/Curl/Types.hs view
@@ -1,11 +1,11 @@-{-# OPTIONS -fffi -fglasgow-exts #-}+{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls #-} -------------------------------------------------------------------- -- | -- Module : Network.Curl.Types--- Copyright : (c) Galois Inc 2007+-- Copyright : (c) Galois Inc 2007-2009 -- License : BSD3 ----- Maintainer: emertens@galois.com+-- Maintainer: Sigbjorn Finne <sof@galois.com> -- Stability : provisional -- Portability: portable --
Setup.hs view
@@ -3,4 +3,4 @@ import Distribution.Simple main :: IO ()-main = defaultMainWithHooks defaultUserHooks+main = defaultMain
curl.cabal view
@@ -1,5 +1,5 @@ name: curl-version: 1.3.3+version: 1.3.4 synopsis: Haskell binding to libcurl description: libcurl is a client-side URL transfer library, supporting FTP, FTPS, HTTP,@@ -8,16 +8,17 @@ HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos4), file transfer resume, http proxy tunneling and more!+ . This package provides a Haskell binding to libcurl. category: Network license: BSD3 license-file: LICENSE author: Sigbjorn Finne-maintainer: emertens@galois.com, diatchki@.galois.com+maintainer: Sigbjorn Finne <sigbjorn.finne@gmail.com> build-depends: base build-type: Configure cabal-version: >= 1.2-extra-source-files: configure, configure.ac, curl.buildinfo.in+extra-source-files: configure, configure.ac, curl.buildinfo.in, CHANGES flag new-base Description: Build with new smaller base library@@ -43,3 +44,5 @@ Build-depends: base >= 3 && < 4, containers else Build-depends: base < 3++ build-depends: bytestring
curlc.c view
@@ -1,3 +1,12 @@+/*+ * Haskell FFI friendly wrappers to curl_easy_* functions+ * for setting/getting option values. Could import these into+ * .hs without too much trouble, but calling out to 'typed'+ * versions saves the C compiler from issuing warnings.+ *+ * (c) 2007-2009, Galois, Inc.+ *+ */ #include <curl/curl.h> int curl_easy_getinfo_long(void *curl, long tg, long *pl)@@ -32,3 +41,29 @@ int curl_easy_setopt_ptr(void *curl, int i, void *x) { return curl_easy_setopt(curl,i,x); }++/*+ * Function curl_version_str()+ *+ * Returns the libcurl version number as a "MAJOR.MINOR.PATCH" string.+ *+ * Note: a static string, so no free()ing required (or asked for! :-)+ */+char*+curl_version_str() {+ return LIBCURL_VERSION;+}++/*+ * Function curl_version_num()+ *+ * Returns the libcurl version number in 3-byte format 0xXXYYZZ,+ * representing major,minor and patch levels. Encoded in a (host)+ * 'int' value, making for easy comparisons.+ *+ * See curlver.h for complete story.+ */+int+curl_version_num() {+ return LIBCURL_VERSION_NUM;+}