From b90215dda1c086c7c288ac9d7e3d75e0516f0fd5 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Sat, 29 Mar 2014 23:19:38 +0400 Subject: [PATCH] handle empty 'value' as domain with no data --- NmcJson.hs | 9 +++++++-- pdns-pipe-nmc.hs | 9 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NmcJson.hs b/NmcJson.hs index 978fb04..651aa46 100644 --- a/NmcJson.hs +++ b/NmcJson.hs @@ -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 diff --git a/pdns-pipe-nmc.hs b/pdns-pipe-nmc.hs index ee5bd37..9e4a729 100644 --- a/pdns-pipe-nmc.hs +++ b/pdns-pipe-nmc.hs @@ -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 -- 2.39.2