diff options
author | joe <joe@jerkface.net> | 2018-06-24 02:27:18 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-24 03:10:43 -0400 |
commit | 55db1198b3da0c706f2b9f1ed9c8fd11fc4ae552 (patch) | |
tree | de035195ed188f8611da54e6e339d9124d2a5b3f /src/Network/Tox | |
parent | 3054de811f4ae7659dfc4dc338aab2c3d11b5c27 (diff) |
XMPP: Type-checking on various uses of SockAddr.
Diffstat (limited to 'src/Network/Tox')
-rw-r--r-- | src/Network/Tox/NodeId.hs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs index e3c6fb36..3a732b43 100644 --- a/src/Network/Tox/NodeId.hs +++ b/src/Network/Tox/NodeId.hs | |||
@@ -278,6 +278,16 @@ b64digit '-' = True | |||
278 | b64digit '/' = True | 278 | b64digit '/' = True |
279 | b64digit c = ('0' <= c && c <= '9') || ( 'a' <= c && c <= 'z') || ( 'A' <= c && c <= 'Z') | 279 | b64digit c = ('0' <= c && c <= '9') || ( 'a' <= c && c <= 'z') || ( 'A' <= c && c <= 'Z') |
280 | 280 | ||
281 | ip_w_port :: Int -> RP.ReadP (IP, PortNumber) | ||
282 | ip_w_port i = do | ||
283 | ip <- RP.between (RP.char '[') (RP.char ']') | ||
284 | (IPv6 <$> RP.readS_to_P (readsPrec i)) | ||
285 | RP.+++ (IPv4 <$> RP.readS_to_P (readsPrec i)) | ||
286 | _ <- RP.char ':' | ||
287 | port <- toEnum <$> RP.readS_to_P (readsPrec i) | ||
288 | return (ip, port) | ||
289 | |||
290 | |||
281 | instance Read NodeInfo where | 291 | instance Read NodeInfo where |
282 | readsPrec i = RP.readP_to_S $ do | 292 | readsPrec i = RP.readP_to_S $ do |
283 | RP.skipSpaces | 293 | RP.skipSpaces |
@@ -292,15 +302,7 @@ instance Read NodeInfo where | |||
292 | _ -> fail "Bad node id." | 302 | _ -> fail "Bad node id." |
293 | return (nid,addrstr) | 303 | return (nid,addrstr) |
294 | (nid,addrstr) <- ( nodeidAt RP.+++ ( (zeroID,) <$> parseAddr) ) | 304 | (nid,addrstr) <- ( nodeidAt RP.+++ ( (zeroID,) <$> parseAddr) ) |
295 | let raddr = do | 305 | (ip,port) <- case RP.readP_to_S (ip_w_port i) addrstr of |
296 | ip <- RP.between (RP.char '[') (RP.char ']') | ||
297 | (IPv6 <$> RP.readS_to_P (readsPrec i)) | ||
298 | RP.+++ (IPv4 <$> RP.readS_to_P (readsPrec i)) | ||
299 | _ <- RP.char ':' | ||
300 | port <- toEnum <$> RP.readS_to_P (readsPrec i) | ||
301 | return (ip, port) | ||
302 | |||
303 | (ip,port) <- case RP.readP_to_S raddr addrstr of | ||
304 | [] -> fail "Bad address." | 306 | [] -> fail "Bad address." |
305 | ((ip,port),_):_ -> return (ip,port) | 307 | ((ip,port),_):_ -> return (ip,port) |
306 | return $ NodeInfo nid ip port | 308 | return $ NodeInfo nid ip port |