diff options
| author | hallgren <hallgren@chalmers.se> | 2011-08-22 16:10:56 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2011-08-22 16:10:56 +0000 |
| commit | cf9f1057edcec8df0aea031660f8b48e0ec14627 (patch) | |
| tree | 03af85d6d7ca6b6009316998b9a08241708f4128 /src/server | |
| parent | d8d80693db7d18cd6ac84b87358b6e3d55be9fbc (diff) | |
pgf service: external service hook: always format the output as a JSON string
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/PGFService.hs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs index 112d416a9..b6b67dd4c 100644 --- a/src/server/PGFService.hs +++ b/src/server/PGFService.hs @@ -135,23 +135,19 @@ pgfMain pgf command = do doExternal Nothing input = throwCGIError 400 "Unknown external command" ["Unknown external command"] doExternal (Just cmd) input = do liftIO $ logError ("External command: "++cmd) - cmds <- liftIO $ (readIO =<< readFile "external_services") + cmds <- liftIO $ (fmap lines $ readFile "external_services") `catch` const (return []) liftIO $ logError ("External services: "++show cmds) - maybe err ok (lookup cmd cmds) + if cmd `elem` cmds then ok else err where err = throwCGIError 400 "Unknown external command" ["Unknown external command: "++cmd] - ok output_type = + ok = do let tmpfile1 = "external_input.txt" tmpfile2 = "external_output.txt" liftIO $ writeFile "external_input.txt" input liftIO $ system $ cmd ++ " " ++ tmpfile1 ++ " > " ++ tmpfile2 liftIO $ removeFile tmpfile1 - r <- case output_type of - "jsonp" -> outputEncodedJSONP =<< liftIO (readFile tmpfile2) - "image/png" -> outputPNG =<< liftIO (BS.readFile tmpfile2) - "text/html" -> outputHTML =<< liftIO (readFile tmpfile2) - _ -> outputPlain =<< liftIO (readFile tmpfile2) + r <- outputJSONP =<< liftIO (readFile tmpfile2) liftIO $ removeFile tmpfile2 return r |
