diff options
Diffstat (limited to 'Presence/XMPPTypes.hs')
-rw-r--r-- | Presence/XMPPTypes.hs | 31 |
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 | ) |
16 | import Network.BSD (getHostName) | 16 | import Network.BSD |
17 | ( getHostName | ||
18 | , hostName | ||
19 | , hostAliases | ||
20 | ) | ||
17 | import System.IO (Handle) | 21 | import System.IO (Handle) |
18 | import Control.Concurrent.STM (TChan) | 22 | import Control.Concurrent.STM (TChan) |
23 | import qualified Data.ByteString.Char8 as S (ByteString,pack,putStr,putStrLn,append) | ||
19 | import Data.ByteString.Lazy.Char8 as L | 24 | import 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 | ) |
27 | import Text.Show.ByteString as L | 33 | import Text.Show.ByteString as L |
28 | import Data.Binary.Builder as B | 34 | import Data.Binary.Builder as B |
@@ -30,6 +36,8 @@ import Data.Binary.Put | |||
30 | import Control.DeepSeq | 36 | import Control.DeepSeq |
31 | import ByteStringOperators | 37 | import ByteStringOperators |
32 | import SocketLike | 38 | import SocketLike |
39 | import GetHostByAddr | ||
40 | import Data.Maybe (listToMaybe,catMaybes) | ||
33 | 41 | ||
34 | class JabberClientSession session where | 42 | class 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 | ||
50 | class JabberPeerSession session where | 59 | class 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 |
63 | data JID = JID { name :: Maybe ByteString | 73 | data JID = JID { name :: Maybe ByteString |
@@ -77,6 +87,9 @@ data Presence = Presence JID JabberShow | |||
77 | data RosterEvent = RequestedSubscription | 87 | data 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 | ||
82 | data Peer = LocalHost | RemotePeer SockAddr | 95 | data 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 | ||
214 | getNamesForPeer :: Peer -> IO [S.ByteString] | ||
215 | getNamesForPeer LocalHost = fmap ((:[]) . S.pack) getHostName | ||
216 | getNamesForPeer 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 | |||
222 | asHostNameJID :: JID -> IO (Maybe ByteString) | ||
223 | asHostNameJID 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) | ||