summaryrefslogtreecommitdiff
path: root/Presence/XMPPServer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPPServer.hs')
-rw-r--r--Presence/XMPPServer.hs63
1 files changed, 0 insertions, 63 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index f607989d..ff50ab1c 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -67,9 +67,6 @@ import qualified Data.Set as Set
67import GetHostByAddr 67import GetHostByAddr
68import XMPPTypes 68import XMPPTypes
69 69
70is_remote (RemotePeer _) = True
71is_remote _ = False
72
73getNamesForPeer :: Peer -> IO [ByteString] 70getNamesForPeer :: Peer -> IO [ByteString]
74getNamesForPeer LocalHost = fmap ((:[]) . pack) getHostName 71getNamesForPeer LocalHost = fmap ((:[]) . pack) getHostName
75getNamesForPeer peer@(RemotePeer addr) = do 72getNamesForPeer peer@(RemotePeer addr) = do
@@ -85,10 +82,6 @@ getNamesForPeer peer@(RemotePeer addr) = do
85 return . map pack $ names 82 return . map pack $ names
86 83
87 84
88peerAddr :: Peer -> SockAddr
89peerAddr (RemotePeer addr) = addr
90-- peerAddr LocalHost = throw exception
91
92 85
93xmlifyPresenceForPeer sock (Presence jid stat) = do 86xmlifyPresenceForPeer sock (Presence jid stat) = do
94 -- TODO: accept socket argument and determine local ip address 87 -- TODO: accept socket argument and determine local ip address
@@ -587,62 +580,6 @@ connect_to_server chan peer = (>> return ()) . runMaybeT $ do
587 L.putStrLn $ "OUT peer: </stream>" 580 L.putStrLn $ "OUT peer: </stream>"
588 581
589 582
590splitJID :: ByteString -> (Maybe ByteString,ByteString,Maybe ByteString)
591splitJID bjid =
592 let xs = L.splitWith (=='@') bjid
593 ys = L.splitWith (=='/') (last xs)
594 server = head ys
595 name
596 = case xs of
597 (n:s:_) -> Just n
598 (s:_) -> Nothing
599 rsrc = case ys of
600 (s:_:_) -> Just $ last ys
601 _ -> Nothing
602 in (name,server,rsrc)
603
604strip_brackets s =
605 case L.uncons s of
606 Just ('[',t) -> L.takeWhile (/=']') t
607 _ -> s
608
609parseAddressJID :: ByteString -> IO JID
610parseAddressJID jid = do
611 let (name,peer_string,rsc) = splitJID jid
612 hints = Just $ defaultHints { addrFlags = [ {- AI_NUMERICHOST, -} AI_CANONNAME ] }
613 peer_string' = unpack . strip_brackets $ peer_string
614 peer <- do
615 -- putStrLn $ "getAddrInfo 2 " ++ Prelude.show ( Just (unpack peer_string))
616 info <- getAddrInfo hints (Just peer_string') Nothing -- (Just "xmpp-server")
617 let info0 = head info
618 return . RemotePeer . addrAddress $ info0
619 return $ JID name peer rsc
620
621parseHostNameJID :: ByteString -> IO JID
622parseHostNameJID jid = do
623 let (name,peer_string,rsc) = splitJID jid
624 hints = Just $ defaultHints { addrFlags = [ AI_CANONNAME ] }
625 peer <- do
626 if peer_string=="localhost"
627 then return LocalHost
628 else do
629 -- putStrLn $ "getAddrInfo 3 " ++ Prelude.show ( Just (unpack peer_string))
630 info <- getAddrInfo hints (Just (unpack peer_string)) Nothing -- (Just "xmpp-server")
631 let info0 = head info
632 cname = addrCanonName info0
633 if cname==Just "localhost"
634 then return LocalHost
635 else do
636 self <- getHostName
637 return $ if Just self==cname
638 then LocalHost
639 else RemotePeer (addrAddress info0)
640 return $ JID name peer rsc
641
642socketFamily (SockAddrInet _ _) = AF_INET
643socketFamily (SockAddrInet6 _ _ _ _) = AF_INET6
644socketFamily (SockAddrUnix _) = AF_UNIX
645
646connect' :: SockAddr -> Int -> IO (Maybe Socket) 583connect' :: SockAddr -> Int -> IO (Maybe Socket)
647connect' addr port = do 584connect' addr port = do
648 proto <- getProtocolNumber "tcp" 585 proto <- getProtocolNumber "tcp"