コード例 #1
0
ファイル: bytestream.py プロジェクト: xiayuming/gajim
 def SendHandler(self):
     """
     Send next portion of data if it is time to do it. Used internally.
     """
     log.debug('SendHandler called')
     for file_props in FilesProp.getAllFileProp():
         if not file_props.direction:
             # it's socks5 bytestream
             continue
         sid = file_props.sid
         if file_props.direction[:2] == '|>':
             # We waitthat other part accept stream
             continue
         if file_props.direction[0] == '>':
             if file_props.paused:
                 continue
             if not file_props.connected:
                 #TODO: Reply with out of order error
                 continue
             chunk = file_props.fp.read(file_props.block_size)
             if chunk:
                 datanode = nbxmpp.Node(
                     nbxmpp.NS_IBB + ' data', {
                         'sid': file_props.transport_sid,
                         'seq': file_props.seq
                     },
                     base64.b64encode(
                         chunk.encode('utf-8')).decode('utf-8'))
                 file_props.seq += 1
                 file_props.started = True
                 if file_props.seq == 65536:
                     file_props.seq = 0
                 self.last_sent_ibb_id = self.connection.send(
                     nbxmpp.Protocol(name='iq',
                                     to=file_props.direction[1:],
                                     typ='set',
                                     payload=[datanode]))
                 current_time = time.time()
                 file_props.elapsed_time += current_time - file_props.last_time
                 file_props.last_time = current_time
                 file_props.received_len += len(chunk)
                 gajim.socks5queue.progress_transfer_cb(
                     self.name, file_props)
             else:
                 # notify the other side about stream closing
                 # notify the local user about sucessfull send
                 # delete the local stream
                 self.connection.send(
                     nbxmpp.Protocol(
                         'iq',
                         file_props.direction[1:],
                         'set',
                         payload=[
                             nbxmpp.Node(nbxmpp.NS_IBB + ' close',
                                         {'sid': file_props.transport_sid})
                         ]))
                 file_props.completed = True
コード例 #2
0
ファイル: bytestream.py プロジェクト: irl/gajim
 def SendHandler(self):
     """
     Send next portion of data if it is time to do it. Used internally.
     """
     log.debug('SendHandler called')
     for file_props in FilesProp.getAllFileProp():
         if not file_props.direction:
             # it's socks5 bytestream
             continue
         sid = file_props.sid
         if file_props.direction[:2] == '|>':
             # We waitthat other part accept stream
             continue
         if file_props.direction[0] == '>':
             if file_props.paused:
                 continue
             if not file_props.connected:
                 #TODO: Reply with out of order error
                 continue
             chunk = file_props.fp.read(file_props.block_size)
             if chunk:
                 datanode = nbxmpp.Node(nbxmpp.NS_IBB + ' data', {
                     'sid': file_props.transport_sid,
                     'seq': file_props.seq}, base64.b64encode(chunk.encode(
                     'utf-8')).decode('utf-8'))
                 file_props.seq += 1
                 file_props.started = True
                 if file_props.seq == 65536:
                     file_props.seq = 0
                 self.last_sent_ibb_id = self.connection.send(
                     nbxmpp.Protocol(name='iq', to=file_props.direction[1:],
                     typ='set', payload=[datanode]))
                 current_time = time.time()
                 file_props.elapsed_time += current_time - file_props.last_time
                 file_props.last_time = current_time
                 file_props.received_len += len(chunk)
                 gajim.socks5queue.progress_transfer_cb(self.name,
                     file_props)
             else:
                 # notify the other side about stream closing
                 # notify the local user about sucessfull send
                 # delete the local stream
                 self.connection.send(nbxmpp.Protocol('iq',
                     file_props.direction[1:], 'set',
                     payload=[nbxmpp.Node(nbxmpp.NS_IBB + ' close',
                     {'sid': file_props.transport_sid})]))
                 file_props.completed = True
コード例 #3
0
ファイル: bytestream.py プロジェクト: xiayuming/gajim
 def IBBAllIqHandler(self, conn, stanza):
     """
     Handle remote side reply about if it agree or not to receive our
     datastream.
     Used internally. Raises xmpppy event specfiying if the data transfer
     is agreed upon.
     """
     syn_id = stanza.getID()
     log.debug('IBBAllIqHandler called syn_id->%s' % syn_id)
     for file_props in FilesProp.getAllFileProp():
         if not file_props.direction or not file_props.connected:
             # It's socks5 bytestream
             # Or we closed the IBB stream
             continue
         if file_props.syn_id == syn_id:
             if stanza.getType() == 'error':
                 if file_props.direction[0] == '<':
                     conn.Event('IBB', 'ERROR ON RECEIVE', file_props)
                 else:
                     conn.Event('IBB', 'ERROR ON SEND', file_props)
             elif stanza.getType() == 'result':
                 if file_props.direction[0] == '|':
                     file_props.direction = file_props.direction[1:]
                     self.SendHandler()
                 else:
                     conn.send(
                         nbxmpp.Error(stanza,
                                      nbxmpp.ERR_UNEXPECTED_REQUEST))
             break
     else:
         if stanza.getTag('data'):
             sid = stanza.getTagAttr('data', 'sid')
             file_props = FilesProp.getFilePropByTransportSid(
                 self.name, sid)
             if file_props.connected and self.IBBMessageHandler(
                     conn, stanza):
                 reply = stanza.buildReply('result')
                 reply.delChild('data')
                 conn.send(reply)
                 raise nbxmpp.NodeProcessed
         elif syn_id == self.last_sent_ibb_id:
             self.SendHandler()
コード例 #4
0
ファイル: bytestream.py プロジェクト: jabber-at/gajim
 def stop_all_active_file_transfers(self, contact):
     """
     Stop all active transfer to or from the given contact
     """
     for file_props in FilesProp.getAllFileProp():
         if is_transfer_stopped(file_props):
             continue
         receiver_jid = unicode(file_props.receiver)
         if contact.get_full_jid() == receiver_jid:
             file_props.error = -5
             self.remove_transfer(file_props)
             from common.connection_handlers_events import \
                 FileRequestErrorEvent
             gajim.nec.push_incoming_event(FileRequestErrorEvent(None,
                 conn=self, jid=contact.jid, file_props=file_props,
                 error_msg=''))
         sender_jid = unicode(file_props.sender)
         if contact.get_full_jid() == sender_jid:
             file_props.error = -3
             self.remove_transfer(file_props)
コード例 #5
0
ファイル: filetransfers_window.py プロジェクト: irl/gajim
 def find_transfer_by_jid(self, account, jid):
     """
     Find all transfers with peer 'jid' that belong to 'account'
     """
     active_transfers = [[], []] # ['senders', 'receivers']
     allfp = FilesProp.getAllFileProp()
     for file_props in allfp:
         if file_props.type_ == 's' and file_props.tt_account == account:
             # 'account' is the sender
             receiver_jid = file_props.receiver.split('/')[0]
             if jid == receiver_jid and not is_transfer_stopped(file_props):
                 active_transfers[0].append(file_props)
         elif file_props.type_ == 'r' and file_props.tt_account == account:
             # 'account' is the recipient
             sender_jid = file_props.sender.split('/')[0]
             if jid == sender_jid and not is_transfer_stopped(file_props):
                 active_transfers[1].append(file_props)
         else:
             raise Exception('file_props has no type')
     return active_transfers
コード例 #6
0
 def find_transfer_by_jid(self, account, jid):
     """
     Find all transfers with peer 'jid' that belong to 'account'
     """
     active_transfers = [[], []] # ['senders', 'receivers']
     allfp = FilesProp.getAllFileProp()
     for file_props in allfp:
         if file_props.type_ == 's' and file_props.tt_account == account:
             # 'account' is the sender
             receiver_jid = file_props.receiver.split('/')[0]
             if jid == receiver_jid and not is_transfer_stopped(file_props):
                 active_transfers[0].append(file_props)
         elif file_props.type_ == 'r' and file_props.tt_account == account:
             # 'account' is the recipient
             sender_jid = file_props.sender.split('/')[0]
             if jid == sender_jid and not is_transfer_stopped(file_props):
                 active_transfers[1].append(file_props)
         else:
             raise Exception('file_props has no type')
     return active_transfers
コード例 #7
0
ファイル: bytestream.py プロジェクト: lheckemann/gajim
 def stop_all_active_file_transfers(self, contact):
     """
     Stop all active transfer to or from the given contact
     """
     for file_props in FilesProp.getAllFileProp():
         if is_transfer_stopped(file_props):
             continue
         receiver_jid = file_props.receiver
         if contact.get_full_jid() == receiver_jid:
             file_props.error = -5
             self.remove_transfer(file_props)
             from common.connection_handlers_events import \
                 FileRequestErrorEvent
             gajim.nec.push_incoming_event(FileRequestErrorEvent(None,
                 conn=self, jid=contact.jid, file_props=file_props,
                 error_msg=''))
         sender_jid = file_props.sender
         if contact.get_full_jid() == sender_jid:
             file_props.error = -3
             self.remove_transfer(file_props)
コード例 #8
0
ファイル: bytestream.py プロジェクト: jabber-at/gajim
 def IBBAllIqHandler(self, conn, stanza):
     """
     Handle remote side reply about if it agree or not to receive our
     datastream.
     Used internally. Raises xmpppy event specfiying if the data transfer
     is agreed upon.
     """
     syn_id = stanza.getID()
     log.debug('IBBAllIqHandler called syn_id->%s' % syn_id)
     for file_props in FilesProp.getAllFileProp():
         if not file_props.direction or not file_props.connected:
             # It's socks5 bytestream
             # Or we closed the IBB stream
             continue
         if file_props.syn_id == syn_id:
             if stanza.getType() == 'error':
                 if file_props.direction[0] == '<':
                     conn.Event('IBB', 'ERROR ON RECEIVE', file_props)
                 else:
                     conn.Event('IBB', 'ERROR ON SEND', file_props)
             elif stanza.getType() == 'result':
                 if file_props.direction[0] == '|':
                     file_props.direction = file_props.direction[1:]
                     self.SendHandler()
                 else:
                     conn.send(nbxmpp.Error(stanza,
                         nbxmpp.ERR_UNEXPECTED_REQUEST))
             break
     else:
         if stanza.getTag('data'):
             sid = stanza.getTagAttr('data', 'sid')
             file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
             if file_props.connected and self.IBBMessageHandler(conn,
             stanza):
                 reply = stanza.buildReply('result')
                 reply.delChild('data')
                 conn.send(reply)
                 raise nbxmpp.NodeProcessed
         elif syn_id == self.last_sent_ibb_id:
             self.SendHandler()
コード例 #9
0
ファイル: bytestream.py プロジェクト: jabber-at/gajim
 def remove_all_transfers(self):
     """
     Stop and remove all active connections from the socks5 pool
     """
     for file_props in FilesProp.getAllFileProp():
         self.remove_transfer(file_props, remove_from_list=False)
コード例 #10
0
ファイル: bytestream.py プロジェクト: xiayuming/gajim
 def remove_all_transfers(self):
     """
     Stop and remove all active connections from the socks5 pool
     """
     for file_props in FilesProp.getAllFileProp():
         self.remove_transfer(file_props, remove_from_list=False)