diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-05 01:26:59 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-05 16:28:25 -0500 |
commit | 6a0dd9d52ea9554c9397211224273caf8832889b (patch) | |
tree | 5cb35f5e64a843eea0d615ceb8cdfbe0ba3af397 /Presence/XMPPServer.hs | |
parent | 3e2a0aad66b7567c8ed2d11214724919790462d7 (diff) |
Factored applyStanza/forwardStanza out of xmppInbound.
Diffstat (limited to 'Presence/XMPPServer.hs')
-rw-r--r-- | Presence/XMPPServer.hs | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index a102ed5a..e3dfd32e 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -42,7 +42,6 @@ module XMPPServer | |||
42 | , flushPassThrough | 42 | , flushPassThrough |
43 | , greet' | 43 | , greet' |
44 | , (<&>) | 44 | , (<&>) |
45 | , grokStanza | ||
46 | ) where | 45 | ) where |
47 | 46 | ||
48 | import ConnectionKey | 47 | import ConnectionKey |
@@ -463,15 +462,16 @@ C->Unrecognized </iq> | |||
463 | -} | 462 | -} |
464 | 463 | ||
465 | 464 | ||
465 | -- Sends all stanzas to announce channel except ping, for which it sends a pong | ||
466 | -- to the output channel. | ||
466 | xmppInbound :: ConnectionData | 467 | xmppInbound :: ConnectionData |
467 | -> XMPPServerParameters -- ^ XXX: unused | ||
468 | -> (Text, IO Text, IO Text, TChan Stanza -> StanzaOrigin) | 468 | -> (Text, IO Text, IO Text, TChan Stanza -> StanzaOrigin) |
469 | -> FlagCommand -- ^ action to check whether the connection needs a ping (XXX: unused) | 469 | -> FlagCommand -- ^ action to check whether the connection needs a ping (XXX: unused) |
470 | -> TChan Stanza -- ^ channel to announce incoming stanzas on | 470 | -> TChan Stanza -- ^ channel to announce incoming stanzas on |
471 | -> TChan Stanza -- ^ channel used to send stanzas | 471 | -> TChan Stanza -- ^ channel used to send stanzas |
472 | -> TMVar () -- ^ mvar that is filled when the connection quits | 472 | -> TMVar () -- ^ mvar that is filled when the connection quits |
473 | -> ConduitM Event o IO () | 473 | -> ConduitM Event o IO () |
474 | xmppInbound cdta xmpp (namespace,tellmyname,tellyourname,mkorigin) pingflag stanzas output donevar = doNestingXML $ do | 474 | xmppInbound cdta (namespace,tellmyname,tellyourname,mkorigin) pingflag stanzas output donevar = doNestingXML $ do |
475 | withXML $ \begindoc -> do | 475 | withXML $ \begindoc -> do |
476 | when (begindoc==EventBeginDocument) $ do | 476 | when (begindoc==EventBeginDocument) $ do |
477 | whenJust nextElement $ \xml -> do | 477 | whenJust nextElement $ \xml -> do |
@@ -971,7 +971,7 @@ forkConnection sv xmpp saddr cdta pingflag src snk stanzas pp_mvar = do | |||
971 | forkIO $ do | 971 | forkIO $ do |
972 | myThreadId >>= flip labelThread (lbl "xmpp-reader.") | 972 | myThreadId >>= flip labelThread (lbl "xmpp-reader.") |
973 | -- src $$ awaitForever (lift . putStrLn . takeWhile (/=' ') . show) | 973 | -- src $$ awaitForever (lift . putStrLn . takeWhile (/=' ') . show) |
974 | runConduit $ src .| xmppInbound cdta xmpp clientOrServer pingflag stanzas output rdone | 974 | runConduit $ src .| xmppInbound cdta clientOrServer pingflag stanzas output rdone |
975 | atomically $ putTMVar rdone () | 975 | atomically $ putTMVar rdone () |
976 | wlog $ "end reader fork: " ++ lbl "" | 976 | wlog $ "end reader fork: " ++ lbl "" |
977 | return output | 977 | return output |
@@ -1209,7 +1209,41 @@ monitor sv params xmpp = do | |||
1209 | -} | 1209 | -} |
1210 | dup <- cloneStanza stanza | 1210 | dup <- cloneStanza stanza |
1211 | 1211 | ||
1212 | forkIO $ do | 1212 | forkIO $ do applyStanza sv quitVar xmpp stanza |
1213 | forwardStanza quitVar xmpp stanza | ||
1214 | |||
1215 | -- We need to clone in the case the stanza is passed on as for Message. | ||
1216 | wantStanzas <- getVerbose XJabber | ||
1217 | verbosity <- xmppVerbosity xmpp | ||
1218 | let notping f | not wantStanzas = return () | ||
1219 | | (verbosity==1) = case stanzaType stanza of Pong -> return () | ||
1220 | _ -> f | ||
1221 | | (verbosity>=2) = f | ||
1222 | | otherwise = return () | ||
1223 | notping $ do | ||
1224 | let typ = Strict8.pack $ c ++ "->"++(concat . take 1 . words $ show (stanzaType stanza))++" " | ||
1225 | c = case stanzaOrigin stanza of | ||
1226 | LocalPeer -> "*" | ||
1227 | ClientOrigin {} -> "C" | ||
1228 | PeerOrigin {} -> "P" | ||
1229 | wlog "" | ||
1230 | liftIO $ takeMVar pp_mvar | ||
1231 | runConduit $ stanzaToConduit dup .| prettyPrint typ | ||
1232 | liftIO $ putMVar pp_mvar () | ||
1233 | ] | ||
1234 | action | ||
1235 | loop | ||
1236 | where | ||
1237 | tomsg k str = printf "%12s %s" str (show k) | ||
1238 | where | ||
1239 | _ = str :: String | ||
1240 | |||
1241 | applyStanza :: Server PeerAddress ConnectionData releaseKey Event | ||
1242 | -> TMVar () | ||
1243 | -> XMPPServerParameters | ||
1244 | -> StanzaWrap (LockedChan Event) | ||
1245 | -> IO () | ||
1246 | applyStanza sv quitVar xmpp stanza = do | ||
1213 | case stanzaOrigin stanza of | 1247 | case stanzaOrigin stanza of |
1214 | ClientOrigin k replyto -> | 1248 | ClientOrigin k replyto -> |
1215 | case stanzaType stanza of | 1249 | case stanzaType stanza of |
@@ -1288,6 +1322,9 @@ monitor sv params xmpp = do | |||
1288 | xmppPeerInformSubscription xmpp fail k stanza | 1322 | xmppPeerInformSubscription xmpp fail k stanza |
1289 | _ -> return () | 1323 | _ -> return () |
1290 | _ -> return () | 1324 | _ -> return () |
1325 | |||
1326 | forwardStanza :: TMVar () -> XMPPServerParameters -> StanzaWrap (LockedChan Event) -> IO () | ||
1327 | forwardStanza quitVar xmpp stanza = do | ||
1291 | let deliver replyto = do | 1328 | let deliver replyto = do |
1292 | -- TODO: Issuing RecipientUnavailable for all errors is a presence leak | 1329 | -- TODO: Issuing RecipientUnavailable for all errors is a presence leak |
1293 | -- and protocol violation | 1330 | -- and protocol violation |
@@ -1312,31 +1349,6 @@ monitor sv params xmpp = do | |||
1312 | ClientOrigin _ replyto -> deliver replyto | 1349 | ClientOrigin _ replyto -> deliver replyto |
1313 | PeerOrigin _ replyto -> deliver replyto | 1350 | PeerOrigin _ replyto -> deliver replyto |
1314 | _ -> return () | 1351 | _ -> return () |
1315 | -- We need to clone in the case the stanza is passed on as for Message. | ||
1316 | wantStanzas <- getVerbose XJabber | ||
1317 | verbosity <- xmppVerbosity xmpp | ||
1318 | let notping f | not wantStanzas = return () | ||
1319 | | (verbosity==1) = case stanzaType stanza of Pong -> return () | ||
1320 | _ -> f | ||
1321 | | (verbosity>=2) = f | ||
1322 | | otherwise = return () | ||
1323 | notping $ do | ||
1324 | let typ = Strict8.pack $ c ++ "->"++(concat . take 1 . words $ show (stanzaType stanza))++" " | ||
1325 | c = case stanzaOrigin stanza of | ||
1326 | LocalPeer -> "*" | ||
1327 | ClientOrigin {} -> "C" | ||
1328 | PeerOrigin {} -> "P" | ||
1329 | wlog "" | ||
1330 | liftIO $ takeMVar pp_mvar | ||
1331 | runConduit $ stanzaToConduit dup .| prettyPrint typ | ||
1332 | liftIO $ putMVar pp_mvar () | ||
1333 | ] | ||
1334 | action | ||
1335 | loop | ||
1336 | where | ||
1337 | tomsg k str = printf "%12s %s" str (show k) | ||
1338 | where | ||
1339 | _ = str :: String | ||
1340 | 1352 | ||
1341 | data ConnectionType = XMPP | Tox | 1353 | data ConnectionType = XMPP | Tox |
1342 | deriving (Eq,Ord,Enum,Show,Read) | 1354 | deriving (Eq,Ord,Enum,Show,Read) |