summaryrefslogtreecommitdiff
path: root/src/server/PGFService.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2010-11-26 14:30:51 +0000
committerhallgren <hallgren@chalmers.se>2010-11-26 14:30:51 +0000
commit72d2d9b204568b3683c29dea0ae794d3a524f2ee (patch)
treef392cb3859e2a173d17a820ae3a6294f4386a755 /src/server/PGFService.hs
parent75ad59b1217e4b81d19fed6eadf4fc80d3ebd2f1 (diff)
Split pgf-server into pgf-fcgi and pgf-http.
The dependency on the fastcgi package made pgf-server difficult to compile, so it is now split into - pgf-fgci (main module in pgf-fcgi.hs), which is built only if fastcgi is already installed or if you turn on the fastcgi flag (e.g. by doing 'cabal install -f fastcgi'). - pgf-http (main module in pgf-http.hs) which is always built (and hopefully has no problematic dependencies.) The modules FastCGIUtils and PGFService no longer depend on fastcgi.
Diffstat (limited to 'src/server/PGFService.hs')
-rw-r--r--src/server/PGFService.hs49
1 files changed, 6 insertions, 43 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs
index fee8c766c..32e2e4e98 100644
--- a/src/server/PGFService.hs
+++ b/src/server/PGFService.hs
@@ -1,17 +1,18 @@
{-# LANGUAGE DeriveDataTypeable, CPP #-}
+module PGFService(cgiMain,cgiMain',getPath,
+ logFile,stderrToFile,
+ newPGFCache) where
import PGF (PGF)
import qualified PGF
import Cache
import FastCGIUtils
import URLEncoding
-import RunHTTP
-import ServeStaticFile
-import Network.FastCGI
+import Network.CGI
import Text.JSON
import Text.PrettyPrint (render, text, (<+>))
-import qualified Codec.Binary.UTF8.String as UTF8 (encodeString, decodeString)
+import qualified Codec.Binary.UTF8.String as UTF8 (decodeString)
import qualified Data.ByteString.Lazy as BS
import Control.Concurrent
@@ -22,53 +23,15 @@ import Data.Function (on)
import Data.List (sortBy,intersperse,mapAccumL,nub)
import qualified Data.Map as Map
import Data.Maybe
-import System.Directory
import System.Random
-import System.FilePath
import System.Process
import System.Exit
import System.IO
-import System.Environment(getArgs)
logFile :: FilePath
logFile = "pgf-error.log"
-
-main :: IO ()
-main = do stderrToFile logFile
- cache <- newCache PGF.readPGF
- args <- getArgs
- case args of
- [] -> fcgiMain cache
- ["http"] -> httpMain cache 41296
- ["http",port] -> httpMain cache =<< readIO port
-
-httpMain cache port = runHTTP port (do log ; serve =<< getPath)
- where
- log = do method <- requestMethod
- uri <- getVarWithDefault "REQUEST_URI" "-"
- logCGI $ method++" "++uri
-
- serve path =
- handleErrors . handleCGIErrors $
- if takeExtension path==".pgf"
- then cgiMain' cache path
- else if takeFileName path=="grammars.cgi"
- then grammarList (takeDirectory path)
- else serveStaticFile path
-
- grammarList dir =
- do paths <- liftIO $ getDirectoryContents dir
- let pgfs = [path|path<-paths, takeExtension path==".pgf"]
- outputJSONP pgfs
-
-fcgiMain :: Cache PGF -> IO ()
-fcgiMain cache =
-#ifndef mingw32_HOST_OS
- runFastCGIConcurrent' forkIO 100 (cgiMain cache)
-#else
- runFastCGI (cgiMain cache)
-#endif
+newPGFCache = newCache PGF.readPGF
getPath = getVarWithDefault "SCRIPT_FILENAME" ""