summaryrefslogtreecommitdiff
path: root/Presence/XMPPTypes.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPPTypes.hs')
-rw-r--r--Presence/XMPPTypes.hs31
1 files changed, 30 insertions, 1 deletions
diff --git a/Presence/XMPPTypes.hs b/Presence/XMPPTypes.hs
index 275f644e..e05d0782 100644
--- a/Presence/XMPPTypes.hs
+++ b/Presence/XMPPTypes.hs
@@ -13,9 +13,14 @@ import Network.Socket
13 , AddrInfo(..) 13 , AddrInfo(..)
14 , AddrInfoFlag(..) 14 , AddrInfoFlag(..)
15 ) 15 )
16import Network.BSD (getHostName) 16import Network.BSD
17 ( getHostName
18 , hostName
19 , hostAliases
20 )
17import System.IO (Handle) 21import System.IO (Handle)
18import Control.Concurrent.STM (TChan) 22import Control.Concurrent.STM (TChan)
23import qualified Data.ByteString.Char8 as S (ByteString,pack,putStr,putStrLn,append)
19import Data.ByteString.Lazy.Char8 as L 24import Data.ByteString.Lazy.Char8 as L
20 ( ByteString 25 ( ByteString
21 , unpack 26 , unpack
@@ -23,6 +28,7 @@ import Data.ByteString.Lazy.Char8 as L
23 , splitWith 28 , splitWith
24 , uncons 29 , uncons
25 , takeWhile 30 , takeWhile
31 , fromChunks
26 ) 32 )
27import Text.Show.ByteString as L 33import Text.Show.ByteString as L
28import Data.Binary.Builder as B 34import Data.Binary.Builder as B
@@ -30,6 +36,8 @@ import Data.Binary.Put
30import Control.DeepSeq 36import Control.DeepSeq
31import ByteStringOperators 37import ByteStringOperators
32import SocketLike 38import SocketLike
39import GetHostByAddr
40import Data.Maybe (listToMaybe,catMaybes)
33 41
34class JabberClientSession session where 42class JabberClientSession session where
35 data XMPPClass session 43 data XMPPClass session
@@ -46,6 +54,7 @@ class JabberClientSession session where
46 getMyPending :: session -> IO [ByteString] 54 getMyPending :: session -> IO [ByteString]
47 getMySolicited :: session -> IO [ByteString] 55 getMySolicited :: session -> IO [ByteString]
48 addSolicited :: session -> ByteString -> JID -> IO () 56 addSolicited :: session -> ByteString -> JID -> IO ()
57 isSubscribed :: session -> ByteString -> IO Bool
49 58
50class JabberPeerSession session where 59class JabberPeerSession session where
51 data XMPPPeerClass session 60 data XMPPPeerClass session
@@ -58,6 +67,7 @@ class JabberPeerSession session where
58 sendPeerMessage :: session -> OutBoundMessage -> IO () 67 sendPeerMessage :: session -> OutBoundMessage -> IO ()
59 getBuddies :: XMPPPeerClass session -> ByteString -> IO [ByteString] 68 getBuddies :: XMPPPeerClass session -> ByteString -> IO [ByteString]
60 getSubscribers :: XMPPPeerClass session -> ByteString -> IO [ByteString] 69 getSubscribers :: XMPPPeerClass session -> ByteString -> IO [ByteString]
70 processApproval :: session -> ByteString -> JID -> IO ()
61 71
62-- | Jabber ID (JID) datatype 72-- | Jabber ID (JID) datatype
63data JID = JID { name :: Maybe ByteString 73data JID = JID { name :: Maybe ByteString
@@ -77,6 +87,9 @@ data Presence = Presence JID JabberShow
77data RosterEvent = RequestedSubscription 87data RosterEvent = RequestedSubscription
78 {- user: -} ByteString 88 {- user: -} ByteString
79 {- contact: -} ByteString 89 {- contact: -} ByteString
90 | NewBuddy
91 {- user: -} ByteString
92 {- contact: -} ByteString
80 deriving Prelude.Show 93 deriving Prelude.Show
81 94
82data Peer = LocalHost | RemotePeer SockAddr 95data Peer = LocalHost | RemotePeer SockAddr
@@ -198,3 +211,19 @@ data OutBoundMessage = OutBoundPresence Presence
198 | Approval JID JID 211 | Approval JID JID
199 deriving Prelude.Show 212 deriving Prelude.Show
200 213
214getNamesForPeer :: Peer -> IO [S.ByteString]
215getNamesForPeer LocalHost = fmap ((:[]) . S.pack) getHostName
216getNamesForPeer peer@(RemotePeer addr) = do
217 ent <- getHostByAddr addr -- AF_UNSPEC addr
218 let names = hostName ent : hostAliases ent
219 return . map S.pack $ names
220
221
222asHostNameJID :: JID -> IO (Maybe ByteString)
223asHostNameJID jid = do
224 let n = name jid
225 rsc = resource jid
226 names <- getNamesForPeer (peer jid)
227 let tostr p = n <$++> "@" <?++> L.fromChunks [p] <++?> "/" <++$> rsc
228 jidstrs = fmap tostr names
229 return (listToMaybe jidstrs)