def get_send_file_props(self, account, contact, file_path, file_name, file_desc=''): """ Create new file_props object and set initial file transfer properties in it """ if os.path.isfile(file_path): stat = os.stat(file_path) else: ErrorDialog(_('Invalid File'), _('File: ') + file_path) return None if stat[6] == 0: ErrorDialog(_('Invalid File'), _('It is not possible to send empty files')) return None file_props = FilesProp.getNewFileProp( account, sid=helpers.get_random_string_16()) mod_date = os.path.getmtime(file_path) file_props.file_name = file_path file_props.name = file_name file_props.date = self.__convert_date(mod_date) file_props.type_ = 's' file_props.desc = file_desc file_props.elapsed_time = 0 file_props.size = stat[6] file_props.sender = account file_props.receiver = contact file_props.tt_account = account return file_props
def on_yes(dummy, fjid, file_props, account): # Delete old file os.remove(file_props.file_name) jid, resource = app.get_room_and_nick_from_fjid(fjid) if resource: contact = app.contacts.get_contact(account, jid, resource) else: contact = app.contacts.get_contact_with_highest_priority( account, jid) fjid = contact.get_full_jid() # Request the file to the sender sid = helpers.get_random_string_16() new_file_props = FilesProp.getNewFileProp(account, sid) new_file_props.file_name = file_props.file_name new_file_props.name = file_props.name new_file_props.desc = file_props.desc new_file_props.size = file_props.size new_file_props.date = file_props.date new_file_props.hash_ = file_props.hash_ new_file_props.type_ = 'r' tsid = app.connections[account].get_module( 'Jingle').start_file_transfer(fjid, new_file_props, True) new_file_props.transport_sid = tsid self.add_transfer(account, contact, new_file_props)
def __init__(self, proxy, sender_jid, testit): """ if testit is False, don't test it, only get IP/port """ self.proxy = proxy self.state = S_INITIAL self.active_connection = None self.connections = [] self.host_tester = None self.receiver_tester = None self.jid = None self.host = None self.port = None self.sid = helpers.get_random_string_16() self.sender_jid = sender_jid self.testit = testit
def start_file_transfer(self, jid, file_props, request=False): logger.info("start file transfer with file: %s", file_props) contact = app.contacts.get_contact_with_highest_priority( self._account, app.get_jid_without_resource(jid)) if app.contacts.is_gc_contact(self._account, jid): gcc = jid.split('/') if len(gcc) == 2: contact = app.contacts.get_gc_contact(self._account, gcc[0], gcc[1]) if contact is None: return None use_security = contact.supports(nbxmpp.NS_JINGLE_XTLS) jingle = JingleSession(self._con, weinitiate=True, jid=jid, werequest=request) # this is a file transfer jingle.session_type_ft = True self._sessions[jingle.sid] = jingle file_props.sid = jingle.sid if contact.supports(nbxmpp.NS_JINGLE_BYTESTREAM): transport = JingleTransportSocks5() elif contact.supports(nbxmpp.NS_JINGLE_IBB): transport = JingleTransportIBB() senders = 'initiator' if request: senders = 'responder' transfer = JingleFileTransfer(jingle, transport=transport, file_props=file_props, use_security=use_security, senders=senders) file_props.transport_sid = transport.sid file_props.algo = self.__hash_support(contact) jingle.add_content('file' + helpers.get_random_string_16(), transfer) jingle.start_session() return transfer.transport.sid