diff options
Diffstat (limited to 'Presence/XMPPServer.hs')
-rw-r--r-- | Presence/XMPPServer.hs | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index 45b89b3d..140c91af 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -130,12 +130,10 @@ copyToChannel f chan closer_stack = awaitForever copy | |||
130 | yield x | 130 | yield x |
131 | 131 | ||
132 | 132 | ||
133 | prettyPrint prefix xs = | 133 | prettyPrint prefix = |
134 | liftIO $ | 134 | XML.renderBytes (XML.def { XML.rsPretty=True }) |
135 | CL.sourceList xs | ||
136 | $= XML.renderBytes (XML.def { XML.rsPretty=True }) | ||
137 | =$= CB.lines | 135 | =$= CB.lines |
138 | $$ CL.mapM_ (wlogb . (prefix <>)) | 136 | =$ CL.mapM_ (wlogb . (prefix <>)) |
139 | 137 | ||
140 | grockStanzaIQGet :: Monad m => XML.Event -> NestingXML o m (Maybe StanzaType) | 138 | grockStanzaIQGet :: Monad m => XML.Event -> NestingXML o m (Maybe StanzaType) |
141 | grockStanzaIQGet stanza = do | 139 | grockStanzaIQGet stanza = do |
@@ -316,22 +314,10 @@ forkConnection k pingflag src snk stanzas = do | |||
316 | fix $ \loop -> do | 314 | fix $ \loop -> do |
317 | what <- atomically $ foldr1 orElse | 315 | what <- atomically $ foldr1 orElse |
318 | [readTChan output >>= \stanza -> return $ do | 316 | [readTChan output >>= \stanza -> return $ do |
319 | let xchan = stanzaChan stanza | 317 | stanzaToConduit stanza |
320 | xfin = stanzaClosers stanza | 318 | $$ awaitForever |
321 | fix $ \inner -> do | 319 | $ liftIO . atomically . Slotted.push slots Nothing |
322 | what <- atomically $ foldr1 orElse | 320 | loop |
323 | [readTChan xchan >>= \xml -> return $ do | ||
324 | atomically $ Slotted.push slots Nothing xml | ||
325 | inner | ||
326 | ,do mb <- readTVar xfin | ||
327 | cempty <- isEmptyTChan xchan | ||
328 | if isNothing mb | ||
329 | then if cempty then return loop else retry | ||
330 | else retry -- todo: send closers | ||
331 | ,do isEmptyTChan xchan >>= check | ||
332 | readTMVar rdone | ||
333 | return (return ())] | ||
334 | what | ||
335 | ,do pingflag >>= check | 321 | ,do pingflag >>= check |
336 | return $ do | 322 | return $ do |
337 | let to = addrToText (callBackAddress k) | 323 | let to = addrToText (callBackAddress k) |
@@ -342,7 +328,7 @@ forkConnection k pingflag src snk stanzas = do | |||
342 | mapM_ (atomically . Slotted.push slots (Just $ PingSlot)) | 328 | mapM_ (atomically . Slotted.push slots (Just $ PingSlot)) |
343 | ping | 329 | ping |
344 | wlog "" | 330 | wlog "" |
345 | prettyPrint "P<-PING " ping | 331 | CL.sourceList ping $$ prettyPrint "P<-Ping " |
346 | loop | 332 | loop |
347 | ,readTMVar rdone >> return (return ()) | 333 | ,readTMVar rdone >> return (return ()) |
348 | ] | 334 | ] |
@@ -380,6 +366,27 @@ peerKey (sock,addr) = do | |||
380 | 366 | ||
381 | clientKey (sock,addr) = return $ ClientKey addr | 367 | clientKey (sock,addr) = return $ ClientKey addr |
382 | 368 | ||
369 | stanzaToConduit :: MonadIO m => Stanza -> ConduitM i Event m () | ||
370 | stanzaToConduit stanza = do | ||
371 | let xchan = stanzaChan stanza | ||
372 | xfin = stanzaClosers stanza | ||
373 | rdone = stanzaInterrupt stanza | ||
374 | loop = return () | ||
375 | fix $ \inner -> do | ||
376 | what <- liftIO . atomically $ foldr1 orElse | ||
377 | [readTChan xchan >>= \xml -> return $ do | ||
378 | yield xml -- atomically $ Slotted.push slots Nothing xml | ||
379 | inner | ||
380 | ,do mb <- readTVar xfin | ||
381 | cempty <- isEmptyTChan xchan | ||
382 | if isNothing mb | ||
383 | then if cempty then return loop else retry | ||
384 | else retry -- todo: send closers | ||
385 | ,do isEmptyTChan xchan >>= check | ||
386 | readTMVar rdone | ||
387 | return (return ())] | ||
388 | what | ||
389 | |||
383 | monitor sv params = do | 390 | monitor sv params = do |
384 | chan <- return $ serverEvent sv | 391 | chan <- return $ serverEvent sv |
385 | stanzas <- atomically newTChan | 392 | stanzas <- atomically newTChan |
@@ -402,11 +409,9 @@ monitor sv params = do | |||
402 | RequiresPing -> return () -- wlog $ tomsg k "RequiresPing" | 409 | RequiresPing -> return () -- wlog $ tomsg k "RequiresPing" |
403 | _ -> return () | 410 | _ -> return () |
404 | , readTChan stanzas >>= \stanza -> return $ do | 411 | , readTChan stanzas >>= \stanza -> return $ do |
405 | -- xs <- readUntilNothing (stanzaChan stanza) | ||
406 | xs <- chanContents (stanzaChan stanza) | ||
407 | let typ = Strict8.pack $ "P->"++(show (stanzaType stanza))++" " | 412 | let typ = Strict8.pack $ "P->"++(show (stanzaType stanza))++" " |
408 | wlog "" | 413 | wlog "" |
409 | prettyPrint typ xs | 414 | stanzaToConduit stanza $$ prettyPrint typ |
410 | ] | 415 | ] |
411 | action | 416 | action |
412 | loop | 417 | loop |