summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/XMPP.hs64
-rw-r--r--Presence/XMPPTypes.hs2
2 files changed, 66 insertions, 0 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 2545e063..179ffd6b 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -265,6 +265,12 @@ isIQOf (EventBeginElement name attrs) testType
265 = True 265 = True
266isIQOf _ _ = False 266isIQOf _ _ = False
267 267
268isServerIQOf (EventBeginElement name attrs) testType
269 | name=="{jabber:server}iq"
270 && matchAttrib "type" testType attrs
271 = True
272isServerIQOf _ _ = False
273
268iq_service_unavailable host iq_id mjid req = 274iq_service_unavailable host iq_id mjid req =
269 [ EventBeginElement "{jabber:client}iq" 275 [ EventBeginElement "{jabber:client}iq"
270 [("type",[ContentText "error"]) 276 [("type",[ContentText "error"])
@@ -879,6 +885,43 @@ peerRejectsSubscription session stanza = do
879 withJust (name tojid) $ \user -> do 885 withJust (name tojid) $ \user -> do
880 liftIO $ processRejection session user fromjid 886 liftIO $ processRejection session user fromjid
881 887
888handlePeerIQGet :: (JabberPeerSession session, MonadIO m) =>
889 session -> XML.Event -> NestingXML o m ()
890handlePeerIQGet session tag = do
891 withJust (lookupAttrib "id" (tagAttrs tag)) $ \stanza_id -> do
892 whenJust nextElement $ \child -> do
893 host <- liftIO $ do
894 names <- getNamesForPeer (peerAddress session)
895 return (S.decodeUtf8 . head $ names)
896 let unhandledGet req = do
897 liftIO $ debugStr ("iq-get: "++show (stanza_id,child))
898 -- TODO: send service-unavailable to peer (See example 9 of XEP-0199)
899 -- Unsupported
900 -- Client equiv: liftIO . atomically . writeTChan cmdChan . Send $ iq_service_unavailable host stanza_id Nothing req
901 case tagName child of
902 -- "{http://jabber.org/protocol/disco#items}query" -> liftIO $ debugStr "iq-get-query-items"
903 "{urn:xmpp:ping}ping" -> liftIO $ do
904 {-
905 let mjid = lookupAttrib "from" (tagAttrs tag)
906 let pong = [ EventBeginElement "{jabber:server}iq"
907 $ (case mjid of
908 Just jid -> (attr "to" jid :)
909 _ -> id )
910 [ attr "type" "result"
911 , attr "id" stanza_id
912 , attr "from" host
913 ]
914 , EventEndElement "{jabber:server}iq"
915 ]
916 -}
917 sendPeerMessage session (Pong (JID Nothing LocalHost Nothing)
918 (JID Nothing (peerAddress session) Nothing)
919 (Just (ContentText stanza_id)))
920 -- Client equiv: atomically . writeTChan cmdChan . Send $ pong
921 return ()
922
923 req -> unhandledGet req
924
882fromPeer :: (MonadThrow m,MonadIO m, JabberPeerSession session) => 925fromPeer :: (MonadThrow m,MonadIO m, JabberPeerSession session) =>
883 session -> Sink XML.Event m () 926 session -> Sink XML.Event m ()
884fromPeer session = doNestingXML $ do 927fromPeer session = doNestingXML $ do
@@ -899,6 +942,7 @@ fromPeer session = doNestingXML $ do
899 xs <- gatherElement stanza Seq.empty 942 xs <- gatherElement stanza Seq.empty
900 prettyPrint "P: " (toList xs) 943 prettyPrint "P: " (toList xs)
901 case () of 944 case () of
945 _ | stanza `isIQOf` iqTypeGet -> handlePeerIQGet session stanza
902 _ | stanza `isPresenceOf` presenceTypeOnline 946 _ | stanza `isPresenceOf` presenceTypeOnline
903 -> handlePeerPresence session stanza True 947 -> handlePeerPresence session stanza True
904 _ | stanza `isPresenceOf` presenceTypeOffline 948 _ | stanza `isPresenceOf` presenceTypeOffline
@@ -950,6 +994,8 @@ instance CommandCache CachedMessages where
950 updateCache (Rejection from to) cache = 994 updateCache (Rejection from to) cache =
951 cache { approvals= mmInsert (False,from) to $ approvals cache } 995 cache { approvals= mmInsert (False,from) to $ approvals cache }
952 updateCache (OutBoundMessage msg) cache = cache -- TODO 996 updateCache (OutBoundMessage msg) cache = cache -- TODO
997 updateCache (Pong _ _ _) cache = cache -- pings are not cached
998 updateCache (Unsupported _ _ _ _) cache = cache -- error messages are not cached
953 999
954instance ThreadChannelCommand OutBoundMessage where 1000instance ThreadChannelCommand OutBoundMessage where
955 isQuitCommand Disconnect = True 1001 isQuitCommand Disconnect = True
@@ -1031,6 +1077,22 @@ toPeer sock cache chan fail = do
1031 sendOrFail (xmlifyMessageForPeer sock msg) 1077 sendOrFail (xmlifyMessageForPeer sock msg)
1032 (OutBoundMessage msg) 1078 (OutBoundMessage msg)
1033 1079
1080 sendPong from to mid =
1081 sendOrFail (xmlifyPong sock from to mid)
1082 (Pong from to mid)
1083 where
1084 xmlifyPong sock from to mid =
1085 return $ [ EventBeginElement "{jabber:server}iq"
1086 $ (case mid of
1087 Just c -> (("id",[c]):)
1088 _ -> id )
1089 [ attr "type" "result"
1090 , attr "to" (toStrict $ L.decodeUtf8 $ L.show to)
1091 , attr "from" (toStrict $ L.decodeUtf8 $ L.show from)
1092 ]
1093 , EventEndElement "{jabber:server}iq"
1094 ]
1095
1034 1096
1035 send greetPeer 1097 send greetPeer
1036 forM_ (Map.assocs . approvals $ cache) $ \(to,froms) -> do 1098 forM_ (Map.assocs . approvals $ cache) $ \(to,froms) -> do
@@ -1067,6 +1129,8 @@ toPeer sock cache chan fail = do
1067 liftIO . debugL $ "sending rejection "<++>bshow (from,to) 1129 liftIO . debugL $ "sending rejection "<++>bshow (from,to)
1068 sendApproval False from to 1130 sendApproval False from to
1069 OutBoundMessage msg -> sendMessage msg 1131 OutBoundMessage msg -> sendMessage msg
1132 Pong from to mid -> sendPong from to mid
1133 Unsupported _ _ _ _ -> todo
1070 Disconnect -> return () 1134 Disconnect -> return ()
1071 when (not . isQuitCommand $ event) loop 1135 when (not . isQuitCommand $ event) loop
1072 return () 1136 return ()
diff --git a/Presence/XMPPTypes.hs b/Presence/XMPPTypes.hs
index 06cfb563..8162ec5d 100644
--- a/Presence/XMPPTypes.hs
+++ b/Presence/XMPPTypes.hs
@@ -281,6 +281,8 @@ data OutBoundMessage = OutBoundPresence Presence
281 | Approval JID JID 281 | Approval JID JID
282 | Rejection JID JID 282 | Rejection JID JID
283 | OutBoundMessage Message 283 | OutBoundMessage Message
284 | Pong JID JID (Maybe Content)
285 | Unsupported JID JID (Maybe Content) XML.Name
284 | Disconnect 286 | Disconnect
285 deriving Prelude.Show 287 deriving Prelude.Show
286 288