FreeRDP
Loading...
Searching...
No Matches
xdg-aad-helper.Session Class Reference

Public Member Functions

 __init__ (self, JsonRpcChannel channel)
 
None navigate (self, msg_id, dict params)
 
None cancel (self)
 
None shutdown (self, msg_id)
 
None prepare_exit (self)
 

Data Fields

 channel
 
 lock
 
 shutting_down
 
 current
 

Detailed Description

Definition at line 195 of file xdg-aad-helper.py.

Constructor & Destructor Documentation

◆ __init__()

xdg-aad-helper.Session.__init__ (   self,
JsonRpcChannel  channel 
)

Definition at line 196 of file xdg-aad-helper.py.

196 def __init__(self, channel: JsonRpcChannel):
197 self.channel = channel
198 self.lock = threading.Lock()
199 self.current: NavigateState | None = None
200 self.shutting_down = False
201

Member Function Documentation

◆ cancel()

None xdg-aad-helper.Session.cancel (   self)

Definition at line 300 of file xdg-aad-helper.py.

300 def cancel(self) -> None:
301 with self.lock:
302 if self.current:
303 self.current.cancelled.set()
304

◆ navigate()

None xdg-aad-helper.Session.navigate (   self,
  msg_id,
dict  params 
)

Definition at line 202 of file xdg-aad-helper.py.

202 def navigate(self, msg_id, params: dict) -> None:
203 with self.lock:
204 if self.shutting_down:
205 self.channel.send(make_error(msg_id, 1, "shutting_down"))
206 return
207 if self.current is not None:
208 self.channel.send(make_error(msg_id, 1, "navigate_already_in_progress"))
209 return
210 state = NavigateState(uuid.uuid4().hex[:12])
211 self.current = state
212
213 title = params.get("title", "")
214 url = params.get("url", "")
215 redirect_uri = params.get("redirect_uri", "")
216 timeout_ms = params.get("timeout_ms") or DEFAULT_TIMEOUT_MS
217
218 if not redirect_uri.lower().startswith(BROKER_SCHEME):
219 with self.lock:
220 self.current = None
221 self.channel.send(make_error(msg_id, 1, "unsupported_redirect_scheme"))
222 return
223
224 effective_url, state.had_original_state = rewrite_state(url, state.freerdp_id)
225
226 runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "/tmp")
227 sock_path = os.path.join(runtime_dir, f"freerdp_aad_{state.freerdp_id}.sock")
228 try:
229 os.unlink(sock_path)
230 except FileNotFoundError:
231 pass
232
233 server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
234 redirect_url = None
235 error = None
236 try:
237 server.bind(sock_path)
238 os.chmod(sock_path, 0o600)
239 server.listen(1)
240 server.settimeout(0.5)
241
242 print(f"[xdgopen-aad-helper] navigate: opening browser for {effective_url!r} "
243 f"(title={title!r}), waiting on {sock_path}", file=sys.stderr)
244 subprocess.Popen(["xdg-open", effective_url])
245
246 deadline = time.monotonic() + timeout_ms / 1000.0
247 while redirect_url is None and error is None:
248 if state.cancelled.is_set():
249 error = "user_cancelled"
250 break
251 with self.lock:
252 if self.shutting_down:
253 error = "shutting_down"
254 break
255 if time.monotonic() >= deadline:
256 error = "timeout"
257 break
258 try:
259 conn, _ = server.accept()
260 except socket.timeout:
261 continue
262 with conn:
263 conn.settimeout(2.0)
264 data = b""
265 try:
266 while True:
267 chunk = conn.recv(4096)
268 if not chunk:
269 break
270 data += chunk
271 except socket.timeout:
272 pass
273 redirect_url = data.decode(errors="replace").strip()
274 finally:
275 server.close()
276 try:
277 os.unlink(sock_path)
278 except FileNotFoundError:
279 pass
280 with self.lock:
281 self.current = None
282
283 if error:
284 self.channel.send(make_error(msg_id, 1, error))
285 return
286
287 redirect_url = restore_state(redirect_url, state.freerdp_id, state.had_original_state)
288
289 parsed = urllib.parse.urlparse(redirect_url)
290 qs = urllib.parse.parse_qs(parsed.query)
291 if "error" in qs:
292 message = qs["error"][0]
293 if "error_subcode" in qs:
294 message += ": " + qs["error_subcode"][0]
295 self.channel.send(make_error(msg_id, 1, message))
296 return
297
298 self.channel.send(make_result(msg_id, {"status": "ok", "redirect_url": redirect_url}))
299

◆ prepare_exit()

None xdg-aad-helper.Session.prepare_exit (   self)

Definition at line 308 of file xdg-aad-helper.py.

308 def prepare_exit(self) -> None:
309 with self.lock:
310 self.shutting_down = True
311 if self.current:
312 self.current.cancelled.set()
313
314

◆ shutdown()

None xdg-aad-helper.Session.shutdown (   self,
  msg_id 
)

Definition at line 305 of file xdg-aad-helper.py.

305 def shutdown(self, msg_id) -> None:
306 self.channel.send(make_result(msg_id, None))
307

Field Documentation

◆ channel

xdg-aad-helper.Session.channel

Definition at line 197 of file xdg-aad-helper.py.

◆ current

xdg-aad-helper.Session.current

Definition at line 211 of file xdg-aad-helper.py.

◆ lock

xdg-aad-helper.Session.lock

Definition at line 198 of file xdg-aad-helper.py.

◆ shutting_down

xdg-aad-helper.Session.shutting_down

Definition at line 200 of file xdg-aad-helper.py.


The documentation for this class was generated from the following file: