From 224999b36312ab18bbaaf1b5746882adcd4115e1 Mon Sep 17 00:00:00 2001 From: paulc Date: Fri, 24 Jul 2009 10:54:32 +0000 Subject: [PATCH] Accept a Jingle version 0 "relay" transport to override another current candidate. git-svn-id: http://voip.null.ro/svn/yate@2767 acf43c95-373e-0410-b603-e72c3f656dc1 --- conf.d/yjinglechan.conf.sample | 4 ++++ modules/yjinglechan.cpp | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/conf.d/yjinglechan.conf.sample b/conf.d/yjinglechan.conf.sample index af5e87ea..e110e389 100644 --- a/conf.d/yjinglechan.conf.sample +++ b/conf.d/yjinglechan.conf.sample @@ -13,6 +13,10 @@ ; Defaults to disable ;secure_rtp=disable +; accept_relay: bool: Accept a "relay" transport type even if we had another type before +; This works only with Jingle version 0 (Google Talk, libjingle) +;accept_relay=disable in server mode, enable in client mode + ; singletone: boolean: Send chan tones as single characters. ; If disabled, the whole text received as chan tone(s) will be sent ; in the same XML element diff --git a/modules/yjinglechan.cpp b/modules/yjinglechan.cpp index 57cb9615..3b87e16a 100644 --- a/modules/yjinglechan.cpp +++ b/modules/yjinglechan.cpp @@ -389,6 +389,7 @@ private: State m_state; // Connection state JGSession* m_session; // Jingle session attached to this connection bool m_rtpStarted; // RTP started flag used by version 0 of the jingle session + bool m_acceptRelay; // Accept to replace with a relay candidate JGSession::Version m_sessVersion; // Jingle session version JabberID m_local; // Local user's JID JabberID m_remote; // Remote user's JID @@ -623,6 +624,7 @@ static bool s_attachPresToCmd = false; // Attach presence to command static bool s_userRoster = false; // Send client roster with user.roster or resource.notify static bool s_useCrypto = false; static bool s_cryptoMandatory = false; +static bool s_acceptRelay = false; static JGSession::Version s_sessVersion = JGSession::VersionUnknown; // Default jingle session version for outgoing calls static YJBEngine* s_jabber = 0; static YJGEngine* s_jingle = 0; @@ -1330,7 +1332,8 @@ YJGConnection::YJGConnection(Message& msg, const char* caller, const char* calle bool available, const char* file) : Channel(&plugin,0,true), m_mutex(true,"YJGConnection"), - m_state(Pending), m_session(0), m_rtpStarted(false), m_sessVersion(s_sessVersion), + m_state(Pending), m_session(0), m_rtpStarted(false), m_acceptRelay(s_acceptRelay), + m_sessVersion(s_sessVersion), m_local(caller), m_remote(called), m_audioContent(0), m_callerPrompt(msg.getValue("callerprompt")), m_sendRawRtpFirst(true), m_useCrypto(s_useCrypto), m_cryptoMandatory(s_cryptoMandatory), @@ -1411,7 +1414,7 @@ YJGConnection::YJGConnection(Message& msg, const char* caller, const char* calle YJGConnection::YJGConnection(JGEvent* event) : Channel(&plugin,0,false), m_mutex(true,"YJGConnection"), - m_state(Active), m_session(event->session()), m_rtpStarted(false), + m_state(Active), m_session(event->session()), m_rtpStarted(false), m_acceptRelay(s_acceptRelay), m_sessVersion(event->session()->version()), m_local(event->session()->local()), m_remote(event->session()->remote()), m_audioContent(0), m_sendRawRtpFirst(true), @@ -2535,9 +2538,23 @@ bool YJGConnection::updateCandidate(unsigned int component, JGSessionContent& lo JGRtpCandidate* rtp = local.m_rtpRemoteCandidates.findByComponent(component); // Version0: check acceptable transport if (m_sessVersion == JGSession::Version0) { - // Don't accept another transport if we already have one - // Check for valid attributes - if (rtp || rtpRecv->m_protocol != "udp" || rtpRecv->m_type != "local") + // We only handle UDP based transports for now + if (rtpRecv->m_protocol != "udp") + return false; + // Only accept a relay as a second transport and only once + if (m_acceptRelay && rtpRecv->m_type == "relay") { + m_acceptRelay = false; + if (rtp) { + Debug(this,DebugNote,"Replacing remote transport type '%s' with a relay [%p]", + rtp->m_type.c_str(),this); + local.m_rtpRemoteCandidates.remove(rtp); + rtp = 0; + clearEndpoint(); + m_rtpStarted = false; + } + } + // Any other transport type accepted only initially + else if (rtp) return false; } if (!rtp) { @@ -4335,6 +4352,7 @@ void YJGDriver::initialize() s_userRoster = sect->getBoolValue("user.roster",false); s_useCrypto = sect->getBoolValue("secure_rtp",false); s_cryptoMandatory = s_useCrypto; + s_acceptRelay = sect->getBoolValue("accept_relay",Engine::clientMode()); s_sessVersion = JGSession::lookupVersion(sect->getValue("jingle_version"),JGSession::Version1); // Init codecs in use. Check each codec in known codecs list against the configuration