- -- Some just put the IP address in the value, especially in the map.
- -- As an ugly hack, try to interpret string as IP (v4) address.
- parseJSON (String s) = return emptyNmcDom { domIp = Just [T.unpack s] }
+ -- Wherever we expect a domain object, there may be a string
+ -- containing IPv4 address. Interpret it as such.
+ -- Question: shall we try to recognize IPv6 addresses too?
+ parseJSON (String s) =
+ return $ if isIPv4 s'
+ then emptyNmcDom { domIp = Just [s'] }
+ else emptyNmcDom
+ where
+ s' = T.unpack s
+ isIPv4 x = all isNibble $ splitOn "." x
+ isNibble x =
+ if all isDigit x then (read x :: Int) < 256
+ else False