diff options
author | Joe Crayne <joe@jerkface.net> | 2019-12-23 02:09:05 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 23:28:00 -0500 |
commit | af2d131e01fed76205c2c0c32a2f29bab8cceb84 (patch) | |
tree | 1332a0cdac6d3870db39662ac27260fc04c2dc21 /dht/Presence/XMPPServer.hs | |
parent | 50e1debec25341ca66456ab14574361a2a994787 (diff) |
Create new tox key automatically + disable non-tox operation.
Diffstat (limited to 'dht/Presence/XMPPServer.hs')
-rw-r--r-- | dht/Presence/XMPPServer.hs | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/dht/Presence/XMPPServer.hs b/dht/Presence/XMPPServer.hs index 2f2a1b4b..65d882bd 100644 --- a/dht/Presence/XMPPServer.hs +++ b/dht/Presence/XMPPServer.hs | |||
@@ -124,9 +124,11 @@ data XMPPServerParameters = | |||
124 | -- the name the client referred to this server by. The second Maybe is the | 124 | -- the name the client referred to this server by. The second Maybe is the |
125 | -- client's preferred resource name. | 125 | -- client's preferred resource name. |
126 | -- | 126 | -- |
127 | -- Note: The returned domain will be discarded and replaced with the result of | 127 | -- The returned domain will be discarded and replaced with the result of |
128 | -- 'xmppTellMyNameToClient'. | 128 | -- 'xmppTellMyNameToClient'. |
129 | xmppChooseResourceName :: ClientAddress -> Remote SockAddr -> Maybe Text -> Maybe Text -> IO Text | 129 | -- |
130 | -- A Left result causes an error stanza to be sent instead. | ||
131 | xmppChooseResourceName :: ClientAddress -> Remote SockAddr -> Maybe Text -> Maybe Text -> IO (Either Text Text) | ||
130 | , -- | This should indicate the server's hostname that all client's see. | 132 | , -- | This should indicate the server's hostname that all client's see. |
131 | xmppTellMyNameToClient :: ClientAddress -> IO Text | 133 | xmppTellMyNameToClient :: ClientAddress -> IO Text |
132 | , xmppTellMyNameToPeer :: Local SockAddr -> IO Text | 134 | , xmppTellMyNameToPeer :: Local SockAddr -> IO Text |
@@ -1436,6 +1438,17 @@ lookupService me mucs to = case Text.toLower to of | |||
1436 | Nothing -> UnknownService service | 1438 | Nothing -> UnknownService service |
1437 | _ -> NotMe | 1439 | _ -> NotMe |
1438 | 1440 | ||
1441 | requestVersion :: Text -> Text -> ConduitT i XML.Event IO () | ||
1442 | requestVersion rsc hostname = do | ||
1443 | yield $ EventBeginElement "{jabber:client}iq" | ||
1444 | [ attr "to" rsc | ||
1445 | , attr "from" hostname | ||
1446 | , attr "type" "get" | ||
1447 | , attr "id" "version"] | ||
1448 | yield $ EventBeginElement "{jabber:iq:version}query" [] | ||
1449 | yield $ EventEndElement "{jabber:iq:version}query" | ||
1450 | yield $ EventEndElement "{jabber:client}iq" | ||
1451 | |||
1439 | applyStanza :: Server PeerAddress ConnectionData releaseKey Event | 1452 | applyStanza :: Server PeerAddress ConnectionData releaseKey Event |
1440 | -> TVar (Map.Map ClientAddress (Map.Map (Text,Text) (TChan Stanza,JoinedRoom ClientAddress))) | 1453 | -> TVar (Map.Map ClientAddress (Map.Map (Text,Text) (TChan Stanza,JoinedRoom ClientAddress))) |
1441 | -> TMVar () | 1454 | -> TMVar () |
@@ -1450,38 +1463,22 @@ applyStanza sv joined_rooms quitVar xmpp stanza = do | |||
1450 | case stanzaType stanza of | 1463 | case stanzaType stanza of |
1451 | RequestResource clientsNameForMe wanted -> do | 1464 | RequestResource clientsNameForMe wanted -> do |
1452 | sockaddr <- socketFromKey sv k | 1465 | sockaddr <- socketFromKey sv k |
1453 | rsc0 <- xmppChooseResourceName xmpp k sockaddr clientsNameForMe wanted | 1466 | xmppChooseResourceName xmpp k sockaddr clientsNameForMe wanted >>= \case |
1454 | hostname <- xmppTellMyNameToClient xmpp k | 1467 | Right rsc0 -> do |
1455 | let rsc = unsplitJID (n,hostname,r) where (n,_,r) = splitJID rsc0 | 1468 | hostname <- xmppTellMyNameToClient xmpp k |
1456 | let reply = iq_bind_reply (stanzaId stanza) rsc | 1469 | let rsc = unsplitJID (n,hostname,r) where (n,_,r) = splitJID rsc0 |
1457 | -- sendReply quitVar SetResource reply replyto | 1470 | let reply = iq_bind_reply (stanzaId stanza) rsc |
1458 | let requestVersion :: ConduitT i XML.Event IO () | 1471 | sendReply quitVar SetResource reply replyto |
1459 | requestVersion = do | 1472 | conduitToStanza (UnrecognizedQuery "{jabber:iq:version}query") |
1460 | yield $ EventBeginElement "{jabber:client}iq" | 1473 | Nothing -- id |
1461 | [ attr "to" rsc | 1474 | (Just hostname) -- from |
1462 | , attr "from" hostname | 1475 | (Just rsc) -- to |
1463 | , attr "type" "get" | 1476 | (requestVersion rsc hostname) |
1464 | , attr "id" "version"] | 1477 | >>= ioWriteChan replyto |
1465 | yield $ EventBeginElement "{jabber:iq:version}query" [] | 1478 | Left err -> do |
1466 | yield $ EventEndElement "{jabber:iq:version}query" | 1479 | hostname <- xmppTellMyNameToClient xmpp k |
1467 | yield $ EventEndElement "{jabber:client}iq" | 1480 | reply <- makeErrorStanza' stanza NotAllowed [] |
1468 | {- | 1481 | sendReply quitVar (Error NotAuthorized (head reply)) reply replyto |
1469 | -- XXX Debug chat: | ||
1470 | yield $ EventBeginElement "{jabber:client}message" | ||
1471 | [ attr "from" $ eventContent (Just [ContentText rsc]) | ||
1472 | , attr "type" "normal" ] -- "blackbird" ] | ||
1473 | yield $ EventBeginElement "{jabber:client}body" [] | ||
1474 | yield $ EventContent $ ContentText ("hello?") | ||
1475 | yield $ EventEndElement "{jabber:client}body" | ||
1476 | yield $ EventEndElement "{jabber:client}message" | ||
1477 | -} | ||
1478 | sendReply quitVar SetResource reply replyto | ||
1479 | conduitToStanza (UnrecognizedQuery "{jabber:iq:version}query") | ||
1480 | Nothing -- id | ||
1481 | (Just hostname) -- from | ||
1482 | (Just rsc) -- to | ||
1483 | requestVersion | ||
1484 | >>= ioWriteChan replyto | ||
1485 | SessionRequest -> do | 1482 | SessionRequest -> do |
1486 | me <- xmppTellMyNameToClient xmpp k | 1483 | me <- xmppTellMyNameToClient xmpp k |
1487 | let reply = iq_session_reply (stanzaId stanza) me | 1484 | let reply = iq_session_reply (stanzaId stanza) me |