{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
Represents a multipart HTTP message body, parsed according to the
syntax of RFC 2046. Of particular interest to HTTP are
multipart/byte-ranges and
multipart/form-data.
Although the headers of a #SoupMultipart body part will contain the
full headers from that body part, libsoup does not interpret them
according to MIME rules. For example, each body part is assumed to
have "binary" Content-Transfer-Encoding, even if its headers
explicitly state otherwise. In other words, don't try to use
#SoupMultipart for handling real MIME multiparts.
-}
module GI.Soup.Structs.Multipart
(
-- * Exported types
Multipart(..) ,
noMultipart ,
-- * Methods
-- ** multipartAppendFormFile
multipartAppendFormFile ,
-- ** multipartAppendFormString
multipartAppendFormString ,
-- ** multipartAppendPart
multipartAppendPart ,
-- ** multipartFree
multipartFree ,
-- ** multipartGetLength
multipartGetLength ,
-- ** multipartGetPart
multipartGetPart ,
-- ** multipartNew
multipartNew ,
-- ** multipartNewFromMessage
multipartNewFromMessage ,
-- ** multipartToMessage
multipartToMessage ,
) where
import Prelude ()
import Data.GI.Base.ShortPrelude
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import GI.Soup.Types
import GI.Soup.Callbacks
newtype Multipart = Multipart (ForeignPtr Multipart)
foreign import ccall "soup_multipart_get_type" c_soup_multipart_get_type ::
IO GType
instance BoxedObject Multipart where
boxedType _ = c_soup_multipart_get_type
noMultipart :: Maybe Multipart
noMultipart = Nothing
-- method Multipart::new
-- method type : Constructor
-- Args : [Arg {argName = "mime_type", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "mime_type", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "Multipart"
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_new" soup_multipart_new ::
CString -> -- mime_type : TBasicType TUTF8
IO (Ptr Multipart)
multipartNew ::
(MonadIO m) =>
T.Text -> -- mime_type
m Multipart
multipartNew mime_type = liftIO $ do
mime_type' <- textToCString mime_type
result <- soup_multipart_new mime_type'
checkUnexpectedReturnNULL "soup_multipart_new" result
result' <- (wrapBoxed Multipart) result
freeMem mime_type'
return result'
-- method Multipart::new_from_message
-- method type : Constructor
-- Args : [Arg {argName = "headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "Multipart"
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_new_from_message" soup_multipart_new_from_message ::
Ptr MessageHeaders -> -- headers : TInterface "Soup" "MessageHeaders"
Ptr MessageBody -> -- body : TInterface "Soup" "MessageBody"
IO (Ptr Multipart)
multipartNewFromMessage ::
(MonadIO m) =>
MessageHeaders -> -- headers
MessageBody -> -- body
m Multipart
multipartNewFromMessage headers body = liftIO $ do
let headers' = unsafeManagedPtrGetPtr headers
let body' = unsafeManagedPtrGetPtr body
result <- soup_multipart_new_from_message headers' body'
checkUnexpectedReturnNULL "soup_multipart_new_from_message" result
result' <- (wrapBoxed Multipart) result
touchManagedPtr headers
touchManagedPtr body
return result'
-- method Multipart::append_form_file
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "control_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "content_type", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "control_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "content_type", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_append_form_file" soup_multipart_append_form_file ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
CString -> -- control_name : TBasicType TUTF8
CString -> -- filename : TBasicType TUTF8
CString -> -- content_type : TBasicType TUTF8
Ptr Buffer -> -- body : TInterface "Soup" "Buffer"
IO ()
multipartAppendFormFile ::
(MonadIO m) =>
Multipart -> -- _obj
T.Text -> -- control_name
T.Text -> -- filename
T.Text -> -- content_type
Buffer -> -- body
m ()
multipartAppendFormFile _obj control_name filename content_type body = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
control_name' <- textToCString control_name
filename' <- textToCString filename
content_type' <- textToCString content_type
let body' = unsafeManagedPtrGetPtr body
soup_multipart_append_form_file _obj' control_name' filename' content_type' body'
touchManagedPtr _obj
touchManagedPtr body
freeMem control_name'
freeMem filename'
freeMem content_type'
return ()
-- method Multipart::append_form_string
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "control_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "control_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_append_form_string" soup_multipart_append_form_string ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
CString -> -- control_name : TBasicType TUTF8
CString -> -- data : TBasicType TUTF8
IO ()
multipartAppendFormString ::
(MonadIO m) =>
Multipart -> -- _obj
T.Text -> -- control_name
T.Text -> -- data
m ()
multipartAppendFormString _obj control_name data_ = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
control_name' <- textToCString control_name
data_' <- textToCString data_
soup_multipart_append_form_string _obj' control_name' data_'
touchManagedPtr _obj
freeMem control_name'
freeMem data_'
return ()
-- method Multipart::append_part
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_append_part" soup_multipart_append_part ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
Ptr MessageHeaders -> -- headers : TInterface "Soup" "MessageHeaders"
Ptr Buffer -> -- body : TInterface "Soup" "Buffer"
IO ()
multipartAppendPart ::
(MonadIO m) =>
Multipart -> -- _obj
MessageHeaders -> -- headers
Buffer -> -- body
m ()
multipartAppendPart _obj headers body = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
let headers' = unsafeManagedPtrGetPtr headers
let body' = unsafeManagedPtrGetPtr body
soup_multipart_append_part _obj' headers' body'
touchManagedPtr _obj
touchManagedPtr headers
touchManagedPtr body
return ()
-- method Multipart::free
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_free" soup_multipart_free ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
IO ()
multipartFree ::
(MonadIO m) =>
Multipart -> -- _obj
m ()
multipartFree _obj = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
soup_multipart_free _obj'
touchManagedPtr _obj
return ()
-- method Multipart::get_length
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TInt32
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_get_length" soup_multipart_get_length ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
IO Int32
multipartGetLength ::
(MonadIO m) =>
Multipart -> -- _obj
m Int32
multipartGetLength _obj = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
result <- soup_multipart_get_length _obj'
touchManagedPtr _obj
return result
-- method Multipart::get_part
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "part", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "body", argType = TInterface "Soup" "Buffer", direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "part", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_get_part" soup_multipart_get_part ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
Int32 -> -- part : TBasicType TInt32
Ptr (Ptr MessageHeaders) -> -- headers : TInterface "Soup" "MessageHeaders"
Ptr Buffer -> -- body : TInterface "Soup" "Buffer"
IO CInt
multipartGetPart ::
(MonadIO m) =>
Multipart -> -- _obj
Int32 -> -- part
m (Bool,MessageHeaders,Buffer)
multipartGetPart _obj part = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
headers <- allocMem :: IO (Ptr (Ptr MessageHeaders))
body <- callocBoxedBytes 16 :: IO (Ptr Buffer)
result <- soup_multipart_get_part _obj' part headers body
let result' = (/= 0) result
headers' <- peek headers
headers'' <- (newBoxed MessageHeaders) headers'
body' <- (wrapBoxed Buffer) body
touchManagedPtr _obj
freeMem headers
return (result', headers'', body')
-- method Multipart::to_message
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "dest_headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "dest_body", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "Multipart", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "dest_headers", argType = TInterface "Soup" "MessageHeaders", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "dest_body", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "soup_multipart_to_message" soup_multipart_to_message ::
Ptr Multipart -> -- _obj : TInterface "Soup" "Multipart"
Ptr MessageHeaders -> -- dest_headers : TInterface "Soup" "MessageHeaders"
Ptr MessageBody -> -- dest_body : TInterface "Soup" "MessageBody"
IO ()
multipartToMessage ::
(MonadIO m) =>
Multipart -> -- _obj
MessageHeaders -> -- dest_headers
MessageBody -> -- dest_body
m ()
multipartToMessage _obj dest_headers dest_body = liftIO $ do
let _obj' = unsafeManagedPtrGetPtr _obj
let dest_headers' = unsafeManagedPtrGetPtr dest_headers
let dest_body' = unsafeManagedPtrGetPtr dest_body
soup_multipart_to_message _obj' dest_headers' dest_body'
touchManagedPtr _obj
touchManagedPtr dest_headers
touchManagedPtr dest_body
return ()