-sysConfDefault sc (BaseURI _)
- = do let conf = scLucuConf sc
- host = C8.unpack $ LC.cnfServerHost conf
- port = case LC.cnfServerPort conf of
- PortNumber num -> fromIntegral num
-
- defaultURI
- = "http://" ++ host ++
+
+deserializeStringPairs :: String -> Maybe [(String, String)]
+deserializeStringPairs = sequence . map deserializePair' . lines
+ where
+ deserializePair' :: String -> Maybe (String, String)
+ deserializePair' s = case break (== ' ') s of
+ (a, ' ':b) -> Just (a, b)
+ _ -> Nothing
+
+
+
+{- config values -}
+
+newtype SiteName = SiteName String deriving (Show, Typeable, Eq)
+instance SysConfValue SiteName where
+ confPath _ = "siteName"
+ serialize (SiteName name) = name
+ deserialize name = Just (SiteName name)
+ defaultValue _ = SiteName "Rakka"
+
+
+newtype BaseURI = BaseURI URI deriving (Show, Typeable, Eq)
+instance SysConfValue BaseURI where
+ confPath _ = "baseURI"
+ serialize (BaseURI uri) = uriToString id uri ""
+ deserialize uri = fmap BaseURI
+ $ do parsed <- parseURI uri
+ when (uriPath parsed == "" ) (fail undefined)
+ when (last (uriPath parsed) /= '/') (fail undefined)
+ when (uriQuery parsed /= "" ) (fail undefined)
+ when (uriFragment parsed /= "" ) (fail undefined)
+ return parsed
+ defaultValue sc
+ = let conf = scLucuConf sc
+ host = C8.unpack $ LC.cnfServerHost conf
+ port = case LC.cnfServerPort conf of
+ PortNumber num -> fromIntegral num :: Int
+ _ -> undefined
+ defaultURI
+ = "http://" ++ host ++ -- FIXME: consider IPv6 address