comparison libervia/cli/cmd_file.py @ 4225:cd889f4771cb

cli (file/receive): handle `CONFIRM` dialog received in pre-flight.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:56 +0100
parents 47401850dec6
children d01b8d002619
comparison
equal deleted inserted replaced
4224:8499b3ad5edb 4225:cd889f4771cb
301 use_verbose=True, 301 use_verbose=True,
302 help=_("wait for a file to be sent by a contact"), 302 help=_("wait for a file to be sent by a contact"),
303 ) 303 )
304 self._overwrite_refused = False # True when one overwrite as already been refused 304 self._overwrite_refused = False # True when one overwrite as already been refused
305 self.action_callbacks = { 305 self.action_callbacks = {
306 C.META_TYPE_CONFIRM: self.on_confirm_action,
306 C.META_TYPE_FILE: self.on_file_action, 307 C.META_TYPE_FILE: self.on_file_action,
307 C.META_TYPE_OVERWRITE: self.on_overwrite_action, 308 C.META_TYPE_OVERWRITE: self.on_overwrite_action,
308 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.on_not_in_roster_action, 309 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.on_not_in_roster_action,
309 } 310 }
310 311
365 ui = ET.fromstring(xml_ui.encode("utf-8")) 366 ui = ET.fromstring(xml_ui.encode("utf-8"))
366 xmlui_id = ui.get("submit") 367 xmlui_id = ui.get("submit")
367 if not xmlui_id: 368 if not xmlui_id:
368 self.disp(_("Invalid XMLUI received"), error=True) 369 self.disp(_("Invalid XMLUI received"), error=True)
369 return xmlui_id 370 return xmlui_id
371
372 async def on_confirm_action(self, action_data, action_id, security_limit, profile):
373 xmlui_id = self.get_xmlui_id(action_data)
374 if xmlui_id is None:
375 return self.host.quit_from_signal(1)
376 if action_data.get("subtype") != C.META_TYPE_FILE:
377 self.disp(_("Ignoring confirm dialog unrelated to file."), 1)
378 return
379
380 # we always accept preflight confirmation dialog, as for now a second dialog is
381 # always sent
382 # FIXME: real confirmation should be done here, and second dialog should not be
383 # sent from backend
384 xmlui_data = {"answer": C.BOOL_TRUE}
385 await self.host.bridge.action_launch(
386 xmlui_id, data_format.serialise(xmlui_data), profile_key=profile
387 )
370 388
371 async def on_file_action(self, action_data, action_id, security_limit, profile): 389 async def on_file_action(self, action_data, action_id, security_limit, profile):
372 xmlui_id = self.get_xmlui_id(action_data) 390 xmlui_id = self.get_xmlui_id(action_data)
373 if xmlui_id is None: 391 if xmlui_id is None:
374 return self.host.quit_from_signal(1) 392 return self.host.quit_from_signal(1)
427 try: 445 try:
428 from_jid = jid.JID(action_data["from_jid"]) 446 from_jid = jid.JID(action_data["from_jid"])
429 except ValueError: 447 except ValueError:
430 self.disp( 448 self.disp(
431 _('invalid "from_jid" value received, ignoring: {value}').format( 449 _('invalid "from_jid" value received, ignoring: {value}').format(
432 value=from_jid 450 value=action_data["from_jid"]
433 ), 451 ),
434 error=True, 452 error=True,
435 ) 453 )
436 return 454 return
437 except KeyError: 455 except KeyError:
457 475
458 async def start(self): 476 async def start(self):
459 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] 477 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
460 self.path = os.path.abspath(self.args.path) 478 self.path = os.path.abspath(self.args.path)
461 if not os.path.isdir(self.path): 479 if not os.path.isdir(self.path):
462 self.disp(_("Given path is not a directory !", error=True)) 480 self.disp(_("Given path is not a directory !"), error=True)
463 self.host.quit(C.EXIT_BAD_ARG) 481 self.host.quit(C.EXIT_BAD_ARG)
464 if self.args.multiple: 482 if self.args.multiple:
465 self.host.quit_on_progress_end = False 483 self.host.quit_on_progress_end = False
466 self.disp(_("waiting for incoming file request"), 2) 484 self.disp(_("waiting for incoming file request"), 2)
467 await self.start_answering() 485 await self.start_answering()