gi-soup-2.4.18: GI/Soup/Objects/ContentSniffer.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)
/No description available in the introspection data./
-}
#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.Soup.Objects.ContentSniffer
(
-- * Exported types
ContentSniffer(..) ,
IsContentSniffer ,
toContentSniffer ,
noContentSniffer ,
-- * Methods
-- ** getBufferSize #method:getBufferSize#
#if ENABLE_OVERLOADING
ContentSnifferGetBufferSizeMethodInfo ,
#endif
contentSnifferGetBufferSize ,
-- ** new #method:new#
contentSnifferNew ,
-- ** sniff #method:sniff#
#if ENABLE_OVERLOADING
ContentSnifferSniffMethodInfo ,
#endif
contentSnifferSniff ,
) 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 qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Soup.Interfaces.SessionFeature as Soup.SessionFeature
import {-# SOURCE #-} qualified GI.Soup.Objects.Message as Soup.Message
import {-# SOURCE #-} qualified GI.Soup.Structs.Buffer as Soup.Buffer
-- | Memory-managed wrapper type.
newtype ContentSniffer = ContentSniffer (ManagedPtr ContentSniffer)
foreign import ccall "soup_content_sniffer_get_type"
c_soup_content_sniffer_get_type :: IO GType
instance GObject ContentSniffer where
gobjectType = c_soup_content_sniffer_get_type
-- | Type class for types which can be safely cast to `ContentSniffer`, for instance with `toContentSniffer`.
class (GObject o, O.IsDescendantOf ContentSniffer o) => IsContentSniffer o
instance (GObject o, O.IsDescendantOf ContentSniffer o) => IsContentSniffer o
instance O.HasParentTypes ContentSniffer
type instance O.ParentTypes ContentSniffer = '[GObject.Object.Object, Soup.SessionFeature.SessionFeature]
-- | Cast to `ContentSniffer`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toContentSniffer :: (MonadIO m, IsContentSniffer o) => o -> m ContentSniffer
toContentSniffer = liftIO . unsafeCastTo ContentSniffer
-- | A convenience alias for `Nothing` :: `Maybe` `ContentSniffer`.
noContentSniffer :: Maybe ContentSniffer
noContentSniffer = Nothing
#if ENABLE_OVERLOADING
type family ResolveContentSnifferMethod (t :: Symbol) (o :: *) :: * where
ResolveContentSnifferMethod "addFeature" o = Soup.SessionFeature.SessionFeatureAddFeatureMethodInfo
ResolveContentSnifferMethod "attach" o = Soup.SessionFeature.SessionFeatureAttachMethodInfo
ResolveContentSnifferMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
ResolveContentSnifferMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
ResolveContentSnifferMethod "detach" o = Soup.SessionFeature.SessionFeatureDetachMethodInfo
ResolveContentSnifferMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
ResolveContentSnifferMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
ResolveContentSnifferMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
ResolveContentSnifferMethod "hasFeature" o = Soup.SessionFeature.SessionFeatureHasFeatureMethodInfo
ResolveContentSnifferMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
ResolveContentSnifferMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
ResolveContentSnifferMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
ResolveContentSnifferMethod "ref" o = GObject.Object.ObjectRefMethodInfo
ResolveContentSnifferMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
ResolveContentSnifferMethod "removeFeature" o = Soup.SessionFeature.SessionFeatureRemoveFeatureMethodInfo
ResolveContentSnifferMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
ResolveContentSnifferMethod "sniff" o = ContentSnifferSniffMethodInfo
ResolveContentSnifferMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
ResolveContentSnifferMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
ResolveContentSnifferMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
ResolveContentSnifferMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
ResolveContentSnifferMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
ResolveContentSnifferMethod "getBufferSize" o = ContentSnifferGetBufferSizeMethodInfo
ResolveContentSnifferMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
ResolveContentSnifferMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
ResolveContentSnifferMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
ResolveContentSnifferMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
ResolveContentSnifferMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
ResolveContentSnifferMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveContentSnifferMethod t ContentSniffer, O.MethodInfo info ContentSniffer p) => OL.IsLabel t (ContentSniffer -> 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
#if ENABLE_OVERLOADING
instance O.HasAttributeList ContentSniffer
type instance O.AttributeList ContentSniffer = ContentSnifferAttributeList
type ContentSnifferAttributeList = ('[ ] :: [(Symbol, *)])
#endif
#if ENABLE_OVERLOADING
#endif
#if ENABLE_OVERLOADING
type instance O.SignalList ContentSniffer = ContentSnifferSignalList
type ContentSnifferSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])
#endif
-- method ContentSniffer::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "ContentSniffer"}))
-- throws : False
-- Skip return : False
foreign import ccall "soup_content_sniffer_new" soup_content_sniffer_new ::
IO (Ptr ContentSniffer)
{- |
Creates a new 'GI.Soup.Objects.ContentSniffer.ContentSniffer'.
/Since: 2.28/
-}
contentSnifferNew ::
(B.CallStack.HasCallStack, MonadIO m) =>
m ContentSniffer
{- ^ __Returns:__ a new 'GI.Soup.Objects.ContentSniffer.ContentSniffer' -}
contentSnifferNew = liftIO $ do
result <- soup_content_sniffer_new
checkUnexpectedReturnNULL "contentSnifferNew" result
result' <- (wrapObject ContentSniffer) result
return result'
#if ENABLE_OVERLOADING
#endif
-- method ContentSniffer::get_buffer_size
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sniffer", argType = TInterface (Name {namespace = "Soup", name = "ContentSniffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupContentSniffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False
foreign import ccall "soup_content_sniffer_get_buffer_size" soup_content_sniffer_get_buffer_size ::
Ptr ContentSniffer -> -- sniffer : TInterface (Name {namespace = "Soup", name = "ContentSniffer"})
IO Word64
{- |
Gets the number of bytes /@sniffer@/ needs in order to properly sniff
a buffer.
/Since: 2.28/
-}
contentSnifferGetBufferSize ::
(B.CallStack.HasCallStack, MonadIO m, IsContentSniffer a) =>
a
{- ^ /@sniffer@/: a 'GI.Soup.Objects.ContentSniffer.ContentSniffer' -}
-> m Word64
{- ^ __Returns:__ the number of bytes to sniff -}
contentSnifferGetBufferSize sniffer = liftIO $ do
sniffer' <- unsafeManagedPtrCastPtr sniffer
result <- soup_content_sniffer_get_buffer_size sniffer'
touchManagedPtr sniffer
return result
#if ENABLE_OVERLOADING
data ContentSnifferGetBufferSizeMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsContentSniffer a) => O.MethodInfo ContentSnifferGetBufferSizeMethodInfo a signature where
overloadedMethod _ = contentSnifferGetBufferSize
#endif
-- method ContentSniffer::sniff
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "sniffer", argType = TInterface (Name {namespace = "Soup", name = "ContentSniffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupContentSniffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "msg", argType = TInterface (Name {namespace = "Soup", name = "Message"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the message to sniff", 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 buffer containing the start of @msg's response body", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "params", argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "return\n location for Content-Type parameters (eg, \"charset\"), or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False
foreign import ccall "soup_content_sniffer_sniff" soup_content_sniffer_sniff ::
Ptr ContentSniffer -> -- sniffer : TInterface (Name {namespace = "Soup", name = "ContentSniffer"})
Ptr Soup.Message.Message -> -- msg : TInterface (Name {namespace = "Soup", name = "Message"})
Ptr Soup.Buffer.Buffer -> -- buffer : TInterface (Name {namespace = "Soup", name = "Buffer"})
Ptr (Ptr (GHashTable CString CString)) -> -- params : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
IO CString
{- |
Sniffs /@buffer@/ to determine its Content-Type. The result may also
be influenced by the Content-Type declared in /@msg@/\'s response
headers.
/Since: 2.28/
-}
contentSnifferSniff ::
(B.CallStack.HasCallStack, MonadIO m, IsContentSniffer a, Soup.Message.IsMessage b) =>
a
{- ^ /@sniffer@/: a 'GI.Soup.Objects.ContentSniffer.ContentSniffer' -}
-> b
{- ^ /@msg@/: the message to sniff -}
-> Soup.Buffer.Buffer
{- ^ /@buffer@/: a buffer containing the start of /@msg@/\'s response body -}
-> m ((T.Text, Map.Map T.Text T.Text))
{- ^ __Returns:__ the sniffed Content-Type of /@buffer@/; this will never be 'Nothing',
but may be \"application\/octet-stream\". -}
contentSnifferSniff sniffer msg buffer = liftIO $ do
sniffer' <- unsafeManagedPtrCastPtr sniffer
msg' <- unsafeManagedPtrCastPtr msg
buffer' <- unsafeManagedPtrGetPtr buffer
params <- allocMem :: IO (Ptr (Ptr (GHashTable CString CString)))
result <- soup_content_sniffer_sniff sniffer' msg' buffer' params
checkUnexpectedReturnNULL "contentSnifferSniff" result
result' <- cstringToText result
freeMem result
params' <- peek params
params'' <- unpackGHashTable params'
let params''' = mapFirst cstringUnpackPtr params''
params'''' <- mapFirstA cstringToText params'''
let params''''' = mapSecond cstringUnpackPtr params''''
params'''''' <- mapSecondA cstringToText params'''''
let params''''''' = Map.fromList params''''''
unrefGHashTable params'
touchManagedPtr sniffer
touchManagedPtr msg
touchManagedPtr buffer
freeMem params
return (result', params''''''')
#if ENABLE_OVERLOADING
data ContentSnifferSniffMethodInfo
instance (signature ~ (b -> Soup.Buffer.Buffer -> m ((T.Text, Map.Map T.Text T.Text))), MonadIO m, IsContentSniffer a, Soup.Message.IsMessage b) => O.MethodInfo ContentSnifferSniffMethodInfo a signature where
overloadedMethod _ = contentSnifferSniff
#endif