only accept file request from peers that we already sent the file to

This commit is contained in:
Jefry Lagrange 2012-09-22 13:25:55 -04:00
parent 589c3081bb
commit f94a8cec1b
3 changed files with 14 additions and 6 deletions

View file

@ -15,6 +15,7 @@
Handles Jingle contents (XEP 0166)
"""
import gajim
import xmpp
from jingle_transport import JingleTransportIBB
@ -194,11 +195,13 @@ class JingleContent(object):
self.file_props.hash_:
h = self._calcHash()
file_tag.addChild(node=h)
pjid = gajim.get_jid_without_resource(self.session.peerjid)
file_info = {'name' : self.file_props.name,
'file-name' : self.file_props.file_name,
'hash' : self.file_props.hash_,
'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)
desc = file_tag.setTag('desc')

View file

@ -134,11 +134,13 @@ class JingleFileTransfer(JingleContent):
payload=[self._calcHash()])])
checksum.setNamespace(xmpp.NS_JINGLE_FILE_TRANSFER)
self.session.__session_info(checksum )
pjid = gajim.get_jid_without_resource(self.session.peerjid)
file_info = {'name' : self.file_props.name,
'file-name' : self.file_props.file_name,
'hash' : self.file_props.hash_,
'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)

View file

@ -513,7 +513,8 @@ class JingleSession(object):
self._session_terminate(reason)
raise xmpp.NodeProcessed
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 = \
jingle.getTag('content').getTag('description').getTag('request')
if request:
@ -524,10 +525,12 @@ class JingleSession(object):
file_info = self.connection.get_files_info(hash_=h)
elif n:
file_info = self.connection.get_files_info(name=n)
if not file_info:
log.warning('The peer ' + self.peerjid + \
pjid = gajim.get_jid_without_resource(self.peerjid)
if not file_info or file_info['peerjid'] != pjid:
log.warning('The peer ' + pjid + \
' is requesting a ' + \
'file that we dont have')
'file that we dont have or' + \
'it is not allowed to request')
self.decline_session()
raise xmpp.NodeProcessed
# If there's no content we understand...