diff options
author | joe <joe@jerkface.net> | 2014-02-12 13:05:43 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-02-12 13:05:43 -0500 |
commit | 5ad7794bcd86a0049d1e62cae2f04f6088a0ef34 (patch) | |
tree | 087de3ad2c7f467c518fd16b5a92eb0f651ec916 | |
parent | 15c2eecebb0608907d55a025c71e53de4065d1a5 (diff) |
pass output channel to xmppInbound handler
-rw-r--r-- | xmppServer.hs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/xmppServer.hs b/xmppServer.hs index aa99c061..85e0cb5c 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -91,8 +91,9 @@ prettyPrint prefix xs = | |||
91 | xmppInbound :: ConnectionKey -> FlagCommand | 91 | xmppInbound :: ConnectionKey -> FlagCommand |
92 | -> Source IO XML.Event | 92 | -> Source IO XML.Event |
93 | -> TChan Stanza | 93 | -> TChan Stanza |
94 | -> TChan Stanza | ||
94 | -> Sink XML.Event IO () | 95 | -> Sink XML.Event IO () |
95 | xmppInbound k pingflag src stanzas = doNestingXML $ do | 96 | xmppInbound k pingflag src stanzas output = doNestingXML $ do |
96 | withXML $ \begindoc -> do | 97 | withXML $ \begindoc -> do |
97 | when (begindoc==EventBeginDocument) $ do | 98 | when (begindoc==EventBeginDocument) $ do |
98 | whenJust nextElement $ \xml -> do | 99 | whenJust nextElement $ \xml -> do |
@@ -167,6 +168,18 @@ peerPing mid to from = | |||
167 | , EventEndElement "{urn:xmpp:ping}ping" | 168 | , EventEndElement "{urn:xmpp:ping}ping" |
168 | , EventEndElement "{jabber:server}iq" ] | 169 | , EventEndElement "{jabber:server}iq" ] |
169 | 170 | ||
171 | peerPong mid to from = | ||
172 | [ EventBeginElement "{jabber:server}iq" | ||
173 | $(case mid of | ||
174 | Just c -> (("id",[ContentText c]):) | ||
175 | _ -> id) | ||
176 | [ attr "type" "result" | ||
177 | , attr "to" to | ||
178 | , attr "from" from | ||
179 | ] | ||
180 | , EventEndElement "{jabber:server}iq" | ||
181 | ] | ||
182 | |||
170 | 183 | ||
171 | forkConnection :: ConnectionKey | 184 | forkConnection :: ConnectionKey |
172 | -> FlagCommand | 185 | -> FlagCommand |
@@ -176,11 +189,6 @@ forkConnection :: ConnectionKey | |||
176 | -> IO (TChan Stanza) | 189 | -> IO (TChan Stanza) |
177 | forkConnection k pingflag src snk stanzas = do | 190 | forkConnection k pingflag src snk stanzas = do |
178 | rdone <- atomically newEmptyTMVar | 191 | rdone <- atomically newEmptyTMVar |
179 | forkIO $ do | ||
180 | -- src $$ awaitForever (lift . putStrLn . takeWhile (/=' ') . show) | ||
181 | src $$ xmppInbound k pingflag src stanzas | ||
182 | atomically $ putTMVar rdone () | ||
183 | wlog $ "end reader fork: " ++ show k | ||
184 | slots <- atomically $ Slotted.new isEventBeginElement isEventEndElement | 192 | slots <- atomically $ Slotted.new isEventBeginElement isEventEndElement |
185 | needsFlush <- atomically $ newTVar False | 193 | needsFlush <- atomically $ newTVar False |
186 | let _ = slots :: Slotted.UpdateStream XMPPState XML.Event | 194 | let _ = slots :: Slotted.UpdateStream XMPPState XML.Event |
@@ -235,6 +243,11 @@ forkConnection k pingflag src snk stanzas = do | |||
235 | ] | 243 | ] |
236 | what | 244 | what |
237 | wlog $ "end pre-queue fork: " ++ show k | 245 | wlog $ "end pre-queue fork: " ++ show k |
246 | forkIO $ do | ||
247 | -- src $$ awaitForever (lift . putStrLn . takeWhile (/=' ') . show) | ||
248 | src $$ xmppInbound k pingflag src stanzas output | ||
249 | atomically $ putTMVar rdone () | ||
250 | wlog $ "end reader fork: " ++ show k | ||
238 | return output | 251 | return output |
239 | 252 | ||
240 | monitor sv params = do | 253 | monitor sv params = do |
@@ -245,9 +258,10 @@ monitor sv params = do | |||
245 | [ readTChan chan >>= \(k,e) -> return $ do | 258 | [ readTChan chan >>= \(k,e) -> return $ do |
246 | case e of | 259 | case e of |
247 | Connection pingflag conread conwrite -> do | 260 | Connection pingflag conread conwrite -> do |
261 | wlog $ tomsg k "Connection" | ||
248 | let (xsrc,xsnk) = xmlStream conread conwrite | 262 | let (xsrc,xsnk) = xmlStream conread conwrite |
249 | forkConnection k pingflag xsrc xsnk stanzas | 263 | forkConnection k pingflag xsrc xsnk stanzas |
250 | wlog $ tomsg k "Connection" | 264 | return () |
251 | EOF -> wlog $ tomsg k "EOF" | 265 | EOF -> wlog $ tomsg k "EOF" |
252 | HalfConnection In -> do | 266 | HalfConnection In -> do |
253 | wlog $ tomsg k "ReadOnly" | 267 | wlog $ tomsg k "ReadOnly" |