[Jingle] Fix make_bin_from_config, improve JingleSession.__parse_contents
This commit is contained in:
parent
484e3970d3
commit
592bacce4a
|
@ -23,6 +23,12 @@ def get_jingle_content(node):
|
||||||
return contents[namespace](node)
|
return contents[namespace](node)
|
||||||
|
|
||||||
|
|
||||||
|
class FailedApplication(Exception):
|
||||||
|
"""
|
||||||
|
Exception that should be raised when a content fails to setup.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class JingleContent(object):
|
class JingleContent(object):
|
||||||
"""
|
"""
|
||||||
An abstraction of content in Jingle sessions
|
An abstraction of content in Jingle sessions
|
||||||
|
|
|
@ -24,7 +24,7 @@ from glib import GError
|
||||||
import gajim
|
import gajim
|
||||||
|
|
||||||
from jingle_transport import JingleTransportICEUDP
|
from jingle_transport import JingleTransportICEUDP
|
||||||
from jingle_content import contents, JingleContent
|
from jingle_content import contents, JingleContent, FailedApplication
|
||||||
|
|
||||||
|
|
||||||
class JingleRTPContent(JingleContent):
|
class JingleRTPContent(JingleContent):
|
||||||
|
@ -92,11 +92,13 @@ class JingleRTPContent(JingleContent):
|
||||||
try:
|
try:
|
||||||
bin = gst.parse_bin_from_description(pipeline
|
bin = gst.parse_bin_from_description(pipeline
|
||||||
% gajim.config.get(config_key), True)
|
% gajim.config.get(config_key), True)
|
||||||
|
return bin
|
||||||
except GError, error_str:
|
except GError, error_str:
|
||||||
self.session.connection.dispatch('ERROR',
|
self.session.connection.dispatch('ERROR',
|
||||||
(_("%s configuration error") % text.capitalize(),
|
(_("%s configuration error") % text.capitalize(),
|
||||||
_("Couldn't setup %s. Check your configuration.\n\nError was:\n%s")
|
_("Couldn't setup %s. Check your configuration.\n\nError was:\n%s")
|
||||||
% (text, error_str)))
|
% (text, error_str)))
|
||||||
|
raise FailedApplication
|
||||||
|
|
||||||
def add_remote_candidates(self, candidates):
|
def add_remote_candidates(self, candidates):
|
||||||
JingleContent.add_remote_candidates(self, candidates)
|
JingleContent.add_remote_candidates(self, candidates)
|
||||||
|
|
|
@ -29,7 +29,7 @@ Handles Jingle sessions (XEP 0166)
|
||||||
import gajim #Get rid of that?
|
import gajim #Get rid of that?
|
||||||
import xmpp
|
import xmpp
|
||||||
from jingle_transport import get_jingle_transport
|
from jingle_transport import get_jingle_transport
|
||||||
from jingle_content import get_jingle_content
|
from jingle_content import get_jingle_content, FailedApplication
|
||||||
|
|
||||||
# FIXME: Move it to JingleSession.States?
|
# FIXME: Move it to JingleSession.States?
|
||||||
class JingleStates(object):
|
class JingleStates(object):
|
||||||
|
@ -394,8 +394,8 @@ class JingleSession(object):
|
||||||
raise OutOfOrder
|
raise OutOfOrder
|
||||||
|
|
||||||
parse_result = self.__parse_contents(jingle)
|
parse_result = self.__parse_contents(jingle)
|
||||||
contents = parse_result[2]
|
contents = parse_result[0]
|
||||||
rejected_contents = parse_result[3]
|
rejected_contents = parse_result[1]
|
||||||
|
|
||||||
for name, creator in rejected_contents:
|
for name, creator in rejected_contents:
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -426,21 +426,13 @@ class JingleSession(object):
|
||||||
# error.
|
# error.
|
||||||
|
|
||||||
# Lets check what kind of jingle session does the peer want
|
# Lets check what kind of jingle session does the peer want
|
||||||
contents_ok, transports_ok, contents, pouet = self.__parse_contents(jingle)
|
contents, contents_rejected, reason = self.__parse_contents(jingle)
|
||||||
|
|
||||||
# If there's no content we understand...
|
# If there's no content we understand...
|
||||||
if not contents_ok:
|
if not contents:
|
||||||
# TODO: http://xmpp.org/extensions/xep-0166.html#session-terminate
|
# TODO: http://xmpp.org/extensions/xep-0166.html#session-terminate
|
||||||
reason = xmpp.Node('reason')
|
reason = xmpp.Node('reason')
|
||||||
reason.setTag('unsupported-applications')
|
reason.setTag(reason)
|
||||||
self.__ack(stanza, jingle, error, action)
|
|
||||||
self._session_terminate(reason)
|
|
||||||
raise xmpp.NodeProcessed
|
|
||||||
|
|
||||||
if not transports_ok:
|
|
||||||
# TODO: http://xmpp.org/extensions/xep-0166.html#session-terminate
|
|
||||||
reason = xmpp.Node('reason')
|
|
||||||
reason.setTag('unsupported-transports')
|
|
||||||
self.__ack(stanza, jingle, error, action)
|
self.__ack(stanza, jingle, error, action)
|
||||||
self._session_terminate(reason)
|
self._session_terminate(reason)
|
||||||
raise xmpp.NodeProcessed
|
raise xmpp.NodeProcessed
|
||||||
|
@ -485,26 +477,37 @@ class JingleSession(object):
|
||||||
# TODO: Needs some reworking
|
# TODO: Needs some reworking
|
||||||
contents = []
|
contents = []
|
||||||
contents_rejected = []
|
contents_rejected = []
|
||||||
contents_ok = False
|
reasons = set()
|
||||||
transports_ok = False
|
|
||||||
|
|
||||||
for element in jingle.iterTags('content'):
|
for element in jingle.iterTags('content'):
|
||||||
transport = get_jingle_transport(element.getTag('transport'))
|
transport = get_jingle_transport(element.getTag('transport'))
|
||||||
content_type = get_jingle_content(element.getTag('description'))
|
content_type = get_jingle_content(element.getTag('description'))
|
||||||
if content_type:
|
if content_type:
|
||||||
contents_ok = True
|
try:
|
||||||
if transport:
|
if transport:
|
||||||
content = content_type(self, transport)
|
content = content_type(self, transport)
|
||||||
self.add_content(element['name'],
|
self.add_content(element['name'],
|
||||||
content, 'peer')
|
content, 'peer')
|
||||||
contents.append((content.media,))
|
contents.append((content.media,))
|
||||||
transports_ok = True
|
else:
|
||||||
else:
|
reasons.add('unsupported-transports')
|
||||||
contents_rejected.append((element['name'], 'peer'))
|
contents_rejected.append((element['name'], 'peer'))
|
||||||
|
except FailedApplication:
|
||||||
|
reasons.add('failed-application')
|
||||||
else:
|
else:
|
||||||
contents_rejected.append((element['name'], 'peer'))
|
contents_rejected.append((element['name'], 'peer'))
|
||||||
|
failed.add('unsupported-applications')
|
||||||
|
|
||||||
return (contents_ok, transports_ok, contents, contents_rejected)
|
failure_reason = None
|
||||||
|
|
||||||
|
# Store the first reason of failure
|
||||||
|
for reason in ('failed-application', 'unsupported-transports',
|
||||||
|
'unsupported-applications'):
|
||||||
|
if reason in reasons:
|
||||||
|
failure_reason = reason
|
||||||
|
break
|
||||||
|
|
||||||
|
return (contents, contents_rejected, failure_reason)
|
||||||
|
|
||||||
def __dispatch_error(self, error, jingle_error=None, text=None):
|
def __dispatch_error(self, error, jingle_error=None, text=None):
|
||||||
if jingle_error:
|
if jingle_error:
|
||||||
|
|
Loading…
Reference in New Issue