diff options
author | James Crayne <jim.crayne@gmail.com> | 2017-10-30 01:35:12 +0000 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2017-10-30 01:35:12 +0000 |
commit | 08c02ea307d056a2825d51699e1f2e111d41a7f0 (patch) | |
tree | b2d0f0da5ad13afd190e83a4dfd0911ecc566333 /src/Network/Tox/Crypto/Transport.hs | |
parent | d65e0f858db8d8df25da24c54bc125cc4eede183 (diff) |
allow messageData to get peerinfos
Diffstat (limited to 'src/Network/Tox/Crypto/Transport.hs')
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 4b2e97ce..5b9a0661 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs | |||
@@ -402,12 +402,17 @@ class HasMessageData x where | |||
402 | instance HasMessageData CryptoMessage where | 402 | instance HasMessageData CryptoMessage where |
403 | getMessageData (UpToN (fromEnum -> 0x63) (sizedAtLeastN 9 -> B.splitAt 9 -> (_,mdata))) = mdata | 403 | getMessageData (UpToN (fromEnum -> 0x63) (sizedAtLeastN 9 -> B.splitAt 9 -> (_,mdata))) = mdata |
404 | getMessageData (UpToN (fromEnum -> 0xC7) (sizedAtLeastN 9 -> B.splitAt 9 -> (_,mdata))) = mdata | 404 | getMessageData (UpToN (fromEnum -> 0xC7) (sizedAtLeastN 9 -> B.splitAt 9 -> (_,mdata))) = mdata |
405 | getMessageData (UpToN (fromEnum -> 0x62) (sizedAtLeastN 3 -> B.splitAt 2 -> (_,B.uncons -> Just (0x09,peerinfos)))) = peerinfos | ||
406 | -- getMessageData on 0x62:0a is equivalent to getTitle but without decoding the utf8 | ||
407 | getMessageData (UpToN (fromEnum -> 0x62) (sizedAtLeastN 3 -> B.splitAt 2 -> (_,B.uncons -> Just (0x0a,title)))) = title | ||
405 | getMessageData _ = error "getMessageData on CryptoMessage without message data field." | 408 | getMessageData _ = error "getMessageData on CryptoMessage without message data field." |
406 | 409 | ||
407 | setMessageData (UpToN xE@(fromEnum -> 0x63) (sizedAtLeastN 9 -> B.splitAt 9 -> (bs,xs))) messagedata -- MESSAGE_GROUPCHAT | 410 | setMessageData (UpToN xE@(fromEnum -> 0x63) (sizedAtLeastN 9 -> B.splitAt 9 -> (bs,xs))) messagedata -- MESSAGE_GROUPCHAT |
408 | = UpToN xE (B.concat [bs,messagedata]) | 411 | = UpToN xE (B.concat [bs,messagedata]) |
409 | setMessageData (UpToN xE@(fromEnum -> 0xC7) (sizedAtLeastN 9 -> B.splitAt 9 -> (bs,xs))) messagedata -- LOSSY_GROUPCHAT | 412 | setMessageData (UpToN xE@(fromEnum -> 0xC7) (sizedAtLeastN 9 -> B.splitAt 9 -> (bs,xs))) messagedata -- LOSSY_GROUPCHAT |
410 | = UpToN xE (B.concat [bs,messagedata]) | 413 | = UpToN xE (B.concat [bs,messagedata]) |
414 | setMessageData (UpToN xE@(fromEnum -> 0x62) (sizedAtLeastN 3 -> B.splitAt 3 -> (bs,xs))) peerinfosOrTitle -- peer/title response packets | ||
415 | = UpToN xE (B.concat [bs,peerinfosOrTitle]) | ||
411 | setMessageData _ _ = error "setMessageData on CryptoMessage without message data field." | 416 | setMessageData _ _ = error "setMessageData on CryptoMessage without message data field." |
412 | 417 | ||
413 | messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x) | 418 | messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x) |
@@ -418,14 +423,14 @@ class HasTitle x where | |||
418 | setTitle :: x -> Text -> x | 423 | setTitle :: x -> Text -> x |
419 | 424 | ||
420 | instance HasTitle CryptoMessage where | 425 | instance HasTitle CryptoMessage where |
421 | getTitle (UpToN DIRECT_GROUPCHAT {-Ox62-} (sizedAtLeastN 4 -> B.splitAt 3 -> (_,B.uncons -> Just (0x0a,mdata)))) = decodeUtf8 mdata | 426 | getTitle (UpToN DIRECT_GROUPCHAT {-Ox62-} (sizedAtLeastN 3 -> B.splitAt 2 -> (_,B.uncons -> Just (0x0a,mdata)))) = decodeUtf8 mdata |
422 | getTitle (UpToN xE (sizedAtLeastN 4 -> B.splitAt 3 -> (_,B.uncons -> Just (toEnum . fromIntegral -> GroupchatTitleChange,mdata)))) | 427 | getTitle (UpToN xE (sizedAtLeastN 9 -> B.splitAt 8 -> (_,B.uncons -> Just (toEnum . fromIntegral -> GroupchatTitleChange,mdata)))) |
423 | | isIndirectGrpChat xE = decodeUtf8 mdata | 428 | | isIndirectGrpChat xE = decodeUtf8 mdata |
424 | getTitle _ = error "getTitle on CryptoMessage without title field." | 429 | getTitle _ = error "getTitle on CryptoMessage without title field." |
425 | 430 | ||
426 | setTitle (UpToN xE@DIRECT_GROUPCHAT {-0x62-} (sizedAtLeastN 4 -> B.splitAt 3 -> (bs,B.uncons -> Just (_,xs)))) messagedata | 431 | setTitle (UpToN xE@DIRECT_GROUPCHAT {-0x62-} (sizedAtLeastN 3 -> B.splitAt 2 -> (bs,B.uncons -> Just (_,xs)))) messagedata |
427 | = UpToN xE (B.concat [bs,B.cons 0x0a (encodeUtf8 messagedata)]) | 432 | = UpToN xE (B.concat [bs,B.cons 0x0a (encodeUtf8 messagedata)]) |
428 | setTitle (UpToN xE (sizedAtLeastN 4 -> B.splitAt 3 -> (bs,B.uncons -> Just (_,xs)))) title | 433 | setTitle (UpToN xE (sizedAtLeastN 9 -> B.splitAt 8 -> (bs,B.uncons -> Just (_,xs)))) title |
429 | | isIndirectGrpChat xE = UpToN xE (B.concat [bs,B.cons (fromIntegral $ fromEnum GroupchatTitleChange) (encodeUtf8 title)]) | 434 | | isIndirectGrpChat xE = UpToN xE (B.concat [bs,B.cons (fromIntegral $ fromEnum GroupchatTitleChange) (encodeUtf8 title)]) |
430 | setTitle _ _ = error "setTitle on CryptoMessage without title field." | 435 | setTitle _ _ = error "setTitle on CryptoMessage without title field." |
431 | 436 | ||