summaryrefslogtreecommitdiff
path: root/Presence/XMPPServer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPPServer.hs')
-rw-r--r--Presence/XMPPServer.hs143
1 files changed, 2 insertions, 141 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 11a27660..a102ed5a 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -102,8 +102,9 @@ import qualified System.Random
102import Data.Void (Void) 102import Data.Void (Void)
103import DPut 103import DPut
104import DebugTag 104import DebugTag
105import Stanza.Type 105import Stanza.Build
106import Stanza.Parse 106import Stanza.Parse
107import Stanza.Types
107 108
108-- peerport :: PortNumber 109-- peerport :: PortNumber
109-- peerport = 5269 110-- peerport = 5269
@@ -450,36 +451,6 @@ sendReply donevar stype reply replychan = do
450 liftIO . atomically $ writeTVar (stanzaClosers replyStanza) Nothing 451 liftIO . atomically $ writeTVar (stanzaClosers replyStanza) Nothing
451 -- liftIO $ wlog "finished reply stanza" 452 -- liftIO $ wlog "finished reply stanza"
452 453
453stanzaFromList :: StanzaType -> [Event] -> IO Stanza
454stanzaFromList stype reply = do
455 let stanzaTag = listToMaybe reply
456 mid = stanzaTag >>= lookupAttrib "id" . tagAttrs
457 mfrom = stanzaTag >>= lookupAttrib "from" . tagAttrs
458 mto = stanzaTag >>= lookupAttrib "to" . tagAttrs
459 {-
460 isInternal (InternalEnableHack {}) = True
461 isInternal (InternalCacheId {}) = True
462 isInternal _ = False
463 -}
464 (donevar,replyChan,replyClsrs) <- atomically $ do
465 donevar <- newEmptyTMVar -- TMVar ()
466 replyChan <- newLockedChan
467 replyClsrs <- newTVar (Just [])
468 return (donevar,replyChan, replyClsrs)
469 forkIO $ do
470 forM_ reply $ atomically . writeLChan replyChan
471 atomically $ do putTMVar donevar ()
472 writeTVar replyClsrs Nothing
473 return Stanza { stanzaType = stype
474 , stanzaId = mid
475 , stanzaTo = mto -- as-is from reply list
476 , stanzaFrom = mfrom -- as-is from reply list
477 , stanzaChan = replyChan
478 , stanzaClosers = replyClsrs
479 , stanzaInterrupt = donevar
480 , stanzaOrigin = LocalPeer
481 }
482
483 454
484 455
485{- 456{-
@@ -492,95 +463,6 @@ C->Unrecognized </iq>
492-} 463-}
493 464
494 465
495mkname :: Text -> Text -> XML.Name
496mkname namespace name = (Name name (Just namespace) Nothing)
497
498makeMessage :: Text -> Text -> Text -> Text -> IO Stanza
499makeMessage namespace from to bod =
500 stanzaFromList typ
501 $ [ EventBeginElement (mkname namespace "message")
502 [ attr "from" from
503 , attr "to" to
504 ]
505 , EventBeginElement (mkname namespace "body") []
506 , EventContent (ContentText bod)
507 , EventEndElement (mkname namespace "body")
508 , EventEndElement (mkname namespace "message") ]
509 where
510 typ = Message { msgThread = Nothing
511 , msgLangMap = [("", lsm)]
512 }
513 lsm = LangSpecificMessage
514 { msgBody = Just bod
515 , msgSubject = Nothing }
516
517makeInformSubscription :: Text -> Text -> Text -> Bool -> IO Stanza
518makeInformSubscription namespace from to approved =
519 stanzaFromList (PresenceInformSubscription approved)
520 $ [ EventBeginElement (mkname namespace "presence")
521 [ attr "from" from
522 , attr "to" to
523 , attr "type" $ if approved then "subscribed"
524 else "unsubscribed" ]
525 , EventEndElement (mkname namespace "presence")]
526
527makePresenceStanza :: Text -> Maybe Text -> JabberShow -> IO Stanza
528makePresenceStanza namespace mjid pstat = do
529 stanzaFromList PresenceStatus { presenceShow = pstat
530 , presencePriority = Nothing
531 , presenceStatus = []
532 , presenceWhiteList = []
533 }
534 $ [ EventBeginElement (mkname namespace "presence")
535 (setFrom $ typ pstat) ]
536 ++ (shw pstat >>= jabberShow) ++
537 [ EventEndElement (mkname namespace "presence")]
538 where
539 setFrom = maybe id
540 (\jid -> (attr "from" jid :) )
541 mjid
542 typ Offline = [attr "type" "unavailable"]
543 typ _ = []
544 shw ExtendedAway = ["xa"]
545 shw Chatty = ["chat"]
546 shw Away = ["away"]
547 shw DoNotDisturb = ["dnd"]
548 shw _ = []
549 jabberShow stat =
550 [ EventBeginElement "{jabber:client}show" []
551 , EventContent (ContentText stat)
552 , EventEndElement "{jabber:client}show" ]
553
554makeRosterUpdate :: Text -> Text -> [(Name, Text)] -> IO Stanza
555makeRosterUpdate tojid contact as = do
556 let attrs = map (uncurry attr) as
557 stanzaFromList Unrecognized
558 [ EventBeginElement "{jabber:client}iq"
559 [ attr "to" tojid
560 , attr "id" "someid"
561 , attr "type" "set"
562 ]
563 , EventBeginElement "{jabber:iq:roster}query" []
564 , EventBeginElement "{jabber:iq:roster}item" (attr "jid" contact : attrs)
565 , EventEndElement "{jabber:iq:roster}item"
566 , EventEndElement "{jabber:iq:roster}query"
567 , EventEndElement "{jabber:client}iq"
568 ]
569
570makePong :: Text -> Maybe Text -> Text -> Text -> [XML.Event]
571makePong namespace mid to from =
572 -- Note: similar to session reply
573 [ EventBeginElement (mkname namespace "iq")
574 $(case mid of
575 Just c -> (("id",[ContentText c]):)
576 _ -> id)
577 [ attr "type" "result"
578 , attr "to" to
579 , attr "from" from
580 ]
581 , EventEndElement (mkname namespace "iq")
582 ]
583
584xmppInbound :: ConnectionData 466xmppInbound :: ConnectionData
585 -> XMPPServerParameters -- ^ XXX: unused 467 -> XMPPServerParameters -- ^ XXX: unused
586 -> (Text, IO Text, IO Text, TChan Stanza -> StanzaOrigin) 468 -> (Text, IO Text, IO Text, TChan Stanza -> StanzaOrigin)
@@ -1549,24 +1431,3 @@ forkXmpp XMPPServer { _xmpp_sv = sv
1549 return mt 1431 return mt
1550 1432
1551 1433
1552#if MIN_VERSION_stm(2,4,0)
1553#else
1554-- |Clone a 'TChan': similar to dupTChan, but the cloned channel starts with the
1555-- same content available as the original channel.
1556--
1557-- Terrible inefficient implementation provided to build against older libraries.
1558cloneTChan :: TChan a -> STM (TChan a)
1559cloneTChan chan = do
1560 contents <- chanContents' chan
1561 chan2 <- dupTChan chan
1562 mapM_ (writeTChan chan) contents
1563 return chan2
1564 where
1565 chanContents' chan = do
1566 b <- isEmptyTChan chan
1567 if b then return [] else do
1568 x <- readTChan chan
1569 xs <- chanContents' chan
1570 return (x:xs)
1571#endif
1572