diff options
Diffstat (limited to 'Presence/main.hs')
-rw-r--r-- | Presence/main.hs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/Presence/main.hs b/Presence/main.hs index 92ef7034..83f11df3 100644 --- a/Presence/main.hs +++ b/Presence/main.hs | |||
@@ -125,6 +125,8 @@ data ClientSession = ClientSession { | |||
125 | -- (*not* the login name of the user) | 125 | -- (*not* the login name of the user) |
126 | unix_uid :: (IORef (Maybe (UserID,L.ByteString))), | 126 | unix_uid :: (IORef (Maybe (UserID,L.ByteString))), |
127 | 127 | ||
128 | unix_pid :: Maybe CPid, | ||
129 | |||
128 | -- unix_resource: This is the detected TTY of the connecting client. | 130 | -- unix_resource: This is the detected TTY of the connecting client. |
129 | unix_resource :: (IORef (Maybe L.ByteString)), | 131 | unix_resource :: (IORef (Maybe L.ByteString)), |
130 | 132 | ||
@@ -134,6 +136,8 @@ data ClientSession = ClientSession { | |||
134 | -- localSubscriber & rosterChannel of the global state record. | 136 | -- localSubscriber & rosterChannel of the global state record. |
135 | chans :: TVar [RefCountedChan], | 137 | chans :: TVar [RefCountedChan], |
136 | 138 | ||
139 | clientChannel :: TChan ClientCommands, | ||
140 | |||
137 | -- presence_state: a reference to the global state. | 141 | -- presence_state: a reference to the global state. |
138 | presence_state :: PresenceState | 142 | presence_state :: PresenceState |
139 | } | 143 | } |
@@ -147,20 +151,25 @@ instance JabberClientSession ClientSession where | |||
147 | muid <- getLocalPeerCred' addr | 151 | muid <- getLocalPeerCred' addr |
148 | L.putStrLn $ "CLIENT SESSION: open " <++> bshow muid | 152 | L.putStrLn $ "CLIENT SESSION: open " <++> bshow muid |
149 | uid_ref <- newIORef muid | 153 | uid_ref <- newIORef muid |
150 | res_ref <- newIORef Nothing | 154 | (mtty,pid) <- getTTYandPID muid |
155 | res_ref <- newIORef mtty | ||
151 | chans <- atomically $ newTVar [] | 156 | chans <- atomically $ newTVar [] |
152 | return $ ClientSession (hostname state) uid_ref res_ref chans state | 157 | clientChan <- atomically $ newTChan |
153 | 158 | return $ ClientSession (hostname state) uid_ref pid res_ref chans clientChan state | |
154 | setResource s resource = do | 159 | where |
160 | getTTYandPID muid = do | ||
161 | us <- fmap Set.toList . readTVarIO $ activeUsers state | ||
162 | let tailOf3 (_,a,b) = (a,b) | ||
163 | (t,pid) <- case muid of | ||
164 | Just (uid,inode) -> identifyTTY (map tailOf3 us) uid inode | ||
165 | Nothing -> return (Nothing,Nothing) | ||
166 | let rsc = t `mplus` fmap ( ("pid."<++>) . bshow ) pid | ||
167 | return (rsc,pid) | ||
168 | |||
169 | setResource s wanted_resource = do | ||
155 | -- TODO: handle resource = empty string | 170 | -- TODO: handle resource = empty string |
156 | us <- fmap Set.toList . readTVarIO $ activeUsers (presence_state s) | 171 | rsc <- readIORef (unix_resource s) |
157 | muid <- readIORef (unix_uid s) | 172 | let rsc' = maybe wanted_resource id rsc |
158 | let tailOf3 (_,a,b) = (a,b) | ||
159 | (t,pid) <- case muid of | ||
160 | Just (uid,inode) -> identifyTTY (map tailOf3 us) uid inode | ||
161 | Nothing -> return (Nothing,Nothing) | ||
162 | let rsc = t `mplus` fmap ( ("pid."<++>) . bshow ) pid | ||
163 | rsc' = maybe resource id rsc | ||
164 | writeIORef (unix_resource s) (Just rsc') | 173 | writeIORef (unix_resource s) (Just rsc') |
165 | L.putStrLn $ "CLIENT SESSION: resource " <++> rsc' | 174 | L.putStrLn $ "CLIENT SESSION: resource " <++> rsc' |
166 | 175 | ||
@@ -197,6 +206,7 @@ instance JabberClientSession ClientSession where | |||
197 | writeTVar (chans session) (RefCountedChan rchan:cs) | 206 | writeTVar (chans session) (RefCountedChan rchan:cs) |
198 | subscribeToChan rchan | 207 | subscribeToChan rchan |
199 | 208 | ||
209 | clientChannel session = Main.clientChannel session | ||
200 | 210 | ||
201 | forCachedPresence s action = do | 211 | forCachedPresence s action = do |
202 | jid <- getJID s | 212 | jid <- getJID s |