only accept file request from peers that we already sent the file to
This commit is contained in:
parent
589c3081bb
commit
f94a8cec1b
3 changed files with 14 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
||||||
Handles Jingle contents (XEP 0166)
|
Handles Jingle contents (XEP 0166)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import gajim
|
||||||
import xmpp
|
import xmpp
|
||||||
from jingle_transport import JingleTransportIBB
|
from jingle_transport import JingleTransportIBB
|
||||||
|
|
||||||
|
@ -194,11 +195,13 @@ class JingleContent(object):
|
||||||
self.file_props.hash_:
|
self.file_props.hash_:
|
||||||
h = self._calcHash()
|
h = self._calcHash()
|
||||||
file_tag.addChild(node=h)
|
file_tag.addChild(node=h)
|
||||||
|
pjid = gajim.get_jid_without_resource(self.session.peerjid)
|
||||||
file_info = {'name' : self.file_props.name,
|
file_info = {'name' : self.file_props.name,
|
||||||
'file-name' : self.file_props.file_name,
|
'file-name' : self.file_props.file_name,
|
||||||
'hash' : self.file_props.hash_,
|
'hash' : self.file_props.hash_,
|
||||||
'size' : self.file_props.size,
|
'size' : self.file_props.size,
|
||||||
'date' : self.file_props.date
|
'date' : self.file_props.date,
|
||||||
|
'peerjid' : pjid
|
||||||
}
|
}
|
||||||
self.session.connection.set_files_info(file_info)
|
self.session.connection.set_files_info(file_info)
|
||||||
desc = file_tag.setTag('desc')
|
desc = file_tag.setTag('desc')
|
||||||
|
|
|
@ -134,11 +134,13 @@ class JingleFileTransfer(JingleContent):
|
||||||
payload=[self._calcHash()])])
|
payload=[self._calcHash()])])
|
||||||
checksum.setNamespace(xmpp.NS_JINGLE_FILE_TRANSFER)
|
checksum.setNamespace(xmpp.NS_JINGLE_FILE_TRANSFER)
|
||||||
self.session.__session_info(checksum )
|
self.session.__session_info(checksum )
|
||||||
|
pjid = gajim.get_jid_without_resource(self.session.peerjid)
|
||||||
file_info = {'name' : self.file_props.name,
|
file_info = {'name' : self.file_props.name,
|
||||||
'file-name' : self.file_props.file_name,
|
'file-name' : self.file_props.file_name,
|
||||||
'hash' : self.file_props.hash_,
|
'hash' : self.file_props.hash_,
|
||||||
'size' : self.file_props.size,
|
'size' : self.file_props.size,
|
||||||
'date' : self.file_props.date
|
'date' : self.file_props.date,
|
||||||
|
'peerjid' : pjid
|
||||||
}
|
}
|
||||||
self.session.connection.set_files_info(file_info)
|
self.session.connection.set_files_info(file_info)
|
||||||
|
|
||||||
|
|
|
@ -513,7 +513,8 @@ class JingleSession(object):
|
||||||
self._session_terminate(reason)
|
self._session_terminate(reason)
|
||||||
raise xmpp.NodeProcessed
|
raise xmpp.NodeProcessed
|
||||||
else:
|
else:
|
||||||
# Stop if we don't have the requested file
|
# Stop if we don't have the requested file or the peer is not
|
||||||
|
# allowed to request the file
|
||||||
request = \
|
request = \
|
||||||
jingle.getTag('content').getTag('description').getTag('request')
|
jingle.getTag('content').getTag('description').getTag('request')
|
||||||
if request:
|
if request:
|
||||||
|
@ -524,10 +525,12 @@ class JingleSession(object):
|
||||||
file_info = self.connection.get_files_info(hash_=h)
|
file_info = self.connection.get_files_info(hash_=h)
|
||||||
elif n:
|
elif n:
|
||||||
file_info = self.connection.get_files_info(name=n)
|
file_info = self.connection.get_files_info(name=n)
|
||||||
if not file_info:
|
pjid = gajim.get_jid_without_resource(self.peerjid)
|
||||||
log.warning('The peer ' + self.peerjid + \
|
if not file_info or file_info['peerjid'] != pjid:
|
||||||
|
log.warning('The peer ' + pjid + \
|
||||||
' is requesting a ' + \
|
' is requesting a ' + \
|
||||||
'file that we dont have')
|
'file that we dont have or' + \
|
||||||
|
'it is not allowed to request')
|
||||||
self.decline_session()
|
self.decline_session()
|
||||||
raise xmpp.NodeProcessed
|
raise xmpp.NodeProcessed
|
||||||
# If there's no content we understand...
|
# If there's no content we understand...
|
||||||
|
|
Loading…
Add table
Reference in a new issue