if the peer supports jingle XTLS, send session-initiate with security element

This commit is contained in:
Zhenchao Li 2010-07-22 15:05:06 +08:00
parent 4583482246
commit 30cbdce234
2 changed files with 27 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import helpers
from jingle_session import JingleSession, JingleStates
from jingle_rtp import JingleAudio, JingleVideo
from jingle_ft import JingleFileTransfer
import gajim
import logging
logger = logging.getLogger('gajim.c.jingle')
@ -140,14 +141,26 @@ class ConnectionJingle(object):
def start_file_transfer(self, jid, file_props):
logger.info("start file transfer with file: %s" % file_props)
jingle = self.get_jingle_session(jid, media='file')
contact = gajim.contacts.get_contact_with_highest_priority(self.name,
gajim.get_jid_without_resource(jid))
if contact is None:
return
if contact.supports(xmpp.NS_JINGLE_XTLS):
use_security = True
else:
use_security = False
if jingle:
file_props['sid'] = jingle.sid
jingle.add_content('file', JingleFileTransfer(jingle, file_props))
jingle.add_content('file',
JingleFileTransfer(jingle, file_props = file_props, use_security=use_security)
)
else:
jingle = JingleSession(self, weinitiate=True, jid=jid)
self.__sessions[jingle.sid] = jingle
file_props['sid'] = jingle.sid
jingle.add_content('file', JingleFileTransfer(jingle, file_props=file_props))
jingle.add_content('file',
JingleFileTransfer(jingle, file_props=file_props, use_security=use_security)
)
jingle.start_session()
return jingle.sid

View File

@ -37,7 +37,7 @@ STATE_TRANSPORT_INFO = 3
STATE_PROXY_ACTIVATED = 4
class JingleFileTransfer(JingleContent):
def __init__(self, session, transport=None, file_props=None):
def __init__(self, session, transport=None, file_props=None, use_security=False):
JingleContent.__init__(self, session, transport)
log.info("transport value: %s" % transport)
@ -54,6 +54,8 @@ class JingleFileTransfer(JingleContent):
self.state = STATE_NOT_STARTED
self.use_security = use_security
self.file_props = file_props
if file_props is None:
self.weinitiate = False
@ -246,6 +248,15 @@ class JingleFileTransfer(JingleContent):
desc.setData(self.file_props['desc'])
description_node.addChild(node=sioffer)
if self.use_security:
security = xmpp.simplexml.Node(tag=xmpp.NS_JINGLE_XTLS + ' security')
# TODO: add fingerprint element
for m in ('x509', ): # supported authentication methods
method = xmpp.simplexml.Node(tag='method')
method.setAttr('name', m)
security.addChild(node=method)
content.addChild(node=security)
content.addChild(node=description_node)