{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

An HTTP cookie.

/@name@/ and /@value@/ will be set for all cookies. If the cookie is
generated from a string that appears to have no name, then /@name@/
will be the empty string.

/@domain@/ and /@path@/ give the host or domain, and path within that
host\/domain, to restrict this cookie to. If /@domain@/ starts with
\".\", that indicates a domain (which matches the string after the
\".\", or any hostname that has /@domain@/ as a suffix). Otherwise, it
is a hostname and must match exactly.

/@expires@/ will be non-'Nothing' if the cookie uses either the original
\"expires\" attribute, or the newer \"max-age\" attribute. If /@expires@/
is 'Nothing', it indicates that neither \"expires\" nor \"max-age\" was
specified, and the cookie expires at the end of the session.

If /@httpOnly@/ is set, the cookie should not be exposed to untrusted
code (eg, javascript), so as to minimize the danger posed by
cross-site scripting attacks.
-}

module GI.Soup.Structs.Cookie
    ( 

-- * Exported types
    Cookie(..)                              ,
    newZeroCookie                           ,
    noCookie                                ,


 -- * Methods
-- ** appliesToUri #method:appliesToUri#
    CookieAppliesToUriMethodInfo            ,
    cookieAppliesToUri                      ,


-- ** copy #method:copy#
    CookieCopyMethodInfo                    ,
    cookieCopy                              ,


-- ** domainMatches #method:domainMatches#
    CookieDomainMatchesMethodInfo           ,
    cookieDomainMatches                     ,


-- ** equal #method:equal#
    CookieEqualMethodInfo                   ,
    cookieEqual                             ,


-- ** free #method:free#
    CookieFreeMethodInfo                    ,
    cookieFree                              ,


-- ** getDomain #method:getDomain#
    CookieGetDomainMethodInfo               ,
    cookieGetDomain                         ,


-- ** getExpires #method:getExpires#
    CookieGetExpiresMethodInfo              ,
    cookieGetExpires                        ,


-- ** getHttpOnly #method:getHttpOnly#
    CookieGetHttpOnlyMethodInfo             ,
    cookieGetHttpOnly                       ,


-- ** getName #method:getName#
    CookieGetNameMethodInfo                 ,
    cookieGetName                           ,


-- ** getPath #method:getPath#
    CookieGetPathMethodInfo                 ,
    cookieGetPath                           ,


-- ** getSecure #method:getSecure#
    CookieGetSecureMethodInfo               ,
    cookieGetSecure                         ,


-- ** getValue #method:getValue#
    CookieGetValueMethodInfo                ,
    cookieGetValue                          ,


-- ** new #method:new#
    cookieNew                               ,


-- ** parse #method:parse#
    cookieParse                             ,


-- ** setDomain #method:setDomain#
    CookieSetDomainMethodInfo               ,
    cookieSetDomain                         ,


-- ** setExpires #method:setExpires#
    CookieSetExpiresMethodInfo              ,
    cookieSetExpires                        ,


-- ** setHttpOnly #method:setHttpOnly#
    CookieSetHttpOnlyMethodInfo             ,
    cookieSetHttpOnly                       ,


-- ** setMaxAge #method:setMaxAge#
    CookieSetMaxAgeMethodInfo               ,
    cookieSetMaxAge                         ,


-- ** setName #method:setName#
    CookieSetNameMethodInfo                 ,
    cookieSetName                           ,


-- ** setPath #method:setPath#
    CookieSetPathMethodInfo                 ,
    cookieSetPath                           ,


-- ** setSecure #method:setSecure#
    CookieSetSecureMethodInfo               ,
    cookieSetSecure                         ,


-- ** setValue #method:setValue#
    CookieSetValueMethodInfo                ,
    cookieSetValue                          ,


-- ** toCookieHeader #method:toCookieHeader#
    CookieToCookieHeaderMethodInfo          ,
    cookieToCookieHeader                    ,


-- ** toSetCookieHeader #method:toSetCookieHeader#
    CookieToSetCookieHeaderMethodInfo       ,
    cookieToSetCookieHeader                 ,




 -- * Properties
-- ** domain #attr:domain#
    clearCookieDomain                       ,
    cookie_domain                           ,
    getCookieDomain                         ,
    setCookieDomain                         ,


-- ** expires #attr:expires#
    clearCookieExpires                      ,
    cookie_expires                          ,
    getCookieExpires                        ,
    setCookieExpires                        ,


-- ** httpOnly #attr:httpOnly#
    cookie_httpOnly                         ,
    getCookieHttpOnly                       ,
    setCookieHttpOnly                       ,


-- ** name #attr:name#
    clearCookieName                         ,
    cookie_name                             ,
    getCookieName                           ,
    setCookieName                           ,


-- ** path #attr:path#
    clearCookiePath                         ,
    cookie_path                             ,
    getCookiePath                           ,
    setCookiePath                           ,


-- ** secure #attr:secure#
    cookie_secure                           ,
    getCookieSecure                         ,
    setCookieSecure                         ,


-- ** value #attr:value#
    clearCookieValue                        ,
    cookie_value                            ,
    getCookieValue                          ,
    setCookieValue                          ,




    ) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 {-# SOURCE #-} qualified GI.Soup.Structs.Date as Soup.Date
import {-# SOURCE #-} qualified GI.Soup.Structs.URI as Soup.URI

newtype Cookie = Cookie (ManagedPtr Cookie)
foreign import ccall "soup_cookie_get_type" c_soup_cookie_get_type :: 
    IO GType

instance BoxedObject Cookie where
    boxedType _ = c_soup_cookie_get_type

-- | Construct a `Cookie` struct initialized to zero.
newZeroCookie :: MonadIO m => m Cookie
newZeroCookie = liftIO $ callocBoxedBytes 48 >>= wrapBoxed Cookie

instance tag ~ 'AttrSet => Constructible Cookie tag where
    new _ attrs = do
        o <- newZeroCookie
        GI.Attributes.set o attrs
        return o


noCookie :: Maybe Cookie
noCookie = Nothing

getCookieName :: MonadIO m => Cookie -> m (Maybe T.Text)
getCookieName 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

setCookieName :: MonadIO m => Cookie -> CString -> m ()
setCookieName s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: CString)

clearCookieName :: MonadIO m => Cookie -> m ()
clearCookieName s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (FP.nullPtr :: CString)

data CookieNameFieldInfo
instance AttrInfo CookieNameFieldInfo where
    type AttrAllowedOps CookieNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint CookieNameFieldInfo = (~) CString
    type AttrBaseTypeConstraint CookieNameFieldInfo = (~) Cookie
    type AttrGetType CookieNameFieldInfo = Maybe T.Text
    type AttrLabel CookieNameFieldInfo = "name"
    type AttrOrigin CookieNameFieldInfo = Cookie
    attrGet _ = getCookieName
    attrSet _ = setCookieName
    attrConstruct = undefined
    attrClear _ = clearCookieName

cookie_name :: AttrLabelProxy "name"
cookie_name = AttrLabelProxy


getCookieValue :: MonadIO m => Cookie -> m (Maybe T.Text)
getCookieValue s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

setCookieValue :: MonadIO m => Cookie -> CString -> m ()
setCookieValue s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: CString)

clearCookieValue :: MonadIO m => Cookie -> m ()
clearCookieValue s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullPtr :: CString)

data CookieValueFieldInfo
instance AttrInfo CookieValueFieldInfo where
    type AttrAllowedOps CookieValueFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint CookieValueFieldInfo = (~) CString
    type AttrBaseTypeConstraint CookieValueFieldInfo = (~) Cookie
    type AttrGetType CookieValueFieldInfo = Maybe T.Text
    type AttrLabel CookieValueFieldInfo = "value"
    type AttrOrigin CookieValueFieldInfo = Cookie
    attrGet _ = getCookieValue
    attrSet _ = setCookieValue
    attrConstruct = undefined
    attrClear _ = clearCookieValue

cookie_value :: AttrLabelProxy "value"
cookie_value = AttrLabelProxy


getCookieDomain :: MonadIO m => Cookie -> m (Maybe T.Text)
getCookieDomain s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

setCookieDomain :: MonadIO m => Cookie -> CString -> m ()
setCookieDomain s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: CString)

clearCookieDomain :: MonadIO m => Cookie -> m ()
clearCookieDomain s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullPtr :: CString)

data CookieDomainFieldInfo
instance AttrInfo CookieDomainFieldInfo where
    type AttrAllowedOps CookieDomainFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint CookieDomainFieldInfo = (~) CString
    type AttrBaseTypeConstraint CookieDomainFieldInfo = (~) Cookie
    type AttrGetType CookieDomainFieldInfo = Maybe T.Text
    type AttrLabel CookieDomainFieldInfo = "domain"
    type AttrOrigin CookieDomainFieldInfo = Cookie
    attrGet _ = getCookieDomain
    attrSet _ = setCookieDomain
    attrConstruct = undefined
    attrClear _ = clearCookieDomain

cookie_domain :: AttrLabelProxy "domain"
cookie_domain = AttrLabelProxy


getCookiePath :: MonadIO m => Cookie -> m (Maybe T.Text)
getCookiePath s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

setCookiePath :: MonadIO m => Cookie -> CString -> m ()
setCookiePath s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (val :: CString)

clearCookiePath :: MonadIO m => Cookie -> m ()
clearCookiePath s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (FP.nullPtr :: CString)

data CookiePathFieldInfo
instance AttrInfo CookiePathFieldInfo where
    type AttrAllowedOps CookiePathFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint CookiePathFieldInfo = (~) CString
    type AttrBaseTypeConstraint CookiePathFieldInfo = (~) Cookie
    type AttrGetType CookiePathFieldInfo = Maybe T.Text
    type AttrLabel CookiePathFieldInfo = "path"
    type AttrOrigin CookiePathFieldInfo = Cookie
    attrGet _ = getCookiePath
    attrSet _ = setCookiePath
    attrConstruct = undefined
    attrClear _ = clearCookiePath

cookie_path :: AttrLabelProxy "path"
cookie_path = AttrLabelProxy


getCookieExpires :: MonadIO m => Cookie -> m (Maybe Soup.Date.Date)
getCookieExpires s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 32) :: IO (Ptr Soup.Date.Date)
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- (newBoxed Soup.Date.Date) val'
        return val''
    return result

setCookieExpires :: MonadIO m => Cookie -> Ptr Soup.Date.Date -> m ()
setCookieExpires s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (val :: Ptr Soup.Date.Date)

clearCookieExpires :: MonadIO m => Cookie -> m ()
clearCookieExpires s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (FP.nullPtr :: Ptr Soup.Date.Date)

data CookieExpiresFieldInfo
instance AttrInfo CookieExpiresFieldInfo where
    type AttrAllowedOps CookieExpiresFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint CookieExpiresFieldInfo = (~) (Ptr Soup.Date.Date)
    type AttrBaseTypeConstraint CookieExpiresFieldInfo = (~) Cookie
    type AttrGetType CookieExpiresFieldInfo = Maybe Soup.Date.Date
    type AttrLabel CookieExpiresFieldInfo = "expires"
    type AttrOrigin CookieExpiresFieldInfo = Cookie
    attrGet _ = getCookieExpires
    attrSet _ = setCookieExpires
    attrConstruct = undefined
    attrClear _ = clearCookieExpires

cookie_expires :: AttrLabelProxy "expires"
cookie_expires = AttrLabelProxy


getCookieSecure :: MonadIO m => Cookie -> m Bool
getCookieSecure s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 40) :: IO CInt
    let val' = (/= 0) val
    return val'

setCookieSecure :: MonadIO m => Cookie -> Bool -> m ()
setCookieSecure s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = (fromIntegral . fromEnum) val
    poke (ptr `plusPtr` 40) (val' :: CInt)

data CookieSecureFieldInfo
instance AttrInfo CookieSecureFieldInfo where
    type AttrAllowedOps CookieSecureFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint CookieSecureFieldInfo = (~) Bool
    type AttrBaseTypeConstraint CookieSecureFieldInfo = (~) Cookie
    type AttrGetType CookieSecureFieldInfo = Bool
    type AttrLabel CookieSecureFieldInfo = "secure"
    type AttrOrigin CookieSecureFieldInfo = Cookie
    attrGet _ = getCookieSecure
    attrSet _ = setCookieSecure
    attrConstruct = undefined
    attrClear _ = undefined

cookie_secure :: AttrLabelProxy "secure"
cookie_secure = AttrLabelProxy


getCookieHttpOnly :: MonadIO m => Cookie -> m Bool
getCookieHttpOnly s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 44) :: IO CInt
    let val' = (/= 0) val
    return val'

setCookieHttpOnly :: MonadIO m => Cookie -> Bool -> m ()
setCookieHttpOnly s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = (fromIntegral . fromEnum) val
    poke (ptr `plusPtr` 44) (val' :: CInt)

data CookieHttpOnlyFieldInfo
instance AttrInfo CookieHttpOnlyFieldInfo where
    type AttrAllowedOps CookieHttpOnlyFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint CookieHttpOnlyFieldInfo = (~) Bool
    type AttrBaseTypeConstraint CookieHttpOnlyFieldInfo = (~) Cookie
    type AttrGetType CookieHttpOnlyFieldInfo = Bool
    type AttrLabel CookieHttpOnlyFieldInfo = "http_only"
    type AttrOrigin CookieHttpOnlyFieldInfo = Cookie
    attrGet _ = getCookieHttpOnly
    attrSet _ = setCookieHttpOnly
    attrConstruct = undefined
    attrClear _ = undefined

cookie_httpOnly :: AttrLabelProxy "httpOnly"
cookie_httpOnly = AttrLabelProxy



instance O.HasAttributeList Cookie
type instance O.AttributeList Cookie = CookieAttributeList
type CookieAttributeList = ('[ '("name", CookieNameFieldInfo), '("value", CookieValueFieldInfo), '("domain", CookieDomainFieldInfo), '("path", CookiePathFieldInfo), '("expires", CookieExpiresFieldInfo), '("secure", CookieSecureFieldInfo), '("httpOnly", CookieHttpOnlyFieldInfo)] :: [(Symbol, *)])

-- method Cookie::new
-- method type : Constructor
-- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "cookie name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "cookie value", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "domain", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "cookie domain or hostname", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "cookie path, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "max_age", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "max age of the cookie, or -1 for a session cookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Cookie"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_new" soup_cookie_new :: 
    CString ->                              -- name : TBasicType TUTF8
    CString ->                              -- value : TBasicType TUTF8
    CString ->                              -- domain : TBasicType TUTF8
    CString ->                              -- path : TBasicType TUTF8
    Int32 ->                                -- max_age : TBasicType TInt
    IO (Ptr Cookie)

{- |
Creates a new 'GI.Soup.Structs.Cookie.Cookie' with the given attributes. (Use
'GI.Soup.Structs.Cookie.cookieSetSecure' and 'GI.Soup.Structs.Cookie.cookieSetHttpOnly' if you
need to set those attributes on the returned cookie.)

If /@domain@/ starts with \".\", that indicates a domain (which matches
the string after the \".\", or any hostname that has /@domain@/ as a
suffix). Otherwise, it is a hostname and must match exactly.

/@maxAge@/ is used to set the \"expires\" attribute on the cookie; pass
-1 to not include the attribute (indicating that the cookie expires
with the current session), 0 for an already-expired cookie, or a
lifetime in seconds. You can use the constants
'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_HOUR', 'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_DAY',
'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_WEEK' and 'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_YEAR' (or
multiples thereof) to calculate this value. (If you really care
about setting the exact time that the cookie will expire, use
'GI.Soup.Structs.Cookie.cookieSetExpires'.)

@since 2.24
-}
cookieNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@name@/: cookie name -}
    -> T.Text
    {- ^ /@value@/: cookie value -}
    -> T.Text
    {- ^ /@domain@/: cookie domain or hostname -}
    -> T.Text
    {- ^ /@path@/: cookie path, or 'Nothing' -}
    -> Int32
    {- ^ /@maxAge@/: max age of the cookie, or -1 for a session cookie -}
    -> m Cookie
    {- ^ __Returns:__ a new 'GI.Soup.Structs.Cookie.Cookie'. -}
cookieNew name value domain path maxAge = liftIO $ do
    name' <- textToCString name
    value' <- textToCString value
    domain' <- textToCString domain
    path' <- textToCString path
    result <- soup_cookie_new name' value' domain' path' maxAge
    checkUnexpectedReturnNULL "cookieNew" result
    result' <- (wrapBoxed Cookie) result
    freeMem name'
    freeMem value'
    freeMem domain'
    freeMem path'
    return result'

-- method Cookie::applies_to_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "uri", argType = TInterface (Name {namespace = "Soup", name = "URI"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupURI", 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_cookie_applies_to_uri" soup_cookie_applies_to_uri :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    Ptr Soup.URI.URI ->                     -- uri : TInterface (Name {namespace = "Soup", name = "URI"})
    IO CInt

{- |
Tests if /@cookie@/ should be sent to /@uri@/.

(At the moment, this does not check that /@cookie@/\'s domain matches
/@uri@/, because it assumes that the caller has already done that.
But don\'t rely on that; it may change in the future.)

@since 2.24
-}
cookieAppliesToUri ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> Soup.URI.URI
    {- ^ /@uri@/: a 'GI.Soup.Structs.URI.URI' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@cookie@/ should be sent to /@uri@/, 'False' if
not -}
cookieAppliesToUri cookie uri = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    uri' <- unsafeManagedPtrGetPtr uri
    result <- soup_cookie_applies_to_uri cookie' uri'
    let result' = (/= 0) result
    touchManagedPtr cookie
    touchManagedPtr uri
    return result'

data CookieAppliesToUriMethodInfo
instance (signature ~ (Soup.URI.URI -> m Bool), MonadIO m) => O.MethodInfo CookieAppliesToUriMethodInfo Cookie signature where
    overloadedMethod _ = cookieAppliesToUri

-- method Cookie::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Cookie"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_copy" soup_cookie_copy :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO (Ptr Cookie)

{- |
Copies /@cookie@/.

@since 2.24
-}
cookieCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m Cookie
    {- ^ __Returns:__ a copy of /@cookie@/ -}
cookieCopy cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_copy cookie'
    checkUnexpectedReturnNULL "cookieCopy" result
    result' <- (wrapBoxed Cookie) result
    touchManagedPtr cookie
    return result'

data CookieCopyMethodInfo
instance (signature ~ (m Cookie), MonadIO m) => O.MethodInfo CookieCopyMethodInfo Cookie signature where
    overloadedMethod _ = cookieCopy

-- method Cookie::domain_matches
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "host", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a URI", 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_cookie_domain_matches" soup_cookie_domain_matches :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CString ->                              -- host : TBasicType TUTF8
    IO CInt

{- |
Checks if the /@cookie@/\'s domain and /@host@/ match in the sense that
/@cookie@/ should be sent when making a request to /@host@/, or that
/@cookie@/ should be accepted when receiving a response from /@host@/.

@since 2.30
-}
cookieDomainMatches ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> T.Text
    {- ^ /@host@/: a URI -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the domains match, 'False' otherwise -}
cookieDomainMatches cookie host = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    host' <- textToCString host
    result <- soup_cookie_domain_matches cookie' host'
    let result' = (/= 0) result
    touchManagedPtr cookie
    freeMem host'
    return result'

data CookieDomainMatchesMethodInfo
instance (signature ~ (T.Text -> m Bool), MonadIO m) => O.MethodInfo CookieDomainMatchesMethodInfo Cookie signature where
    overloadedMethod _ = cookieDomainMatches

-- method Cookie::equal
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie1", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cookie2", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", 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_cookie_equal" soup_cookie_equal :: 
    Ptr Cookie ->                           -- cookie1 : TInterface (Name {namespace = "Soup", name = "Cookie"})
    Ptr Cookie ->                           -- cookie2 : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CInt

{- |
Tests if /@cookie1@/ and /@cookie2@/ are equal.

Note that currently, this does not check that the cookie domains
match. This may change in the future.

@since 2.24
-}
cookieEqual ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie1@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> Cookie
    {- ^ /@cookie2@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m Bool
    {- ^ __Returns:__ whether the cookies are equal. -}
cookieEqual cookie1 cookie2 = liftIO $ do
    cookie1' <- unsafeManagedPtrGetPtr cookie1
    cookie2' <- unsafeManagedPtrGetPtr cookie2
    result <- soup_cookie_equal cookie1' cookie2'
    let result' = (/= 0) result
    touchManagedPtr cookie1
    touchManagedPtr cookie2
    return result'

data CookieEqualMethodInfo
instance (signature ~ (Cookie -> m Bool), MonadIO m) => O.MethodInfo CookieEqualMethodInfo Cookie signature where
    overloadedMethod _ = cookieEqual

-- method Cookie::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_free" soup_cookie_free :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO ()

{- |
Frees /@cookie@/

@since 2.24
-}
cookieFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m ()
cookieFree cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    soup_cookie_free cookie'
    touchManagedPtr cookie
    return ()

data CookieFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo CookieFreeMethodInfo Cookie signature where
    overloadedMethod _ = cookieFree

-- method Cookie::get_domain
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_get_domain" soup_cookie_get_domain :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CString

{- |
Gets /@cookie@/\'s domain

@since 2.32
-}
cookieGetDomain ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m T.Text
    {- ^ __Returns:__ /@cookie@/\'s domain -}
cookieGetDomain cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_domain cookie'
    checkUnexpectedReturnNULL "cookieGetDomain" result
    result' <- cstringToText result
    touchManagedPtr cookie
    return result'

data CookieGetDomainMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CookieGetDomainMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetDomain

-- method Cookie::get_expires
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Date"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_get_expires" soup_cookie_get_expires :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO (Ptr Soup.Date.Date)

{- |
Gets /@cookie@/\'s expiration time

@since 2.32
-}
cookieGetExpires ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m Soup.Date.Date
    {- ^ __Returns:__ /@cookie@/\'s expiration time, which is
owned by /@cookie@/ and should not be modified or freed. -}
cookieGetExpires cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_expires cookie'
    checkUnexpectedReturnNULL "cookieGetExpires" result
    result' <- (newBoxed Soup.Date.Date) result
    touchManagedPtr cookie
    return result'

data CookieGetExpiresMethodInfo
instance (signature ~ (m Soup.Date.Date), MonadIO m) => O.MethodInfo CookieGetExpiresMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetExpires

-- method Cookie::get_http_only
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", 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_cookie_get_http_only" soup_cookie_get_http_only :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CInt

{- |
Gets /@cookie@/\'s HttpOnly attribute

@since 2.32
-}
cookieGetHttpOnly ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m Bool
    {- ^ __Returns:__ /@cookie@/\'s HttpOnly attribute -}
cookieGetHttpOnly cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_http_only cookie'
    let result' = (/= 0) result
    touchManagedPtr cookie
    return result'

data CookieGetHttpOnlyMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo CookieGetHttpOnlyMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetHttpOnly

-- method Cookie::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_get_name" soup_cookie_get_name :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CString

{- |
Gets /@cookie@/\'s name

@since 2.32
-}
cookieGetName ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m T.Text
    {- ^ __Returns:__ /@cookie@/\'s name -}
cookieGetName cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_name cookie'
    checkUnexpectedReturnNULL "cookieGetName" result
    result' <- cstringToText result
    touchManagedPtr cookie
    return result'

data CookieGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CookieGetNameMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetName

-- method Cookie::get_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_get_path" soup_cookie_get_path :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CString

{- |
Gets /@cookie@/\'s path

@since 2.32
-}
cookieGetPath ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m T.Text
    {- ^ __Returns:__ /@cookie@/\'s path -}
cookieGetPath cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_path cookie'
    checkUnexpectedReturnNULL "cookieGetPath" result
    result' <- cstringToText result
    touchManagedPtr cookie
    return result'

data CookieGetPathMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CookieGetPathMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetPath

-- method Cookie::get_secure
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", 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_cookie_get_secure" soup_cookie_get_secure :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CInt

{- |
Gets /@cookie@/\'s secure attribute

@since 2.32
-}
cookieGetSecure ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m Bool
    {- ^ __Returns:__ /@cookie@/\'s secure attribute -}
cookieGetSecure cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_secure cookie'
    let result' = (/= 0) result
    touchManagedPtr cookie
    return result'

data CookieGetSecureMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo CookieGetSecureMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetSecure

-- method Cookie::get_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_get_value" soup_cookie_get_value :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CString

{- |
Gets /@cookie@/\'s value

@since 2.32
-}
cookieGetValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m T.Text
    {- ^ __Returns:__ /@cookie@/\'s value -}
cookieGetValue cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_get_value cookie'
    checkUnexpectedReturnNULL "cookieGetValue" result
    result' <- cstringToText result
    touchManagedPtr cookie
    return result'

data CookieGetValueMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CookieGetValueMethodInfo Cookie signature where
    overloadedMethod _ = cookieGetValue

-- method Cookie::set_domain
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "domain", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new domain", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_domain" soup_cookie_set_domain :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CString ->                              -- domain : TBasicType TUTF8
    IO ()

{- |
Sets /@cookie@/\'s domain to /@domain@/

@since 2.24
-}
cookieSetDomain ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> T.Text
    {- ^ /@domain@/: the new domain -}
    -> m ()
cookieSetDomain cookie domain = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    domain' <- textToCString domain
    soup_cookie_set_domain cookie' domain'
    touchManagedPtr cookie
    freeMem domain'
    return ()

data CookieSetDomainMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo CookieSetDomainMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetDomain

-- method Cookie::set_expires
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "expires", argType = TInterface (Name {namespace = "Soup", name = "Date"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new expiration time, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_expires" soup_cookie_set_expires :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    Ptr Soup.Date.Date ->                   -- expires : TInterface (Name {namespace = "Soup", name = "Date"})
    IO ()

{- |
Sets /@cookie@/\'s expiration time to /@expires@/. If /@expires@/ is 'Nothing',
/@cookie@/ will be a session cookie and will expire at the end of the
client\'s session.

(This sets the same property as 'GI.Soup.Structs.Cookie.cookieSetMaxAge'.)

@since 2.24
-}
cookieSetExpires ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> Soup.Date.Date
    {- ^ /@expires@/: the new expiration time, or 'Nothing' -}
    -> m ()
cookieSetExpires cookie expires = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    expires' <- unsafeManagedPtrGetPtr expires
    soup_cookie_set_expires cookie' expires'
    touchManagedPtr cookie
    touchManagedPtr expires
    return ()

data CookieSetExpiresMethodInfo
instance (signature ~ (Soup.Date.Date -> m ()), MonadIO m) => O.MethodInfo CookieSetExpiresMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetExpires

-- method Cookie::set_http_only
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "http_only", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new value for the HttpOnly attribute", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_http_only" soup_cookie_set_http_only :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CInt ->                                 -- http_only : TBasicType TBoolean
    IO ()

{- |
Sets /@cookie@/\'s HttpOnly attribute to /@httpOnly@/. If 'True', /@cookie@/
will be marked as \"http only\", meaning it should not be exposed to
web page scripts or other untrusted code.

@since 2.24
-}
cookieSetHttpOnly ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> Bool
    {- ^ /@httpOnly@/: the new value for the HttpOnly attribute -}
    -> m ()
cookieSetHttpOnly cookie httpOnly = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    let httpOnly' = (fromIntegral . fromEnum) httpOnly
    soup_cookie_set_http_only cookie' httpOnly'
    touchManagedPtr cookie
    return ()

data CookieSetHttpOnlyMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m) => O.MethodInfo CookieSetHttpOnlyMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetHttpOnly

-- method Cookie::set_max_age
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "max_age", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new max age", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_max_age" soup_cookie_set_max_age :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    Int32 ->                                -- max_age : TBasicType TInt
    IO ()

{- |
Sets /@cookie@/\'s max age to /@maxAge@/. If /@maxAge@/ is -1, the cookie
is a session cookie, and will expire at the end of the client\'s
session. Otherwise, it is the number of seconds until the cookie
expires. You can use the constants 'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_HOUR',
'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_DAY', 'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_WEEK' and
'GI.Soup.Constants.COOKIE_MAX_AGE_ONE_YEAR' (or multiples thereof) to calculate
this value. (A value of 0 indicates that the cookie should be
considered already-expired.)

(This sets the same property as 'GI.Soup.Structs.Cookie.cookieSetExpires'.)

@since 2.24
-}
cookieSetMaxAge ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> Int32
    {- ^ /@maxAge@/: the new max age -}
    -> m ()
cookieSetMaxAge cookie maxAge = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    soup_cookie_set_max_age cookie' maxAge
    touchManagedPtr cookie
    return ()

data CookieSetMaxAgeMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m) => O.MethodInfo CookieSetMaxAgeMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetMaxAge

-- method Cookie::set_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_name" soup_cookie_set_name :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CString ->                              -- name : TBasicType TUTF8
    IO ()

{- |
Sets /@cookie@/\'s name to /@name@/

@since 2.24
-}
cookieSetName ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> T.Text
    {- ^ /@name@/: the new name -}
    -> m ()
cookieSetName cookie name = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    name' <- textToCString name
    soup_cookie_set_name cookie' name'
    touchManagedPtr cookie
    freeMem name'
    return ()

data CookieSetNameMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo CookieSetNameMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetName

-- method Cookie::set_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new path", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_path" soup_cookie_set_path :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CString ->                              -- path : TBasicType TUTF8
    IO ()

{- |
Sets /@cookie@/\'s path to /@path@/

@since 2.24
-}
cookieSetPath ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> T.Text
    {- ^ /@path@/: the new path -}
    -> m ()
cookieSetPath cookie path = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    path' <- textToCString path
    soup_cookie_set_path cookie' path'
    touchManagedPtr cookie
    freeMem path'
    return ()

data CookieSetPathMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo CookieSetPathMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetPath

-- method Cookie::set_secure
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "secure", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new value for the secure attribute", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_secure" soup_cookie_set_secure :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CInt ->                                 -- secure : TBasicType TBoolean
    IO ()

{- |
Sets /@cookie@/\'s secure attribute to /@secure@/. If 'True', /@cookie@/ will
only be transmitted from the client to the server over secure
(https) connections.

@since 2.24
-}
cookieSetSecure ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> Bool
    {- ^ /@secure@/: the new value for the secure attribute -}
    -> m ()
cookieSetSecure cookie secure = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    let secure' = (fromIntegral . fromEnum) secure
    soup_cookie_set_secure cookie' secure'
    touchManagedPtr cookie
    return ()

data CookieSetSecureMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m) => O.MethodInfo CookieSetSecureMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetSecure

-- method Cookie::set_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new value", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_set_value" soup_cookie_set_value :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    CString ->                              -- value : TBasicType TUTF8
    IO ()

{- |
Sets /@cookie@/\'s value to /@value@/

@since 2.24
-}
cookieSetValue ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> T.Text
    {- ^ /@value@/: the new value -}
    -> m ()
cookieSetValue cookie value = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    value' <- textToCString value
    soup_cookie_set_value cookie' value'
    touchManagedPtr cookie
    freeMem value'
    return ()

data CookieSetValueMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m) => O.MethodInfo CookieSetValueMethodInfo Cookie signature where
    overloadedMethod _ = cookieSetValue

-- method Cookie::to_cookie_header
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_to_cookie_header" soup_cookie_to_cookie_header :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CString

{- |
Serializes /@cookie@/ in the format used by the Cookie header (ie, for
returning a cookie from a 'GI.Soup.Objects.Session.Session' to a server).

@since 2.24
-}
cookieToCookieHeader ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m T.Text
    {- ^ __Returns:__ the header -}
cookieToCookieHeader cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_to_cookie_header cookie'
    checkUnexpectedReturnNULL "cookieToCookieHeader" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr cookie
    return result'

data CookieToCookieHeaderMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CookieToCookieHeaderMethodInfo Cookie signature where
    overloadedMethod _ = cookieToCookieHeader

-- method Cookie::to_set_cookie_header
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "cookie", argType = TInterface (Name {namespace = "Soup", name = "Cookie"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupCookie", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_to_set_cookie_header" soup_cookie_to_set_cookie_header :: 
    Ptr Cookie ->                           -- cookie : TInterface (Name {namespace = "Soup", name = "Cookie"})
    IO CString

{- |
Serializes /@cookie@/ in the format used by the Set-Cookie header
(ie, for sending a cookie from a 'GI.Soup.Objects.Server.Server' to a client).

@since 2.24
-}
cookieToSetCookieHeader ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Cookie
    {- ^ /@cookie@/: a 'GI.Soup.Structs.Cookie.Cookie' -}
    -> m T.Text
    {- ^ __Returns:__ the header -}
cookieToSetCookieHeader cookie = liftIO $ do
    cookie' <- unsafeManagedPtrGetPtr cookie
    result <- soup_cookie_to_set_cookie_header cookie'
    checkUnexpectedReturnNULL "cookieToSetCookieHeader" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr cookie
    return result'

data CookieToSetCookieHeaderMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.MethodInfo CookieToSetCookieHeaderMethodInfo Cookie signature where
    overloadedMethod _ = cookieToSetCookieHeader

-- method Cookie::parse
-- method type : MemberFunction
-- Args : [Arg {argCName = "header", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a cookie string (eg, the value of a Set-Cookie header)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "origin", argType = TInterface (Name {namespace = "Soup", name = "URI"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "origin of the cookie, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Cookie"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_cookie_parse" soup_cookie_parse :: 
    CString ->                              -- header : TBasicType TUTF8
    Ptr Soup.URI.URI ->                     -- origin : TInterface (Name {namespace = "Soup", name = "URI"})
    IO (Ptr Cookie)

{- |
Parses /@header@/ and returns a 'GI.Soup.Structs.Cookie.Cookie'. (If /@header@/ contains
multiple cookies, only the first one will be parsed.)

If /@header@/ does not have \"path\" or \"domain\" attributes, they will
be defaulted from /@origin@/. If /@origin@/ is 'Nothing', path will default
to \"\/\", but domain will be left as 'Nothing'. Note that this is not a
valid state for a 'GI.Soup.Structs.Cookie.Cookie', and you will need to fill in some
appropriate string for the domain if you want to actually make use
of the cookie.

@since 2.24
-}
cookieParse ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@header@/: a cookie string (eg, the value of a Set-Cookie header) -}
    -> Soup.URI.URI
    {- ^ /@origin@/: origin of the cookie, or 'Nothing' -}
    -> m (Maybe Cookie)
    {- ^ __Returns:__ a new 'GI.Soup.Structs.Cookie.Cookie', or 'Nothing' if it could
not be parsed, or contained an illegal \"domain\" attribute for a
cookie originating from /@origin@/. -}
cookieParse header origin = liftIO $ do
    header' <- textToCString header
    origin' <- unsafeManagedPtrGetPtr origin
    result <- soup_cookie_parse header' origin'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Cookie) result'
        return result''
    touchManagedPtr origin
    freeMem header'
    return maybeResult

type family ResolveCookieMethod (t :: Symbol) (o :: *) :: * where
    ResolveCookieMethod "appliesToUri" o = CookieAppliesToUriMethodInfo
    ResolveCookieMethod "copy" o = CookieCopyMethodInfo
    ResolveCookieMethod "domainMatches" o = CookieDomainMatchesMethodInfo
    ResolveCookieMethod "equal" o = CookieEqualMethodInfo
    ResolveCookieMethod "free" o = CookieFreeMethodInfo
    ResolveCookieMethod "toCookieHeader" o = CookieToCookieHeaderMethodInfo
    ResolveCookieMethod "toSetCookieHeader" o = CookieToSetCookieHeaderMethodInfo
    ResolveCookieMethod "getDomain" o = CookieGetDomainMethodInfo
    ResolveCookieMethod "getExpires" o = CookieGetExpiresMethodInfo
    ResolveCookieMethod "getHttpOnly" o = CookieGetHttpOnlyMethodInfo
    ResolveCookieMethod "getName" o = CookieGetNameMethodInfo
    ResolveCookieMethod "getPath" o = CookieGetPathMethodInfo
    ResolveCookieMethod "getSecure" o = CookieGetSecureMethodInfo
    ResolveCookieMethod "getValue" o = CookieGetValueMethodInfo
    ResolveCookieMethod "setDomain" o = CookieSetDomainMethodInfo
    ResolveCookieMethod "setExpires" o = CookieSetExpiresMethodInfo
    ResolveCookieMethod "setHttpOnly" o = CookieSetHttpOnlyMethodInfo
    ResolveCookieMethod "setMaxAge" o = CookieSetMaxAgeMethodInfo
    ResolveCookieMethod "setName" o = CookieSetNameMethodInfo
    ResolveCookieMethod "setPath" o = CookieSetPathMethodInfo
    ResolveCookieMethod "setSecure" o = CookieSetSecureMethodInfo
    ResolveCookieMethod "setValue" o = CookieSetValueMethodInfo
    ResolveCookieMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCookieMethod t Cookie, O.MethodInfo info Cookie p) => O.IsLabelProxy t (Cookie -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveCookieMethod t Cookie, O.MethodInfo info Cookie p) => O.IsLabel t (Cookie -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif