Merge branch 'jingleft' into 'master'

Update JingleFT support, and fix sending files

See merge request !89
This commit is contained in:
Yann Leboulanger 2017-06-16 21:19:38 +02:00
commit 4650615010
14 changed files with 37 additions and 38 deletions

View File

@ -51,7 +51,7 @@ from common.logger import KindConstant
from nbxmpp.protocol import NS_XHTML, NS_XHTML_IM, NS_FILE, NS_MUC from nbxmpp.protocol import NS_XHTML, NS_XHTML_IM, NS_FILE, NS_MUC
from nbxmpp.protocol import NS_ESESSION from nbxmpp.protocol import NS_ESESSION
from nbxmpp.protocol import NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO from nbxmpp.protocol import NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO
from nbxmpp.protocol import NS_JINGLE_ICE_UDP, NS_JINGLE_FILE_TRANSFER from nbxmpp.protocol import NS_JINGLE_ICE_UDP, NS_JINGLE_FILE_TRANSFER_5
from nbxmpp.protocol import NS_CHATSTATES from nbxmpp.protocol import NS_CHATSTATES
from common.connection_handlers_events import MessageOutgoingEvent from common.connection_handlers_events import MessageOutgoingEvent
from common.exceptions import GajimGeneralException from common.exceptions import GajimGeneralException
@ -387,7 +387,7 @@ class ChatControl(ChatControlBase):
# Send file # Send file
if ((self.contact.supports(NS_FILE) or \ if ((self.contact.supports(NS_FILE) or \
self.contact.supports(NS_JINGLE_FILE_TRANSFER)) and \ self.contact.supports(NS_JINGLE_FILE_TRANSFER_5)) and \
(self.type_id == 'chat' or self.gc_contact.resource)) and \ (self.type_id == 'chat' or self.gc_contact.resource)) and \
self.contact.show != 'offline': self.contact.show != 'offline':
self._send_file_button.set_sensitive(True) self._send_file_button.set_sensitive(True)
@ -395,7 +395,7 @@ class ChatControl(ChatControlBase):
else: else:
self._send_file_button.set_sensitive(False) self._send_file_button.set_sensitive(False)
if not (self.contact.supports(NS_FILE) or self.contact.supports( if not (self.contact.supports(NS_FILE) or self.contact.supports(
NS_JINGLE_FILE_TRANSFER)): NS_JINGLE_FILE_TRANSFER_5)):
self._send_file_button.set_tooltip_text(_( self._send_file_button.set_tooltip_text(_(
"This contact does not support file transfer.")) "This contact does not support file transfer."))
else: else:

View File

@ -39,11 +39,11 @@ log = logging.getLogger('gajim.c.caps_cache')
from nbxmpp import (NS_XHTML_IM, NS_ESESSION, NS_CHATSTATES, from nbxmpp import (NS_XHTML_IM, NS_ESESSION, NS_CHATSTATES,
NS_JINGLE_ICE_UDP, NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO, NS_JINGLE_ICE_UDP, NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO,
NS_JINGLE_FILE_TRANSFER) NS_JINGLE_FILE_TRANSFER_5)
# Features where we cannot safely assume that the other side supports them # Features where we cannot safely assume that the other side supports them
FEATURE_BLACKLIST = [NS_CHATSTATES, NS_XHTML_IM, NS_ESESSION, FEATURE_BLACKLIST = [NS_CHATSTATES, NS_XHTML_IM, NS_ESESSION,
NS_JINGLE_ICE_UDP, NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO, NS_JINGLE_ICE_UDP, NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO,
NS_JINGLE_FILE_TRANSFER] NS_JINGLE_FILE_TRANSFER_5]
# Query entry status codes # Query entry status codes
NEW = 0 NEW = 0

View File

@ -187,7 +187,7 @@ class ConnectionDisco:
query.setAttr('node', 'http://gajim.org#' + gajim.version.split('-', 1)[ query.setAttr('node', 'http://gajim.org#' + gajim.version.split('-', 1)[
0]) 0])
for f in (nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE, for f in (nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE,
nbxmpp.NS_COMMANDS, nbxmpp.NS_JINGLE_FILE_TRANSFER, nbxmpp.NS_COMMANDS, nbxmpp.NS_JINGLE_FILE_TRANSFER_5,
nbxmpp.NS_JINGLE_XTLS, nbxmpp.NS_PUBKEY_PUBKEY, nbxmpp.NS_PUBKEY_REVOKE, nbxmpp.NS_JINGLE_XTLS, nbxmpp.NS_PUBKEY_PUBKEY, nbxmpp.NS_PUBKEY_REVOKE,
nbxmpp.NS_PUBKEY_ATTEST): nbxmpp.NS_PUBKEY_ATTEST):
feature = nbxmpp.Node('feature') feature = nbxmpp.Node('feature')

View File

@ -2306,12 +2306,12 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.file_props.session_type = 'jingle' self.file_props.session_type = 'jingle'
self.file_props.stream_methods = nbxmpp.NS_BYTESTREAM self.file_props.stream_methods = nbxmpp.NS_BYTESTREAM
desc = self.jingle_content.getTag('description') desc = self.jingle_content.getTag('description')
if desc.getTag('offer'): if self.jingle_content.getAttr('creator') == 'initiator':
file_tag = desc.getTag('offer').getTag('file') file_tag = desc.getTag('file')
self.file_props.sender = self.fjid self.file_props.sender = self.fjid
self.file_props.receiver = self.conn._ft_get_our_jid() self.file_props.receiver = self.conn._ft_get_our_jid()
else: else:
file_tag = desc.getTag('request').getTag('file') file_tag = desc.getTag('file')
h = file_tag.getTag('hash') h = file_tag.getTag('hash')
h = h.getData() if h else None h = h.getData() if h else None
n = file_tag.getTag('name') n = file_tag.getTag('name')

View File

@ -253,7 +253,7 @@ gajim_common_features = [nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE,
nbxmpp.NS_REGISTER, nbxmpp.NS_VERSION, nbxmpp.NS_DATA, nbxmpp.NS_ENCRYPTED, nbxmpp.NS_REGISTER, nbxmpp.NS_VERSION, nbxmpp.NS_DATA, nbxmpp.NS_ENCRYPTED,
'msglog', 'sslc2s', 'stringprep', nbxmpp.NS_PING, nbxmpp.NS_TIME_REVISED, 'msglog', 'sslc2s', 'stringprep', nbxmpp.NS_PING, nbxmpp.NS_TIME_REVISED,
nbxmpp.NS_SSN, nbxmpp.NS_MOOD, nbxmpp.NS_ACTIVITY, nbxmpp.NS_NICK, nbxmpp.NS_SSN, nbxmpp.NS_MOOD, nbxmpp.NS_ACTIVITY, nbxmpp.NS_NICK,
nbxmpp.NS_ROSTERX, nbxmpp.NS_SECLABEL, nbxmpp.NS_HASHES, nbxmpp.NS_ROSTERX, nbxmpp.NS_SECLABEL, nbxmpp.NS_HASHES_2,
nbxmpp.NS_HASHES_MD5, nbxmpp.NS_HASHES_SHA1, nbxmpp.NS_HASHES_SHA256, nbxmpp.NS_HASHES_MD5, nbxmpp.NS_HASHES_SHA1, nbxmpp.NS_HASHES_SHA256,
nbxmpp.NS_HASHES_SHA512, nbxmpp.NS_CONFERENCE] nbxmpp.NS_HASHES_SHA512, nbxmpp.NS_CONFERENCE]

View File

@ -1289,7 +1289,7 @@ def update_optional_features(account = None):
gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_RTP_VIDEO) gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_RTP_VIDEO)
gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_ICE_UDP) gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_ICE_UDP)
gajim.gajim_optional_features[a].append( gajim.gajim_optional_features[a].append(
nbxmpp.NS_JINGLE_FILE_TRANSFER) nbxmpp.NS_JINGLE_FILE_TRANSFER_5)
gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_XTLS) gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_XTLS)
gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_BYTESTREAM) gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_BYTESTREAM)
gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_IBB) gajim.gajim_optional_features[a].append(nbxmpp.NS_JINGLE_IBB)

View File

@ -172,15 +172,19 @@ class ConnectionJingle(object):
return c.transport.sid return c.transport.sid
def __hash_support(self, contact): def __hash_support(self, contact):
if contact.supports(nbxmpp.NS_HASHES): if contact.supports(nbxmpp.NS_HASHES_2):
if contact.supports(nbxmpp.NS_HASHES_SHA512): if contact.supports(nbxmpp.NS_HASHES_BLAKE2B_512):
return 'blake2b-512'
elif contact.supports(nbxmpp.NS_HASHES_BLAKE2B_256):
return 'blake2b-256'
elif contact.supports(nbxmpp.NS_HASHES_SHA3_512):
return 'sha3-512'
elif contact.supports(nbxmpp.NS_HASHES_SHA3_256):
return 'sha3-256'
elif contact.supports(nbxmpp.NS_HASHES_SHA512):
return 'sha-512' return 'sha-512'
elif contact.supports(nbxmpp.NS_HASHES_SHA256): elif contact.supports(nbxmpp.NS_HASHES_SHA256):
return 'sha-256' return 'sha-256'
elif contact.supports(nbxmpp.NS_HASHES_SHA1):
return 'sha-1'
elif contact.supports(nbxmpp.NS_HASHES_MD5):
return 'md5'
return None return None
def iter_jingle_sessions(self, jid, sid=None, media=None): def iter_jingle_sessions(self, jid, sid=None, media=None):

View File

@ -175,12 +175,8 @@ class JingleContent:
def _fill_content(self, content): def _fill_content(self, content):
description_node = nbxmpp.simplexml.Node( description_node = nbxmpp.simplexml.Node(
tag=nbxmpp.NS_JINGLE_FILE_TRANSFER + ' description') tag=nbxmpp.NS_JINGLE_FILE_TRANSFER_5 + ' description')
if self.session.werequest: file_tag = description_node.setTag('file')
simode = nbxmpp.simplexml.Node(tag='request')
else:
simode = nbxmpp.simplexml.Node(tag='offer')
file_tag = simode.setTag('file')
if self.file_props.name: if self.file_props.name:
node = nbxmpp.simplexml.Node(tag='name') node = nbxmpp.simplexml.Node(tag='name')
node.addData(self.file_props.name) node.addData(self.file_props.name)
@ -196,7 +192,7 @@ class JingleContent:
if self.file_props.type_ == 'r': if self.file_props.type_ == 'r':
if self.file_props.hash_: if self.file_props.hash_:
file_tag.addChild('hash', attrs={'algo': self.file_props.algo}, file_tag.addChild('hash', attrs={'algo': self.file_props.algo},
namespace=nbxmpp.NS_HASHES, namespace=nbxmpp.NS_HASHES_2,
payload=self.file_props.hash_) payload=self.file_props.hash_)
else: else:
# if the file is less than 10 mb, then it is small # if the file is less than 10 mb, then it is small
@ -217,7 +213,6 @@ class JingleContent:
desc = file_tag.setTag('desc') desc = file_tag.setTag('desc')
if self.file_props.desc: if self.file_props.desc:
desc.setData(self.file_props.desc) desc.setData(self.file_props.desc)
description_node.addChild(node=simode)
if self.use_security: if self.use_security:
security = nbxmpp.simplexml.Node( security = nbxmpp.simplexml.Node(
tag=nbxmpp.NS_JINGLE_XTLS + ' security') tag=nbxmpp.NS_JINGLE_XTLS + ' security')

View File

@ -155,7 +155,7 @@ class JingleFileTransfer(JingleContent):
checksum = nbxmpp.Node(tag='checksum', checksum = nbxmpp.Node(tag='checksum',
payload=[nbxmpp.Node(tag='file', payload=[nbxmpp.Node(tag='file',
payload=[self._compute_hash()])]) payload=[self._compute_hash()])])
checksum.setNamespace(nbxmpp.NS_JINGLE_FILE_TRANSFER) checksum.setNamespace(nbxmpp.NS_JINGLE_FILE_TRANSFER_5)
self.session.__session_info(checksum) self.session.__session_info(checksum)
pjid = gajim.get_jid_without_resource(self.session.peerjid) pjid = gajim.get_jid_without_resource(self.session.peerjid)
file_info = {'name' : self.file_props.name, file_info = {'name' : self.file_props.name,
@ -176,7 +176,7 @@ class JingleFileTransfer(JingleContent):
except IOError: except IOError:
# can't open file # can't open file
return return
h = nbxmpp.Hashes() h = nbxmpp.Hashes2()
hash_ = h.calculateHash(self.file_props.algo, file_) hash_ = h.calculateHash(self.file_props.algo, file_)
file_.close() file_.close()
# DEBUG # DEBUG
@ -410,4 +410,4 @@ class JingleFileTransfer(JingleContent):
def get_content(desc): def get_content(desc):
return JingleFileTransfer return JingleFileTransfer
contents[nbxmpp.NS_JINGLE_FILE_TRANSFER] = get_content contents[nbxmpp.NS_JINGLE_FILE_TRANSFER_5] = get_content

View File

@ -444,9 +444,9 @@ class JingleSession:
for child in payload: for child in payload:
if child.getName() == 'checksum': if child.getName() == 'checksum':
hash_ = child.getTag('file').getTag(name='hash', hash_ = child.getTag('file').getTag(name='hash',
namespace=nbxmpp.NS_HASHES) namespace=nbxmpp.NS_HASHES_2)
algo = hash_.getAttr('algo') algo = hash_.getAttr('algo')
if algo in nbxmpp.Hashes.supported: if algo in nbxmpp.Hashes2.supported:
file_props = FilesProp.getFileProp(self.connection.name, file_props = FilesProp.getFileProp(self.connection.name,
self.sid) self.sid)
file_props.algo = algo file_props.algo = algo

View File

@ -926,10 +926,10 @@ class ConnectionIBBytestream(ConnectionBytestream):
log.debug('ReceiveHandler called sid->%s seq->%s' % (sid, seq)) log.debug('ReceiveHandler called sid->%s seq->%s' % (sid, seq))
try: try:
seq = int(seq) seq = int(seq)
data = base64.b64decode(data.encode('utf-8')).decode('utf-8') data = base64.b64decode(data.encode('utf-8'))
except Exception: except Exception:
seq = '' seq = ''
data = '' data = b''
err = None err = None
file_props = FilesProp.getFilePropByTransportSid(self.name, sid) file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
if file_props is None: if file_props is None:

View File

@ -40,7 +40,7 @@ from common import helpers
from common.file_props import FilesProp from common.file_props import FilesProp
from common.protocol.bytestream import (is_transfer_active, is_transfer_paused, from common.protocol.bytestream import (is_transfer_active, is_transfer_paused,
is_transfer_stopped) is_transfer_stopped)
from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER_5
import logging import logging
log = logging.getLogger('gajim.filetransfer_window') log = logging.getLogger('gajim.filetransfer_window')
@ -357,7 +357,7 @@ class FileTransfersWindow:
file_path, file_name, file_desc) file_path, file_name, file_desc)
if file_props is None: if file_props is None:
return False return False
if contact.supports(NS_JINGLE_FILE_TRANSFER): if contact.supports(NS_JINGLE_FILE_TRANSFER_5):
log.info("contact %s supports jingle file transfer"%(contact.get_full_jid())) log.info("contact %s supports jingle file transfer"%(contact.get_full_jid()))
gajim.connections[account].start_file_transfer(contact.get_full_jid(), gajim.connections[account].start_file_transfer(contact.get_full_jid(),
file_props) file_props)

View File

@ -73,7 +73,7 @@ from session import ChatControlSession
from common import sleepy from common import sleepy
from nbxmpp import idlequeue from nbxmpp import idlequeue
from nbxmpp import Hashes from nbxmpp import Hashes2
from common.zeroconf import connection_zeroconf from common.zeroconf import connection_zeroconf
from common import resolver from common import resolver
from common import caps_cache from common import caps_cache
@ -988,7 +988,7 @@ class Interface:
session = gajim.connections[account].get_jingle_session(jid=None, session = gajim.connections[account].get_jingle_session(jid=None,
sid=file_props.sid) sid=file_props.sid)
ft_win = self.instances['file_transfers'] ft_win = self.instances['file_transfers']
h = Hashes() h = Hashes2()
try: try:
file_ = open(file_props.file_name, 'rb') file_ = open(file_props.file_name, 'rb')
except: except:

View File

@ -27,7 +27,7 @@ from common import gajim
from common import helpers from common import helpers
from common import i18n from common import i18n
from nbxmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC, NS_ESESSION from nbxmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC, NS_ESESSION
from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER, NS_CONFERENCE from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER_5, NS_CONFERENCE
from gtkgui_helpers import get_action from gtkgui_helpers import get_action
def build_resources_submenu(contacts, account, action, room_jid=None, def build_resources_submenu(contacts, account, action, room_jid=None,
@ -260,7 +260,7 @@ control=None, gc_contact=None, is_anonymous=True):
else: else:
start_chat_menuitem.connect('activate', start_chat_menuitem.connect('activate',
gajim.interface.on_open_chat_window, contact, account) gajim.interface.on_open_chat_window, contact, account)
if contact.supports(NS_FILE) or contact.supports(NS_JINGLE_FILE_TRANSFER): if contact.supports(NS_FILE) or contact.supports(NS_JINGLE_FILE_TRANSFER_5):
send_file_menuitem.set_sensitive(True) send_file_menuitem.set_sensitive(True)
send_file_menuitem.connect('activate', send_file_menuitem.connect('activate',
roster.on_send_file_menuitem_activate, contact, account) roster.on_send_file_menuitem_activate, contact, account)