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() transport = JingleTransportSocks5()
elif contact.supports(nbxmpp.NS_JINGLE_IBB): elif contact.supports(nbxmpp.NS_JINGLE_IBB):
transport = JingleTransportIBB() transport = JingleTransportIBB()
senders = 'initiator'
if request:
senders = 'responder'
c = JingleFileTransfer(jingle, transport=transport, c = JingleFileTransfer(jingle, transport=transport,
file_props=file_props, file_props=file_props,
use_security=use_security) use_security=use_security,
senders=senders)
file_props.algo = self.__hash_support(contact) file_props.algo = self.__hash_support(contact)
jingle.add_content('file' + helpers.get_random_string_16(), c) jingle.add_content('file' + helpers.get_random_string_16(), c)
jingle.start_session() jingle.start_session()

View file

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

View file

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

View file

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