diff options
author | joe <joe@jerkface.net> | 2014-02-17 14:14:39 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-02-17 14:14:39 -0500 |
commit | 20fc48ccedd78a724662c9494e93b9c108885f09 (patch) | |
tree | 95d197f1ca00d3296e40e85dfce3bda15af47ba0 /xmppServer.hs | |
parent | e2ea71232ef6bda4dacd74de0f2b42000b9c7569 (diff) |
communicate roster files
Diffstat (limited to 'xmppServer.hs')
-rw-r--r-- | xmppServer.hs | 26 |
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) | |||
24 | import Control.Exception ({-evaluate,-}handle,SomeException(..),bracketOnError,ErrorCall(..)) | 24 | import Control.Exception ({-evaluate,-}handle,SomeException(..),bracketOnError,ErrorCall(..)) |
25 | import System.Posix.User (getUserEntryForID,userName) | 25 | import System.Posix.User (getUserEntryForID,userName) |
26 | import qualified Data.ByteString.Lazy.Char8 as L | 26 | import qualified Data.ByteString.Lazy.Char8 as L |
27 | import qualified ConfigFiles | ||
27 | 28 | ||
28 | import UTmp (ProcessID,users) | 29 | import UTmp (ProcessID,users) |
29 | import LocalPeerCred | 30 | import 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 | ||
55 | lazyByteStringToText = (foldr1 (<>) . map Text.decodeUtf8 . L.toChunks) | 56 | lazyByteStringToText = (foldr1 (<>) . map Text.decodeUtf8 . L.toChunks) |
57 | textToLazyByteString s = L.fromChunks [Text.encodeUtf8 s] | ||
56 | 58 | ||
57 | identifyTTY' ttypids uid inode = ttypid | 59 | identifyTTY' 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 | ||
102 | tellClientHisName state k = forClient state k fallback go | 104 | tellClientHisName 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 | |||
109 | rosterGetStuff what state k = forClient state k (return []) | ||
110 | $ \client -> do | ||
111 | fmap (map lazyByteStringToText) | ||
112 | $ what (textToLazyByteString $ clientUser client) | ||
113 | |||
114 | rosterGetBuddies = rosterGetStuff ConfigFiles.getBuddies | ||
115 | rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited | ||
116 | rosterGetOthers = rosterGetStuff ConfigFiles.getOthers | ||
117 | rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers | ||
106 | 118 | ||
107 | 119 | ||
108 | main = runResourceT $ do | 120 | main = 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 |