Revision 6e47412f src/Ganeti/UDSServer.hs
b/src/Ganeti/UDSServer.hs | ||
---|---|---|
38 | 38 |
, closeClient |
39 | 39 |
, closeServer |
40 | 40 |
, buildResponse |
41 |
, parseCall |
|
41 | 42 |
, recvMsg |
42 | 43 |
, recvMsgExt |
43 | 44 |
, sendMsg |
44 | 45 |
) where |
45 | 46 |
|
47 |
import Control.Applicative |
|
46 | 48 |
import Control.Exception (catch) |
47 | 49 |
import Data.IORef |
48 | 50 |
import qualified Data.ByteString as B |
... | ... | |
56 | 58 |
import System.IO (hClose, hFlush, hWaitForInput, Handle, IOMode(..)) |
57 | 59 |
import System.IO.Error (isEOFError) |
58 | 60 |
import System.Timeout |
59 |
import Text.JSON (encodeStrict) |
|
61 |
import Text.JSON (encodeStrict, decodeStrict) |
|
62 |
import qualified Text.JSON as J |
|
60 | 63 |
import Text.JSON.Types |
61 | 64 |
|
65 |
import Ganeti.BasicTypes |
|
66 |
import Ganeti.JSON |
|
62 | 67 |
import Ganeti.Runtime (GanetiDaemon(..), MiscGroup(..), GanetiGroup(..)) |
63 | 68 |
import Ganeti.THH |
64 | 69 |
import Ganeti.Utils |
... | ... | |
214 | 219 |
else RecvError (show e) |
215 | 220 |
|
216 | 221 |
|
222 |
-- | Parse the required keys out of a call. |
|
223 |
parseCall :: (J.JSON mth) => String -> Result (mth, JSValue) |
|
224 |
parseCall s = do |
|
225 |
arr <- fromJResult "parsing top-level JSON message" $ |
|
226 |
decodeStrict s :: Result (JSObject JSValue) |
|
227 |
let keyFromObj :: (J.JSON a) => MsgKeys -> Result a |
|
228 |
keyFromObj = fromObj (fromJSObject arr) . strOfKey |
|
229 |
(,) <$> keyFromObj Method <*> keyFromObj Args |
|
230 |
|
|
231 |
|
|
217 | 232 |
-- | Serialize the response to String. |
218 | 233 |
buildResponse :: Bool -- ^ Success |
219 | 234 |
-> JSValue -- ^ The arguments |
Also available in: Unified diff