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

A #SoupURI represents a (parsed) URI. #SoupURI supports RFC 3986
(URI Generic Syntax), and can parse any valid URI. However, libsoup
only uses "http" and "https" URIs internally; You can use
SOUP_URI_VALID_FOR_HTTP() to test if a #SoupURI is a valid HTTP
URI.

@scheme will always be set in any URI. It is an interned string and
is always all lowercase. (If you parse a URI with a non-lowercase
scheme, it will be converted to lowercase.) The macros
%SOUP_URI_SCHEME_HTTP and %SOUP_URI_SCHEME_HTTPS provide the
interned values for "http" and "https" and can be compared against
URI @scheme values.

@user and @password are parsed as defined in the older URI specs
(ie, separated by a colon; RFC 3986 only talks about a single
"userinfo" field). Note that @password is not included in the
output of soup_uri_to_string(). libsoup does not normally use these
fields; authentication is handled via #SoupSession signals.

@host contains the hostname, and @port the port specified in the
URI. If the URI doesn't contain a hostname, @host will be %NULL,
and if it doesn't specify a port, @port may be 0. However, for
"http" and "https" URIs, @host is guaranteed to be non-%NULL
(trying to parse an http URI with no @host will return %NULL), and
@port will always be non-0 (because libsoup knows the default value
to use when it is not specified in the URI).

@path is always non-%NULL. For http/https URIs, @path will never be
an empty string either; if the input URI has no path, the parsed
#SoupURI will have a @path of "/".

@query and @fragment are optional for all URI types.
soup_form_decode() may be useful for parsing @query.

Note that @path, @query, and @fragment may contain
%<!-- -->-encoded characters. soup_uri_new() calls
soup_uri_normalize() on them, but not soup_uri_decode(). This is
necessary to ensure that soup_uri_to_string() will generate a URI
that has exactly the same meaning as the original. (In theory,
#SoupURI should leave @user, @password, and @host partially-encoded
as well, but this would be more annoying than useful.)
-}

module GI.Soup.Structs.URI
    ( 

-- * Exported types
    URI(..)                                 ,
    noURI                                   ,


 -- * Methods
-- ** uRICopy
    uRICopy                                 ,


-- ** uRICopyHost
    uRICopyHost                             ,


-- ** uRIEqual
    uRIEqual                                ,


-- ** uRIFree
    uRIFree                                 ,


-- ** uRIGetFragment
    uRIGetFragment                          ,


-- ** uRIGetHost
    uRIGetHost                              ,


-- ** uRIGetPassword
    uRIGetPassword                          ,


-- ** uRIGetPath
    uRIGetPath                              ,


-- ** uRIGetPort
    uRIGetPort                              ,


-- ** uRIGetQuery
    uRIGetQuery                             ,


-- ** uRIGetScheme
    uRIGetScheme                            ,


-- ** uRIGetUser
    uRIGetUser                              ,


-- ** uRIHostEqual
    uRIHostEqual                            ,


-- ** uRIHostHash
    uRIHostHash                             ,


-- ** uRINew
    uRINew                                  ,


-- ** uRINewWithBase
    uRINewWithBase                          ,


-- ** uRISetFragment
    uRISetFragment                          ,


-- ** uRISetHost
    uRISetHost                              ,


-- ** uRISetPassword
    uRISetPassword                          ,


-- ** uRISetPath
    uRISetPath                              ,


-- ** uRISetPort
    uRISetPort                              ,


-- ** uRISetQuery
    uRISetQuery                             ,


-- ** uRISetQueryFromForm
    uRISetQueryFromForm                     ,


-- ** uRISetScheme
    uRISetScheme                            ,


-- ** uRISetUser
    uRISetUser                              ,


-- ** uRIToString
    uRIToString                             ,


-- ** uRIUsesDefaultPort
    uRIUsesDefaultPort                      ,




 -- * Properties
-- ** Fragment
    uRIReadFragment                         ,


-- ** Host
    uRIReadHost                             ,


-- ** Password
    uRIReadPassword                         ,


-- ** Path
    uRIReadPath                             ,


-- ** Port
    uRIReadPort                             ,


-- ** Query
    uRIReadQuery                            ,


-- ** Scheme
    uRIReadScheme                           ,


-- ** User
    uRIReadUser                             ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Soup.Types
import GI.Soup.Callbacks

newtype URI = URI (ForeignPtr URI)
foreign import ccall "soup_uri_get_type" c_soup_uri_get_type :: 
    IO GType

instance BoxedObject URI where
    boxedType _ = c_soup_uri_get_type

noURI :: Maybe URI
noURI = Nothing

uRIReadScheme :: URI -> IO T.Text
uRIReadScheme s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CString
    val' <- cstringToText val
    return val'

uRIReadUser :: URI -> IO T.Text
uRIReadUser s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO CString
    val' <- cstringToText val
    return val'

uRIReadPassword :: URI -> IO T.Text
uRIReadPassword s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO CString
    val' <- cstringToText val
    return val'

uRIReadHost :: URI -> IO T.Text
uRIReadHost s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO CString
    val' <- cstringToText val
    return val'

uRIReadPort :: URI -> IO Word32
uRIReadPort s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 32) :: IO Word32
    return val

uRIReadPath :: URI -> IO T.Text
uRIReadPath s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 40) :: IO CString
    val' <- cstringToText val
    return val'

uRIReadQuery :: URI -> IO T.Text
uRIReadQuery s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 48) :: IO CString
    val' <- cstringToText val
    return val'

uRIReadFragment :: URI -> IO T.Text
uRIReadFragment s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 56) :: IO CString
    val' <- cstringToText val
    return val'

-- method URI::new
-- method type : Constructor
-- Args : [Arg {argName = "uri_string", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "uri_string", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "URI"
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_new" soup_uri_new :: 
    CString ->                              -- uri_string : TBasicType TUTF8
    IO (Ptr URI)


uRINew ::
    (MonadIO m) =>
    Maybe (T.Text) ->                       -- uri_string
    m URI
uRINew uri_string = liftIO $ do
    maybeUri_string <- case uri_string of
        Nothing -> return nullPtr
        Just jUri_string -> do
            jUri_string' <- textToCString jUri_string
            return jUri_string'
    result <- soup_uri_new maybeUri_string
    checkUnexpectedReturnNULL "soup_uri_new" result
    result' <- (wrapBoxed URI) result
    freeMem maybeUri_string
    return result'

-- method URI::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "URI"
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_copy" soup_uri_copy :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO (Ptr URI)


uRICopy ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m URI
uRICopy _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_copy _obj'
    checkUnexpectedReturnNULL "soup_uri_copy" result
    result' <- (wrapBoxed URI) result
    touchManagedPtr _obj
    return result'

-- method URI::copy_host
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "URI"
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_copy_host" soup_uri_copy_host :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO (Ptr URI)


uRICopyHost ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m URI
uRICopyHost _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_copy_host _obj'
    checkUnexpectedReturnNULL "soup_uri_copy_host" result
    result' <- (wrapBoxed URI) result
    touchManagedPtr _obj
    return result'

-- method URI::equal
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri2", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri2", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_equal" soup_uri_equal :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    Ptr URI ->                              -- uri2 : TInterface "Soup" "URI"
    IO CInt


uRIEqual ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    URI ->                                  -- uri2
    m Bool
uRIEqual _obj uri2 = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let uri2' = unsafeManagedPtrGetPtr uri2
    result <- soup_uri_equal _obj' uri2'
    let result' = (/= 0) result
    touchManagedPtr _obj
    touchManagedPtr uri2
    return result'

-- method URI::free
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_free" soup_uri_free :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO ()


uRIFree ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m ()
uRIFree _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    soup_uri_free _obj'
    touchManagedPtr _obj
    return ()

-- method URI::get_fragment
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_fragment" soup_uri_get_fragment :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetFragment ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetFragment _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_fragment _obj'
    checkUnexpectedReturnNULL "soup_uri_get_fragment" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::get_host
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_host" soup_uri_get_host :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetHost ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetHost _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_host _obj'
    checkUnexpectedReturnNULL "soup_uri_get_host" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::get_password
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_password" soup_uri_get_password :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetPassword ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetPassword _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_password _obj'
    checkUnexpectedReturnNULL "soup_uri_get_password" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::get_path
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_path" soup_uri_get_path :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetPath ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetPath _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_path _obj'
    checkUnexpectedReturnNULL "soup_uri_get_path" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::get_port
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt32
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_port" soup_uri_get_port :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO Word32


uRIGetPort ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m Word32
uRIGetPort _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_port _obj'
    touchManagedPtr _obj
    return result

-- method URI::get_query
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_query" soup_uri_get_query :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetQuery ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetQuery _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_query _obj'
    checkUnexpectedReturnNULL "soup_uri_get_query" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::get_scheme
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_scheme" soup_uri_get_scheme :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetScheme ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetScheme _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_scheme _obj'
    checkUnexpectedReturnNULL "soup_uri_get_scheme" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::get_user
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_get_user" soup_uri_get_user :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CString


uRIGetUser ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m T.Text
uRIGetUser _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_get_user _obj'
    checkUnexpectedReturnNULL "soup_uri_get_user" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URI::host_equal
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "v2", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "v2", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_host_equal" soup_uri_host_equal :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    Ptr URI ->                              -- v2 : TInterface "Soup" "URI"
    IO CInt


uRIHostEqual ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    URI ->                                  -- v2
    m Bool
uRIHostEqual _obj v2 = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let v2' = unsafeManagedPtrGetPtr v2
    result <- soup_uri_host_equal _obj' v2'
    let result' = (/= 0) result
    touchManagedPtr _obj
    touchManagedPtr v2
    return result'

-- method URI::host_hash
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUInt32
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_host_hash" soup_uri_host_hash :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO Word32


uRIHostHash ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m Word32
uRIHostHash _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_host_hash _obj'
    touchManagedPtr _obj
    return result

-- method URI::new_with_base
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri_string", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri_string", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "URI"
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_new_with_base" soup_uri_new_with_base :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- uri_string : TBasicType TUTF8
    IO (Ptr URI)


uRINewWithBase ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    T.Text ->                               -- uri_string
    m URI
uRINewWithBase _obj uri_string = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    uri_string' <- textToCString uri_string
    result <- soup_uri_new_with_base _obj' uri_string'
    checkUnexpectedReturnNULL "soup_uri_new_with_base" result
    result' <- (wrapBoxed URI) result
    touchManagedPtr _obj
    freeMem uri_string'
    return result'

-- method URI::set_fragment
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "fragment", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "fragment", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_fragment" soup_uri_set_fragment :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- fragment : TBasicType TUTF8
    IO ()


uRISetFragment ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Maybe (T.Text) ->                       -- fragment
    m ()
uRISetFragment _obj fragment = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    maybeFragment <- case fragment of
        Nothing -> return nullPtr
        Just jFragment -> do
            jFragment' <- textToCString jFragment
            return jFragment'
    soup_uri_set_fragment _obj' maybeFragment
    touchManagedPtr _obj
    freeMem maybeFragment
    return ()

-- method URI::set_host
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "host", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "host", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_host" soup_uri_set_host :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- host : TBasicType TUTF8
    IO ()


uRISetHost ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Maybe (T.Text) ->                       -- host
    m ()
uRISetHost _obj host = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    maybeHost <- case host of
        Nothing -> return nullPtr
        Just jHost -> do
            jHost' <- textToCString jHost
            return jHost'
    soup_uri_set_host _obj' maybeHost
    touchManagedPtr _obj
    freeMem maybeHost
    return ()

-- method URI::set_password
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "password", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_password" soup_uri_set_password :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- password : TBasicType TUTF8
    IO ()


uRISetPassword ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Maybe (T.Text) ->                       -- password
    m ()
uRISetPassword _obj password = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    maybePassword <- case password of
        Nothing -> return nullPtr
        Just jPassword -> do
            jPassword' <- textToCString jPassword
            return jPassword'
    soup_uri_set_password _obj' maybePassword
    touchManagedPtr _obj
    freeMem maybePassword
    return ()

-- method URI::set_path
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_path" soup_uri_set_path :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- path : TBasicType TUTF8
    IO ()


uRISetPath ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    T.Text ->                               -- path
    m ()
uRISetPath _obj path = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    path' <- textToCString path
    soup_uri_set_path _obj' path'
    touchManagedPtr _obj
    freeMem path'
    return ()

-- method URI::set_port
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "port", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "port", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_port" soup_uri_set_port :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    Word32 ->                               -- port : TBasicType TUInt32
    IO ()


uRISetPort ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Word32 ->                               -- port
    m ()
uRISetPort _obj port = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    soup_uri_set_port _obj' port
    touchManagedPtr _obj
    return ()

-- method URI::set_query
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "query", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "query", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_query" soup_uri_set_query :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- query : TBasicType TUTF8
    IO ()


uRISetQuery ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Maybe (T.Text) ->                       -- query
    m ()
uRISetQuery _obj query = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    maybeQuery <- case query of
        Nothing -> return nullPtr
        Just jQuery -> do
            jQuery' <- textToCString jQuery
            return jQuery'
    soup_uri_set_query _obj' maybeQuery
    touchManagedPtr _obj
    freeMem maybeQuery
    return ()

-- method URI::set_query_from_form
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "form", argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "form", argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_query_from_form" soup_uri_set_query_from_form :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    Ptr (GHashTable CString CString) ->     -- form : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    IO ()


uRISetQueryFromForm ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Map.Map T.Text T.Text ->                -- form
    m ()
uRISetQueryFromForm _obj form = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let form' = Map.toList form
    form'' <- mapFirstA textToCString form'
    form''' <- mapSecondA textToCString form''
    let form'''' = mapFirst cstringPackPtr form'''
    let form''''' = mapSecond cstringPackPtr form''''
    form'''''' <- packGHashTable gStrHash gStrEqual (Just ptr_to_g_free) (Just ptr_to_g_free) form'''''
    soup_uri_set_query_from_form _obj' form''''''
    touchManagedPtr _obj
    unrefGHashTable form''''''
    return ()

-- method URI::set_scheme
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "scheme", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "scheme", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_scheme" soup_uri_set_scheme :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- scheme : TBasicType TUTF8
    IO ()


uRISetScheme ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    T.Text ->                               -- scheme
    m ()
uRISetScheme _obj scheme = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    scheme' <- textToCString scheme
    soup_uri_set_scheme _obj' scheme'
    touchManagedPtr _obj
    freeMem scheme'
    return ()

-- method URI::set_user
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_set_user" soup_uri_set_user :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CString ->                              -- user : TBasicType TUTF8
    IO ()


uRISetUser ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Maybe (T.Text) ->                       -- user
    m ()
uRISetUser _obj user = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    maybeUser <- case user of
        Nothing -> return nullPtr
        Just jUser -> do
            jUser' <- textToCString jUser
            return jUser'
    soup_uri_set_user _obj' maybeUser
    touchManagedPtr _obj
    freeMem maybeUser
    return ()

-- method URI::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "just_path_and_query", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "just_path_and_query", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_to_string" soup_uri_to_string :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    CInt ->                                 -- just_path_and_query : TBasicType TBoolean
    IO CString


uRIToString ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    Bool ->                                 -- just_path_and_query
    m T.Text
uRIToString _obj just_path_and_query = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let just_path_and_query' = (fromIntegral . fromEnum) just_path_and_query
    result <- soup_uri_to_string _obj' just_path_and_query'
    checkUnexpectedReturnNULL "soup_uri_to_string" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method URI::uses_default_port
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "URI", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "soup_uri_uses_default_port" soup_uri_uses_default_port :: 
    Ptr URI ->                              -- _obj : TInterface "Soup" "URI"
    IO CInt


uRIUsesDefaultPort ::
    (MonadIO m) =>
    URI ->                                  -- _obj
    m Bool
uRIUsesDefaultPort _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_uri_uses_default_port _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'