~alcinnz/hurl

cdc252ef0c0155c55282ca43b7b855d4120336e2 — Adrian Cochrane 3 years ago 6d7fb39
Various fixes.
4 files changed, 12 insertions(+), 32 deletions(-)

M hurl.cabal
M src/Network/MIME/Info.hs
M src/Network/URI/Fetch.hs
M src/Network/URI/XDG.hs
M hurl.cabal => hurl.cabal +6 -14
@@ 73,11 73,6 @@ Flag freedesktop
  Default:     True
  Manual:      True

Flag appstream
  Description:  Failing to dispatch URIs and MIMEtypes as per `freedesktop`, consults the local AppStream database to suggest apps to install. Only has an effect if the `freedesktop` is also set.
  Default:      True
  Manual:       True

Flag rewriters
  Description:  Support regexp-based URI rewriting/blocking plugins
  Default:		True


@@ 89,10 84,10 @@ source-repository head

library
  -- Modules exported by the library.
  exposed-modules:     Network.URI.Charset, Network.URI.Fetch
  exposed-modules:     Network.URI.Charset, Network.URI.Fetch, Network.MIME.Info
  
  -- Modules included in this library but not exported.
  other-modules:       Network.URI.Locale, Network.URI.Messages, Network.URI.Types, Network.MIME.Info
  other-modules:       Network.URI.Locale, Network.URI.Messages, Network.URI.Types
  
  -- LANGUAGE extensions used by modules in this package.
  -- other-extensions:    


@@ 100,7 95,7 @@ library
  -- Other library packages from which modules are imported.
  build-depends:       base >=4.9 && <5, text >= 1.2 && <1.3,
                       network-uri >=2.6 && <2.7, bytestring >= 0.10 && < 0.11,
                       async >= 2.1 && < 2.3, filepath, directory,
                       async >= 2.1 && < 2.3, filepath, directory >= 1.3.2,
                       time >= 1.6
  
  -- Directories containing source files.


@@ 126,13 121,10 @@ library
    build-depends: base64-bytestring >=1.0 && <2.0
  if flag(freedesktop)
    CPP-options:   -DWITH_XDG
    build-depends: process >= 1.2 && <2.0
    build-depends: process >= 1.2 && <2.0, xml-conduit >=1.8, zlib >= 0.6 && < 0.7, containers
    other-modules: Network.URI.XDG.Ini, Network.URI.XDG.MimeApps,
        Network.URI.XDG.DesktopEntry, Network.URI.XDG.MimeInfo, Network.URI.XDG
  if flag(freedesktop) && flag(appstream)
    CPP-options:   -DWITH_APPSTREAM
    build-depends: xml-conduit >=1.8, zlib >= 0.6 && < 0.7, containers
    other-modules: Network.URI.XDG.AppStream, Network.URI.XDG.AppStreamOutput
        Network.URI.XDG.DesktopEntry, Network.URI.XDG.MimeInfo, Network.URI.XDG,
        Network.URI.XDG.AppStream, Network.URI.XDG.AppStreamOutput
  if flag(rewriters)
    CPP-options:   -DWITH_PLUGIN_REWRITES
    build-depends: regex, regex-tdfa >= 1.2 && < 1.4

M src/Network/MIME/Info.hs => src/Network/MIME/Info.hs +1 -1
@@ 1,5 1,5 @@
{-# LANGUAGE CPP #-}
module Network.MIME.Info(mimeInfo, MIME(..)) where
module Network.MIME.Info(mimeInfo, MIME, Application(..)) where

#ifdef WITH_XDG
import Network.URI.XDG.MimeInfo (readMimeInfo)

M src/Network/URI/Fetch.hs => src/Network/URI/Fetch.hs +5 -2
@@ 98,7 98,9 @@ data Session = Session {
    -- | How many redirects to follow for Gemini or HTTP(S) requests
    redirectCount :: Int,
    -- | Whether to cache network responses, avoiding sending requests
    cachingEnabled :: Bool
    cachingEnabled :: Bool,
    -- | App-specific config subdirectory to check
    appName :: String
}

data LogRecord = LogRecord {


@@ 158,7 160,8 @@ newSession' appname = do
        aboutPages = [],
        requestLog = Nothing,
        redirectCount = 5,
        cachingEnabled = True
        cachingEnabled = True,
        appName = appname
    }

llookup key fallback map = fallback `fromMaybe` listToMaybe [v | (k, v) <- map, k == key]

M src/Network/URI/XDG.hs => src/Network/URI/XDG.hs +0 -15
@@ 10,7 10,6 @@ import Network.URI.XDG.MimeApps
import Data.List (stripPrefix)
import Data.Maybe (catMaybes)

#if WITH_APPSTREAM
import qualified Text.XML as XML
import qualified Data.Map as M
import Data.Text (Text)


@@ 19,14 18,11 @@ import Network.URI.XDG.AppStream
import Network.URI.XDG.AppStreamOutput
import Control.Monad (forM)
import Network.URI
#endif

data XDGConfig = XDGConfig {
#if WITH_APPSTREAM
    components :: M.Map Text Component,
    componentsByMIME :: M.Map Text [Component],
    iconCache :: IconCache,
#endif
    handlers :: HandlersConfig,
    locales :: [String]
}


@@ 34,13 30,9 @@ data XDGConfig = XDGConfig {
loadXDGConfig :: [String] -> IO XDGConfig
loadXDGConfig locales = do
    handlers <- loadHandlers
#if WITH_APPSTREAM
    components <- loadDatabase locales
    icons <- scanIconCache
    return $ XDGConfig components (buildMIMEIndex components) icons handlers locales
#else
    return $ XDGConfig handlers locales
#endif

dispatchURIByMIME :: XDGConfig -> URI -> String -> IO Errors
dispatchURIByMIME config uri mime = do


@@ 50,7 42,6 @@ dispatchURIByMIME config uri mime = do
        Nothing -> reportUnsupported config mime uri

reportUnsupported :: XDGConfig -> String -> URI -> IO Errors
#if WITH_APPSTREAM
reportUnsupported XDGConfig { components = comps } "x-scheme-handler/appstream" URI {
        uriAuthority = Just (URIAuth { uriRegName = ident })
    } | Just el <- xmlForID comps $ Txt.pack ident = return $ RawXML $ serializeXML el


@@ 61,12 52,6 @@ reportUnsupported XDGConfig { iconCache = icondirs, componentsByMIME = index } m
        icons' <- testLocalIcons $ icons app
        return $ app {icons = icons'}
    return $ RequiresInstall mime $ outputApps apps'
#else
reportUnsupported _ mime _
    | Just scheme <- "x-scheme-handler/" `stripPrefix` mime =
        return $ UnsupportedScheme (scheme ++ ":")
    | otherwise = return $ UnsupportedMIME mime
#endif

mapFirstM :: [a] -> (a -> IO (Maybe b)) -> IO (Maybe b)
mapFirstM (x:xs) cb = do