~alcinnz/hurl

8161527bf5f88a97bb07a81f4967f6ec008455d0 — Adrian Cochrane 3 years ago b9a5ac6
Add compile flag for executable extensions thereby fixing build system.

Might also be some crash fixes in here, I just realized I haven't committed these changes.
4 files changed, 19 insertions(+), 6 deletions(-)

M hurl.cabal
M src/Network/MIME/Info.hs
M src/Network/URI/Fetch.hs
M src/Network/URI/XDG/MimeInfo.hs
M hurl.cabal => hurl.cabal +9 -1
@@ 78,6 78,11 @@ Flag rewriters
  Default:		True
  Manual: 		True

Flag executables
  Description:  Support executable plugins exposing a `ext:` URI scheme.
  Default:      True
  Manual:       True

source-repository head
    type: git
    location: https://git.adrian.geek.nz/hurl.git


@@ 96,7 101,7 @@ library
  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 >= 1.3.2,
                       process >= 1.2 && <2.0, time >= 1.6
                       time >= 1.6
  
  -- Directories containing source files.
  hs-source-dirs:      src


@@ 129,6 134,9 @@ library
    CPP-options:   -DWITH_PLUGIN_REWRITES
    build-depends: regex, regex-tdfa >= 1.2 && < 1.4
    other-modules: Network.URI.PlugIns.Rewriters
  if flag(executables)
    CPP-options:   -DWITH_PLUGIN_EXEC
    build-depends: process >= 1.2 && <2.0

executable hurl
  -- .hs file containing the Main module

M src/Network/MIME/Info.hs => src/Network/MIME/Info.hs +2 -2
@@ 8,7 8,7 @@ import Network.URI.Locale (rfc2616Locale)
import Network.URI.Types (Application(..))

import qualified Data.Map as M
import Control.Concurrent.MVar (MVar, newMVar, readMVar, putMVar)
import Control.Concurrent.MVar (MVar, newMVar, readMVar, modifyMVar_)
import System.IO.Unsafe (unsafePerformIO)
import Data.Char (toLower)



@@ 25,7 25,7 @@ mimeInfo = unsafePerformIO $ do
    inner mime _ _ cache | Just val <- mime `M.lookup` cache = return val
    inner mime locales cache' cache = do
        ret <- readMimeInfo locales mime
        putMVar cache' $ M.insert mime ret cache
        modifyMVar_ cache' $ return . M.insert mime ret
        return ret

#ifndef WITH_XDG

M src/Network/URI/Fetch.hs => src/Network/URI/Fetch.hs +2 -0
@@ 206,6 206,7 @@ fetchURL' session mimes uri
    | Just uri' <- applyRewriter (rewriter session) uri = fetchURL' session mimes uri'
#endif

#ifdef WITH_PLUGIN_EXEC
fetchURL' session@Session { appName = appname, locale = l } mimes
        uri@(URI "ext:" Nothing path query _) = do
    dir <- getXdgDirectory XdgData "nz.geek.adrian.hurl"


@@ 236,6 237,7 @@ fetchURL' session@Session { appName = appname, locale = l } mimes
    strip = dropWhile isSpace . dropWhileEnd isSpace
    isSuccess ExitSuccess = True
    isSuccess _ = False
#endif

fetchURL' session mimes uri@(URI {uriScheme = "about:", uriPath = ""}) =
    fetchURL' session mimes $ uri {uriPath = "version"}

M src/Network/URI/XDG/MimeInfo.hs => src/Network/URI/XDG/MimeInfo.hs +6 -3
@@ 16,15 16,18 @@ import Control.Monad (forM)
import Control.Exception (catch)
import Data.Maybe (catMaybes, maybeToList, fromMaybe, mapMaybe)

import System.Directory (getHomeDirectory)

readMimeInfo :: [String] -> String -> IO Application
readMimeInfo locales mime = do
    dirs <- lookupEnv "XDG_DATA_DIRS"
    homedir <- lookupEnv "XDG_DATA_HOME"
    let dirs' = fromMaybe' "~/.local/share/" homedir :
    cwd <- getHomeDirectory
    let dirs' = fromMaybe' (cwd </> ".local/share/") homedir :
            split ':' (fromMaybe' "/usr/local/share/:/usr/share/" dirs)

    files <- forM dirs' $ \dir -> do
        let file = dir </> mime <.> "xml"
        let file = dir </> "mime" </> mime <.> "xml"
        exists <- doesFileExist file
        if exists then (Just <$> XML.readFile def file) `catch` handleBadXML else return Nothing



@@ 49,7 52,7 @@ readMimeInfo' locales mime el = Application {
    }
  where
    readEl key attr fallback
        | (val:_) <- [v | l <- locales ++ [""], v <- maybeToList $ lookup key els] = unpack val
        | (val:_) <- [v | l <- locales ++ [""], v <- maybeToList $ lookup l els] = unpack val
        | otherwise = fallback
      where els = readEl' (pack key) attr $ elementNodes el
    readEl' key Nothing (NodeElement (Element name attrs childs):sibs)