From 0a27aaf1e6823ea2c81f91265e97d98d2d20d9ea Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 13 Apr 2011 14:58:01 +0000 Subject: Added a preliminary "gf -server" mode. The command "gf -server" now starts a simple HTTP server on port 41295, providing a simple web API to the GF compiler. It currently support the follwing operations: * creating new temporary directories for grammar uploads, * uploading grammars files for use in the GF shell, * executing GF shell commands, and * accessing static files. This means that GF now depends on some additional networking related packages, but they should be available and easy to install on all platforms. There is also a new configuration flag "server" in gf.cabal, so GF will be compiled without support for server mode if the extra packages are unavailable. Note that running gf -server while connected to the internet can be a security risk. To prevent unauthorized access to the rest of the system, it is advisable to run the server in GF_RESTRICTED mode and as a user with suitably restricted file permissions. --- src/compiler/GFI.hs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/compiler/GFI.hs') diff --git a/src/compiler/GFI.hs b/src/compiler/GFI.hs index 8d89f146c..bec2e3b0e 100644 --- a/src/compiler/GFI.hs +++ b/src/compiler/GFI.hs @@ -1,5 +1,5 @@ {-# LANGUAGE ScopedTypeVariables, CPP #-} -module GFI (mainGFI,mainRunGFI) where +module GFI (mainGFI,mainRunGFI,mainServerGFI) where import GF.Command.Interpreter import GF.Command.Importing @@ -44,6 +44,9 @@ import Control.Monad import Data.Version import Text.PrettyPrint (render) import GF.System.Signal +#ifdef SERVER_MODE +import GFServer(server) +#endif --import System.IO.Error (try) #ifdef mingw32_HOST_OS import System.Win32.Console @@ -53,9 +56,9 @@ import System.Win32.NLS import Paths_gf mainRunGFI :: Options -> [FilePath] -> IO () -mainRunGFI opts files = do - let opts1 = addOptions (modifyFlags (\f -> f{optVerbosity=Quiet})) opts - shell opts1 files +mainRunGFI opts files = shell (beQuiet opts) files + +beQuiet = addOptions (modifyFlags (\f -> f{optVerbosity=Quiet})) mainGFI :: Options -> [FilePath] -> IO () mainGFI opts files = do @@ -64,6 +67,15 @@ mainGFI opts files = do shell opts files = loop opts =<< importInEnv emptyGFEnv opts files +#ifdef SERVER_MODE +mainServerGFI opts0 files = + server (execute1 opts) =<< importInEnv emptyGFEnv opts files + where opts = beQuiet opts0 +#else +mainServerGFI opts files = + error "GF has not been compiled with server mode support" +#endif + -- | Read end execute commands until it is time to quit loop :: Options -> GFEnv -> IO () loop opts gfenv = maybe (return ()) (loop opts) =<< readAndExecute1 opts gfenv -- cgit v1.2.3