Add senders attr to Jingle FT

This is a MUST see https://xmpp.org/extensions/xep-0234.html

Fixes #8662
This commit is contained in:
Philipp Hörist 2017-08-07 17:41:32 +02:00
parent 1eeb53bee6
commit 413c7f52d7
5 changed files with 27 additions and 16 deletions

View File

@ -163,9 +163,14 @@ class ConnectionJingle(object):
transport = JingleTransportSocks5()
elif contact.supports(nbxmpp.NS_JINGLE_IBB):
transport = JingleTransportIBB()
senders = 'initiator'
if request:
senders = 'responder'
c = JingleFileTransfer(jingle, transport=transport,
file_props=file_props,
use_security=use_security)
use_security=use_security,
senders=senders)
file_props.algo = self.__hash_support(contact)
jingle.add_content('file' + helpers.get_random_string_16(), c)
jingle.start_session()

View File

@ -42,7 +42,7 @@ class JingleContent:
An abstraction of content in Jingle sessions
"""
def __init__(self, session, transport):
def __init__(self, session, transport, senders):
self.session = session
self.transport = transport
# will be filled by JingleSession.add_content()
@ -56,7 +56,10 @@ class JingleContent:
self.media = None
self.senders = 'both' #FIXME
self.senders = senders
if self.senders is None:
self.senders = 'both'
self.allow_sending = True # Used for stream direction, attribute 'senders'
# These were found by the Politie
@ -138,7 +141,9 @@ class JingleContent:
if payload is None:
payload = []
return nbxmpp.Node('content',
attrs={'name': self.name, 'creator': self.creator},
attrs={'name': self.name,
'creator': self.creator,
'senders': self.senders},
payload=payload)
def send_candidate(self, candidate):

View File

@ -58,8 +58,8 @@ class State(IntEnum):
class JingleFileTransfer(JingleContent):
def __init__(self, session, transport=None, file_props=None,
use_security=False):
JingleContent.__init__(self, session, transport)
use_security=False, senders=None):
JingleContent.__init__(self, session, transport, senders)
log.info("transport value: %s", transport)
# events we might be interested in
self.callbacks['session-initiate'] += [self.__on_session_initiate]

View File

@ -526,7 +526,7 @@ class JingleSession:
contents, contents_rejected, reason_txt = self.__parse_contents(jingle)
# If we are not receivin a file
# Check if there's already a session with this user:
if contents[0][0] != 'file':
if contents[0].media != 'file':
for session in self.connection.iter_jingle_sessions(self.peerjid):
if session is not self:
reason = nbxmpp.Node('reason')
@ -538,8 +538,7 @@ class JingleSession:
else:
# Stop if we don't have the requested file or the peer is not
# allowed to request the file
request = \
jingle.getTag('content').getTag('description').getTag('request')
request = contents[0].senders == 'responder'
if request:
self.request = True
hash_tag = request.getTag('file').getTag('hash')
@ -568,7 +567,7 @@ class JingleSession:
gajim.nec.push_incoming_event(JingleRequestReceivedEvent(None,
conn=self.connection,
jingle_session=self,
contents=contents))
contents=contents[0]))
def __broadcast(self, stanza, jingle, error, action):
"""
@ -624,6 +623,7 @@ class JingleSession:
contents_rejected = []
reasons = set()
for element in jingle.iterTags('content'):
senders = element.getAttr('senders')
transport = get_jingle_transport(element.getTag('transport'))
if transport:
transport.ourjid = self.ourjid
@ -631,10 +631,11 @@ class JingleSession:
if content_type:
try:
if transport:
content = content_type(self, transport)
content = content_type(
self, transport=transport, senders=senders)
self.add_content(element['name'],
content, 'peer')
contents.append((content.media,))
contents.append(content)
else:
reasons.add('unsupported-transports')
contents_rejected.append((element['name'], 'peer'))
@ -711,12 +712,12 @@ class JingleSession:
@staticmethod
def __append_content(jingle, content):
"""
Append <content/> element to <jingle/> element, with (full=True) or
without (full=False) <content/> children
Append <content/> element to <jingle/> element
"""
jingle.addChild('content',
attrs={'name': content.name,
'creator': content.creator})
'creator': content.creator,
'senders': content.senders})
def __append_contents(self, jingle):
"""

View File

@ -1225,7 +1225,7 @@ class Interface:
# TODO: conditional blocking if peer is not in roster
account = obj.conn.name
content_types = set(c[0] for c in obj.contents)
content_types = obj.contents.media
# check type of jingle session
if 'audio' in content_types or 'video' in content_types: