send session-accept stanza if user approve file transfer

This commit is contained in:
Zhenchao Li 2010-06-14 20:41:24 +08:00
parent 182a448630
commit 5f96675d56
2 changed files with 33 additions and 0 deletions

View File

@ -47,10 +47,20 @@ class JingleFileTransfer(JingleContent):
else:
self.weinitiate = True
if self.file_props != None:
self.file_props['sender'] = session.ourjid
self.file_props['session-type'] = 'jingle'
self.file_props['sid'] = session.sid
self.file_props['transfered_size'] = []
log.info("FT request: %s"%file_props)
if transport == None:
self.transport = JingleTransportICEUDP()
self.session = session
self.media = 'file'
def __on_session_initiate(self, stanza, content, error, action):
jid = unicode(stanza.getFrom())
@ -60,6 +70,8 @@ class JingleFileTransfer(JingleContent):
file_props['sender'] = jid
file_props['request-id'] = unicode(stanza.getAttr('id'))
file_props['session-type'] = 'jingle'
file_tag = content.getTag('description').getTag('offer').getTag('file')
for attribute in file_tag.getAttrs():
if attribute in ('name', 'size', 'hash', 'date'):
@ -75,6 +87,8 @@ class JingleFileTransfer(JingleContent):
log.info("ourjid: %s"%self.session.ourjid)
file_props['sid'] = unicode(stanza.getTag('jingle').getAttr('sid'))
file_props['transfered_size'] = []
self.file_props = file_props
log.info("FT request: %s"%file_props)

View File

@ -37,6 +37,9 @@ from common import dataforms
from common.socks5 import Socks5Receiver
import logging
log = logging.getLogger('gajim.c.protocol.bytestream')
def is_transfer_paused(file_props):
if 'stopped' in file_props and file_props['stopped']:
@ -125,6 +128,21 @@ class ConnectionBytestream:
# user response to ConfirmationDialog may come after we've disconneted
if not self.connection or self.connected < 2:
return
#file transfer initiated by a jingle session
log.info("send_file_approval: jingle session accept")
if file_props.get('session-type') == 'jingle':
session = self.get_jingle_session(file_props['sender'], file_props['sid'])
if not session:
return
jid = gajim.get_jid_without_resource(file_props['sender'])
resource = gajim.get_resource_from_jid(file_props['sender'])
if not session.accepted:
session.approve_session()
session.approve_content('file')
return
iq = xmpp.Iq(to=unicode(file_props['sender']), typ='result')
iq.setAttr('id', file_props['request-id'])
si = iq.setTag('si', namespace=xmpp.NS_SI)
@ -138,6 +156,7 @@ class ConnectionBytestream:
field = _feature.setField('stream-method')
field.delAttr('type')
field.setValue(xmpp.NS_BYTESTREAM)
log.info("send_file_approval: %s"%(str(iq)))
self.connection.send(iq)
def send_file_rejection(self, file_props, code='403', typ=None):