gi-soup-2.4.18: GI/Soup/Structs/MessageBody.hs
{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)
A 'GI.Soup.Objects.Message.Message' request or response body.
Note that while /@length@/ always reflects the full length of the
message body, /@data@/ is normally 'Nothing', and will only be filled in
after 'GI.Soup.Structs.MessageBody.messageBodyFlatten' is called. For client-side
messages, this automatically happens for the response body after it
has been fully read, unless you set the
'GI.Soup.Flags.MessageFlagsOverwriteChunks' 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@/).
-}
#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.Soup.Structs.MessageBody
(
-- * Exported types
MessageBody(..) ,
newZeroMessageBody ,
noMessageBody ,
-- * Methods
-- ** append #method:append#
#if ENABLE_OVERLOADING
MessageBodyAppendMethodInfo ,
#endif
messageBodyAppend ,
-- ** appendBuffer #method:appendBuffer#
#if ENABLE_OVERLOADING
MessageBodyAppendBufferMethodInfo ,
#endif
messageBodyAppendBuffer ,
-- ** complete #method:complete#
#if ENABLE_OVERLOADING
MessageBodyCompleteMethodInfo ,
#endif
messageBodyComplete ,
-- ** flatten #method:flatten#
#if ENABLE_OVERLOADING
MessageBodyFlattenMethodInfo ,
#endif
messageBodyFlatten ,
-- ** free #method:free#
#if ENABLE_OVERLOADING
MessageBodyFreeMethodInfo ,
#endif
messageBodyFree ,
-- ** getAccumulate #method:getAccumulate#
#if ENABLE_OVERLOADING
MessageBodyGetAccumulateMethodInfo ,
#endif
messageBodyGetAccumulate ,
-- ** getChunk #method:getChunk#
#if ENABLE_OVERLOADING
MessageBodyGetChunkMethodInfo ,
#endif
messageBodyGetChunk ,
-- ** gotChunk #method:gotChunk#
#if ENABLE_OVERLOADING
MessageBodyGotChunkMethodInfo ,
#endif
messageBodyGotChunk ,
-- ** new #method:new#
messageBodyNew ,
-- ** setAccumulate #method:setAccumulate#
#if ENABLE_OVERLOADING
MessageBodySetAccumulateMethodInfo ,
#endif
messageBodySetAccumulate ,
-- ** truncate #method:truncate#
#if ENABLE_OVERLOADING
MessageBodyTruncateMethodInfo ,
#endif
messageBodyTruncate ,
-- ** wroteChunk #method:wroteChunk#
#if ENABLE_OVERLOADING
MessageBodyWroteChunkMethodInfo ,
#endif
messageBodyWroteChunk ,
-- * Properties
-- ** data #attr:data#
{- | the data
-}
clearMessageBodyData ,
getMessageBodyData ,
#if ENABLE_OVERLOADING
messageBody_data ,
#endif
setMessageBodyData ,
-- ** length #attr:length#
{- | length of /@data@/
-}
getMessageBodyLength ,
#if ENABLE_OVERLOADING
messageBody_length ,
#endif
setMessageBodyLength ,
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import {-# SOURCE #-} qualified GI.Soup.Structs.Buffer as Soup.Buffer
-- | Memory-managed wrapper type.
newtype MessageBody = MessageBody (ManagedPtr 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
-- | Construct a `MessageBody` struct initialized to zero.
newZeroMessageBody :: MonadIO m => m MessageBody
newZeroMessageBody = liftIO $ callocBoxedBytes 16 >>= wrapBoxed MessageBody
instance tag ~ 'AttrSet => Constructible MessageBody tag where
new _ attrs = do
o <- newZeroMessageBody
GI.Attributes.set o attrs
return o
-- | A convenience alias for `Nothing` :: `Maybe` `MessageBody`.
noMessageBody :: Maybe MessageBody
noMessageBody = Nothing
{- |
Get the value of the “@data@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
@
'Data.GI.Base.Attributes.get' messageBody #data
@
-}
getMessageBodyData :: MonadIO m => MessageBody -> m (Maybe T.Text)
getMessageBodyData s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO CString
result <- SP.convertIfNonNull val $ \val' -> do
val'' <- cstringToText val'
return val''
return result
{- |
Set the value of the “@data@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
@
'Data.GI.Base.Attributes.set' messageBody [ #data 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMessageBodyData :: MonadIO m => MessageBody -> CString -> m ()
setMessageBodyData s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (val :: CString)
{- |
Set the value of the “@data@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
@
'Data.GI.Base.Attributes.clear' #data
@
-}
clearMessageBodyData :: MonadIO m => MessageBody -> m ()
clearMessageBodyData s = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (FP.nullPtr :: CString)
#if ENABLE_OVERLOADING
data MessageBodyDataFieldInfo
instance AttrInfo MessageBodyDataFieldInfo where
type AttrAllowedOps MessageBodyDataFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint MessageBodyDataFieldInfo = (~) CString
type AttrBaseTypeConstraint MessageBodyDataFieldInfo = (~) MessageBody
type AttrGetType MessageBodyDataFieldInfo = Maybe T.Text
type AttrLabel MessageBodyDataFieldInfo = "data"
type AttrOrigin MessageBodyDataFieldInfo = MessageBody
attrGet _ = getMessageBodyData
attrSet _ = setMessageBodyData
attrConstruct = undefined
attrClear _ = clearMessageBodyData
messageBody_data :: AttrLabelProxy "data"
messageBody_data = AttrLabelProxy
#endif
{- |
Get the value of the “@length@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
@
'Data.GI.Base.Attributes.get' messageBody #length
@
-}
getMessageBodyLength :: MonadIO m => MessageBody -> m Int64
getMessageBodyLength s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 8) :: IO Int64
return val
{- |
Set the value of the “@length@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
@
'Data.GI.Base.Attributes.set' messageBody [ #length 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMessageBodyLength :: MonadIO m => MessageBody -> Int64 -> m ()
setMessageBodyLength s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 8) (val :: Int64)
#if ENABLE_OVERLOADING
data MessageBodyLengthFieldInfo
instance AttrInfo MessageBodyLengthFieldInfo where
type AttrAllowedOps MessageBodyLengthFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint MessageBodyLengthFieldInfo = (~) Int64
type AttrBaseTypeConstraint MessageBodyLengthFieldInfo = (~) MessageBody
type AttrGetType MessageBodyLengthFieldInfo = Int64
type AttrLabel MessageBodyLengthFieldInfo = "length"
type AttrOrigin MessageBodyLengthFieldInfo = MessageBody
attrGet _ = getMessageBodyLength
attrSet _ = setMessageBodyLength
attrConstruct = undefined
attrClear _ = undefined
messageBody_length :: AttrLabelProxy "length"
messageBody_length = AttrLabelProxy
#endif
#if ENABLE_OVERLOADING
instance O.HasAttributeList MessageBody
type instance O.AttributeList MessageBody = MessageBodyAttributeList
type MessageBodyAttributeList = ('[ '("data", MessageBodyDataFieldInfo), '("length", MessageBodyLengthFieldInfo)] :: [(Symbol, *)])
#endif
-- method MessageBody::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "MessageBody"}))
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_new" soup_message_body_new ::
IO (Ptr MessageBody)
{- |
Creates a new 'GI.Soup.Structs.MessageBody.MessageBody'. 'GI.Soup.Objects.Message.Message' uses this internally; you
will not normally need to call it yourself.
-}
messageBodyNew ::
(B.CallStack.HasCallStack, MonadIO m) =>
m MessageBody
{- ^ __Returns:__ a new 'GI.Soup.Structs.MessageBody.MessageBody'. -}
messageBodyNew = liftIO $ do
result <- soup_message_body_new
checkUnexpectedReturnNULL "messageBodyNew" result
result' <- (wrapBoxed MessageBody) result
return result'
#if ENABLE_OVERLOADING
#endif
-- method MessageBody::append_buffer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Soup", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_append_buffer" soup_message_body_append_buffer ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
Ptr Soup.Buffer.Buffer -> -- buffer : TInterface (Name {namespace = "Soup", name = "Buffer"})
IO ()
{- |
Appends the data from /@buffer@/ to /@body@/. ('GI.Soup.Structs.MessageBody.MessageBody' uses
@/SoupBuffers/@ internally, so this is normally a constant-time
operation that doesn\'t actually require copying the data in
/@buffer@/.)
-}
messageBodyAppendBuffer ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> Soup.Buffer.Buffer
{- ^ /@buffer@/: a 'GI.Soup.Structs.Buffer.Buffer' -}
-> m ()
messageBodyAppendBuffer body buffer = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
buffer' <- unsafeManagedPtrGetPtr buffer
soup_message_body_append_buffer body' buffer'
touchManagedPtr body
touchManagedPtr buffer
return ()
#if ENABLE_OVERLOADING
data MessageBodyAppendBufferMethodInfo
instance (signature ~ (Soup.Buffer.Buffer -> m ()), MonadIO m) => O.MethodInfo MessageBodyAppendBufferMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyAppendBuffer
#endif
-- method MessageBody::append
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TCArray False (-1) 2 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "data to append", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "length", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "length of @data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "length", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "length of @data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_append_take" soup_message_body_append_take ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
Ptr Word8 -> -- data : TCArray False (-1) 2 (TBasicType TUInt8)
Word64 -> -- length : TBasicType TUInt64
IO ()
{- |
Appends /@length@/ bytes from /@data@/ to /@body@/.
This function is exactly equivalent to @/soup_message_body_append()/@
with 'GI.Soup.Enums.MemoryUseTake' as second argument; it exists mainly for
convenience and simplifying language bindings.
/Since: 2.32/
-}
messageBodyAppend ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> ByteString
{- ^ /@data@/: data to append -}
-> m ()
messageBodyAppend body data_ = liftIO $ do
let length_ = fromIntegral $ B.length data_
body' <- unsafeManagedPtrGetPtr body
data_' <- packByteString data_
soup_message_body_append_take body' data_' length_
touchManagedPtr body
return ()
#if ENABLE_OVERLOADING
data MessageBodyAppendMethodInfo
instance (signature ~ (ByteString -> m ()), MonadIO m) => O.MethodInfo MessageBodyAppendMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyAppend
#endif
-- method MessageBody::complete
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_complete" soup_message_body_complete ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
IO ()
{- |
Tags /@body@/ as being complete; Call this when using chunked encoding
after you have appended the last chunk.
-}
messageBodyComplete ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> m ()
messageBodyComplete body = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
soup_message_body_complete body'
touchManagedPtr body
return ()
#if ENABLE_OVERLOADING
data MessageBodyCompleteMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MessageBodyCompleteMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyComplete
#endif
-- method MessageBody::flatten
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Buffer"}))
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_flatten" soup_message_body_flatten ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
IO (Ptr Soup.Buffer.Buffer)
{- |
Fills in /@body@/\'s data field with a buffer containing all of the
data in /@body@/ (plus an additional \'\\0\' byte not counted by /@body@/\'s
length field).
-}
messageBodyFlatten ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> m Soup.Buffer.Buffer
{- ^ __Returns:__ a 'GI.Soup.Structs.Buffer.Buffer' containing the same data as /@body@/.
(You must free this buffer if you do not want it.) -}
messageBodyFlatten body = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
result <- soup_message_body_flatten body'
checkUnexpectedReturnNULL "messageBodyFlatten" result
result' <- (wrapBoxed Soup.Buffer.Buffer) result
touchManagedPtr body
return result'
#if ENABLE_OVERLOADING
data MessageBodyFlattenMethodInfo
instance (signature ~ (m Soup.Buffer.Buffer), MonadIO m) => O.MethodInfo MessageBodyFlattenMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyFlatten
#endif
-- method MessageBody::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_free" soup_message_body_free ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
IO ()
{- |
Frees /@body@/. You will not normally need to use this, as
'GI.Soup.Objects.Message.Message' frees its associated message bodies automatically.
-}
messageBodyFree ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> m ()
messageBodyFree body = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
soup_message_body_free body'
touchManagedPtr body
return ()
#if ENABLE_OVERLOADING
data MessageBodyFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MessageBodyFreeMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyFree
#endif
-- method MessageBody::get_accumulate
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_get_accumulate" soup_message_body_get_accumulate ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
IO CInt
{- |
Gets the accumulate flag on /@body@/; see
'GI.Soup.Structs.MessageBody.messageBodySetAccumulate' for details.
/Since: 2.24/
-}
messageBodyGetAccumulate ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> m Bool
{- ^ __Returns:__ the accumulate flag for /@body@/. -}
messageBodyGetAccumulate body = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
result <- soup_message_body_get_accumulate body'
let result' = (/= 0) result
touchManagedPtr body
return result'
#if ENABLE_OVERLOADING
data MessageBodyGetAccumulateMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo MessageBodyGetAccumulateMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyGetAccumulate
#endif
-- method MessageBody::get_chunk
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an offset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Buffer"}))
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_get_chunk" soup_message_body_get_chunk ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
Int64 -> -- offset : TBasicType TInt64
IO (Ptr Soup.Buffer.Buffer)
{- |
Gets a 'GI.Soup.Structs.Buffer.Buffer' containing data from /@body@/ starting at /@offset@/.
The size of the returned chunk is unspecified. You can iterate
through the entire body by first calling
'GI.Soup.Structs.MessageBody.messageBodyGetChunk' with an offset of 0, and then on each
successive call, increment the offset by the length of the
previously-returned chunk.
If /@offset@/ is greater than or equal to the total length of /@body@/,
then the return value depends on whether or not
'GI.Soup.Structs.MessageBody.messageBodyComplete' has been called or not; if it has,
then 'GI.Soup.Structs.MessageBody.messageBodyGetChunk' will return a 0-length chunk
(indicating the end of /@body@/). If it has not, then
'GI.Soup.Structs.MessageBody.messageBodyGetChunk' will return 'Nothing' (indicating that
/@body@/ may still potentially have more data, but that data is not
currently available).
-}
messageBodyGetChunk ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> Int64
{- ^ /@offset@/: an offset -}
-> m (Maybe Soup.Buffer.Buffer)
{- ^ __Returns:__ a 'GI.Soup.Structs.Buffer.Buffer', or 'Nothing'. -}
messageBodyGetChunk body offset = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
result <- soup_message_body_get_chunk body' offset
maybeResult <- convertIfNonNull result $ \result' -> do
result'' <- (wrapBoxed Soup.Buffer.Buffer) result'
return result''
touchManagedPtr body
return maybeResult
#if ENABLE_OVERLOADING
data MessageBodyGetChunkMethodInfo
instance (signature ~ (Int64 -> m (Maybe Soup.Buffer.Buffer)), MonadIO m) => O.MethodInfo MessageBodyGetChunkMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyGetChunk
#endif
-- method MessageBody::got_chunk
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "chunk", argType = TInterface (Name {namespace = "Soup", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupBuffer received from the network", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_got_chunk" soup_message_body_got_chunk ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
Ptr Soup.Buffer.Buffer -> -- chunk : TInterface (Name {namespace = "Soup", name = "Buffer"})
IO ()
{- |
Handles the 'GI.Soup.Structs.MessageBody.MessageBody' part of receiving a chunk of data from
the network. Normally this means appending /@chunk@/ to /@body@/, exactly
as with 'GI.Soup.Structs.MessageBody.messageBodyAppendBuffer', but if you have set
/@body@/\'s accumulate flag to 'False', then that will not happen.
This is a low-level method which you should not normally need to
use.
/Since: 2.24/
-}
messageBodyGotChunk ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> Soup.Buffer.Buffer
{- ^ /@chunk@/: a 'GI.Soup.Structs.Buffer.Buffer' received from the network -}
-> m ()
messageBodyGotChunk body chunk = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
chunk' <- unsafeManagedPtrGetPtr chunk
soup_message_body_got_chunk body' chunk'
touchManagedPtr body
touchManagedPtr chunk
return ()
#if ENABLE_OVERLOADING
data MessageBodyGotChunkMethodInfo
instance (signature ~ (Soup.Buffer.Buffer -> m ()), MonadIO m) => O.MethodInfo MessageBodyGotChunkMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyGotChunk
#endif
-- method MessageBody::set_accumulate
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "accumulate", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether or not to accumulate body chunks in @body", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_set_accumulate" soup_message_body_set_accumulate ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
CInt -> -- accumulate : TBasicType TBoolean
IO ()
{- |
Sets or clears the accumulate flag on /@body@/. (The default value is
'True'.) If set to 'False', /@body@/\'s @/data/@ field will not be filled in
after the body is fully sent\/received, and the chunks that make up
/@body@/ may be discarded when they are no longer needed.
In particular, if you set this flag to 'False' on an \"incoming\"
message body (that is, the 'GI.Soup.Objects.Message.Message':@/response_body/@ of a
client-side message, or 'GI.Soup.Objects.Message.Message':@/request_body/@ of a server-side
message), this will cause each chunk of the body to be discarded
after its corresponding 'GI.Soup.Objects.Message.Message'::@/got_chunk/@ signal is emitted.
(This is equivalent to setting the deprecated
'GI.Soup.Flags.MessageFlagsOverwriteChunks' flag on the message.)
If you set this flag to 'False' on the 'GI.Soup.Objects.Message.Message':@/response_body/@ of
a server-side message, it will cause each chunk of the body to be
discarded after its corresponding 'GI.Soup.Objects.Message.Message'::@/wrote_chunk/@ signal
is emitted.
If you set the flag to 'False' on the 'GI.Soup.Objects.Message.Message':@/request_body/@ of a
client-side message, it will block the accumulation of chunks into
/@body@/\'s @/data/@ field, but it will not normally cause the chunks to
be discarded after being written like in the server-side
'GI.Soup.Objects.Message.Message':@/response_body/@ case, because the request body needs to
be kept around in case the request needs to be sent a second time
due to redirection or authentication. However, if you set the
'GI.Soup.Flags.MessageFlagsCanRebuild' flag on the message, then the chunks will
be discarded, and you will be responsible for recreating the
request body after the 'GI.Soup.Objects.Message.Message'::@/restarted/@ signal is emitted.
/Since: 2.24/
-}
messageBodySetAccumulate ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> Bool
{- ^ /@accumulate@/: whether or not to accumulate body chunks in /@body@/ -}
-> m ()
messageBodySetAccumulate body accumulate = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
let accumulate' = (fromIntegral . fromEnum) accumulate
soup_message_body_set_accumulate body' accumulate'
touchManagedPtr body
return ()
#if ENABLE_OVERLOADING
data MessageBodySetAccumulateMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m) => O.MethodInfo MessageBodySetAccumulateMethodInfo MessageBody signature where
overloadedMethod _ = messageBodySetAccumulate
#endif
-- method MessageBody::truncate
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_truncate" soup_message_body_truncate ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
IO ()
{- |
Deletes all of the data in /@body@/.
-}
messageBodyTruncate ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> m ()
messageBodyTruncate body = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
soup_message_body_truncate body'
touchManagedPtr body
return ()
#if ENABLE_OVERLOADING
data MessageBodyTruncateMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MessageBodyTruncateMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyTruncate
#endif
-- method MessageBody::wrote_chunk
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMessageBody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "chunk", argType = TInterface (Name {namespace = "Soup", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupBuffer returned from soup_message_body_get_chunk()", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False
foreign import ccall "soup_message_body_wrote_chunk" soup_message_body_wrote_chunk ::
Ptr MessageBody -> -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
Ptr Soup.Buffer.Buffer -> -- chunk : TInterface (Name {namespace = "Soup", name = "Buffer"})
IO ()
{- |
Handles the 'GI.Soup.Structs.MessageBody.MessageBody' part of writing a chunk of data to the
network. Normally this is a no-op, but if you have set /@body@/\'s
accumulate flag to 'False', then this will cause /@chunk@/ to be
discarded to free up memory.
This is a low-level method which you should not need to use, and
there are further restrictions on its proper use which are not
documented here.
/Since: 2.24/
-}
messageBodyWroteChunk ::
(B.CallStack.HasCallStack, MonadIO m) =>
MessageBody
{- ^ /@body@/: a 'GI.Soup.Structs.MessageBody.MessageBody' -}
-> Soup.Buffer.Buffer
{- ^ /@chunk@/: a 'GI.Soup.Structs.Buffer.Buffer' returned from 'GI.Soup.Structs.MessageBody.messageBodyGetChunk' -}
-> m ()
messageBodyWroteChunk body chunk = liftIO $ do
body' <- unsafeManagedPtrGetPtr body
chunk' <- unsafeManagedPtrGetPtr chunk
soup_message_body_wrote_chunk body' chunk'
touchManagedPtr body
touchManagedPtr chunk
return ()
#if ENABLE_OVERLOADING
data MessageBodyWroteChunkMethodInfo
instance (signature ~ (Soup.Buffer.Buffer -> m ()), MonadIO m) => O.MethodInfo MessageBodyWroteChunkMethodInfo MessageBody signature where
overloadedMethod _ = messageBodyWroteChunk
#endif
#if ENABLE_OVERLOADING
type family ResolveMessageBodyMethod (t :: Symbol) (o :: *) :: * where
ResolveMessageBodyMethod "appendBuffer" o = MessageBodyAppendBufferMethodInfo
ResolveMessageBodyMethod "append" o = MessageBodyAppendMethodInfo
ResolveMessageBodyMethod "complete" o = MessageBodyCompleteMethodInfo
ResolveMessageBodyMethod "flatten" o = MessageBodyFlattenMethodInfo
ResolveMessageBodyMethod "free" o = MessageBodyFreeMethodInfo
ResolveMessageBodyMethod "gotChunk" o = MessageBodyGotChunkMethodInfo
ResolveMessageBodyMethod "truncate" o = MessageBodyTruncateMethodInfo
ResolveMessageBodyMethod "wroteChunk" o = MessageBodyWroteChunkMethodInfo
ResolveMessageBodyMethod "getAccumulate" o = MessageBodyGetAccumulateMethodInfo
ResolveMessageBodyMethod "getChunk" o = MessageBodyGetChunkMethodInfo
ResolveMessageBodyMethod "setAccumulate" o = MessageBodySetAccumulateMethodInfo
ResolveMessageBodyMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveMessageBodyMethod t MessageBody, O.MethodInfo info MessageBody p) => OL.IsLabel t (MessageBody -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif