config parser works
This commit is contained in:
parent
df0b72235f
commit
f03f91f917
4 changed files with 65 additions and 14 deletions
|
@ -1,9 +1,9 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
module Config(Configuration(..),defaultConfiguration,configurationCodec) where
|
||||||
module Config() where
|
|
||||||
|
|
||||||
import Toml (TomlCodec, (.=))
|
import Toml (TomlCodec, (.=))
|
||||||
import qualified Toml
|
import qualified Toml
|
||||||
|
import System.IO
|
||||||
|
|
||||||
-- this module should handle everything connected to our TOML config
|
-- this module should handle everything connected to our TOML config
|
||||||
#if defined(HTTP_SUPPORT) || defined(HTTPS_SUPPORT)
|
#if defined(HTTP_SUPPORT) || defined(HTTPS_SUPPORT)
|
||||||
|
@ -16,17 +16,18 @@ import qualified Network.Wai.Handler.WarpTLS as HTTPS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
data Configuration = Configuration {
|
data Configuration = Configuration {
|
||||||
|
cppDummy :: () -- this is a hack to get around the , rules of haskell records and the preprocessor
|
||||||
#ifdef HTTP_SUPPORT
|
#ifdef HTTP_SUPPORT
|
||||||
httpConf :: [HTTP.Settings]
|
, httpConf :: [HTTP.Settings]
|
||||||
#endif
|
#endif
|
||||||
#ifdef HTTPS_SUPPORT
|
#ifdef HTTPS_SUPPORT
|
||||||
httpsConf :: [(HTTP.Settings,HTTPS.TLSSettings)]
|
, httpsConf :: [(HTTP.Settings,HTTPS.TLSSettings)]
|
||||||
#endif
|
#endif
|
||||||
#ifdef FASTCGI_SUPPORT
|
#ifdef FASTCGI_SUPPORT
|
||||||
fastCgiConf :: [FastCgiConfiguration]
|
, fastCgiConf :: [FastCgiConfiguration]
|
||||||
#endif
|
#endif
|
||||||
#ifdef CGI_SUPPORT
|
#ifdef CGI_SUPPORT
|
||||||
cgiConf :: [CgiConfiguration]
|
, cgiConf :: [CgiConfiguration]
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +39,22 @@ data FastCgiConfiguration = FastCgiConfiguration
|
||||||
data CgiConfiguration = CgiConfiguration
|
data CgiConfiguration = CgiConfiguration
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HTTP_SUPPORT) || defined(HTTPS_SUPPORT)
|
defaultConfiguration :: Configuration
|
||||||
|
defaultConfiguration = Configuration ()
|
||||||
|
#ifdef HTTP_SUPPORT
|
||||||
|
[HTTP.defaultSettings]
|
||||||
|
#endif
|
||||||
|
#ifdef HTTPS_SUPPORT
|
||||||
|
[(HTTP.defaultSettings,HTTPS.defaultTlsSettings)]
|
||||||
|
#endif
|
||||||
|
#ifdef FASTCGI_SUPPORT
|
||||||
|
[FastCgiConfiguration]
|
||||||
|
#endif
|
||||||
|
#ifdef CGI_SUPPORT
|
||||||
|
[CgiConfiguration]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HTTP_SUPPORT) || defined(HTTPS_SUPPORT)
|
||||||
-- this should not need to exist!!! It is realy ugly crap, but the only we to construct and deconstruct
|
-- this should not need to exist!!! It is realy ugly crap, but the only we to construct and deconstruct
|
||||||
-- this datatype is via fromString, read, show. And as we want the fromString syntax we want an inverse
|
-- this datatype is via fromString, read, show. And as we want the fromString syntax we want an inverse
|
||||||
-- of it too, but we don't get something nice exposed. Also we don't get the constructors exposed so we
|
-- of it too, but we don't get something nice exposed. Also we don't get the constructors exposed so we
|
||||||
|
@ -62,8 +77,41 @@ httpConfigCodec = httpConfigConstructor
|
||||||
<*> Toml.string "Bind" .= (httpShowHostPreference . HTTP.getHost)
|
<*> Toml.string "Bind" .= (httpShowHostPreference . HTTP.getHost)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HTTPS_SUPPORT
|
||||||
|
httpsConfigCodec :: TomlCodec (HTTP.Settings,HTTPS.TLSSettings)
|
||||||
|
httpsConfigCodec = Toml.pair httpConfigCodec httpsConfigCodec'
|
||||||
|
|
||||||
|
httpsConfigCodec' :: TomlCodec (HTTPS.TLSSettings)
|
||||||
|
httpsConfigCodec' = HTTPS.tlsSettingsChain
|
||||||
|
-- the hardcoded strings are a bloody hack, but we can't extract the values back out of a config (they are there
|
||||||
|
-- warp just doesn't export the neccesarry types). So we hardcode default values, which is kind of realy bad, but
|
||||||
|
-- we don't need it in our usecase
|
||||||
|
<$> Toml.string "Certificate" .= (const "certificate.pem")
|
||||||
|
<*> Toml.arrayOf Toml._String "CertChain" .= (const [])
|
||||||
|
<*> Toml.string "KeyFile" .= (const "key.pem")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FASTCGI_SUPPORT
|
||||||
|
fastCgiConfigCodec :: TomlCodec FastCgiConfiguration
|
||||||
|
fastCgiConfigCodec = pure FastCgiConfiguration
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CGI_SUPPORT
|
||||||
|
cgiConfigCodec :: TomlCodec CgiConfiguration
|
||||||
|
cgiConfigCodec = pure CgiConfiguration
|
||||||
|
#endif
|
||||||
|
|
||||||
configurationCodec :: TomlCodec Configuration
|
configurationCodec :: TomlCodec Configuration
|
||||||
configurationCodec = pure Configuration
|
configurationCodec = pure (Configuration ())
|
||||||
#ifdef HTTP_SUPPORT
|
#ifdef HTTP_SUPPORT
|
||||||
<*> Toml.list httpConfigCodec "http" .= httpConf
|
<*> Toml.list httpConfigCodec "http" .= httpConf
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HTTPS_SUPPORT
|
||||||
|
<*> Toml.list httpsConfigCodec "https" .= httpsConf
|
||||||
|
#endif
|
||||||
|
#ifdef FASTCGI_SUPPORT
|
||||||
|
<*> Toml.list fastCgiConfigCodec "fast-cgi" .= fastCgiConf
|
||||||
|
#endif
|
||||||
|
#ifdef CGI_SUPPORT
|
||||||
|
<*> Toml.list cgiConfigCodec "cgi" .= cgiConf
|
||||||
|
#endif
|
||||||
|
|
|
@ -27,15 +27,15 @@ flags:
|
||||||
https:
|
https:
|
||||||
description: Build with https support
|
description: Build with https support
|
||||||
manual: true
|
manual: true
|
||||||
default: false
|
default: true
|
||||||
fast-cgi:
|
fast-cgi:
|
||||||
description: Build with fastcgi support -- this depends on the fcgi c library
|
description: Build with fastcgi support -- this depends on the fcgi c library
|
||||||
manual: true
|
manual: true
|
||||||
default: false
|
default: true
|
||||||
cgi:
|
cgi:
|
||||||
description: Build with cgi support
|
description: Build with cgi support
|
||||||
manual: true
|
manual: true
|
||||||
default: false
|
default: true
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
- base >= 4.7 && < 5
|
- base >= 4.7 && < 5
|
||||||
|
|
|
@ -50,6 +50,9 @@ extra-deps:
|
||||||
flags:
|
flags:
|
||||||
tickLeisteServer:
|
tickLeisteServer:
|
||||||
http: true
|
http: true
|
||||||
|
https: true
|
||||||
|
fast-cgi: true
|
||||||
|
cgi: true
|
||||||
|
|
||||||
# Extra package databases containing global packages
|
# Extra package databases containing global packages
|
||||||
# extra-package-dbs: []
|
# extra-package-dbs: []
|
||||||
|
|
|
@ -26,12 +26,12 @@ source-repository head
|
||||||
flag cgi
|
flag cgi
|
||||||
description: Build with cgi support
|
description: Build with cgi support
|
||||||
manual: True
|
manual: True
|
||||||
default: False
|
default: True
|
||||||
|
|
||||||
flag fast-cgi
|
flag fast-cgi
|
||||||
description: Build with fastcgi support -- this depends on the fcgi c library
|
description: Build with fastcgi support -- this depends on the fcgi c library
|
||||||
manual: True
|
manual: True
|
||||||
default: False
|
default: True
|
||||||
|
|
||||||
flag http
|
flag http
|
||||||
description: Build with http support
|
description: Build with http support
|
||||||
|
@ -41,7 +41,7 @@ flag http
|
||||||
flag https
|
flag https
|
||||||
description: Build with https support
|
description: Build with https support
|
||||||
manual: True
|
manual: True
|
||||||
default: False
|
default: True
|
||||||
|
|
||||||
executable tickLeisteServer
|
executable tickLeisteServer
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue