{- | Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte License : LGPL-2.1 Maintainer : Iñaki García Etxebarria (garetxe@gmail.com) A #SoupMessage request or response body. Note that while @length always reflects the full length of the message body, @data is normally %NULL, and will only be filled in after soup_message_body_flatten() is called. For client-side messages, this automatically happens for the response body after it has been fully read, unless you set the %SOUP_MESSAGE_OVERWRITE_CHUNKS flags. Likewise, for server-side messages, the request body is automatically filled in after being read. As an added bonus, when @data is filled in, it is always terminated with a '\0' byte (which is not reflected in @length). -} module GI.Soup.Structs.MessageBody ( -- * Exported types MessageBody(..) , noMessageBody , -- * Methods -- ** messageBodyAppend messageBodyAppend , -- ** messageBodyAppendBuffer messageBodyAppendBuffer , -- ** messageBodyComplete messageBodyComplete , -- ** messageBodyFlatten messageBodyFlatten , -- ** messageBodyFree messageBodyFree , -- ** messageBodyGetAccumulate messageBodyGetAccumulate , -- ** messageBodyGetChunk messageBodyGetChunk , -- ** messageBodyGotChunk messageBodyGotChunk , -- ** messageBodyNew messageBodyNew , -- ** messageBodySetAccumulate messageBodySetAccumulate , -- ** messageBodyTruncate messageBodyTruncate , -- ** messageBodyWroteChunk messageBodyWroteChunk , -- * Properties -- ** Data messageBodyReadData , -- ** Length messageBodyReadLength , ) 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 MessageBody = MessageBody (ForeignPtr MessageBody) foreign import ccall "soup_message_body_get_type" c_soup_message_body_get_type :: IO GType instance BoxedObject MessageBody where boxedType _ = c_soup_message_body_get_type noMessageBody :: Maybe MessageBody noMessageBody = Nothing messageBodyReadData :: MessageBody -> IO T.Text messageBodyReadData s = withManagedPtr s $ \ptr -> do val <- peek (ptr `plusPtr` 0) :: IO CString val' <- cstringToText val return val' messageBodyReadLength :: MessageBody -> IO Int64 messageBodyReadLength s = withManagedPtr s $ \ptr -> do val <- peek (ptr `plusPtr` 8) :: IO Int64 return val -- method MessageBody::new -- method type : Constructor -- Args : [] -- Lengths : [] -- hInArgs : [] -- returnType : TInterface "Soup" "MessageBody" -- throws : False -- Skip return : False foreign import ccall "soup_message_body_new" soup_message_body_new :: IO (Ptr MessageBody) messageBodyNew :: (MonadIO m) => m MessageBody messageBodyNew = liftIO $ do result <- soup_message_body_new checkUnexpectedReturnNULL "soup_message_body_new" result result' <- (wrapBoxed MessageBody) result return result' -- method MessageBody::append_buffer -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "buffer", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "buffer", 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_message_body_append_buffer" soup_message_body_append_buffer :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" Ptr Buffer -> -- buffer : TInterface "Soup" "Buffer" IO () messageBodyAppendBuffer :: (MonadIO m) => MessageBody -> -- _obj Buffer -> -- buffer m () messageBodyAppendBuffer _obj buffer = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj let buffer' = unsafeManagedPtrGetPtr buffer soup_message_body_append_buffer _obj' buffer' touchManagedPtr _obj touchManagedPtr buffer return () -- method MessageBody::append -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TCArray False (-1) 2 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything},Arg {argName = "length", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [Arg {argName = "length", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "data", argType = TCArray False (-1) 2 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}] -- returnType : TBasicType TVoid -- throws : False -- Skip return : False foreign import ccall "soup_message_body_append_take" soup_message_body_append_take :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" Ptr Word8 -> -- data : TCArray False (-1) 2 (TBasicType TUInt8) Word64 -> -- length : TBasicType TUInt64 IO () messageBodyAppend :: (MonadIO m) => MessageBody -> -- _obj ByteString -> -- data m () messageBodyAppend _obj data_ = liftIO $ do let length_ = fromIntegral $ B.length data_ let _obj' = unsafeManagedPtrGetPtr _obj data_' <- packByteString data_ soup_message_body_append_take _obj' data_' length_ touchManagedPtr _obj return () -- method MessageBody::complete -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", 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_message_body_complete" soup_message_body_complete :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" IO () messageBodyComplete :: (MonadIO m) => MessageBody -> -- _obj m () messageBodyComplete _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj soup_message_body_complete _obj' touchManagedPtr _obj return () -- method MessageBody::flatten -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TInterface "Soup" "Buffer" -- throws : False -- Skip return : False foreign import ccall "soup_message_body_flatten" soup_message_body_flatten :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" IO (Ptr Buffer) messageBodyFlatten :: (MonadIO m) => MessageBody -> -- _obj m Buffer messageBodyFlatten _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj result <- soup_message_body_flatten _obj' checkUnexpectedReturnNULL "soup_message_body_flatten" result result' <- (wrapBoxed Buffer) result touchManagedPtr _obj return result' -- method MessageBody::free -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", 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_message_body_free" soup_message_body_free :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" IO () messageBodyFree :: (MonadIO m) => MessageBody -> -- _obj m () messageBodyFree _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj soup_message_body_free _obj' touchManagedPtr _obj return () -- method MessageBody::get_accumulate -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TBoolean -- throws : False -- Skip return : False foreign import ccall "soup_message_body_get_accumulate" soup_message_body_get_accumulate :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" IO CInt messageBodyGetAccumulate :: (MonadIO m) => MessageBody -> -- _obj m Bool messageBodyGetAccumulate _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj result <- soup_message_body_get_accumulate _obj' let result' = (/= 0) result touchManagedPtr _obj return result' -- method MessageBody::get_chunk -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "offset", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "offset", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TInterface "Soup" "Buffer" -- throws : False -- Skip return : False foreign import ccall "soup_message_body_get_chunk" soup_message_body_get_chunk :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" Int64 -> -- offset : TBasicType TInt64 IO (Ptr Buffer) messageBodyGetChunk :: (MonadIO m) => MessageBody -> -- _obj Int64 -> -- offset m Buffer messageBodyGetChunk _obj offset = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj result <- soup_message_body_get_chunk _obj' offset checkUnexpectedReturnNULL "soup_message_body_get_chunk" result result' <- (wrapBoxed Buffer) result touchManagedPtr _obj return result' -- method MessageBody::got_chunk -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "chunk", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "chunk", 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_message_body_got_chunk" soup_message_body_got_chunk :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" Ptr Buffer -> -- chunk : TInterface "Soup" "Buffer" IO () messageBodyGotChunk :: (MonadIO m) => MessageBody -> -- _obj Buffer -> -- chunk m () messageBodyGotChunk _obj chunk = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj let chunk' = unsafeManagedPtrGetPtr chunk soup_message_body_got_chunk _obj' chunk' touchManagedPtr _obj touchManagedPtr chunk return () -- method MessageBody::set_accumulate -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "accumulate", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "accumulate", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- returnType : TBasicType TVoid -- throws : False -- Skip return : False foreign import ccall "soup_message_body_set_accumulate" soup_message_body_set_accumulate :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" CInt -> -- accumulate : TBasicType TBoolean IO () messageBodySetAccumulate :: (MonadIO m) => MessageBody -> -- _obj Bool -> -- accumulate m () messageBodySetAccumulate _obj accumulate = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj let accumulate' = (fromIntegral . fromEnum) accumulate soup_message_body_set_accumulate _obj' accumulate' touchManagedPtr _obj return () -- method MessageBody::truncate -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", 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_message_body_truncate" soup_message_body_truncate :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" IO () messageBodyTruncate :: (MonadIO m) => MessageBody -> -- _obj m () messageBodyTruncate _obj = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj soup_message_body_truncate _obj' touchManagedPtr _obj return () -- method MessageBody::wrote_chunk -- method type : OrdinaryMethod -- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "chunk", argType = TInterface "Soup" "Buffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}] -- Lengths : [] -- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "MessageBody", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "chunk", 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_message_body_wrote_chunk" soup_message_body_wrote_chunk :: Ptr MessageBody -> -- _obj : TInterface "Soup" "MessageBody" Ptr Buffer -> -- chunk : TInterface "Soup" "Buffer" IO () messageBodyWroteChunk :: (MonadIO m) => MessageBody -> -- _obj Buffer -> -- chunk m () messageBodyWroteChunk _obj chunk = liftIO $ do let _obj' = unsafeManagedPtrGetPtr _obj let chunk' = unsafeManagedPtrGetPtr chunk soup_message_body_wrote_chunk _obj' chunk' touchManagedPtr _obj touchManagedPtr chunk return ()