diff options
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/XMPPServer.hs | 206 |
1 files changed, 103 insertions, 103 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index e3dfd32e..f9938570 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -1243,112 +1243,112 @@ applyStanza :: Server PeerAddress ConnectionData releaseKey Event | |||
1243 | -> XMPPServerParameters | 1243 | -> XMPPServerParameters |
1244 | -> StanzaWrap (LockedChan Event) | 1244 | -> StanzaWrap (LockedChan Event) |
1245 | -> IO () | 1245 | -> IO () |
1246 | applyStanza sv quitVar xmpp stanza = do | 1246 | |
1247 | case stanzaOrigin stanza of | 1247 | applyStanza sv quitVar xmpp stanza = case stanzaOrigin stanza of |
1248 | ClientOrigin k replyto -> | 1248 | ClientOrigin k replyto -> |
1249 | case stanzaType stanza of | 1249 | case stanzaType stanza of |
1250 | RequestResource clientsNameForMe wanted -> do | 1250 | RequestResource clientsNameForMe wanted -> do |
1251 | sockaddr <- socketFromKey sv k | 1251 | sockaddr <- socketFromKey sv k |
1252 | rsc0 <- xmppChooseResourceName xmpp k sockaddr clientsNameForMe wanted | 1252 | rsc0 <- xmppChooseResourceName xmpp k sockaddr clientsNameForMe wanted |
1253 | hostname <- xmppTellMyNameToClient xmpp k | 1253 | hostname <- xmppTellMyNameToClient xmpp k |
1254 | let rsc = unsplitJID (n,hostname,r) where (n,_,r) = splitJID rsc0 | 1254 | let rsc = unsplitJID (n,hostname,r) where (n,_,r) = splitJID rsc0 |
1255 | let reply = iq_bind_reply (stanzaId stanza) rsc | 1255 | let reply = iq_bind_reply (stanzaId stanza) rsc |
1256 | -- sendReply quitVar SetResource reply replyto | 1256 | -- sendReply quitVar SetResource reply replyto |
1257 | let requestVersion :: ConduitT i XML.Event IO () | 1257 | let requestVersion :: ConduitT i XML.Event IO () |
1258 | requestVersion = do | 1258 | requestVersion = do |
1259 | yield $ EventBeginElement "{jabber:client}iq" | 1259 | yield $ EventBeginElement "{jabber:client}iq" |
1260 | [ attr "to" rsc | 1260 | [ attr "to" rsc |
1261 | , attr "from" hostname | 1261 | , attr "from" hostname |
1262 | , attr "type" "get" | 1262 | , attr "type" "get" |
1263 | , attr "id" "version"] | 1263 | , attr "id" "version"] |
1264 | yield $ EventBeginElement "{jabber:iq:version}query" [] | 1264 | yield $ EventBeginElement "{jabber:iq:version}query" [] |
1265 | yield $ EventEndElement "{jabber:iq:version}query" | 1265 | yield $ EventEndElement "{jabber:iq:version}query" |
1266 | yield $ EventEndElement "{jabber:client}iq" | 1266 | yield $ EventEndElement "{jabber:client}iq" |
1267 | {- | 1267 | {- |
1268 | -- XXX Debug chat: | 1268 | -- XXX Debug chat: |
1269 | yield $ EventBeginElement "{jabber:client}message" | 1269 | yield $ EventBeginElement "{jabber:client}message" |
1270 | [ attr "from" $ eventContent (Just [ContentText rsc]) | 1270 | [ attr "from" $ eventContent (Just [ContentText rsc]) |
1271 | , attr "type" "normal" ] -- "blackbird" ] | 1271 | , attr "type" "normal" ] -- "blackbird" ] |
1272 | yield $ EventBeginElement "{jabber:client}body" [] | 1272 | yield $ EventBeginElement "{jabber:client}body" [] |
1273 | yield $ EventContent $ ContentText ("hello?") | 1273 | yield $ EventContent $ ContentText ("hello?") |
1274 | yield $ EventEndElement "{jabber:client}body" | 1274 | yield $ EventEndElement "{jabber:client}body" |
1275 | yield $ EventEndElement "{jabber:client}message" | 1275 | yield $ EventEndElement "{jabber:client}message" |
1276 | -} | 1276 | -} |
1277 | sendReply quitVar SetResource reply replyto | 1277 | sendReply quitVar SetResource reply replyto |
1278 | conduitToStanza (UnrecognizedQuery "{jabber:iq:version}query") | 1278 | conduitToStanza (UnrecognizedQuery "{jabber:iq:version}query") |
1279 | Nothing -- id | 1279 | Nothing -- id |
1280 | (Just hostname) -- from | 1280 | (Just hostname) -- from |
1281 | (Just rsc) -- to | 1281 | (Just rsc) -- to |
1282 | requestVersion | 1282 | requestVersion |
1283 | >>= ioWriteChan replyto | 1283 | >>= ioWriteChan replyto |
1284 | SessionRequest -> do | 1284 | SessionRequest -> do |
1285 | me <- xmppTellMyNameToClient xmpp k | 1285 | me <- xmppTellMyNameToClient xmpp k |
1286 | let reply = iq_session_reply (stanzaId stanza) me | 1286 | let reply = iq_session_reply (stanzaId stanza) me |
1287 | sendReply quitVar Pong reply replyto | 1287 | sendReply quitVar Pong reply replyto |
1288 | RequestRoster -> do | 1288 | RequestRoster -> do |
1289 | sendRoster stanza xmpp k replyto | 1289 | sendRoster stanza xmpp k replyto |
1290 | xmppSubscribeToRoster xmpp k | 1290 | xmppSubscribeToRoster xmpp k |
1291 | PresenceStatus {} -> do | 1291 | PresenceStatus {} -> do |
1292 | xmppInformClientPresence xmpp k stanza | 1292 | xmppInformClientPresence xmpp k stanza |
1293 | PresenceRequestSubscription {} -> do | 1293 | PresenceRequestSubscription {} -> do |
1294 | let fail = return () -- todo | 1294 | let fail = return () -- todo |
1295 | xmppClientSubscriptionRequest xmpp fail k stanza replyto | 1295 | xmppClientSubscriptionRequest xmpp fail k stanza replyto |
1296 | PresenceInformSubscription {} -> do | 1296 | PresenceInformSubscription {} -> do |
1297 | let fail = return () -- todo | 1297 | let fail = return () -- todo |
1298 | xmppClientInformSubscription xmpp fail k stanza | 1298 | xmppClientInformSubscription xmpp fail k stanza |
1299 | NotifyClientVersion name version -> do | 1299 | NotifyClientVersion name version -> do |
1300 | enableClientHacks name version replyto | 1300 | enableClientHacks name version replyto |
1301 | UnrecognizedQuery query -> do | 1301 | UnrecognizedQuery query -> do |
1302 | me <- xmppTellMyNameToClient xmpp k | 1302 | me <- xmppTellMyNameToClient xmpp k |
1303 | let reply = iq_service_unavailable (stanzaId stanza) me query | 1303 | let reply = iq_service_unavailable (stanzaId stanza) me query |
1304 | sendReply quitVar (Error ServiceUnavailable (head reply)) reply replyto | 1304 | sendReply quitVar (Error ServiceUnavailable (head reply)) reply replyto |
1305 | Message {} -> do | 1305 | Message {} -> do |
1306 | -- wlog $ "LANGMAP "++show (stanzaId stanza, msgLangMap (stanzaType stanza)) | 1306 | -- wlog $ "LANGMAP "++show (stanzaId stanza, msgLangMap (stanzaType stanza)) |
1307 | maybe (return ()) (flip cacheMessageId replyto) $ do | 1307 | maybe (return ()) (flip cacheMessageId replyto) $ do |
1308 | guard . not . null . mapMaybe (msgBody . snd) $ msgLangMap (stanzaType stanza) | 1308 | guard . not . null . mapMaybe (msgBody . snd) $ msgLangMap (stanzaType stanza) |
1309 | stanzaId stanza | 1309 | stanzaId stanza |
1310 | _ -> return () | 1310 | _ -> return () |
1311 | PeerOrigin k replyto -> | 1311 | PeerOrigin k replyto -> |
1312 | case stanzaType stanza of | 1312 | case stanzaType stanza of |
1313 | PresenceRequestStatus {} -> do | 1313 | PresenceRequestStatus {} -> do |
1314 | xmppAnswerProbe xmpp k stanza replyto | 1314 | xmppAnswerProbe xmpp k stanza replyto |
1315 | PresenceStatus {} -> do | 1315 | PresenceStatus {} -> do |
1316 | xmppInformPeerPresence xmpp k stanza | 1316 | xmppInformPeerPresence xmpp k stanza |
1317 | PresenceRequestSubscription {} -> do | 1317 | PresenceRequestSubscription {} -> do |
1318 | let fail = return () -- todo | 1318 | let fail = return () -- todo |
1319 | xmppPeerSubscriptionRequest xmpp fail k stanza replyto | 1319 | xmppPeerSubscriptionRequest xmpp fail k stanza replyto |
1320 | PresenceInformSubscription {} -> do | 1320 | PresenceInformSubscription {} -> do |
1321 | let fail = return () -- todo | 1321 | let fail = return () -- todo |
1322 | xmppPeerInformSubscription xmpp fail k stanza | 1322 | xmppPeerInformSubscription xmpp fail k stanza |
1323 | _ -> return () | 1323 | _ -> return () |
1324 | _ -> return () | 1324 | _ -> return () |
1325 | 1325 | ||
1326 | forwardStanza :: TMVar () -> XMPPServerParameters -> StanzaWrap (LockedChan Event) -> IO () | 1326 | forwardStanza :: TMVar () -> XMPPServerParameters -> StanzaWrap (LockedChan Event) -> IO () |
1327 | forwardStanza quitVar xmpp stanza = do | 1327 | forwardStanza quitVar xmpp stanza = do |
1328 | let deliver replyto = do | 1328 | let deliver replyto = do |
1329 | -- TODO: Issuing RecipientUnavailable for all errors is a presence leak | 1329 | -- TODO: Issuing RecipientUnavailable for all errors is a presence leak |
1330 | -- and protocol violation | 1330 | -- and protocol violation |
1331 | let fail = do | 1331 | let fail = do |
1332 | wlog $ "Failed delivery id="++show (stanzaId stanza) -- TODO | 1332 | wlog $ "Failed delivery id="++show (stanzaId stanza) -- TODO |
1333 | reply <- makeErrorStanza stanza | 1333 | reply <- makeErrorStanza stanza |
1334 | tag <- stanzaFirstTag stanza | 1334 | tag <- stanzaFirstTag stanza |
1335 | sendReply quitVar (Error RecipientUnavailable tag) reply replyto | 1335 | sendReply quitVar (Error RecipientUnavailable tag) reply replyto |
1336 | xmppDeliverMessage xmpp fail stanza | 1336 | xmppDeliverMessage xmpp fail stanza |
1337 | -- -- bad idea: | 1337 | -- -- bad idea: |
1338 | -- let newStream = greet'' "jabber:client" "blackbird" | 1338 | -- let newStream = greet'' "jabber:client" "blackbird" |
1339 | -- sendReply quitVar Error newStream replyto | 1339 | -- sendReply quitVar Error newStream replyto |
1340 | case stanzaType stanza of | 1340 | case stanzaType stanza of |
1341 | Message {} -> do | 1341 | Message {} -> do |
1342 | case stanzaOrigin stanza of | 1342 | case stanzaOrigin stanza of |
1343 | LocalPeer {} -> return () | 1343 | LocalPeer {} -> return () |
1344 | ClientOrigin _ replyto -> deliver replyto | 1344 | ClientOrigin _ replyto -> deliver replyto |
1345 | PeerOrigin _ replyto -> deliver replyto | 1345 | PeerOrigin _ replyto -> deliver replyto |
1346 | Error {} -> do | 1346 | Error {} -> do |
1347 | case stanzaOrigin stanza of | 1347 | case stanzaOrigin stanza of |
1348 | LocalPeer {} -> return () | 1348 | LocalPeer {} -> return () |
1349 | ClientOrigin _ replyto -> deliver replyto | 1349 | ClientOrigin _ replyto -> deliver replyto |
1350 | PeerOrigin _ replyto -> deliver replyto | 1350 | PeerOrigin _ replyto -> deliver replyto |
1351 | _ -> return () | 1351 | _ -> return () |
1352 | 1352 | ||
1353 | data ConnectionType = XMPP | Tox | 1353 | data ConnectionType = XMPP | Tox |
1354 | deriving (Eq,Ord,Enum,Show,Read) | 1354 | deriving (Eq,Ord,Enum,Show,Read) |