]> www.average.org Git - pdns-pipe-nmc.git/commitdiff
handle empty 'value' as domain with no data
authorEugene Crosser <crosser@average.org>
Sat, 29 Mar 2014 19:19:38 +0000 (23:19 +0400)
committerEugene Crosser <crosser@average.org>
Sat, 29 Mar 2014 19:19:38 +0000 (23:19 +0400)
NmcJson.hs
pdns-pipe-nmc.hs

index 978fb04b67cda0bf2a00776e608eed12c1b844b0..651aa46f1be2631fd8245f8ff899544af59546c8 100644 (file)
@@ -2,6 +2,7 @@
 
 module NmcJson  ( NmcRes(..)
                 , NmcDom
+                , emptyNmcDom
                 ) where
 
 import Data.ByteString.Lazy (ByteString)
@@ -28,7 +29,7 @@ instance FromJSON NmcRRService where
                 <*> o .: "host"
         parseJSON _ = empty
 
-data NmcRRI2p = NmcRRI2p -- unused
+data NmcRRI2p = NmcRRI2p
                         { i2pDestination :: String
                         , i2pName        :: String
                         , i2pB32         :: String
@@ -84,8 +85,12 @@ instance FromJSON NmcDom where
                 <*> o .:? "ds"
         parseJSON _ = empty
 
+emptyNmcDom = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing
+                     Nothing Nothing Nothing Nothing Nothing Nothing
+                     Nothing Nothing Nothing Nothing Nothing Nothing
+
 data NmcRes = NmcRes    { resName       :: String
-                        , resValue      :: ByteString -- NmcDom
+                        , resValue      :: ByteString -- string with NmcDom
                         , resTxid       :: String
                         , resAddress    :: String
                         , resExpires_in :: Int
index ee5bd3771a900dd880f2add5c7dcacff6a100ae9..9e4a72930691ab6b58e53e6220c4d6c495c5e4ce 100644 (file)
@@ -43,9 +43,12 @@ qRsp rsp =
     case parseJsonRpc (responseBody rsp) :: Either JsonRpcError NmcRes of
       Left  jerr -> Left $ "Unparseable response: " ++ (show (responseBody rsp))
       Right jrsp ->
-        case decode (resValue jrsp) :: Maybe NmcDom of
-          Nothing  -> Left $ "Unparseable value: " ++ (show (resValue jrsp))
-          Just dom -> Right dom
+        case resValue jrsp of
+          "" -> Right emptyNmcDom
+          vstr ->
+            case decode vstr :: Maybe NmcDom of
+              Nothing  -> Left $ "Unparseable value: " ++ (show vstr)
+              Just dom -> Right dom
 
 -- NMC interface