summaryrefslogtreecommitdiff
path: root/xmppServer.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-02-17 14:14:39 -0500
committerjoe <joe@jerkface.net>2014-02-17 14:14:39 -0500
commit20fc48ccedd78a724662c9494e93b9c108885f09 (patch)
tree95d197f1ca00d3296e40e85dfce3bda15af47ba0 /xmppServer.hs
parente2ea71232ef6bda4dacd74de0f2b42000b9c7569 (diff)
communicate roster files
Diffstat (limited to 'xmppServer.hs')
-rw-r--r--xmppServer.hs26
1 files changed, 19 insertions, 7 deletions
diff --git a/xmppServer.hs b/xmppServer.hs
index 80adaf21..e787f973 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -24,6 +24,7 @@ import Data.Map (Map)
24import Control.Exception ({-evaluate,-}handle,SomeException(..),bracketOnError,ErrorCall(..)) 24import Control.Exception ({-evaluate,-}handle,SomeException(..),bracketOnError,ErrorCall(..))
25import System.Posix.User (getUserEntryForID,userName) 25import System.Posix.User (getUserEntryForID,userName)
26import qualified Data.ByteString.Lazy.Char8 as L 26import qualified Data.ByteString.Lazy.Char8 as L
27import qualified ConfigFiles
27 28
28import UTmp (ProcessID,users) 29import UTmp (ProcessID,users)
29import LocalPeerCred 30import LocalPeerCred
@@ -53,6 +54,7 @@ getConsolePids state = do -- return [("tty7", 23)] -- todo
53 return $ map (\(_,tty,pid)->(lazyByteStringToText tty,pid)) us 54 return $ map (\(_,tty,pid)->(lazyByteStringToText tty,pid)) us
54 55
55lazyByteStringToText = (foldr1 (<>) . map Text.decodeUtf8 . L.toChunks) 56lazyByteStringToText = (foldr1 (<>) . map Text.decodeUtf8 . L.toChunks)
57textToLazyByteString s = L.fromChunks [Text.encodeUtf8 s]
56 58
57identifyTTY' ttypids uid inode = ttypid 59identifyTTY' ttypids uid inode = ttypid
58 where ttypids' = map (\(tty,pid)->(L.fromChunks [Text.encodeUtf8 tty], pid)) ttypids 60 where ttypids' = map (\(tty,pid)->(L.fromChunks [Text.encodeUtf8 tty], pid)) ttypids
@@ -97,12 +99,22 @@ forClient state k fallback f = do
97 mclient <- atomically $ do 99 mclient <- atomically $ do
98 cs <- readTVar (clients state) 100 cs <- readTVar (clients state)
99 return $ Map.lookup k cs 101 return $ Map.lookup k cs
100 maybe (fallback k) (flip f k) mclient 102 maybe fallback f mclient
101 103
102tellClientHisName state k = forClient state k fallback go 104tellClientHisName state k = forClient state k fallback go
103 where 105 where
104 fallback k = localJID "nobody" "fallback" 106 fallback = localJID "nobody" "fallback"
105 go client k = localJID (clientUser client) (clientResource client) 107 go client = localJID (clientUser client) (clientResource client)
108
109rosterGetStuff what state k = forClient state k (return [])
110 $ \client -> do
111 fmap (map lazyByteStringToText)
112 $ what (textToLazyByteString $ clientUser client)
113
114rosterGetBuddies = rosterGetStuff ConfigFiles.getBuddies
115rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited
116rosterGetOthers = rosterGetStuff ConfigFiles.getOthers
117rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers
106 118
107 119
108main = runResourceT $ do 120main = runResourceT $ do
@@ -124,10 +136,10 @@ main = runResourceT $ do
124 , xmppTellClientNameOfPeer = peerKeyToResolvedName 136 , xmppTellClientNameOfPeer = peerKeyToResolvedName
125 , xmppNewConnection = \k outchan -> return () 137 , xmppNewConnection = \k outchan -> return ()
126 , xmppEOF = \k -> return () 138 , xmppEOF = \k -> return ()
127 , xmppRosterBuddies = \k -> return [] 139 , xmppRosterBuddies = rosterGetBuddies state
128 , xmppRosterSubscribers = \k -> return [] 140 , xmppRosterSubscribers = rosterGetSubscribers state
129 , xmppRosterSolicited = \k -> return [] 141 , xmppRosterSolicited = rosterGetSolicited state
130 , xmppRosterOthers = \k -> return [] 142 , xmppRosterOthers = rosterGetOthers state
131 , xmppSubscribeToRoster = \k -> return () 143 , xmppSubscribeToRoster = \k -> return ()
132 -- , xmppLookupClientJID = \k -> return $ "nobody@" <> hostname <> "/tty666" 144 -- , xmppLookupClientJID = \k -> return $ "nobody@" <> hostname <> "/tty666"
133 , xmppDeliverMessage = \fail msg -> do 145 , xmppDeliverMessage = \fail msg -> do