diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-02 00:16:58 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-02 00:21:52 -0400 |
commit | 72bbe42ea51261d306b45fc0fddef57d57c54cef (patch) | |
tree | abaf9083c9a76b377702b16eb128ba1f4c142dd3 /Presence/XMPPServer.hs | |
parent | adc61071fb1c3a72f2d8f06866e0f3abaf50c6f5 (diff) |
Avoid deprecated Conduit interface in library modules.
Diffstat (limited to 'Presence/XMPPServer.hs')
-rw-r--r-- | Presence/XMPPServer.hs | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index 24cfd055..2345cb67 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -297,11 +297,11 @@ wlog = dput XJabber | |||
297 | wlogb :: ByteString -> IO () | 297 | wlogb :: ByteString -> IO () |
298 | wlogb = wlog . Strict8.unpack | 298 | wlogb = wlog . Strict8.unpack |
299 | 299 | ||
300 | flushPassThrough :: Monad m => Conduit a m b -> Conduit (Flush a) m (Flush b) | 300 | flushPassThrough :: Monad m => ConduitT a b m () -> ConduitT (Flush a) (Flush b) m () |
301 | flushPassThrough c = getZipConduit $ ZipConduit (onlyChunks =$= mapOutput Chunk c) <* ZipConduit onlyFlushes | 301 | flushPassThrough c = getZipConduit $ ZipConduit (onlyChunks .| mapOutput Chunk c) <* ZipConduit onlyFlushes |
302 | where | 302 | where |
303 | onlyChunks :: Monad m => Conduit (Flush a) m a | 303 | onlyChunks :: Monad m => ConduitT (Flush a) a m () |
304 | onlyFlushes :: Monad m => Conduit (Flush a) m (Flush b) | 304 | onlyFlushes :: Monad m => ConduitT (Flush a) (Flush b) m () |
305 | onlyChunks = awaitForever yieldChunk | 305 | onlyChunks = awaitForever yieldChunk |
306 | onlyFlushes = awaitForever yieldFlush | 306 | onlyFlushes = awaitForever yieldFlush |
307 | yieldFlush Flush = yield Flush | 307 | yieldFlush Flush = yield Flush |
@@ -309,17 +309,17 @@ flushPassThrough c = getZipConduit $ ZipConduit (onlyChunks =$= mapOutput Chunk | |||
309 | yieldChunk (Chunk x) = yield x | 309 | yieldChunk (Chunk x) = yield x |
310 | yieldChunk _ = return () | 310 | yieldChunk _ = return () |
311 | 311 | ||
312 | xmlStream :: ReadCommand -> WriteCommand -> ( Source IO XML.Event | 312 | xmlStream :: ReadCommand -> WriteCommand -> ( ConduitT () XML.Event IO () |
313 | , Sink (Flush XML.Event) IO () ) | 313 | , ConduitT (Flush XML.Event) Void IO () ) |
314 | xmlStream conread conwrite = (xsrc,xsnk) | 314 | xmlStream conread conwrite = (xsrc,xsnk) |
315 | where | 315 | where |
316 | xsrc = src $= XML.parseBytes XML.def | 316 | xsrc = src .| XML.parseBytes XML.def |
317 | xsnk :: Sink (Flush Event) IO () | 317 | xsnk :: ConduitT (Flush Event) Void IO () |
318 | xsnk = -- XML.renderBytes XML.def =$ snk | 318 | xsnk = -- XML.renderBytes XML.def =$ snk |
319 | flushPassThrough (XML.renderBuilder XML.def) | 319 | flushPassThrough (XML.renderBuilder XML.def) |
320 | =$= builderToByteStringFlush | 320 | .| builderToByteStringFlush |
321 | =$= discardFlush | 321 | .| discardFlush |
322 | =$ snk | 322 | .| snk |
323 | where | 323 | where |
324 | discardFlush :: Monad m => ConduitM (Flush a) a m () | 324 | discardFlush :: Monad m => ConduitM (Flush a) a m () |
325 | discardFlush = awaitForever yieldChunk | 325 | discardFlush = awaitForever yieldChunk |
@@ -365,8 +365,8 @@ copyToChannel f chan closer_stack = awaitForever copy | |||
365 | prettyPrint :: ByteString -> ConduitM Event Void IO () | 365 | prettyPrint :: ByteString -> ConduitM Event Void IO () |
366 | prettyPrint prefix = | 366 | prettyPrint prefix = |
367 | XML.renderBytes (XML.def { XML.rsPretty=True }) | 367 | XML.renderBytes (XML.def { XML.rsPretty=True }) |
368 | =$= CB.lines | 368 | .| CB.lines |
369 | =$ CL.mapM_ (wlogb . (prefix <>)) | 369 | .| CL.mapM_ (wlogb . (prefix <>)) |
370 | 370 | ||
371 | swapNamespace :: Monad m => Text -> Text -> ConduitM Event Event m () | 371 | swapNamespace :: Monad m => Text -> Text -> ConduitM Event Event m () |
372 | swapNamespace old new = awaitForever (yield . swapit old new) | 372 | swapNamespace old new = awaitForever (yield . swapit old new) |
@@ -403,14 +403,14 @@ fixHeaders Stanza { stanzaType=typ, stanzaTo=mto, stanzaFrom=mfrom } = do | |||
403 | delAttrib akey as = filter ((/=akey) . fst) as | 403 | delAttrib akey as = filter ((/=akey) . fst) as |
404 | 404 | ||
405 | conduitToChan | 405 | conduitToChan |
406 | :: Conduit () IO Event | 406 | :: ConduitT () Event IO () |
407 | -> IO (LockedChan Event, TVar (Maybe [Event]), TMVar a) | 407 | -> IO (LockedChan Event, TVar (Maybe [Event]), TMVar a) |
408 | conduitToChan c = do | 408 | conduitToChan c = do |
409 | chan <- atomically newLockedChan | 409 | chan <- atomically newLockedChan |
410 | clsrs <- atomically $ newTVar (Just []) | 410 | clsrs <- atomically $ newTVar (Just []) |
411 | quitvar <- atomically $ newEmptyTMVar | 411 | quitvar <- atomically $ newEmptyTMVar |
412 | forkIO $ do | 412 | forkIO $ do |
413 | c =$= copyToChannel id chan clsrs $$ awaitForever (const $ return ()) | 413 | runConduit $ c .| copyToChannel id chan clsrs .| awaitForever (const $ return ()) |
414 | atomically $ writeTVar clsrs Nothing | 414 | atomically $ writeTVar clsrs Nothing |
415 | return (chan,clsrs,quitvar) | 415 | return (chan,clsrs,quitvar) |
416 | 416 | ||
@@ -419,7 +419,7 @@ conduitToStanza | |||
419 | -> Maybe Text -- ^ id | 419 | -> Maybe Text -- ^ id |
420 | -> Maybe Text -- ^ from | 420 | -> Maybe Text -- ^ from |
421 | -> Maybe Text -- ^ to | 421 | -> Maybe Text -- ^ to |
422 | -> Conduit () IO Event | 422 | -> ConduitT () Event IO () |
423 | -> IO Stanza | 423 | -> IO Stanza |
424 | conduitToStanza stype mid from to c = do | 424 | conduitToStanza stype mid from to c = do |
425 | (chan,clsrs,quitvar) <- conduitToChan c | 425 | (chan,clsrs,quitvar) <- conduitToChan c |
@@ -476,7 +476,7 @@ sendModifiedStanzaToPeer stanza chan = do | |||
476 | where | 476 | where |
477 | old = "jabber:client" | 477 | old = "jabber:client" |
478 | new = "jabber:server" | 478 | new = "jabber:server" |
479 | c = stanzaToConduit stanza =$= swapNamespace old new =$= fixHeaders stanza | 479 | c = stanzaToConduit stanza .| swapNamespace old new .| fixHeaders stanza |
480 | processedType (Error cond tag) = Error cond (swapit old new tag) | 480 | processedType (Error cond tag) = Error cond (swapit old new tag) |
481 | processedType x = x | 481 | processedType x = x |
482 | 482 | ||
@@ -498,7 +498,7 @@ sendModifiedStanzaToClient stanza chan = do | |||
498 | where | 498 | where |
499 | old = "jabber:server" | 499 | old = "jabber:server" |
500 | new = "jabber:client" | 500 | new = "jabber:client" |
501 | c = stanzaToConduit stanza =$= swapNamespace old new =$= fixHeaders stanza | 501 | c = stanzaToConduit stanza .| swapNamespace old new .| fixHeaders stanza |
502 | processedType (Error cond tag) = Error cond (swapit old new tag) | 502 | processedType (Error cond tag) = Error cond (swapit old new tag) |
503 | processedType x = x | 503 | processedType x = x |
504 | 504 | ||
@@ -939,7 +939,7 @@ xmppInbound cdta xmpp (namespace,tellmyname,tellyourname,mkorigin) pingflag stan | |||
939 | liftIO . atomically $ do | 939 | liftIO . atomically $ do |
940 | writeLChan chan stanzaTag | 940 | writeLChan chan stanzaTag |
941 | modifyTVar' clsrs (fmap (closerFor stanzaTag:)) | 941 | modifyTVar' clsrs (fmap (closerFor stanzaTag:)) |
942 | copyToChannel id chan clsrs =$= do | 942 | copyToChannel id chan clsrs .| do |
943 | let mid = lookupAttrib "id" $ tagAttrs stanzaTag | 943 | let mid = lookupAttrib "id" $ tagAttrs stanzaTag |
944 | mfrom = lookupAttrib "from" $ tagAttrs stanzaTag | 944 | mfrom = lookupAttrib "from" $ tagAttrs stanzaTag |
945 | mto = lookupAttrib "to" $ tagAttrs stanzaTag | 945 | mto = lookupAttrib "to" $ tagAttrs stanzaTag |
@@ -1218,7 +1218,7 @@ slotsToSource :: | |||
1218 | -> TVar (Maybe (StanzaWrap XML.Event)) | 1218 | -> TVar (Maybe (StanzaWrap XML.Event)) |
1219 | -> TVar Bool | 1219 | -> TVar Bool |
1220 | -> TMVar () | 1220 | -> TMVar () |
1221 | -> Source IO (Flush XML.Event) | 1221 | -> ConduitT () (Flush XML.Event) IO () |
1222 | slotsToSource slots nesting lastStanza needsFlush rdone = | 1222 | slotsToSource slots nesting lastStanza needsFlush rdone = |
1223 | fix $ \slot_src -> join . lift . atomically $ foldr1 orElse | 1223 | fix $ \slot_src -> join . lift . atomically $ foldr1 orElse |
1224 | [Slotted.pull slots >>= \x -> do | 1224 | [Slotted.pull slots >>= \x -> do |
@@ -1255,11 +1255,11 @@ forkConnection :: Server PeerAddress ConnectionData releaseKey XML.Event | |||
1255 | -> PeerAddress -- SockAddr (XXX(what?): remote for peer, local for client) | 1255 | -> PeerAddress -- SockAddr (XXX(what?): remote for peer, local for client) |
1256 | -> ConnectionData | 1256 | -> ConnectionData |
1257 | -> FlagCommand | 1257 | -> FlagCommand |
1258 | -> Source IO XML.Event | 1258 | -> ConduitT () XML.Event IO () |
1259 | -> Sink (Flush XML.Event) IO () | 1259 | -> ConduitT (Flush XML.Event) Void IO () |
1260 | -> TChan Stanza | 1260 | -> TChan Stanza |
1261 | -> MVar () | 1261 | -> MVar () |
1262 | -> IO (TChan Stanza) | 1262 | -> IO (TChan Stanza) |
1263 | forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | 1263 | forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do |
1264 | let auxAddr = cdAddr cdta | 1264 | let auxAddr = cdAddr cdta |
1265 | clientOrServer@(namespace,tellmyname,telltheirname,_) = case auxAddr of | 1265 | clientOrServer@(namespace,tellmyname,telltheirname,_) = case auxAddr of |
@@ -1283,7 +1283,7 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1283 | nesting <- atomically $ newTVar 0 | 1283 | nesting <- atomically $ newTVar 0 |
1284 | let _ = slots :: Slotted.UpdateStream XMPPState (Either (StanzaWrap XML.Event) XML.Event) | 1284 | let _ = slots :: Slotted.UpdateStream XMPPState (Either (StanzaWrap XML.Event) XML.Event) |
1285 | let greet_src = do | 1285 | let greet_src = do |
1286 | CL.sourceList (greet' namespace me) =$= CL.map Chunk | 1286 | CL.sourceList (greet' namespace me) .| CL.map Chunk |
1287 | yield Flush | 1287 | yield Flush |
1288 | slot_src = slotsToSource slots nesting lastStanza needsFlush rdone | 1288 | slot_src = slotsToSource slots nesting lastStanza needsFlush rdone |
1289 | -- client.PeerAddress {peerAddress = [::1]:5222} | 1289 | -- client.PeerAddress {peerAddress = [::1]:5222} |
@@ -1302,7 +1302,7 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1302 | -- Read all slots-queued XML events or stanzas and yield them | 1302 | -- Read all slots-queued XML events or stanzas and yield them |
1303 | -- upstream. This should continue until the connection is | 1303 | -- upstream. This should continue until the connection is |
1304 | -- closed. | 1304 | -- closed. |
1305 | (greet_src >> slot_src) $$ snk | 1305 | runConduit $ (greet_src >> slot_src) .| snk |
1306 | 1306 | ||
1307 | -- Connection is now closed. Here we handle any unsent stanzas. | 1307 | -- Connection is now closed. Here we handle any unsent stanzas. |
1308 | last <- atomically $ readTVar lastStanza | 1308 | last <- atomically $ readTVar lastStanza |
@@ -1360,7 +1360,7 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1360 | Left _ -> "P" | 1360 | Left _ -> "P" |
1361 | wlog "" | 1361 | wlog "" |
1362 | liftIO $ takeMVar pp_mvar | 1362 | liftIO $ takeMVar pp_mvar |
1363 | stanzaToConduit dup $$ prettyPrint typ | 1363 | runConduit $ stanzaToConduit dup .| prettyPrint typ |
1364 | liftIO $ putMVar pp_mvar () | 1364 | liftIO $ putMVar pp_mvar () |
1365 | -- wlog $ "hacks: "++show (stanzaId stanza) | 1365 | -- wlog $ "hacks: "++show (stanzaId stanza) |
1366 | case stanzaType stanza of | 1366 | case stanzaType stanza of |
@@ -1371,10 +1371,10 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1371 | -- wlog $ "cache id thread: " ++ show x | 1371 | -- wlog $ "cache id thread: " ++ show x |
1372 | atomically $ modifyTVar' msgids (take 3 . (x:)) | 1372 | atomically $ modifyTVar' msgids (take 3 . (x:)) |
1373 | _ -> return () | 1373 | _ -> return () |
1374 | stanzaToConduit stanza =$= wrapStanzaConduit stanza | 1374 | runConduit $ stanzaToConduit stanza .| wrapStanzaConduit stanza |
1375 | $$ awaitForever | 1375 | .| awaitForever |
1376 | -- TODO: PresenceStatus stanzas should be pushed to appropriate slots | 1376 | -- TODO: PresenceStatus stanzas should be pushed to appropriate slots |
1377 | $ liftIO . atomically . Slotted.push slots Nothing | 1377 | (liftIO . atomically . Slotted.push slots Nothing) |
1378 | case stanzaType stanza of | 1378 | case stanzaType stanza of |
1379 | Error err tag | tagName tag=="{jabber:client}message" -> do | 1379 | Error err tag | tagName tag=="{jabber:client}message" -> do |
1380 | wlog $ "handling Error hacks" | 1380 | wlog $ "handling Error hacks" |
@@ -1388,9 +1388,9 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1388 | when b $ do | 1388 | when b $ do |
1389 | let sim = simulateChatError err (stanzaFrom stanza) | 1389 | let sim = simulateChatError err (stanzaFrom stanza) |
1390 | wlog $ "sending simulated chat for error message." | 1390 | wlog $ "sending simulated chat for error message." |
1391 | CL.sourceList sim =$= wrapStanzaConduit stanza -- not quite right, but whatever | 1391 | runConduit $ CL.sourceList sim .| wrapStanzaConduit stanza -- not quite right, but whatever |
1392 | $$ awaitForever | 1392 | .| awaitForever |
1393 | $ liftIO . atomically . Slotted.push slots Nothing | 1393 | (liftIO . atomically . Slotted.push slots Nothing) |
1394 | Error e _ -> do | 1394 | Error e _ -> do |
1395 | wlog $ "no hacks for error: " ++ show e | 1395 | wlog $ "no hacks for error: " ++ show e |
1396 | _ -> return () | 1396 | _ -> return () |
@@ -1406,9 +1406,9 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1406 | mapM_ (atomically . Slotted.push slots (Just $ PingSlot)) | 1406 | mapM_ (atomically . Slotted.push slots (Just $ PingSlot)) |
1407 | ping | 1407 | ping |
1408 | wlog "" | 1408 | wlog "" |
1409 | CL.sourceList ping0 $$ prettyPrint $ case auxAddr of | 1409 | runConduit $ CL.sourceList ping0 .| prettyPrint (case auxAddr of |
1410 | Right _ -> "C<-Ping" | 1410 | Right _ -> "C<-Ping" |
1411 | Left _ -> "P<-Ping " | 1411 | Left _ -> "P<-Ping ") |
1412 | loop | 1412 | loop |
1413 | ,readTMVar rdone >> return (return ()) | 1413 | ,readTMVar rdone >> return (return ()) |
1414 | ] | 1414 | ] |
@@ -1417,7 +1417,7 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
1417 | forkIO $ do | 1417 | forkIO $ do |
1418 | myThreadId >>= flip labelThread (lbl "xmpp-reader.") | 1418 | myThreadId >>= flip labelThread (lbl "xmpp-reader.") |
1419 | -- src $$ awaitForever (lift . putStrLn . takeWhile (/=' ') . show) | 1419 | -- src $$ awaitForever (lift . putStrLn . takeWhile (/=' ') . show) |
1420 | src $$ xmppInbound cdta xmpp clientOrServer pingflag stanzas output rdone | 1420 | runConduit $ src .| xmppInbound cdta xmpp clientOrServer pingflag stanzas output rdone |
1421 | atomically $ putTMVar rdone () | 1421 | atomically $ putTMVar rdone () |
1422 | wlog $ "end reader fork: " ++ lbl "" | 1422 | wlog $ "end reader fork: " ++ lbl "" |
1423 | return output | 1423 | return output |
@@ -1764,7 +1764,7 @@ monitor sv params xmpp = do | |||
1764 | let rsc = unsplitJID (n,hostname,r) where (n,_,r) = splitJID rsc0 | 1764 | let rsc = unsplitJID (n,hostname,r) where (n,_,r) = splitJID rsc0 |
1765 | let reply = iq_bind_reply (stanzaId stanza) rsc | 1765 | let reply = iq_bind_reply (stanzaId stanza) rsc |
1766 | -- sendReply quitVar SetResource reply replyto | 1766 | -- sendReply quitVar SetResource reply replyto |
1767 | let requestVersion :: Producer IO XML.Event | 1767 | let requestVersion :: ConduitT i XML.Event IO () |
1768 | requestVersion = do | 1768 | requestVersion = do |
1769 | yield $ EventBeginElement "{jabber:client}iq" | 1769 | yield $ EventBeginElement "{jabber:client}iq" |
1770 | [ attr "to" rsc | 1770 | [ attr "to" rsc |
@@ -1872,7 +1872,7 @@ monitor sv params xmpp = do | |||
1872 | PeerOrigin {} -> "P" | 1872 | PeerOrigin {} -> "P" |
1873 | wlog "" | 1873 | wlog "" |
1874 | liftIO $ takeMVar pp_mvar | 1874 | liftIO $ takeMVar pp_mvar |
1875 | stanzaToConduit dup $$ prettyPrint typ | 1875 | runConduit $ stanzaToConduit dup .| prettyPrint typ |
1876 | liftIO $ putMVar pp_mvar () | 1876 | liftIO $ putMVar pp_mvar () |
1877 | ] | 1877 | ] |
1878 | action | 1878 | action |