]> www.average.org Git - pdns-pipe-nmc.git/blobdiff - NmcJson.hs
move most formatting to PowerDns
[pdns-pipe-nmc.git] / NmcJson.hs
index b7449297d3796aca706f78a645b0e49fba28f987..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
@@ -98,14 +103,3 @@ instance FromJSON NmcRes where
                 <*> o .: "address"
                 <*> o .: "expires_in"
         parseJSON _ = empty
-
-main = do
-  let l = "{\"name\":\"d/dot-bit\",\"value\":\"{\\\"info\\\":{\\\"description\\\":\\\"Dot-BIT Project - Official Website\\\",\\\"registrar\\\":\\\"http://register.dot-bit.org\\\"},\\\"fingerprint\\\":[\\\"30:B0:60:94:32:08:EC:F5:BE:DF:F4:BB:EE:52:90:2C:5D:47:62:46\\\"],\\\"ns\\\":[\\\"ns0.web-sweet-web.net\\\",\\\"ns1.web-sweet-web.net\\\"],\\\"map\\\":{\\\"\\\":{\\\"ns\\\":[\\\"ns0.web-sweet-web.net\\\",\\\"ns1.web-sweet-web.net\\\"]}},\\\"email\\\":\\\"register@dot-bit.org\\\"}\",\"txid\":\"7412603f2e6c3459be56accc6e1f3646b603f3d4a4188119a4072f125c1340d5\",\"address\":\"Mw3KCQcqC44nm75w7r79ZifZbEqT8RetWn\",\"expires_in\":18915}"
-  let r = decode l :: Maybe NmcRes
-  case r of
-    Just resp -> do
-      let value = (resValue resp)
-      let dom = decode value :: Maybe NmcDom
-      print dom
-    Nothing   ->
-      print "Unparseable NMC response"